public void InsertAccounts(JArray accounts)
 {
     if (accounts != null && accounts.Count > 0)
     {
         foreach (var account in accounts.Values<JObject>())
         {
             InsertAccount(account);
         }
     }
 }
        public void AsyncStorageModule_testGetAllKeys()
        {
            var mStorage = new AsyncStorageModule();
            var waitHandle = new AutoResetEvent(false);

            var error = default(JObject);
            var result = default(JArray);
            var callback = new MockCallback(res =>
            {
                error = res.Length > 0 ? (JObject)res[0] : null;
                result = res.Length > 1 ? (JArray)res[1] : null;
                waitHandle.Set();
            });

            mStorage.clear(callback);
            Assert.IsTrue(waitHandle.WaitOne());
            Assert.IsNull(error);
            Assert.IsNull(result);

            var keys = new[] { "foo", "foo2" };
            var values = new[] { "bar", "bar2" };

            var keyValues = new[]
            {
                new[]
                {
                    keys[0],
                    values[0],
                },
                new[]
                {
                    keys[1],
                    values[1],
                },
            };

            mStorage.multiSet(keyValues, callback);
            Assert.IsTrue(waitHandle.WaitOne());
            Assert.IsNull(error);
            Assert.IsNull(result);

            mStorage.getAllKeys(callback);
            Assert.IsTrue(waitHandle.WaitOne());
            Assert.IsNull(error);

            var storedKeys = new JArray
            {
                keys[0],
                keys[1],
            };

            var set = new SortedSet<string>();
            IEnumerable<string> enumerator = storedKeys.Values<string>();

            foreach (var value in enumerator)
            {
                set.Add(value);
            }

            set.SymmetricExceptWith(result.Values<string>());
            Assert.AreEqual(set.Count, 0);

            mStorage.multiRemove(keys, callback);
            Assert.IsTrue(waitHandle.WaitOne());
            Assert.IsNull(error);
            Assert.IsNull(result);

            mStorage.getAllKeys(callback);
            Assert.IsTrue(waitHandle.WaitOne());
            Assert.IsNull(error);
            Assert.AreEqual(result.Count, 0);
        }
        private void RefreshCache(JArray results)
        {
            try
            {
                this.AccessControl.WaitOne();
                this.BlockRequests = true;
                this.LastRefreshTime = DateTime.Now;

                BiMap<int, string> newCache = new BiMap<int, string>(null, StringComparer.OrdinalIgnoreCase);

                foreach (JObject obj in results.Values<JObject>())
                {
                    int id = obj.GetId() ?? 0;
                    string label = this.Model.DisplayConverter(obj);

                    newCache.AddPair(id, label);
                }

                // I'm going to pray that assignment is atomic
                this.PublicCache = newCache;

                if (DataRefreshed != null)
                    DataRefreshed(this.PublicCache);
            }
            finally
            {
                this.BlockRequests = false;
                this.AccessControl.ReleaseMutex();
            }
        }
        public void LoadArray(JArray data)
        {
            this.CachedData = data;
            this.CachedObjectTable = this.BuildCachedObjectTable();

            this.Table = new DataTable();

            // create hidden 'key' and 'model' fields so that each row can be re-attributed
            // to a persistent instance later
            var keyColumn = this.Table.Columns.Add(KeyColumn, typeof(int));
            keyColumn.ReadOnly = true;
            keyColumn.ColumnMapping = MappingType.Hidden;

            var modelColumn = this.Table.Columns.Add(ModelColumn, typeof(string));
            bool hideModel = this.ModelMappings.Count <= 1;
            modelColumn.ReadOnly = true;
            modelColumn.ColumnMapping = hideModel ? MappingType.Hidden : MappingType.Attribute;

            foreach (string s in this.Columns)
            {
                DataColumn column = this.Table.Columns.Add(s, typeof(string));
                column.Caption = s.SymbolToNatural();

                DataColumn trueColumn = this.Table.Columns.Add(this.TrueColumnName(s), typeof(string));
                trueColumn.ColumnMapping = MappingType.Hidden;
                trueColumn.DefaultValue = null;
            }

            foreach (JObject dataObj in data.Values<JObject>())
            {
                this.AddRow(dataObj);
            }

            this.DataGrid.InvokeEx(() =>
            {
                this.DataGrid.DataSource = this.Table;
            });
        }
Beispiel #5
0
        public static Inventory Init(JArray items)
        {
            Inventory inventory = new Inventory();

            //Separate books, cds, dvds
            if (items != null && items.Count > 0)
            {
                IList<JObject> booklist = items.Values<JObject>().Where(x => x["type"].Value<string>() == "book").ToList();
                IList<JObject> dvdlist = items.Values<JObject>().Where(x => x["type"].Value<string>() == "dvd").ToList();
                IList<JObject> cdlist = items.Values<JObject>().Where(x => x["type"].Value<string>() == "cd").ToList();

                try
                {
                    foreach (var book in booklist)
                        inventory.Books.Add(JsonConvert.DeserializeObject<Book>(book.ToString()));
                    foreach (var dvd in dvdlist)
                        inventory.DVDs.Add(JsonConvert.DeserializeObject<DVD>(dvd.ToString()));
                    foreach (var cd in cdlist)
                        inventory.CDs.Add(JsonConvert.DeserializeObject<CD>(cd.ToString()));
                }
                catch ( Exception ex){
                }

            }

            return inventory;
        }
 public void InsertOpportunities(JArray opportunities)
 {
     if (opportunities != null && opportunities.Count > 0)
     {
         foreach (var opportunity in opportunities.Values<JObject>())
         {
             InsertOpportunity(opportunity);
         }
     }
 }