public RecipeItem(Data.Recipe recipe, MainWindow parentWindow) { InitializeComponent(); this._recipe = recipe; this._parentWindow = parentWindow; // hide others components this.cIconContainer.Visibility = System.Windows.Visibility.Collapsed; this.tbRecipeDescription.Visibility = System.Windows.Visibility.Collapsed; this.tbGwSpidyHyperLinkContainer.Visibility = System.Windows.Visibility.Collapsed; this.tbWikiHyperLinkContainer.Visibility = System.Windows.Visibility.Collapsed; if (this._recipe.SomethingIsWrong) { this.tbRecipeName.Foreground = new System.Windows.Media.SolidColorBrush(Colors.Red); this.tbRecipeName.Text = String.Format("[{0}] {1}", this._recipe.Id, Properties.Resources.SomethingIsWrongWithThisRecipe); // hide button bExpandRecipe this.bExpandRecipe.Visibility = System.Windows.Visibility.Collapsed; // destruct tooltip over the recipe name this.tbRecipeName.ToolTip = null; return; } if (this._recipe.Is_checked) { this.cbCheckRecipe.IsChecked = true; } this.tbRecipeName.Text = String.Format("[{0}] {1}", this._recipe.Id, this._recipe.Name); this.tbRecipeName.Foreground = this._recipe.RarityColor; if (!String.IsNullOrEmpty(recipe.Image)) { this.iRecipeIcon.ImageSource = new BitmapImage(new Uri(recipe.Image)); } this.cIconContainer.Visibility = System.Windows.Visibility.Visible; this.iTradingPost.Source = new BitmapImage(new Uri(Config.TRADING_POST_ICON_URL)); this.tbOutputItemsCount.Text = recipe.OutputItemsCount.ToString(); hlGw2SpidyLink.NavigateUri = new Uri(string.Format(Properties.Resources.Gw2SpidyItemHyperLinkUrlBase, recipe.OutputItemId)); hlWikiLink.NavigateUri = new Uri(string.Format(Properties.Resources.WikiHyperLinkUrlBase, recipe.Name)); this.tbWikiHyperLinkContainer.Visibility = System.Windows.Visibility.Visible; this.tbGwSpidyHyperLinkContainer.Visibility = System.Windows.Visibility.Visible; }
private void SaveChange(Data.Recipe recipe) { // save modifications BackgroundWorker recipeCheckerWorker = new BackgroundWorker(); recipeCheckerWorker.DoWork += (object sender, DoWorkEventArgs e) => { Data.Cache.GetCache().SaveRecipe(recipe); }; recipeCheckerWorker.RunWorkerCompleted += (object sender, RunWorkerCompletedEventArgs e) => { if (e.Error != null) { MessageBox.Show(((Exception)e.Error).Message, "Erreur"); } }; recipeCheckerWorker.RunWorkerAsync(); }
private void DownloadNewRecipes() { BackgroundWorker downloadWorker = new BackgroundWorker(); downloadWorker.WorkerReportsProgress = true; List <int> recipe_ids = null; MainWindow win = this; downloadWorker.DoWork += (object sender, DoWorkEventArgs e) => { try { Dispatcher.BeginInvoke(new Action(() => { this.tbCurrentTask.Text = Properties.Resources.TextBoxCurrentDownloadStarting; })); recipe_ids = Data.DataProvider.GetRecipeIDs(); // get only not cached recipes List <int> cached_recipe_ids = Data.Cache.GetCache().Recipes.Select <Data.Recipe, int>(p => (int)p.Id).ToList(); recipe_ids = recipe_ids.Where(id => !cached_recipe_ids.Contains(id)).ToList(); Dispatcher.BeginInvoke(new Action(() => { this.tbCurrentTask.Text = String.Format(Properties.Resources.TextBoxCurrentDownloadNewRecipesFoundNotification, recipe_ids.Count); this.pbDownloadIndicator.Minimum = 0; this.pbDownloadIndicator.Maximum = recipe_ids.Count; })); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); for (int i = 0; i <= recipe_ids.Count - 1; i++) { if (e.Cancel) { break; } int recipe_id = recipe_ids[i]; try { sw.Start(); Data.API.ANet.Recipe recipe = Data.DataProvider.GetANetRecipe(recipe_id, Config.Lang); if (recipe == null) { throw new System.Net.WebException(String.Format("Something goes wrong with recipe {0}!", recipe_id)); } sw.Stop(); DownloadState.AddNewTimeElapsed(sw.ElapsedMilliseconds); downloadWorker.ReportProgress(i + 1, new DownloadState() { Current = i + 1, Total = recipe_ids.Count, Recipe = recipe }); } finally { sw.Reset(); } } } catch (Exception) { // Ignore exceptions at this point - failed to take from queue } }; downloadWorker.ProgressChanged += (object sender, ProgressChangedEventArgs e) => { DownloadState state = (DownloadState)e.UserState; TimeSpan t = TimeSpan.FromMilliseconds(DownloadState.AverageMilliseconds * (state.Total - state.Current)); this.pbDownloadIndicator.Value = state.Current; this.tbCurrentTask.Text = String.Format( Properties.Resources.TextBoxCurrentDownloadInProgress, state.Current, state.Total, state.Percent, t.Minutes, t.Seconds); // cache new recipe Data.Recipe recipe = Data.Cache.GetCache().AddRecipe(state.Recipe); // add to view this.RefreshDownloadResultsCount(); }; downloadWorker.RunWorkerCompleted += (object sender, RunWorkerCompletedEventArgs e) => { if (e.Error != null) { this.tbCurrentTask.Text = String.Format(Properties.Resources.TextBoxCurrentDownloadSomethingGoesWrong); } else { if (recipe_ids == null) { this.tbCurrentTask.Text = Properties.Resources.SomethingIsWrongNoDownloadPossible; } else { if (recipe_ids != null && recipe_ids.Count == 0) { this.tbCurrentTask.Text = Properties.Resources.TextBoxCurrentDownloadNoNewRecipesFoundNotification; } else { this.tbCurrentTask.Text = Properties.Resources.TextBoxCurrentDownloadFinished; } } } this.pbDownloadIndicator.Visibility = System.Windows.Visibility.Collapsed; }; downloadWorker.RunWorkerAsync(); }
private void AddRecipeToView(Data.Recipe recipe) { RecipeItem ri = new RecipeItem(recipe, this); recipeItems.Add(ri); }