Esempio n. 1
0
		protected override async void OnHandleIntent (Intent intent)
		{
			var download = new DbDownloadHelper ();
			var upload = new DbUploadHelper ();
			var newEntries = TimeManager.GetUnSynchedTimeeEntries ();
			var newLocations = GpsLocationManager.GetUnSynchedGpsLocations ();
			//getting jobs, codes and version
			await download.GetData();
			await upload.UploadAll (newEntries, newLocations);

			//wait until is over
			var success = !download.DownloadFailed () && !upload.UploadFailed ();
			if (download.bCodes.Any () && download.nbCodes.Any () && download.jobs.Any ()) {
				var update = new DbUpdateHelper ();
				update.UpdateAll (download.jobs, download.bCodes, download.nbCodes, newEntries, newLocations);
			}

			string resultString = success ? "Synch Successfull" : "Synch Unsuccessfull";
			string textString = download.message + " " + upload.message;

			var ic = success ? Resource.Drawable.sync : Resource.Drawable.unsynch;

			var pendingIntent = PendingIntent.GetActivity (this, 0, new Intent (this, typeof(MainActivity)), 0);

			var builder = new NotificationCompat.Builder (this)
				.SetAutoCancel (true)
				.SetContentIntent (pendingIntent)
				.SetContentTitle (resultString)
				.SetSmallIcon (ic)
				.SetContentInfo ("ETC Sync Notification")
				.SetContentText (textString);

			// Finally publish the notification
			var notificationManager = (NotificationManager)GetSystemService (NotificationService);
			notificationManager.Notify (0, builder.Build ());
			Intent applicationIntent = new Intent (Forms.Context, typeof(MainActivity));
			applicationIntent.AddFlags (ActivityFlags.NewTask);
			//Forms.Context.StartActivity (applicationIntent);
		}
Esempio n. 2
0
		public async Task ConsolidateEntries()
		{
			var download = new DbDownloadHelper ();
			var upload = new DbUploadHelper ();
			var synchedEntries = download.DownloadEntriesByIMEI (DeviceHelper.GetMyIMEI ());
			var localEntries = TimeManager.GetTimeEntries ()
				.Where(x => x.Start > DateTime.Now.AddDays(-15) && x.isSynched == 1);

			var wrongEntries = localEntries.Except (synchedEntries);

			var count = wrongEntries.Count ();
			var updatedEntries = new List<TimeEntry> ();

			for (int i = 0; i  < 100; i++) {
				var someEntries = wrongEntries.Skip(i * 100).Take (100);
				await upload.UploadTimeEntries (someEntries.ToList());
				updatedEntries.AddRange (someEntries);
			}

			var remainingEntries = wrongEntries.Except (updatedEntries);
			await upload.UploadTimeEntries (remainingEntries.ToList());
		}