Beispiel #1
0
 void ProccessResults(DBRecord[] results)
 {
     records = results.ToDictionary(x => x.Fields["Name"].ToString(), x => x);
     foreach (var result in results)
     {
         var    name = result.Fields["Name"].ToString();
         Monkey monkey;
         monkeyDictionary.TryGetValue(name, out monkey);
         if (monkey == null)
         {
             monkey = result.ToMonkey();
             monkeyDictionary.Add(name, monkey);
         }
         else
         {
             monkey.Update(result);
         }
     }
     Monkeys = monkeyDictionary.Select(x => x.Value).OrderBy(x => x.Z).ToArray();
     store.BeginInvokeOnMainThread(() => {
         if (MonkeysUpdated != null)
         {
             MonkeysUpdated(this, EventArgs.Empty);
         }
     });
 }
        void ProcessResults(DBRecord[] results)
        {
            _raceRecords = results.ToDictionary(x => x.Fields ["Code"].ToString(), x => x);
            foreach (var result in results)
            {
                var         code = result.Fields ["Code"].ToString();
                DropboxRace race;
                _raceDictionary.TryGetValue(code, out race);

                if (race == null)
                {
                    race = result.ToRace();
                    _raceDictionary.Add(code, race);
                }
                else
                {
                    race.Update(result);
                }

                UpdateRaceInformation(race);
            }
            _generalStore.BeginInvokeOnMainThread(() => {
                if (RaceListUpdated != null)
                {
                    RaceListUpdated(this, EventArgs.Empty);
                }
            });
        }
        public void Init()
        {
            if (store != null)
            {
                return;
            }
            DBError error;

            store = DBDatastore.OpenDefaultStoreForAccount(DBAccountManager.SharedManager.LinkedAccount, out error);
            var sync = store.Sync(null);

            store.AddObserver(store, () => {
                LoadData();
            });
            AutoUpdating = true;
            store.BeginInvokeOnMainThread(() => {
                timer = NSTimer.CreateRepeatingScheduledTimer(1, () => {
                    if (!AutoUpdating)
                    {
                        return;
                    }
                    store.Sync(null);
                });
            });
        }
        public Task LoadData()
        {
            var task = Task.Factory.StartNew(() => {
                var table     = store.GetTable("lines");
                DBError error = new DBError();

                var results = table.Query(null, out error);
                if (results.Length != 0)
                {
                    ProccessResults(results);
                }
                else
                {
                    store.BeginInvokeOnMainThread(() => {
                        ClearLines(this, EventArgs.Empty);
                    });
                }
            });

            return(task);
        }
        void ProcessSequenceItems(DBRecord[] results, bool justRead)
        {
            _sequenceRecords = results
                               .ToDictionary(
                x => new Tuple <string, string, int>(x.Fields["Name"].ToString(), x.Fields["Token"].ToString(), ((NSNumber)x.Fields["StartNumber"]).IntValue),
                x => x);
            var writtenLocations = new List <Tuple <string, string> >();

            foreach (var kvp in _sequenceRecords)
            {
                ISequenceItem item;
                _sequenceDictionary.TryGetValue(kvp.Key, out item);

                // this check means we are only going to be writing for a change we've not seen
                if (item == null)
                {
                    IBoat boat;
                    if (kvp.Key.Item3 <= 0)
                    {
                        boat = new BoatFactory().SetNumber(kvp.Key.Item3).Create();
                    }
                    else
                    {
                        boat = _boatDictionary[kvp.Key.Item3];
                    }
                    item = kvp.Value.ToItem(boat);
                    _sequenceDictionary.Add(kvp.Key, item);
                    writtenLocations.Add(new Tuple <string, string>(kvp.Key.Item1, kvp.Key.Item2));
                }
                // todo - the super user will want to have all changes written
            }

            if (!justRead)
            {
                WriteDropboxFile(writtenLocations.Distinct(), _sequenceDictionary);
            }

            _raceStore.BeginInvokeOnMainThread(() => {
                if (ItemsListUpdated != null)
                {
                    ItemsListUpdated(this, EventArgs.Empty);
                }
            });
        }
