コード例 #1
0
        private void ButtonScript_Click(object sender, RoutedEventArgs e)
        {
            //NavigationService.Navigate();
            var d = new Utils.ScriptDownloader();
            var item = (sender as Button).Tag as OnlineScriptViewModel;
            d.Download(item, this.Dispatcher,
                (simpleScriptDetail) =>
                {
                    var baseItem = new ItemViewModel()
                    {
                        CategoryTag = simpleScriptDetail.TagsAsText,
                        Code = simpleScriptDetail.Code,
                        Title = simpleScriptDetail.Title,
                        UniqueId = simpleScriptDetail.ScriptId
                    };

                    bool sameAuthor = false;
                    if (App.ViewModel.Account.UserName != null)
                        sameAuthor = (simpleScriptDetail.AuthorName.ToLowerInvariant() == App.ViewModel.Account.UserName.ToLowerInvariant());

                    if (sameAuthor)
                    {
                        var existing = App.ViewModel.Items.Where(x => x.UniqueId == simpleScriptDetail.ScriptId).FirstOrDefault();
                        if (existing != null)
                        {
                            var result = MessageBox.Show("Replace your current script?", Iron7.Common.Constants.Title, MessageBoxButton.OKCancel);
                            if (result != MessageBoxResult.OK)
                                return;
                            App.ViewModel.Items.Remove(existing);
                        }                        
                    }
                    App.ViewModel.CreateNewItemBasedOn(baseItem, NavigationService, !sameAuthor, sameAuthor);
                });
        }
コード例 #2
0
ファイル: EditPage.xaml.cs プロジェクト: slodge/main
 private void ApplicationBarUpdateFromIron7_Click(object sender, EventArgs e)
 {
     var d = new Utils.ScriptDownloader();
     var item = new OnlineScriptViewModel
     {
         Author = App.ViewModel.Account.UserName,
         ScriptId = base.CurrentItem.UniqueId,
         Title = base.CurrentItem.Title
     };
     d.Download(item, this.Dispatcher,
         (simpleScriptDetail) =>
         {
             base.CurrentItem.CategoryTag = simpleScriptDetail.TagsAsText;
             base.CurrentItem.Title = simpleScriptDetail.Title;
             base.CurrentItem.Code = simpleScriptDetail.Code;
             base.CurrentItem.WhenLastModified = DateTime.UtcNow.Ticks;
             try
             {
                 webBrowser1.InvokeScript("showCode", CurrentItem.Code);
             }
             catch (Exception exc)
             {
                 // ho hum!
                 MessageBox.Show("Sorry - there was a problem updating the editor - " + exc.Message);
             }
         });
 }