Ejemplo n.º 1
0
        public override bool OnStopJob(JobParameters jobParams)
        {
            //StaticObjects.jobCancelled = true;

            //PhoneThread.Abort();
            //WoundThread.Abort();
            //WatchThread.Abort();
            //CloudSyncThread.Abort();

            //PhoneThread = null;
            // WoundThread = null;
            //WatchThread = null;
            //CloudSyncThread = null;

            //if (WoundPage.ConnectionDelete != null)
            //{
            //    WoundPage.ConnectionDelete(true);
            //}

            var message = new CollectionMessage
            {
                Message = "Job Restarting..."
            };

            Device.BeginInvokeOnMainThread(
                () => MessagingCenter.Send(message, "CollectionMessage")
                );

            return(true);
        }
Ejemplo n.º 2
0
 private void OnMessage(string mes, string userID)
 {
     if (mes.Equals(""))
     {
         OutRoomVoid();
         //If don't have this line, user Second will not be Stop HubConnect,
         //But if have this line, Will be disconnected, before done line 104 (await ChatHub.Invoke(chat..)
         if (!IGetOut)
         {
             if (HubConnect.State == ConnectionState.Connected)
             {
                 HubConnect.Stop();
             }
         }
     }
     else
     {
         Device.BeginInvokeOnMainThread(() => {
             var msg = new Message()
             {
                 Content = mes, IsMine = userID == HubConnect.ConnectionId
             };
             CollectionMessage.Add(msg);
         });
     }
 }
        public async Task DBOperationsAsync()
        {
            //while (StaticObjects.jobCancelled == false)
            //{
            try
            {
                //token.ThrowIfCancellationRequested();

                var message = new CollectionMessage
                {
                    Message = "Pushing Data..."
                };

                Device.BeginInvokeOnMainThread(() =>
                {
                    MessagingCenter.Send(message, "CollectionMessage");
                });

                //INSERTS INTO REMOTE LOCATION
                await SensorDataService.Instance.CurrentClient.SyncContext.PushAsync();

                //await SensorDataService.Instance.phoneSensorTable.PurgeAsync(true);
                //await SensorDataService.Instance.woundSensorTable.PurgeAsync(true);
                //await SensorDataService.Instance.watchSensorTable.PurgeAsync(true);

                //if (StaticObjects.path.Length > 8e6)
                //{
                //    await SensorDataService.Instance.phoneSensorTable.PurgeAsync(true);
                //    await SensorDataService.Instance.woundSensorTable.PurgeAsync(true);
                //    await SensorDataService.Instance.watchSensorTable.PurgeAsync(true);
                //}

                var _message = new CollectionMessage
                {
                    Message = "Push Complete. Waiting..."
                };
                Device.BeginInvokeOnMainThread(
                    () => MessagingCenter.Send(_message, "CollectionMessage")
                    );
                //Thread.Sleep(30000);
            }

            catch (Exception ex)
            {
                ExceptionErrorLogger.writeFileOnInternalStorage(ex.ToString());

                var _message = new CollectionMessage {
                    Message = "Error Pushing"
                };
                Device.BeginInvokeOnMainThread(() => MessagingCenter.Send(_message, "CollectionMessage"));

                var message = new NotifyMessage {
                    Message = "Error pushing to cloud. The job will restart soon (Maximum 15 minutes)"
                };
                Device.BeginInvokeOnMainThread(() => MessagingCenter.Send(_message, "NotifyMessage"));
            }
            //}
        }
Ejemplo n.º 4
0
 private void OutRoomVoid()
 {
     Device.BeginInvokeOnMainThread(() => {
         MainButton.IsEnabled = true;
         OutRoom.IsEnabled    = false;
         SendButton.IsEnabled = false;
         IsReady = false;
         CollectionMessage.Clear();
         UpdateStatus("......");
     });
     //HubConnect.Stop();
 }
Ejemplo n.º 5
0
        public void StoreService()
        {
            Task.Run(() =>
            {
                try
                {
                    //INVOKE THE SHARED CODE
                    if (!isRunning)
                    {
                        var net = new NetworkCommunicationManager();
                        //net.DBOperations(_cts.Token);
                    }
                }
                catch (Exception ex)
                {
                    ExceptionErrorLogger.writeFileOnInternalStorage(ex.ToString());

                    var message = new CollectionMessage
                    {
                        Message = "Connection Error"
                    };
                    Device.BeginInvokeOnMainThread(
                        () => MessagingCenter.Send(message, "CollectionMessage")
                        );
                }
                finally
                {
                    if (_cts.IsCancellationRequested)
                    {
                        var message = new CancelledMessage();
                        Device.BeginInvokeOnMainThread(
                            () => MessagingCenter.Send(message, "CancelledMessage")
                            );
                    }
                    else
                    {
                        StaticObjects.IsCollecting = false;
                        //var _message = new StopLongRunningTaskMessage();
                        //MessagingCenter.Send(_message, "StopLongRunningTaskMessage");

                        var message = new CollectionMessage
                        {
                            Message = "Database push resuming..."
                        };
                        Device.BeginInvokeOnMainThread(
                            () => MessagingCenter.Send(message, "CollectionMessage")
                            );
                    }
                }
            }, _cts.Token);
        }
        public override bool OnStopJob(JobParameters @params)
        {
            WatchCollectionThread.Abort();

            WatchCollectionThread = null;

            if (SmartWatchPage.ClearGraphs != null)
            {
                SmartWatchPage.ClearGraphs();
            }

            var message = new CollectionMessage {
                Message = "Connection Restarting..."
            };

            Device.BeginInvokeOnMainThread(() => MessagingCenter.Send(message, "CollectionMessage"));

            return(true);
        }
Ejemplo n.º 7
0
        public async Task Start()
        {
            _cts = new CancellationTokenSource();
            StaticObjects.IsCollecting = true;
            _taskId = UIApplication.SharedApplication.BeginBackgroundTask("LongRunningTask", OnExpiration);

            try
            {
                var net = new NetworkCommunicationManager();
                //await net.DBOperations(_cts.Token);
            }
            catch (OperationCanceledException)
            {
            }
            finally
            {
                if (_cts.IsCancellationRequested)
                {
                    var message = new CancelledMessage();
                    Device.BeginInvokeOnMainThread(
                        () => MessagingCenter.Send(message, "CancelledMessage")
                        );
                }
                else
                {
                    StaticObjects.IsCollecting = false;

                    var message = new CollectionMessage
                    {
                        Message = "Push Complete"
                    };
                    Device.BeginInvokeOnMainThread(
                        () => MessagingCenter.Send(message, "CollectionMessage")
                        );
                }
            }

            UIApplication.SharedApplication.EndBackgroundTask(_taskId);
        }
Ejemplo n.º 8
0
        public override bool OnStartJob(JobParameters jobParameters)
        {
            Task.Run(async() =>
            {
                try
                {
                    //token.ThrowIfCancellationRequested();

                    var message = new CollectionMessage
                    {
                        Message = "Pushing Data..."
                    };

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        MessagingCenter.Send(message, "CollectionMessage");
                    });

                    //INSERTS INTO REMOTE LOCATION
                    await SensorDataService.Instance.CurrentClient.SyncContext.PushAsync();
                    //await SensorDataService.Instance.phoneSensorTable.PurgeAsync(true);
                    //await SensorDataService.Instance.woundSensorTable.PurgeAsync(true);
                    //await SensorDataService.Instance.watchSensorTable.PurgeAsync(true);

                    //if (StaticObjects.path.Length > 8e6)
                    //{
                    //    await SensorDataService.Instance.phoneSensorTable.PurgeAsync(true);
                    //    await SensorDataService.Instance.woundSensorTable.PurgeAsync(true);
                    //    await SensorDataService.Instance.watchSensorTable.PurgeAsync(true);
                    //}

                    var _message = new CollectionMessage
                    {
                        Message = "Push Complete. Waiting..."
                    };
                    Device.BeginInvokeOnMainThread(
                        () => MessagingCenter.Send(_message, "CollectionMessage")
                        );
                    //Thread.Sleep(30000);
                }

                catch (Exception ex)
                {
                    ExceptionErrorLogger.writeFileOnInternalStorage(ex.ToString());

                    var _message = new CollectionMessage {
                        Message = "Error Pushing"
                    };
                    Device.BeginInvokeOnMainThread(() => MessagingCenter.Send(_message, "CollectionMessage"));

                    var message = new NotifyMessage {
                        Message = "Error pushing to cloud. The job will restart soon (Maximum 15 minutes)"
                    };
                    Device.BeginInvokeOnMainThread(() => MessagingCenter.Send(_message, "NotifyMessage"));
                }
            });


            //Task.Run(async () =>
            //{

            //    try
            //    {
            //        if (!isRunning)
            //        {
            //            var sen = new SensorCollectionManager();
            //            await sen.PhoneSensorOperations(_cts.Token);
            //        }

            //    }
            //    catch (Exception ex)
            //    {
            //        ExceptionErrorLogger.writeFileOnInternalStorage(ex.ToString());
            //    }
            //    finally
            //    {
            //        if (_cts.IsCancellationRequested)
            //        {
            //            var message = new CancelledMessage();
            //            Device.BeginInvokeOnMainThread(
            //                () => MessagingCenter.Send(message, "CancelledMessage")
            //            );
            //        }
            //    }

            //    JobFinished(jobParameters, false);
            //});

            return(true);
        }