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);
			});
		}
Ejemplo n.º 2
0
        public static DropboxRace Update(this DropboxRace race, DBRecord record)
        {
            race.Code = record.Fields ["Code"].ToString ();
            if(record.Fields.ContainsKey(new NSString("IntermediateLocations")))
            {
                var locations = race.Locations.ToList();
                IList<ILocation> toAdd = new List<ILocation>();
                foreach(var location in
                    record
                        .Fields["IntermediateLocations"]
                        .ToString()
                        .Split(',')
                        .Union(new List<string>{"start","finish"}))
                {
                    if(!locations.Select(l => l.Name).Contains(location))
                        toAdd.Add(new LocationFactory().SetName(location).Create());
                }
                if(toAdd.Count > 0)
                    race.Locations = locations.Union(toAdd);
            }
            if(record.Fields.ContainsKey(new NSString("DatastoreID")))
                race.DataStoreID = record.Fields ["DatastoreID"].ToString();
            if(record.Fields.ContainsKey(new NSString("FullName")))
                race.Name = record.Fields ["FullName"].ToString();
            if(record.Fields.ContainsKey(new NSString("RaceDate")))
            {
                var rd = record.Fields["RaceDate"];
                var nsd = (NSDate)rd;
                var dt = DateTime.SpecifyKind(nsd, DateTimeKind.Unspecified);
                race.Date = dt;
            }
            if(record.Fields.ContainsKey(new NSString("BoatsUpdated")))
                race.BoatsUpdated = DateTime.SpecifyKind(((NSDate)record.Fields["BoatsUpdated"]), DateTimeKind.Unspecified);
            if(record.Fields.ContainsKey(new NSString("DetailsUpdated")))
                race.DetailsUpdated = DateTime.SpecifyKind(((NSDate)record.Fields["DetailsUpdated"]), DateTimeKind.Unspecified);

            return race;
        }
		public static Monkey Update (this Monkey monkey, DBRecord record)
		{
            monkey.Name = record.Fields ["Name"].ToString ();
            monkey.Rotation = ((NSNumber)record.Fields ["Rotation"]).FloatValue;
            monkey.Scale = ((NSNumber)record.Fields ["Scale"]).FloatValue;
            monkey.X = ((NSNumber)record.Fields ["X"]).FloatValue;
            monkey.Y =((NSNumber)record.Fields ["Y"]).FloatValue;
            monkey.Z =((NSNumber)record.Fields ["Z"]).IntValue;
			return monkey;
		}
Ejemplo n.º 4
0
 public static Monkey Update(this Monkey monkey, DBRecord record)
 {
     monkey.Name = record.Fields [new NSString ("Name")].ToString ();
     monkey.Rotation = float.Parse (record.Fields [new NSString ("Rotation")].ToString ());
     monkey.Scale = float.Parse (record.Fields [new NSString ("Scale")].ToString ());
     monkey.X = float.Parse (record.Fields [new NSString ("X")].ToString ());
     monkey.Y = float.Parse (record.Fields [new NSString ("Y")].ToString ());
     monkey.Z = int.Parse (record.Fields [new NSString ("Z")].ToString ());
     return monkey;
 }
        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);
            });
        }
        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 static TodoItem Update (this TodoItem t, DBRecord record)
		{
			t.ID = record.RecordId;

			t.Name = record.Fields [new NSString ("Title")].ToString ();
			t.Notes = record.Fields [new NSString ("Description")].ToString ();
			t.Done = Convert.ToBoolean (record.Fields [new NSString ("IsDone")].ToString ());
			return t;
		}
		//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");
			}
		}