コード例 #1
0
        private void _OnSignalREvent(string aEventName, object aEventData)
        {
            switch (aEventName)
            {
            case "ProductListCreated":
                {
                    var lEventData = (JObject)aEventData;
                    var lList = new ProductListDTO()
                    {
                        Id = (int)lEventData["Id"],
                        Name = (string)lEventData["Name"] 
                    };
                    lock (this.ProductLists)
                        mProductLists.Add(lList);

                    _NotifyPropertyChanged("ProductLists");
                }
                break;
            case "ProductListDeleted":
                {
                    var lEventData = (JObject)aEventData;
                    var lList = mProductLists.FirstOrDefault(aList => aList.Id == (int)lEventData["Id"]);
                    if (lList != null)
                    {
                        lock (this.ProductLists)
                            mProductLists.Remove(lList);

                        _NotifyPropertyChanged("ProductLists");
                    }
                }
                break;
            case "ProductEntryCreated":
                {
                    var lEventData = (JObject)aEventData;
                    var lList = mProductLists.FirstOrDefault(aList => aList.Id == (int)lEventData["ListId"]);
                    if (lList != null)
                    {
                        var lEntry = new ProductEntryDTO()
                        {
                            Id = (int)lEventData["Id"],
                            ProductName = (string)lEventData["Name"],
                            Amount = (int)lEventData["Amount"],
                            Comments = (string)lEventData["Comments"],
                            OwnerList = lList
                        };
                        lEntry.PropertyChanged += _OnProductEntryPropertyChanged;
                        lock (lList.mProductEntries)
                            lList.mProductEntries.Add(lEntry);

                        lList._NotifyPropertyChanged("ProductEntries");
                    }
                }
                break;
            case "ProductEntryEdited":
                {
                    var lEventData = (JObject)aEventData;
                    var lList = mProductLists.FirstOrDefault(aList => aList.Id == (int)lEventData["ListId"]);
                    if (lList != null)
                    {
                        var lEntry = lList.ProductEntries.FirstOrDefault(aEntry => aEntry.Id == (int)lEventData["Id"]);
                        if (lEntry != null)
                        {
                            lEntry.Amount = (int)lEventData["Amount"];
                            lEntry.Comments = (string)lEventData["Comments"];
                        }
                    }
                }
                break;
            case "ProductEntryDeleted":
                {
                    var lEventData = (JObject)aEventData;
                    var lList = mProductLists.FirstOrDefault(aList => aList.Id == (int)lEventData["ListId"]);
                    if (lList != null)
                    {
                        var lEntry = lList.ProductEntries.FirstOrDefault(aEntry => aEntry.Id == (int)lEventData["Id"]);
                        if (lEntry != null)
                        {
                            lock (lList.mProductEntries)
                                lList.mProductEntries.Remove(lEntry);

                            lList._NotifyPropertyChanged("ProductEntries");
                        }
                    }
                }
                break;
            }
        }
コード例 #2
0
 public async Task DeleteProductEntry(ProductListDTO aList, ProductEntryDTO aProductEntry)
 {
     using (this.SetBusy())
     {
         var lResponse = await mJSONRequester.Delete(this.ServerURL, string.Format(APIConstants.URL_DELETE_PRODUCT_ENTRY, aList.Id, aProductEntry.Id), mRequestHeaders);
         lResponse.EnsureSuccessStatusCode();
     }
 }
コード例 #3
0
        public async Task QueryProductEntries(ProductListDTO aList)
        {
            using (this.SetBusy())
            {
                var lResponse = await mJSONRequester.Get(this.ServerURL, string.Format(APIConstants.URL_PRODUCT_ENTRIES, aList.Id), mRequestHeaders);
                lResponse.EnsureSuccessStatusCode();
                List<ProductEntryDTO> lProductEntries = await lResponse.Content.ReadAsAsync<List<ProductEntryDTO>>();

                //Unsuscribe from previous event listeners
                foreach (var lProductEntry in aList.ProductEntries)
                {
                    lProductEntry.PropertyChanged -= _OnProductEntryPropertyChanged;
                    lProductEntry.OwnerList = null;
                }
                //Suscribe to new product entries
                foreach (var lProductEntry in lProductEntries)
                {
                    lProductEntry.PropertyChanged += _OnProductEntryPropertyChanged;
                    lProductEntry.OwnerList = aList;
                }

                lock (aList.mProductEntries)
                {
                    aList.mProductEntries.Clear();
                    foreach (var lProductEntry in lProductEntries)
                        aList.mProductEntries.Add(lProductEntry);
                }
                aList._NotifyPropertyChanged("ProductEntries");
            }
        }
コード例 #4
0
 public async Task CreateProductList(ProductListDTO aProductList)
 {
     using (this.SetBusy())
     {
         var lResponse = await mJSONRequester.Post<ProductListDTO>(this.ServerURL, APIConstants.URL_CREATE_PRODUCT_LIST, aProductList, mRequestHeaders);
         lResponse.EnsureSuccessStatusCode();
     }
 }
コード例 #5
0
 private async Task _DeleteProductEntry(ProductListDTO aProductList, ProductEntryDTO aProductEntry)
 {
     string lErrorMsg = null;
     try
     {
         await APIClient.DeleteProductEntry(aProductList, aProductEntry);
     }
     catch (Exception ex)
     {
         //In very high concurrent scenarios race conditions may ocurr, that lead the application to delete an already (just) deleted product entry
         if (ex is HttpRequestException && ex.Message.Contains(((int)HttpStatusCode.NotFound).ToString()))
         {
             //The given product entry was not found (probably already deleted in a race condition) Nothing is done
         }
         else if (ex is HttpRequestException && ex.Message.Contains(((int)HttpStatusCode.Forbidden).ToString()))
             lErrorMsg = "The server rejected the connection. Please update your client to the last version";
         else
             lErrorMsg = "Error communicating with server";
     }
     if (lErrorMsg != null)
         await _ShowMessageBox_Ok(lErrorMsg);
 }
コード例 #6
0
 private async Task _DeleteProductEntry(ProductListDTO aProductList, ProductEntryDTO aProductEntry)
 {
     try
     {
         await APIClient.DeleteProductEntry(aProductList, aProductEntry);
     }
     catch (Exception ex)
     {
         //In very high concurrent scenarios race conditions may ocurr, that lead the application to delete an already (just) deleted product entry
         if (ex is HttpRequestException && ex.Message.Contains(((int)HttpStatusCode.NotFound).ToString()))
         {
             //The given product entry was not found (probably already deleted in a race condition) Nothing is done
         }
         else if (ex is HttpRequestException && ex.Message.Contains(((int)HttpStatusCode.Forbidden).ToString()))
             MessageBox.Show(this, "The server rejected the connection. Please update your client to the last version", "Forbidden", MessageBoxButton.OK, MessageBoxImage.Stop);
         else
             MessageBox.Show(this, "Error communicating with server", "Network error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }