コード例 #1
0
        public PlaySessionViewModel2(SessionModel session, INavigation navigation)
        {
            this.session          = session;
            Navigation            = navigation;
            sessionInit           = new SessionInit();
            sessionInit.SessionId = session.ID;
            sessionInit.Date      = DateTime.Now;

            Loading    = true;
            ColorFrame = "Red";

            lDeviceData = new List <DeviceData>();

            Title        = session.Name;
            ActivityName = session.ActivityName;

            ResetChronometer();

            ActivityModel activity = Json.getActivityByName(session.ActivityName);

            lDevices = new List <DeviceModel>(activity.Devices);

            BlobCache.UserAccount.InsertObject("currentActivity", activity);

            adapter = CrossBluetoothLE.Current.Adapter;

            SearchDevice();
        }
コード例 #2
0
 public int SaveSessionInit(SessionInit item)
 {
     if (item.ID != 0)
     {
         return(database.Update(item));
     }
     else
     {
         return(database.Insert(item));
     }
 }
コード例 #3
0
        private async void DeleteCommandExecute(SessionInit session)
        {
            var answer = await Application.Current.MainPage.DisplayAlert("Eliminar", "¿Desea eliminar el elemento?", "Si", "No");

            if (answer)
            {
                App.Database.DeleteSessionInit(session);
                await Application.Current.MainPage.DisplayAlert("Información", "Eliminado correctamente", "Aceptar");

                RefreshData();
            }
        }
コード例 #4
0
        public static void saveData(SessionInit sessionInit)
        {
            Debug.WriteLine("Guardando datos.....");
            App.Database.SaveSessionInit(sessionInit);

            foreach (DeviceData deviceData in lDeviceData)
            {
                SessionData sessionData = new SessionData();
                sessionData.SessionInitId = sessionInit.ID;
                sessionData.DeviceName    = deviceData.DeviceName;
                sessionData.Data          = deviceData.Data;
                App.Database.SaveSessionData(sessionData);
            }
        }
コード例 #5
0
        public PlaySessionViewModel(SessionModel session, INavigation navigation)
        {
            this.session          = session;
            Navigation            = navigation;
            sessionInit           = new SessionInit();
            sessionInit.SessionId = session.ID;
            sessionInit.Date      = DateTime.Now;

            Loading    = true;
            ColorFrame = "#e6475f";

            lDeviceData     = new List <DeviceData>();
            characteristics = new List <ICharacteristic>();

            /*source = new CancellationTokenSource();
             * token.WaitHandle.WaitOne(TimeSpan.FromSeconds(5));
             * token = source.Token;*/

            Title        = session.Name;
            ActivityName = session.ActivityName;

            ResetChronometer();
            Task.Run(() =>
            {
                currentActivity = Json.GetActivityByName(session.ActivityName);
                BlobCache.UserAccount.InsertObject("currentActivity", currentActivity);
                lDevices = new List <DeviceModel>(currentActivity.Devices);
            });

            adapter = CrossBluetoothLE.Current.Adapter;

            /*  Device.BeginInvokeOnMainThread(async () =>
             * {
             *    await InitBLEConexion(token);
             * });*/
        }
コード例 #6
0
        private async void TimerCommandExecute()
        {
            if (String.IsNullOrEmpty(StudentCode))
            {
                await Application.Current.MainPage.DisplayAlert("Atención", "Debe rellenar el código de alumno", "Aceptar");

                return;
            }

            if (!IsAllConnectedDevices(lDevices))
            {
                await Application.Current.MainPage.DisplayAlert("Atención", "Hay dispositivos que no están conectados. Por favor, pulse el botón reconnectar", "Aceptar");

                return;
            }

            sessionInit             = new SessionInit();
            sessionInit.SessionId   = session.ID;
            sessionInit.StudentCode = StudentCode;
            sessionInit.Date        = DateTime.Now;


            StudentCode = StudentCode;
            if (StartStop.Equals(INICIAR) || StartStop.Equals(REANUDAR))
            {
                StudentCodeEntry = false;
                StartStop        = DETENER;
            }
            else
            {
                StudentCodeEntry = true;
                StartStop        = INICIAR;
            }

            WriteDevices("1");

            Device.StartTimer(TimeSpan.FromMilliseconds(10), () =>
            {
                if (StartStop.Equals(INICIAR) || StartStop.Equals(REANUDAR))
                {
                    WriteDevices("0");
                    return(false);
                }
                else
                {
                    intMilliseconds += 10;

                    if (intMilliseconds == 1000)
                    {
                        intMilliseconds = 0;
                        intSeconds++;
                    }

                    if (intSeconds == 60)
                    {
                        intSeconds = 0;
                        intMinutes++;
                    }

                    if (intMinutes / 10 == 0)
                    {
                        Minutes = "0" + intMinutes.ToString();
                    }
                    else
                    {
                        Minutes = intMinutes.ToString();
                    }

                    if (intSeconds / 10 == 0)
                    {
                        Seconds = "0" + intSeconds.ToString();
                    }
                    else
                    {
                        Seconds = intSeconds.ToString();
                    }

                    if (intMilliseconds / 100 == 0)
                    {
                        Milliseconds = "0" + (intMilliseconds / 10).ToString();
                    }
                    else
                    {
                        Milliseconds = (intMilliseconds / 10).ToString();
                    }

                    return(true);
                }
            });

            if (StartStop.Equals(INICIAR))
            {
                StartStop = REANUDAR;
                var action = await Application.Current.MainPage.DisplayActionSheet("¿Que desea hacer?", PAUSAR, FINALIZAR);

                if (action.Equals(FINALIZAR))
                {
                    sessionInit.Time = Minutes + ":" + Seconds + ":" + Milliseconds;
                    ResetChronometer();
                    Debug.WriteLine("Guardando datos.....");
                    App.Database.SaveSessionInit(sessionInit);

                    foreach (DeviceData deviceData in lDeviceData)
                    {
                        SessionData sessionData = new SessionData();
                        sessionData.SessionInitId = sessionInit.ID;
                        sessionData.DeviceName    = deviceData.DeviceName;
                        sessionData.Data          = deviceData.Data;
                        App.Database.SaveSessionData(sessionData);
                    }
                }
            }
        }
