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();
        }
Пример #2
0
        public static void CheckPendingItem(Mobile m)
        {
            List <Item> list;

            if (PendingItems.TryGetValue(m, out list))
            {
                var index = list.Count;

                while (--index >= 0)
                {
                    if (index >= list.Count)
                    {
                        continue;
                    }

                    var item = list[index];

                    if (item != null)
                    {
                        if (m.Backpack != null && m.Alive && m.Backpack.TryDropItem(m, item, false))
                        {
                            if (item is IPromotionalToken && ((IPromotionalToken)item).ItemName != null)
                            {
                                // A token has been placed in your backpack. Double-click it to redeem your ~1_PROMO~.
                                m.SendLocalizedMessage(1075248, ((IPromotionalToken)item).ItemName.ToString());
                            }
                            else if (item.LabelNumber > 0 || item.Name != null)
                            {
                                var name = item.LabelNumber > 0 ? ("#" + item.LabelNumber) : item.Name;

                                // Your purchase of ~1_ITEM~ has been placed in your backpack.
                                m.SendLocalizedMessage(1156844, name);
                            }
                            else
                            {
                                // Your purchased item has been placed in your backpack.
                                m.SendLocalizedMessage(1156843);
                            }

                            list.RemoveAt(index);
                        }
                    }
                    else
                    {
                        list.RemoveAt(index);
                    }
                }

                if (list.Count == 0 && PendingItems.Remove(m))
                {
                    list.TrimExcess();
                }
            }
        }
Пример #3
0
        public static void AddPendingItem(Mobile m, Item item)
        {
            if (!PendingItems.TryGetValue(m, out List <Item> list))
            {
                PendingItems[m] = list = new List <Item>();
            }

            if (!list.Contains(item))
            {
                list.Add(item);
            }

            UltimaStoreContainer.DropItem(item);
        }
Пример #4
0
        public static void AddPendingItem(Mobile m, Item item)
        {
            if (PendingItems == null)
            {
                PendingItems = new Dictionary <Mobile, List <Item> >();
            }

            if (!PendingItems.ContainsKey(m))
            {
                PendingItems[m] = new List <Item>();
            }

            PendingItems[m].Add(item);
            UltimaStoreContainer.DropItem(item);
        }
Пример #5
0
        public static void CheckPendingItem(Mobile m)
        {
            if (PendingItems == null)
            {
                return;
            }

            if (PendingItems.ContainsKey(m))
            {
                var list = new List <Item>(PendingItems[m]);

                foreach (Item item in list)
                {
                    if (item != null)
                    {
                        if (m.Backpack != null && m.Alive && m.Backpack.TryDropItem(m, item, false))
                        {
                            if (item is IPromotionalToken && ((IPromotionalToken)item).ItemName != null)
                            {
                                m.SendLocalizedMessage(1075248, ((IPromotionalToken)item).ItemName.ToString()); // A token has been placed in your backpack. Double-click it to redeem your ~1_PROMO~.
                            }
                            else if (item.LabelNumber > 0 || item.Name != null)
                            {
                                m.SendLocalizedMessage(1156844, item.LabelNumber > 0 ? String.Format("#{0}", item.LabelNumber.ToString()) : item.Name);
                                // Your purchase of ~1_ITEM~ has been placed in your backpack.
                            }
                            else
                            {
                                m.SendLocalizedMessage(1156843); // Your purchased item has been placed in your backpack.
                            }

                            PendingItems[m].Remove(item);
                        }
                    }
                }

                ColUtility.Free(list);

                if (PendingItems[m].Count == 0)
                {
                    PendingItems.Remove(m);
                }
            }
        }
Пример #6
0
 public static bool HasPendingItem(PlayerMobile pm)
 {
     return(PendingItems.ContainsKey(pm));
 }
Пример #7
0
 public void Validate()
 {
     Items.ValidateOptional("Items");
     PendingItems.ValidateOptional("PendingItems");
 }