Beispiel #6
0
        public void Init(DBAccount account)
        {
            Console.WriteLine("Init");
            if (store != null)
            {
                return;
            }

            store = DBDatastore.OpenDefault(account);

            store.Sync();

//			store.AddObserver (store, () => {
//				Console.Write("AddObserver");
//
//				DBError error2;
//				store.Sync(out error2); // needed?
//
//				var table = store.GetTable (tableName);
//				var results = table.Query (null, out error);
//
//				Console.WriteLine(results.Length);
//
//				ProccessResults (results);
//			});


            // TIMER TO AUTOUPDATE
            AutoUpdating = true;

                        #if __IOS__
            store.BeginInvokeOnMainThread(() => {
                timer = NSTimer.CreateRepeatingScheduledTimer(2, () => {
                    if (!AutoUpdating)
                    {
                        return;
                    }
                    //Console.WriteLine("AutoUpdating"); // SPAM
                    DBError error3;
                    store.Sync(out error3);
                });
            });
                        #endif
        }
Beispiel #7
0
        public void Init()
        {
            Console.Write("Init");
            if (store != null)
            {
                return;
            }
            DBError error;

            store = DBDatastore.OpenDefaultStore(DBAccountManager.SharedManager.LinkedAccount, out error);
            DBError error1;
            var     sync = store.Sync(out error1);

            store.AddObserver(store, () => {
                Console.Write("AddObserver");

                DBError error2;
                store.Sync(out error2);                 // needed?

                var table   = store.GetTable(tableName);
                var results = table.Query(null, out error);

                Console.WriteLine(results.Length);

                ProccessResults(results);
            });


            // TIMER TO AUTOUPDATE
            AutoUpdating = true;

            store.BeginInvokeOnMainThread(() => {
                timer = NSTimer.CreateRepeatingScheduledTimer(2, () => {
                    if (!AutoUpdating)
                    {
                        return;
                    }
                    //Console.WriteLine("AutoUpdating"); // SPAM
                    DBError error3;
                    store.Sync(out error3);
                });
            });
        }
Beispiel #8
0
        //TODO: tidy up this method!!!
        void ProccessResults(DBRecord[] results)
        {
            taskDictionary.Clear();

            records = results.ToDictionary(x => x.RecordId.ToString(), x => x);
            lock (locker) {
                Console.WriteLine("ProcessResults" + results.Length.ToString());

                //foreach (var result in results) {
                for (var i = 0; i < results.Length; i++)
                {
                    var result = results [i];
                    var id     = result.RecordId.ToString();
                    Console.WriteLine("id " + id + " " + i);
                    TodoItem t;
                    taskDictionary.TryGetValue(id, out t);
                    if (t == null)
                    {
                        t = result.ToTask();
                        taskDictionary.Add(id, t);
                    }
                    else
                    {
                        t.Update(result);
                    }
                }

                store.BeginInvokeOnMainThread(() => {
                    Items = taskDictionary.Select(x => x.Value).OrderBy(x => x.Name).ToList();
                    Console.WriteLine("Updated Items property: " + Items.Count);


                    if (ItemsUpdated != null)
                    {
                        Console.WriteLine("TasksUpdated handler called " + Items.Count);
                        ItemsUpdated(this, EventArgs.Empty);
                    }
                });

                Console.WriteLine("DONE");
            }
        }
		public void Init (DBAccount account)
		{
			Console.WriteLine("Init");
			if (store != null)
				return;

			store = DBDatastore.OpenDefault (account);

			store.Sync ();

//			store.AddObserver (store, () => {
//				Console.Write("AddObserver");
//
//				DBError error2;
//				store.Sync(out error2); // needed?
//
//				var table = store.GetTable (tableName);
//				var results = table.Query (null, out error);
//
//				Console.WriteLine(results.Length);
//
//				ProccessResults (results);
//			});


			// TIMER TO AUTOUPDATE
			AutoUpdating = true;

			#if __IOS__
			store.BeginInvokeOnMainThread(()=>{
				timer = NSTimer.CreateRepeatingScheduledTimer(2,()=>{
					if(!AutoUpdating)
						return;
					//Console.WriteLine("AutoUpdating"); // SPAM
					DBError error3;
					store.Sync(out error3);
				});
			});
			#endif

		}