def onTick(timer, e): global username, password if not String.IsNullOrEmpty(username) and not String.IsNullOrEmpty( password): update() timer.Stop() timer.Interval = TimeSpan.FromMinutes(5) timer.Start()
def getTermList(dictionary, text): stringBuilder = StringBuilder(text) selectedTermList = List[String]() while stringBuilder.Length > 0: s1 = stringBuilder.ToString() selectedTerm1 = None if dictionary.ContainsKey(s1[0]): for term in dictionary[s1[0]]: if s1.StartsWith(term, StringComparison.Ordinal) and term.Length > ( 0 if selectedTerm1 is None else selectedTerm1.Length): selectedTerm1 = term if String.IsNullOrEmpty(selectedTerm1): stringBuilder.Remove(0, 1) else: sb = StringBuilder( stringBuilder.ToString(1, stringBuilder.Length - 1)) selectedTerm2 = None i = 0 max = 0 while sb.Length > 0 and i < selectedTerm1.Length: s2 = sb.ToString() if dictionary.ContainsKey(s2[0]): for term in dictionary[s2[0]]: if s2.StartsWith( term, StringComparison.Ordinal ) and term.Length > (0 if selectedTerm2 is None else selectedTerm2.Length): selectedTerm2 = term max = i + selectedTerm2.Length sb.Remove(0, 1) i += 1 if not String.IsNullOrEmpty( selectedTerm2 ) and selectedTerm1.Length < selectedTerm2.Length: if not selectedTermList.Contains(selectedTerm2): selectedTermList.Add(selectedTerm2) stringBuilder.Remove(0, max) else: if not selectedTermList.Contains(selectedTerm1): selectedTermList.Add(selectedTerm1) stringBuilder.Remove(0, selectedTerm1.Length) return selectedTermList
def parseOutline(m, n): if not n.HasChildNodes: return None for xmlNode in n.ChildNodes: if xmlNode.Name.Equals("outline"): text = None xmlUrl = None htmlUrl = None for xmlAttribute in xmlNode.Attributes: if xmlAttribute.Name.Equals( "title") or xmlAttribute.Name.Equals("text"): text = xmlAttribute.Value elif xmlAttribute.Name.Equals("xmlUrl"): xmlUrl = xmlAttribute.Value elif xmlAttribute.Name.Equals("htmlUrl"): htmlUrl = xmlAttribute.Value if not String.IsNullOrEmpty(text): if String.IsNullOrEmpty(xmlUrl): mi = MenuItem() mi.Header = text parsedMenuItem = parseOutline(mi, xmlNode) if parsedMenuItem is None: m.Items.Add(mi) else: m.Items.Add(parsedMenuItem) elif not String.IsNullOrEmpty(xmlUrl): mi = MenuItem() def onClick(sender, args): if not String.IsNullOrEmpty(sender.Tag): def onStart(state): Process.Start(state) Task.Factory.StartNew(onStart, sender.Tag) mi.Header = text mi.Click += onClick mi.Tag = htmlUrl m.Items.Add(mi) return m
def onClick(sender, args): if not String.IsNullOrEmpty(sender.Tag): def onStart(state): Process.Start(state) Task.Factory.StartNew(onStart, sender.Tag)
def onUpdate(): if NetworkInterface.GetIsNetworkAvailable(): try: response = None stream = None try: response = request.GetResponse() stream = response.GetResponseStream() doc = XmlDocument() doc.Load(stream) for itemXmlNode in doc.GetElementsByTagName("item"): entry = Entry() epicenter = None maxLevel = None for xmlNode in itemXmlNode.ChildNodes: if xmlNode.Name.Equals("link"): entry.Resource = Uri(xmlNode.InnerText) elif xmlNode.Name.Equals("description"): entry.Description = xmlNode.InnerText elif xmlNode.Name.Equals("tenkiJP:earthquake"): for attribute in xmlNode.Attributes: if attribute.Name.Equals("epicenter"): epicenter = attribute.Value elif attribute.Name.Equals("max_level"): maxLevel = attribute.Value elif attribute.Name.Equals( "outbreak_datetime"): entry.Created = entry.Modified = DateTime.Parse( attribute.Value) if epicenter is not None: if String.IsNullOrEmpty(maxLevel): maxLevel = "N/A" if CultureInfo.CurrentCulture.Equals( CultureInfo.GetCultureInfo("ja-JP")): entry.Title = String.Format( "震度{0} - {1}", maxLevel, epicenter) else: entry.Title = String.Format( "Intensity {0} - {1}", maxLevel, epicenter) entryList.Add(entry) finally: if stream is not None: stream.Close() if response is not None: response.Close() except Exception, e: Trace.WriteLine(e.clsException.Message) Trace.WriteLine(e.clsException.StackTrace)
def onStart(s, e): global timer, menuItem, separator if String.IsNullOrEmpty(username) or String.IsNullOrEmpty(password): if menuItem is None: menuItem = MenuItem() menuItem.Header = "Gmail" for window in Application.Current.Windows: if window is Application.Current.MainWindow and window.ContextMenu is not None: if not window.ContextMenu.Items.Contains(menuItem): window.ContextMenu.Opened += onOpened window.ContextMenu.Items.Insert( window.ContextMenu.Items.Count - 4, menuItem) if not clr.GetClrType(Separator).IsInstanceOfType( window.ContextMenu.Items[10]): separator = Separator() window.ContextMenu.Items.Insert(10, separator) timer.Start()
def CmbClassSelectedIndexChanged(self, sender, e): conn = self.GetConnection() if conn is None: return schemaName = self.GetSchemaName() if String.IsNullOrEmpty(schemaName): return className = self.GetClassName() if String.IsNullOrEmpty(className): return svc = conn.CreateFeatureService() try: cls = svc.GetClassByName(schemaName, className) if not cls is None: properties = List[str]() for prop in cls.Properties: if prop.PropertyType == PropertyType.PropertyType_DataProperty: properties.Add(prop.Name) if properties.Count > 0: self._cmbProperty.DataSource = properties self._cmbProperty.SelectedIndex = 0 finally: svc.Dispose() pass
def CmbSchemaSelectedIndexChanged(self, sender, e): conn = self.GetConnection() if conn is None: return schemaName = self.GetSchemaName() if String.IsNullOrEmpty(schemaName): return svc = conn.CreateFeatureService() try: classNames = svc.GetClassNames(schemaName) if classNames.Count > 0: self._cmbClass.DataSource = classNames self._cmbClass.SelectedIndex = 0 finally: svc.Dispose() pass
def onEdit(sender, args): global program path = sender.Tag def onStart(state): Process.Start(state) psi = ProcessStartInfo() if String.IsNullOrEmpty(program): psi.FileName = path else: psi.FileName = program psi.Arguments = path Task.Factory.StartNew(onStart, psi)
def BtnPreviewClick(self, sender, e): conn = self.GetConnection() if conn is None: return className = self.GetClassName() if String.IsNullOrEmpty(className): return propName = self.GetPropertyName() if String.IsNullOrEmpty(propName): return svc = conn.CreateFeatureService() propertyValues = List[str]() try: canDistinct = conn.Capability.GetBooleanCapability( CapabilityType.FdoCapabilityType_SupportsSelectDistinct) if canDistinct: #SortedList not only allows us to hackishly get set-like qualities, but we get sorting for free. values = SortedList[str, str]() query = FeatureAggregateOptions(className) query.AddFeatureProperty(propName) query.Distinct = True reader = svc.SelectAggregates(query) try: while reader.ReadNext(): if not reader.IsNull(propName): values.Add(reader[propName].ToString(), String.Empty) finally: reader.Dispose() propertyValues.AddRange(values.Keys) elif svc.SupportsCommand(CommandType.CommandType_SQLCommand): sql = "SELECT DISTINCT " + propName + " FROM " + className + " ORDER BY " + propName values = List[str]() reader = svc.ExecuteSQLQuery(sql) try: while reader.ReadNext(): if not reader.IsNull(propName): values.Add(reader[propName].ToString()) finally: reader.Dispose() propertyValues.AddRange(values) else: if App.Ask( "Get Values", "About to fetch distinct values by brute force. Continue?" ): #SortedList not only allows us to hackishly get set-like qualities, but we get sorting for free. values = SortedList[str, str]() query = FeatureQueryOptions(className) query.AddFeatureProperty(propName) reader = svc.SelectFeatures(query) try: while reader.ReadNext(): if not reader.IsNull(propName): values.Add(reader[propName].ToString(), String.Empty) finally: reader.Dispose() propertyValues.AddRange(values.Keys) finally: svc.Dispose() if propertyValues.Count > 0: self._grdRules.Rows.Clear() for pval in propertyValues: className = self._txtClassPrefix.Text + pval + self._txtClassSuffix.Text filter = propName + " = '" + pval + "'" self._grdRules.Rows.Add(pval, className, filter) pass
def onClick(source, args): global username, password if not String.IsNullOrEmpty( usernameTextBox.Text) and not String.IsNullOrEmpty( passwordBox.Password): username = usernameTextBox.Text password = passwordBox.Password def onSave(): try: fs = None sr = None sw = None try: fs = FileStream(__file__, FileMode.Open, FileAccess.ReadWrite, FileShare.Read) encoding = UTF8Encoding(False) sr = StreamReader(fs, encoding, True) lines = Regex.Replace( Regex.Replace( sr.ReadToEnd(), "username\\s*=\\s*\"\"", String.Format("username = \"{0}\"", username), RegexOptions.CultureInvariant), "password\\s*=\\s*\"\"", String.Format("password = \"{0}\"", password), RegexOptions.CultureInvariant) fs.SetLength(0) sw = StreamWriter(fs, encoding) sw.Write(lines) finally: if sw is not None: sw.Close() if sr is not None: sr.Close() if fs is not None: fs.Close() except Exception, e: Trace.WriteLine(e.clsException.Message) Trace.WriteLine(e.clsException.StackTrace) def onCompleted(task): global menuItem for window in Application.Current.Windows: if window is Application.Current.MainWindow and window.ContextMenu is not None: if window.ContextMenu.Items.Contains(menuItem): window.ContextMenu.Items.Remove(menuItem) window.ContextMenu.Opened -= onOpened if window.ContextMenu.Items[10].GetType( ).IsInstanceOfType(window.ContextMenu.Items[ window.ContextMenu.Items.Count - 4]): window.ContextMenu.Items.RemoveAt(10) menuItem = None Task.Factory.StartNew( onSave, TaskCreationOptions.LongRunning).ContinueWith( onCompleted, TaskScheduler.FromCurrentSynchronizationContext())
def items_needed(self, for_employment): self.determine_status() for_employment = not not for_employment items = [] # Just Added: Should not process Just Added profiles because they may be duplicates. if self.person.MemberStatusId == 50: items.append('JuAdd') return items # get minors out of the way if not for_employment and (self.statusExp['isMin'] & 8 == 8): return items # if the subject is a minor not looking for employment, they need nothing. # Bio: Full Name, Email, etc. if (String.IsNullOrEmpty(self.person.FirstName) or String.IsNullOrEmpty(self.person.LastName) or (self.person.GenderId != 1 and self.person.GenderId != 2) or self.person.BirthYear < 1900 # meant to detect if null ) and ((for_employment and self.statusExp['paEmp'] & 8 == 0) or self.statusExp['paVol'] & 8 == 0 or self.statusExp['basic'] & 8 == 0): items.append('Bio') # SSN if String.IsNullOrEmpty(self.person.Ssn) and ( (for_employment and self.statusExp['paEmp'] & 8 == 0) or self.statusExp['paVol'] & 8 == 0 or self.statusExp['basic'] & 8 == 0): items.append('Ssn') # PMM Submission if for_employment and self.statusExp['paEmp'] & bgc.Statuses[ 'CHECK_STARTED'] == 0: items.append("submit_emp") elif not for_employment and self.statusExp['paVol'] & bgc.Statuses[ 'CHECK_STARTED'] == 0: items.append("submit_vol") elif self.statusExp['basic'] & bgc.Statuses['CHECK_STARTED'] == 0: items.append("submit_basic") # PMM Completion Actions if for_employment and self.statusExp['paEmp'] & bgc.Statuses['CHECK_STARTED'] == 1 and \ self.statusExp['paEmp'] & bgc.Statuses['CHECK_COMPLETE'] == 0: items.append("receive_emp") elif self.statusExp['paVol'] & bgc.Statuses['CHECK_STARTED'] == 1 and \ self.statusExp['paVol'] & bgc.Statuses['CHECK_COMPLETE'] == 0: items.append("receive_vol") elif self.statusExp['basic'] & bgc.Statuses['CHECK_STARTED'] == 1 and \ self.statusExp['basic'] & bgc.Statuses['CHECK_COMPLETE'] == 0: items.append("receive_basic") # PMM Review Actions if for_employment and self.statusExp['paEmp'] & bgc.Statuses['CHECK_COMPLETE'] == 2 and \ self.statusExp['paEmp'] & bgc.Statuses['REVIEW_COMPLETE'] == 0: items.append("review_emp") elif self.statusExp['paVol'] & bgc.Statuses['CHECK_COMPLETE'] == 2 and \ self.statusExp['paVol'] & bgc.Statuses['REVIEW_COMPLETE'] == 0: items.append("review_vol") elif self.statusExp['basic'] & bgc.Statuses['CHECK_COMPLETE'] == 2 and \ self.statusExp['basic'] & bgc.Statuses['REVIEW_COMPLETE'] == 0: items.append("review_bas") # FBI or Affidavit Submission if for_employment and self.statusExp['fingr'] & bgc.Statuses[ 'CHECK_COMPLETE'] == 0: items.append("submit_fbi") elif not for_employment and self.statusExp['fingr'] & bgc.Statuses['CHECK_COMPLETE'] == 0 and \ self.statusExp['affid'] & bgc.Statuses['CHECK_COMPLETE'] == 0: items.append("submit_fbi_aff") # FBI or Affid Approval TODO return items
def onCompleted(task): global dateTime, processDictionary nowDateTime = DateTime.Now isNew = True dictionary = None termList = List[String]() if processDictionary.Count > 0: isNew = False for kvp in processList: isUpdated = False mainWindowTitle = None if processDictionary.ContainsKey(kvp.Key): mainWindowTitle = processDictionary[kvp.Key] if not String.IsNullOrEmpty(kvp.Value): if not kvp.Value.Equals(mainWindowTitle): isUpdated = True processDictionary[kvp.Key] = kvp.Value else: if not String.IsNullOrEmpty(kvp.Value): processDictionary.Add(kvp.Key, kvp.Value) if not isNew: isUpdated = True if isUpdated: previousTermList = List[String]() if dictionary is None: dictionary = Dictionary[Char, List[String]]() for word in Script.Instance.Words: if word.Name.Length > 0: if not dictionary.ContainsKey(word.Name[0]): dictionary.Add(word.Name[0], List[String]()) dictionary[word.Name[0]].Add(word.Name) if not String.IsNullOrEmpty(mainWindowTitle): previousTermList.AddRange(getTermList(dictionary, mainWindowTitle)) for term in getTermList(dictionary, kvp.Value): if not previousTermList.Contains(term) and not termList.Contains(term): termList.Add(term) if termList.Count > 0: sequenceList = List[Sequence]() for sequence in Script.Instance.Sequences: if sequence.Name.Equals("Activate"): sequenceList.Add(sequence) Script.Instance.TryEnqueue(Script.Instance.Prepare(sequenceList, None, termList)) keyList = List[Int32](processDictionary.Keys) for key in keyList: removable = True for kvp in processList: if key == kvp.Key: removable = False if removable: processDictionary.Remove(key) dateTime = nowDateTime