/// <summary> /// resets current state of the program /// </summary> private void RestartButton_Click(object sender, RoutedEventArgs e) { FinishButton.Visibility = Visibility.Hidden; ConclusionTextBox.Visibility = Visibility.Visible; ConclusionInfo.Visibility = Visibility.Visible; mySemaphore = new MySemaphore(0, 1); ConcreteObservations.Clear(); Rules.Clear(); Observations.Clear(); /* * string[] testExamples = * { * "AKO e1 ONDA (0.3)z1", * "AKO z1 ILI - z2 ONDA (0.6)z", * "AKO e2 ONDA (0.6)z2", * "AKO e3 ONDA (0.7)z1", * "AKO e4 ONDA (0.5)z1" * }; * * foreach (var testExample in testExamples) * { * Rule rule = PostfixConverter.RuleConversion(testExample); * AddRule(rule); * } */ RichTextBox.Document.Blocks.Clear(); }
private static void Main(string[] args) { var autoReset = new AutoResetEvent(false); var r = new Random(); var o = new TrulyObservableCollection <DataPoint>(); var subscription1 = Observable.Interval(TimeSpan.FromSeconds(1)).Take(3).Subscribe( i => { o.Add( new DataPoint { ItemCount = r.Next(100) }); Console.WriteLine("Fire1 {0}", i); }); var subscription2 = Observable.FromEventPattern <NotifyCollectionChangedEventArgs>(o, "CollectionChanged") .Subscribe(s => { Console.WriteLine("List changed. Current total {0}", o.Sum(s1 => s1.ItemCount)); }); var subscription3 = Observable.Interval(TimeSpan.FromSeconds(1)).Delay(TimeSpan.FromSeconds(3)).Take(3).Finally( () => { o.Clear(); autoReset.Set(); }).Subscribe( i => { if (o.Any()) { o[r.Next(o.Count)].ItemCount = r.Next(100); Console.WriteLine("Fire3 {0}", i); } }); autoReset.WaitOne(); }
private void btnParseAmazonCode_Click(object sender, RoutedEventArgs e) { //string regex = @"USD ([$\d\.]*)[\s]*Amazon.com Gift Card claim code: ([\d\w\-]*)"; string regex = @"\$([\d\.]*).([\w\d]{4}-[\w\d]{6}-[\w\d]{4})"; MatchCollection matches = Regex.Matches(txtUnparsedAmazonCodes.Text, regex); bool noValue = false; if (matches.Count < 1) { regex = @"([\w\d]{4}-[\w\d]{6}-[\w\d]{4})"; matches = Regex.Matches(txtUnparsedAmazonCodes.Text, regex); noValue = true; } StringBuilder sb = new StringBuilder(); colParsedAmazonGiftCodes.Clear(); int codeCount = 0; foreach (Match m in matches) { codeCount++; if (noValue) { colParsedAmazonGiftCodes.Add(new AmazonGiftCode(codeCount, m.Groups[1].Value, null)); } else { colParsedAmazonGiftCodes.Add(new AmazonGiftCode(codeCount, m.Groups[2].Value, decimal.Parse(m.Groups[1].Value))); } } if (colParsedAmazonGiftCodes.Count < 1) { txtUnparsedAmazonCodes.Background = System.Windows.Media.Brushes.Pink; } else { txtExpectedValue.Text = colParsedAmazonGiftCodes.Sum(p => p.Value).ToString(); if (txtExpectedValue.Text == String.Empty) { txtExpectedValue.Background = System.Windows.Media.Brushes.Pink; } else { var listDuplicateGiftCodes = colParsedAmazonGiftCodes.GroupBy(p => p.Code).Where(g => g.Count() > 1).Select(p => p.Key).ToList(); if (listDuplicateGiftCodes.Count > 0) { sb = new StringBuilder(); sb.AppendLine("Duplicate gift codes detected!"); foreach (var gc in listDuplicateGiftCodes) { sb.AppendLine(gc); } MessageBox.Show(sb.ToString()); } decimal expectedValue = 0; decimal.TryParse(txtExpectedValue.Text, out expectedValue); if (expectedValue > 0) { txtExpectedValue.Background = System.Windows.Media.Brushes.White; } else { txtExpectedValue.Background = System.Windows.Media.Brushes.Pink; } } txtUnparsedAmazonCodes.Background = System.Windows.Media.Brushes.White; } //txtExpectedValue.Focus(); //txtExpectedValue.SelectAll(); }
protected void LoadTournamentNamesFromWebResponse( string webResponse, TrulyObservableCollection<TournamentName> tournamentNames, bool loadAll) { tournamentNames.Clear(); var jss = new JavaScriptSerializer(); TournamentName[] names = jss.Deserialize<TournamentName[]>(webResponse); foreach (var tournamentName in names) { if (loadAll) { tournamentNames.Add(tournamentName); } else if (tournamentName.StartDate.AddMonths(3) > DateTime.Now) { tournamentNames.Add(tournamentName); } } OnTournamentsUpdated(); }
/// <summary> /// Searches the directory and adds files to the File list /// </summary> /// <param name="folder">The starting folder</param> public void SearchDirectories(string folder, string workdir = "") { //Throws exception if no permissions try { nonAccessibleFiles = 0; _fileList.Clear(); filesList.Clear(); int i = 1; bool flag = false; ApplyAllFiles(folder, ProcessFile); string[] files = filesList.ToArray(); foreach (string file in files) { foreach (WhiteList wl in _currentWhiteList) { if (wl.Extension == Path.GetExtension(file)) { if (Properties.Settings.Default.Setting_General_UseRelativePath) { string temp = MakeRelativePath(workdir + "\\", System.IO.Path.GetDirectoryName(file) + "\\"); temp += System.IO.Path.GetFileName(file); _fileList.Add(new MyFile(System.IO.Path.GetFileNameWithoutExtension(file), temp, System.IO.Path.GetExtension(file), i)); i++; flag = true; break; } else { _fileList.Add(new MyFile(System.IO.Path.GetFileNameWithoutExtension(file), file, System.IO.Path.GetExtension(file), i)); i++; flag = true; break; } } } if (flag) { continue; } } if (nonAccessibleFiles != 0) { NotifyMessage = "Some files were not accessible, restart as admin to get all files"; StatusText = nonAccessibleFiles + "/" + (i - 1 + nonAccessibleFiles) + " Files could not be accessed"; FlyoutOpen = true; } else { StatusText = (i - 1) + " Files found"; } } catch (UnauthorizedAccessException ex) { string outputString; outputString = Environment.NewLine + "Exception caught" + Environment.NewLine + "Date: " + DateTime.UtcNow.Date.ToString("dd/MM/yyyy") + ", Time: " + DateTime.Now.ToString("HH:mm:ss tt") + Environment.NewLine + ex.Message + Environment.NewLine + ex.ToString() + Environment.NewLine; using (System.IO.StreamWriter file = new System.IO.StreamWriter(assemblyPath + "\\CrashLog.txt", true)) { file.WriteLine(outputString); } outputString = null; NotifyMessage = "Unauthorized access, restart as Admin to gain access"; FlyoutOpen = true; } catch (Exception ex) { string outputString; outputString = Environment.NewLine + "Exception caught" + Environment.NewLine + "Date: " + DateTime.UtcNow.Date.ToString("dd/MM/yyyy") + ", Time: " + DateTime.Now.ToString("HH:mm:ss tt") + Environment.NewLine + ex.Message + Environment.NewLine + ex.ToString() + Environment.NewLine; using (System.IO.StreamWriter file = new System.IO.StreamWriter(assemblyPath + "\\CrashLog.txt", true)) { file.WriteLine(outputString); } outputString = null; } }