public MainViewModel() { // Takes 15 Items to upload var itemsObservable = Observable .Interval(TimeSpan.FromSeconds(5)) .Select(id => new Item(string.Format("Item {0}", id + 1))) .Take(15) .Publish(); // We observe the incoming items to show them into the view itemsObservable .ObserveOnDispatcher() .Subscribe(item => PendingItems.Add(item)); // We also observe the items that uploaded successfully (the uploader holds them) uploader = new Uploader(itemsObservable); uploader.UploadedItems .ObserveOnDispatcher() .Subscribe(uploadResults => UploadedItems.Add(uploadResults)); uploader.Failed.Subscribe(failedItem => FailedItem = failedItem); //The command that will be invoked when the user "fixes" an item and wants to retry it. It will be available only when there is a item that failed to upload. RetryCommand = new RelayCommand(_ => Retry(), _ => FailedItem != null); PendingItems = new ObservableCollection <Item>(); UploadedItems = new ObservableCollection <UploadResults>(); itemsObservable.Connect(); }
/// <summary>Executes the event.</summary> /// <param name="uploadedItems">The uploaded items.</param> protected void Done(string uploadedItems) { Assert.ArgumentNotNull((object)uploadedItems, "uploadedItems"); List <Item> items = new List <Item>(); string str = uploadedItems; char[] chArray = new char[1] { '|' }; foreach (string itemUri1 in new ListString(str.TrimEnd(chArray)).Items) { ItemUri itemUri2 = ItemUri.Parse(itemUri1); Assert.IsNotNull((object)itemUri2, "uploaded uri"); Database database = Factory.GetDatabase(itemUri2.DatabaseName); Assert.IsNotNull((object)database, "database"); Item obj = database.GetItem(itemUri2.ToDataUri()); if (obj != null) { items.Add(obj); } } UploadedItems.Set(items); SheerResponse.Eval("document.body.parentNode.removeChild(document.body);"); SheerResponse.Eval("scForm.getParentForm().postRequest('', '', '', 'item:refreshchildren(id=" + WebUtil.GetQueryString("id") + ")');"); SheerResponse.Eval("scForm.getParentForm().postRequest('', '', '', 'item:refresh');"); }
/// <summary>Renders the item.</summary> /// <param name="output">The output.</param> /// <param name="item">The item to render.</param> /// <contract> /// <requires name="output" condition="not null" /> /// <requires name="item" condition="not null" /> /// </contract> protected override void RenderItem(HtmlTextWriter output, Item item) { Assert.ArgumentNotNull((object)output, "output"); Assert.ArgumentNotNull((object)item, "item"); string str1 = string.Empty; string str2 = string.Empty; string str3 = string.Empty; if (UploadedItems.Include(item)) { UploadedItems.RenewExpiration(); } string str4; int num1; if (item.TemplateID == TemplateIDs.MediaFolder || item.TemplateID == TemplateIDs.Folder || item.TemplateID == TemplateIDs.Node) { str4 = Themes.MapTheme("Applications/48x48/folder.png"); num1 = 48; int num2 = UserOptions.View.ShowHiddenItems ? item.Children.Count : this.GetVisibleChildCount(item); str1 = num2.ToString() + " " + Translate.Text(num2 == 1 ? "item" : "items"); } else { MediaItem mediaItem = (MediaItem)item; MediaUrlOptions thumbnailOptions = MediaUrlOptions.GetThumbnailOptions((MediaItem)item); num1 = MediaManager.HasMediaContent((Item)mediaItem) ? 72 : 48; thumbnailOptions.Width = num1; thumbnailOptions.Height = num1; thumbnailOptions.UseDefaultIcon = true; str4 = MediaManager.GetMediaUrl(mediaItem, thumbnailOptions); MediaMetaDataFormatter metaDataFormatter = MediaManager.Config.GetMetaDataFormatter(mediaItem.Extension); if (metaDataFormatter != null) { MediaMetaDataCollection metaData1 = mediaItem.GetMetaData(); MediaMetaDataCollection metaData2 = new MediaMetaDataCollection(); foreach (string key in metaData1.Keys) { metaData2[key] = HttpUtility.HtmlEncode(metaData1[key]); } if (str1 != null) { str1 = metaDataFormatter.Format(metaData2, MediaMetaDataFormatterOutput.HtmlNoKeys); } } str2 = new MediaValidatorFormatter().Format(mediaItem.ValidateMedia(), MediaValidatorFormatterOutput.HtmlPopup); ItemLink[] referrers = Globals.LinkDatabase.GetReferrers(item); if (referrers.Length > 0) { str3 = referrers.Length.ToString() + " " + Translate.Text(referrers.Length == 1 ? "usage" : "usages"); } } Tag tag = new Tag("a"); tag.Add("id", "I" + (object)item.ID.ToShortID()); tag.Add("href", "#"); tag.Add("onclick", "javascript:scForm.getParentForm().invoke('item:load(id=" + (object)item.ID + ")');return false"); if (UploadedItems.Include(item)) { tag.Add("class", "highlight"); } tag.Start(output); ImageBuilder imageBuilder1 = new ImageBuilder(); imageBuilder1.Src = str4; imageBuilder1.Class = "scMediaIcon"; imageBuilder1.Width = num1; imageBuilder1.Height = num1; ImageBuilder imageBuilder2 = imageBuilder1; string str5 = string.Empty; if (num1 < 72) { str5 = string.Format("padding:{0}px {0}px {0}px {0}px", (object)((72 - num1) / 2)); } if (!string.IsNullOrEmpty(str5)) { str5 = " style=\"" + str5 + "\""; } output.Write("<div class=\"scMediaBorder\"" + str5 + ">"); output.Write(imageBuilder2.ToString()); output.Write("</div>"); output.Write("<div class=\"scMediaTitle\">" + item.DisplayName + "</div>"); if (!string.IsNullOrEmpty(str1)) { output.Write("<div class=\"scMediaDetails\">" + str1 + "</div>"); } if (!string.IsNullOrEmpty(str2)) { output.Write("<div class=\"scMediaValidation\">" + str2 + "</div>"); } if (!string.IsNullOrEmpty(str3)) { output.Write("<div class=\"scMediaUsages\">" + str3 + "</div>"); } tag.End(output); }