コード例 #7
0
 public int DeleteSessionInit(SessionInit item)
 {
     DeleteSessionDataById(GetSessionData(item.ID));
     return(database.Delete(item));
 }
コード例 #8
0
        private async void TimerCommandExecute()
        {
            if (String.IsNullOrEmpty(StudentCode))
            {
                await Application.Current.MainPage.DisplayAlert("Atención", "Debe rellenar el código de alumno", "Aceptar");

                return;
            }

            if (!isAllConnectedDevices(lDevices))
            {
                Loading = true;
                var answer = await Application.Current.MainPage.DisplayAlert("Atención", "No se ha podido establecer conexión con todos los dispositivos. ¿Desea intentarlo de nuevo?", "Reintentar", "Cancelar");

                if (answer)
                {
                    await CrossBluetoothLE.Current.Adapter.StartScanningForDevicesAsync();

                    if (isAllConnectedDevices(lDevices))
                    {
                        ColorFrame = "Green";
                        Loading    = false;
                    }
                    else
                    {
                        ColorFrame = "Red";
                    }

                    return;
                }
                else
                {
                    Loading = false;
                }
            }

            sessionInit             = new SessionInit();
            sessionInit.SessionId   = session.ID;
            sessionInit.StudentCode = StudentCode;
            sessionInit.Date        = DateTime.Now;


            StudentCode = StudentCode;
            if (StartStop.Equals(INICIAR) || StartStop.Equals(REANUDAR))
            {
                StudentCodeEntry = false;
                StartStop        = DETENER;
            }
            else
            {
                StudentCodeEntry = true;
                StartStop        = INICIAR;
            }
            WriteDevices("1");

            Device.StartTimer(TimeSpan.FromMilliseconds(10), () =>
            {
                if (StartStop.Equals(INICIAR) || StartStop.Equals(REANUDAR))
                {
                    WriteDevices("0");
                    return(false);
                }
                else
                {
                    intMilliseconds = intMilliseconds + 10;

                    if (intMilliseconds == 1000)
                    {
                        intMilliseconds = 0;
                        intSeconds++;
                    }

                    if (intSeconds == 60)
                    {
                        intSeconds = 0;
                        intMinutes++;
                    }

                    if (intMinutes / 10 == 0)
                    {
                        Minutes = "0" + intMinutes.ToString();
                    }
                    else
                    {
                        Minutes = intMinutes.ToString();
                    }

                    if (intSeconds / 10 == 0)
                    {
                        Seconds = "0" + intSeconds.ToString();
                    }
                    else
                    {
                        Seconds = intSeconds.ToString();
                    }

                    if (intMilliseconds / 100 == 0)
                    {
                        Milliseconds = "0" + (intMilliseconds / 10).ToString();
                    }
                    else
                    {
                        Milliseconds = (intMilliseconds / 10).ToString();
                    }

                    return(true);
                }
            });

            if (StartStop.Equals(INICIAR))
            {
                StartStop = REANUDAR;
                var action = await Application.Current.MainPage.DisplayActionSheet("¿Que desea hacer?", PAUSAR, FINALIZAR);

                if (action.Equals(FINALIZAR))
                {
                    sessionInit.Time = Minutes + ":" + Seconds + ":" + Milliseconds;
                    ResetChronometer();
                    ConnectDevices.saveData(sessionInit);
                }
            }
        }