예제 #1
0
        public static void CreateNotification(TaskModel data)
        {
            // NghiaTT - Add toast notification
            // TODO: test
            const string xmlFormat = "<toast><visual><binding template='ToastText02'><text id='1'>{0}</text><text id='2'>{1}</text></binding></visual></toast>";
            var xmlString = string.Format(xmlFormat, data.Name, data.Description);
            var xmlDom = new XmlDocument();
            xmlDom.LoadXml(xmlString);
            var dueTime = RepositoryUtils.GetDateTimeFromStrings(data.StartDate, data.StartTime).AddSeconds(15); // 15' before the start time

            var endTime = RepositoryUtils.GetDateTimeFromStrings(data.EndDate, data.EndTime);

            var deviation = (endTime.Year * 365 + endTime.Month * 30 + endTime.Day) - (dueTime.Year * 365 + dueTime.Month * 30 + dueTime.Day);

            if (dueTime < DateTime.Now) return;
            //var dueTime = DateTime.Now.AddSeconds(5);
            ScheduledToastNotification toast;

            switch (data.RepeatType)
            {
                    // NghiaTT: Why 1e9?? Snooze a billion times?
                case 1:
                    toast = new ScheduledToastNotification(xmlDom, dueTime, TimeSpan.FromDays(1), (uint)1e9);
                    break;
                case 2:
                    try
                    {
                        toast = new ScheduledToastNotification(xmlDom, dueTime, TimeSpan.FromDays(7), (uint)1e9 / 7);
                    }
                    catch (Exception)
                    {
                        
                        throw;
                    }
                    
                    break;
                case 3:
                    // TODO: check for day in month
                    toast = new ScheduledToastNotification(xmlDom, dueTime, TimeSpan.FromDays(30), (uint)1e9 / 30);
                    break;
                case 4:
                    // TODO: check for leap year
                    toast = new ScheduledToastNotification(xmlDom, dueTime, TimeSpan.FromDays(365), (uint)1e9 / 365);
                    break;
                default:
                    toast = new ScheduledToastNotification(xmlDom, dueTime);
                    break;
            }
            toast.Id = data.ID.ToString();
            ToastNotificationManager.CreateToastNotifier().AddToSchedule(toast);
        }
예제 #2
0
 public TaskModel(TaskModel newTask)
 {
     ID = newTask.ID;
     Name = newTask.Name;
     Description = newTask.Description;
     Priority = newTask.Priority;
     Status = newTask.Status;
     Category = newTask.Category;
     RepeatType = newTask.RepeatType;
     Period = newTask.Period;
     StartTime = newTask.StartTime;
     StartDate = newTask.StartDate;
     EndTime = newTask.EndTime;
     EndDate = newTask.EndDate;
     UserID = newTask.UserID;
     ProjectID = newTask.ProjectID;
     IsConfirmed = newTask.IsConfirmed;
     IsBreakable = newTask.IsBreakable;
 }
예제 #3
0
        private async void BindingStaticData(TaskModel pim)
        {
            Status = new ObservableCollection<string> { LanguageProvider.Resource["Tsk_Status_NotDone"], LanguageProvider.Resource["Tsk_Status_Done"] };

            var temp = await ProjectRepository.Instance.GetAllProjects();
            if (temp != null)
            {
                var t = new ObservableCollection<ProjectInformationModel>(temp);
                    
                t.Insert(0,new ProjectInformationModel
                            {
                                ID = -1,
                                Name = LanguageProvider.Resource["Tsk_Project_None"]
                            });

                Projects = t;
                //SelectedProjectIndex = 0;//Projects.IndexOf(Projects.FirstOrDefault(p => p.ID == (Information.ProjectID ?? -1)));
            }

            _subCate = await CategoryRepository.Instance.GetSubCategories();
            _cate = await CategoryRepository.Instance.GetMainCategories();
            //Categories = new ObservableCollection<CategoryModel>(_subCate.Union(_cate));

            Priorities = await PriorityRepository.Instance.GetAllPriorities();
            RepeatTypes = await RepeatTypeRepository.Instance.GetAllRepeatTypes();

            //pim.ProjectID = -1;
            if (GlobalData.TemporaryTask != null)
            {
                Information = GlobalData.TemporaryTask;
            }
            else
            {
                if (pim.ID == -1)
                {
                    pim.UserID = GlobalData.MyUserID;
                }

                Information = new TaskModel(pim);
            }
        }
예제 #4
0
        public AddTaskViewModel(TaskModel pim)
        {
            Messenger.Instance.Register<RebindCbo>(Rebind);

            BindingStaticData(pim);
        }
예제 #5
0
        private async Task<HttpResponseMessage> EditUserCommit(int id, dynamic targetObject, bool edit = false)
        {
            try
            {
                //if (targetObject.StartDate != null)
                //{
                //    targetObject.StartDate =
                //        Convert.ToDateTime(targetObject.StartDate).ToString(CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern);
                //}

                //if (targetObject.EndDate != null)
                //{
                //    targetObject.EndDate =
                //        Convert.ToDateTime(targetObject.EndDate).ToString(CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern);
                //}

                // TODO: Emi commented out because exception in vietnamese
                //if (!edit)
                //{
                   
                //}

                var person = new TaskModel((TaskModel)targetObject)
                                 {
                                     StartDate = RepositoryUtils.JustifyDateTimeCulture(targetObject.StartDate),
                                     EndDate = RepositoryUtils.DateTimeCulture(targetObject.EndDate)
                                 };

                using (var ms = new MemoryStream())
                {
                    var djs = new DataContractJsonSerializer(typeof(TaskModel));
                    djs.WriteObject(ms, person);
                    ms.Position = 0;
                    var sc = new StreamContent(ms);
                    sc.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

                    var resp = id == -1
                                   ? await HttpClient.PostAsync(new Uri(ApiRoot), sc)
                                   : await HttpClient.PutAsync(new Uri(ApiRoot + @"/" + id), sc);

                    resp.EnsureSuccessStatusCode();
                    var tmp = await resp.Content.ReadAsStringAsync();
                    return resp;
                }

            }
            catch (Exception ex)
            {
                LogManager.Instance.LogException(ex.ToString());
                return new HttpResponseMessage(HttpStatusCode.NotModified);
            }
        }