Example #1
0
        private void LoadSettings()
        {
            try
            {
                CognitoSyncViewModel.GetInstance().CreateDataset("Settings");
                string settingsStringFormat = CognitoSyncViewModel.GetInstance().ReadDataset("Settings", "UserSettings");
                if (settingsStringFormat == null)
                {
                    settings = new Settings();
                }
                else
                {
                    settings = JsonConvert.DeserializeObject <Settings>(settingsStringFormat);
                }

                this.car                     = settings.car;
                this.bike                    = settings.bike;
                this.publicTransport         = settings.publicTransport;
                this.minimizeCarbonFootPrint = settings.minimizeCarbonFootPrint;
                this.lunchBreak              = settings.lunchBreak;
                this.timeBreak               = settings.timeBreak;
                this.timeInterval            = settings.timeInterval.TotalMinutes.ToString();
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception.Message);
            }
        }
Example #2
0
        /* CalendarViewModel handles mostly all the events that may be triggered when interacting with buttons/gestures of CalendarPage, which may be, for example,
         * a change of view mode (Month mode to Years mode), a new page may be pushed (if Settings button is pressed, a SettingsPage() will be shown. If a new appointment is
         * added, we will switch to AppointmentCreationPage(). */
        public CalendarViewModel(CalendarPage page, INavigation navigation, RadCalendar calendar)
        {
            this.page       = page;
            this.navigation = navigation;
            this.calendar   = calendar;

            LoadAppointments();

            MessagingCenter.Subscribe <AppointmentCreationPage, object[]>(this, "CreationAppointments", (sender, values) =>
            {
                if (values[0].ToString() == "Update")
                {
                    Appointment oldAppointment = values[1] as Appointment;
                    appointmentsList.Remove(oldAppointment);
                    CognitoSyncViewModel.GetInstance().RemoveFromDataset(Constants.APPOINTMENTS_DATASET_NAME, oldAppointment.Key);
                }

                Appointment newAppointment = values[2] as Appointment;
                appointmentsList.Add(newAppointment);

                string json = JsonConvert.SerializeObject(newAppointment);
                CognitoSyncViewModel.GetInstance().WriteDataset(Constants.APPOINTMENTS_DATASET_NAME, newAppointment.Key, json);

                calendar.AppointmentsSource = AppointmentList;
            });

            calendar.AppointmentTapped += async(sender, e) =>
            {
                Appointment a  = (e.Appointment as Appointment);
                var         az = appointmentsList.FirstOrDefault(item => item.Title == a.Title && item.StartDate == a.StartDate && item.EndDate == a.EndDate && item.IsAllDay == a.IsAllDay);
                /* We can safely assume we got the key */
                a.Key = az.Key;
                await navigation.PushAsync(new AppointmentCreationPage(appointmentsList, "Update", a));
            };
        }
Example #3
0
        private async Task SyncSettings(Settings settings)
        {
            string settingJSON = JsonConvert.SerializeObject(settings);

            CognitoSyncViewModel.GetInstance().WriteDataset("Settings", "UserSettings", settingJSON);
            MessagingCenter.Send <SettingsPage> (this.page, "SettingsChangedEvent");
            await navigation.PopAsync();
        }
Example #4
0
        /// <summary>
        /// Removing the ticket.
        /// </summary>
        public void RemoveTicket(string name)
        {
            name = Tickets.FirstOrDefault(x => x.Value == name).Key;
            if (name != null)
            {
                Tickets.Remove(name);
            }

            CognitoSyncViewModel.GetInstance().RemoveFromDataset(DATASET_NAME, name);
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }
Example #5
0
        private void LoadAppointments()
        {
            appointmentsList = new ObservableCollection <Appointment>();
            CognitoSyncViewModel.GetInstance().CreateDataset(Constants.APPOINTMENTS_DATASET_NAME);
            IDictionary <string, string> appointments = CognitoSyncViewModel.GetInstance().ReadWholeDataset(Constants.APPOINTMENTS_DATASET_NAME);

            foreach (KeyValuePair <string, string> item in appointments)
            {
                Appointment a = JsonConvert.DeserializeObject <Appointment>(item.Value);
                a.Color = parseColor(item.Value);
                appointmentsList.Add(a);
            }
            calendar.AppointmentsSource = AppointmentList;
        }
Example #6
0
 /// <summary>
 /// Saving the ticket path in AWS and locally
 /// </summary>
 public void SaveTicket(string name, string path)
 {
     try
     {
         name = Regex.Replace(name, @"\s+", "");
         Tickets.Add(name, path);
         if (PropertyChanged != null)
         {
             PropertyChanged(this, null);
         }
     }
     catch (Exception e)
     {
         DependencyService.Get <IMessage> ().ShortAlert("Ticket already added");
     }
     CognitoSyncViewModel.GetInstance().WriteDataset(DATASET_NAME, name, path);
 }
Example #7
0
 private void ReadSettingsData()
 {
     try
     {
         CognitoSyncViewModel.GetInstance().CreateDataset("Settings");
         string  json       = CognitoSyncViewModel.GetInstance().ReadDataset("Settings", "UserSettings");
         JObject rootObject = JObject.Parse(json);
         settingsValue    = new object[3];
         settingsValue[0] = rootObject["lunchBreak"].ToObject <bool>();
         settingsValue[1] = rootObject["timeBreak"].ToObject <TimeSpan>();
         settingsValue[2] = rootObject["timeInterval"].ToObject <TimeSpan>();
     }
     catch (Exception e)
     {
         System.Diagnostics.Debug.WriteLine("Dataset does not exist. Exception: " + e.Message);
     }
 }
Example #8
0
 /// <summary>
 /// Loading the saved tickets.
 /// </summary>
 private IDictionary <string, string> LoadTickets()
 {
     CognitoSyncViewModel.GetInstance().CreateDataset("Tickets");
     return(CognitoSyncViewModel.GetInstance().ReadWholeDataset(DATASET_NAME));
 }
Example #9
0
 private LoginViewModel()
 {
     cognitoSyncViewModel = CognitoSyncViewModel.GetInstance();
 }