/// <summary> /// Сгенерить задачу для json /// </summary> /// <param name="root"></param> /// <param name="id"></param> /// <param name="task"></param> /// <returns></returns> public static TASK GetTaskJSON(RootObject root, ref int id, Task task) { var repeatNew = ""; var repeatFrom = 0; var dueDateModifier = "0"; var dueDate = task.EndDate; var priority = 0; switch (task.Recurrense.TypeInterval) { case TimeIntervals.Нет: dueDateModifier = "2"; repeatNew = ""; repeatFrom = 0; dueDate = task.BeginDateProperty == DateTime.MinValue ? MainViewModel.selectedTime : task.BeginDateProperty; priority = -1; break; case TimeIntervals.Сразу: dueDateModifier = "1"; repeatFrom = 1; repeatNew = "Every 1 day"; dueDate = task.EndDate; priority = 1; break; case TimeIntervals.Ежедневно: dueDateModifier = "1"; repeatFrom = 1; repeatNew = "Daily"; dueDate = task.EndDate; priority = 1; break; case TimeIntervals.Будни: dueDateModifier = "1"; repeatFrom = 1; repeatNew = "BusinessDay"; dueDate = task.EndDate; priority = 1; break; case TimeIntervals.Выходные: dueDateModifier = "1"; repeatFrom = 1; repeatNew = "Weekend"; dueDate = task.EndDate; priority = 1; break; case TimeIntervals.День: case TimeIntervals.ДниСначала: dueDateModifier = "1"; repeatFrom = 1; repeatNew = $"Every {task.Recurrense.Interval} day"; dueDate = task.BeginDateProperty == DateTime.MinValue ? MainViewModel.selectedTime : task.BeginDateProperty; priority = 1; break; case TimeIntervals.Неделя: case TimeIntervals.НеделиСНачала: dueDateModifier = "1"; repeatFrom = 1; repeatNew = $"Every {task.Recurrense.Interval} Weeks"; dueDate = task.BeginDateProperty == DateTime.MinValue ? MainViewModel.selectedTime : task.BeginDateProperty; priority = 2; break; case TimeIntervals.МесяцыСНачала: case TimeIntervals.Месяц: dueDateModifier = "1"; repeatFrom = 1; repeatNew = $"Every {task.Recurrense.Interval} Month"; dueDate = task.BeginDateProperty == DateTime.MinValue ? MainViewModel.selectedTime : task.BeginDateProperty; priority = 2; break; case TimeIntervals.ДниНедели: case TimeIntervals.ДниНеделиСНачала: dueDateModifier = "1"; repeatFrom = 1; var weekDays = string.Empty; foreach (var source in task.DaysOfWeekRepeats.Where(n => n.CheckedProperty)) { if (!string.IsNullOrEmpty(weekDays)) { weekDays += ", "; } switch (source.Day) { case DayOfWeek.Monday: weekDays += "Mon"; break; case DayOfWeek.Tuesday: weekDays += "Tue"; break; case DayOfWeek.Wednesday: weekDays += "Wed"; break; case DayOfWeek.Thursday: weekDays += "Thu"; break; case DayOfWeek.Friday: weekDays += "Fri"; break; case DayOfWeek.Saturday: weekDays += "Sat"; break; case DayOfWeek.Sunday: weekDays += "Sun"; break; } } repeatNew = $"Every {weekDays}"; dueDate = task.BeginDateProperty == DateTime.MinValue ? MainViewModel.selectedTime : task.BeginDateProperty; priority = 2; break; } // Контексты для задачи var context = task.Recurrense.TypeInterval == TimeIntervals.Нет? root.CONTEXT[1]: root.CONTEXT[0]; var tag = GetTagsForTask(root, task); dueDate = dueDate >= task.BeginDateProperty ? dueDate : task.BeginDateProperty; dueDate = dueDate >= MainViewModel.selectedTime ? dueDate : MainViewModel.selectedTime; var taskJson = new TASK { ID = id, NOTE = task.GUID, TITLE = task.NameOfProperty + task.GetPlusName(true), PRIORITY = priority, DUE_DATE = GetDateJSON(dueDate), DUE_DATE_MODIFIER = dueDateModifier, CONTEXT = context.ID, TAG = tag, CREATED = GetDateJSON(MainViewModel.selectedTime), MODIFIED = GetDateJSON(MainViewModel.selectedTime), REMINDER = -1, START_DATE = GetDateJSON(DateTime.MinValue), HIDE = 0, HIDE_UNTIL = 0, REPEAT_FROM = 0, REPEAT_NEW = repeatNew, START_TIME_SET = 0, STATUS = StaticMetods.PersProperty.Statuses.IndexOf(task.TaskStatus) }; return(taskJson); }
private static void GetTasks(Pers pers, RootObject root, int id) { var tasks = pers.Tasks.Where(n => n.IsEnabled).OrderBy(n => n); Action <Sample.Model.TASK, Task> setDateAndro = (TASK, tsk) => { DateTime dt = new DateTime(tsk.BeginDateProperty.Year, tsk.BeginDateProperty.Month, tsk.BeginDateProperty.Day); dt = dt.AddMinutes(tsk.EndMinutesAndroid); TASK.DUE_DATE = GetDateJSON(dt); TASK.DUE_TIME_SET = 1; }; DateTime dtt = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day); foreach (var task in tasks) { task.EndMinutesAndroid = Convert.ToInt32(task.TimeProperty.TimeOfDay.TotalMinutes); } int counter = 100; // Задачи скиллов foreach (var task in tasks.Where(n => n.IsSkill)) { var taskJson = GetTaskJSON(root, ref id, task); var ctr = counter.ToString().Remove(0, 1); taskJson.TITLE = $"{ctr}) {taskJson.TITLE}"; counter++; setDateAndro(taskJson, task); taskJson.STATUS = 1; root.TASK.Add(taskJson); id++; } // Квесты var qw = pers.Aims.Where(n => n.IsActiveProperty && !n.IsDoneProperty).OrderBy(n => n).ToList(); foreach (var qwest in qw) { int status = 3; DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); dt = dt.AddMinutes(qw.IndexOf(qwest)); var qwNeeds = qwest.NeedsTasks.Select(n => n.TaskProperty).Where(n => n.IsEnabled).ToList(); if (!qwNeeds.Any()) { continue; } // Добавляем квест var taskJson = new TASK { ID = id, NOTE = qwest.GUID, TITLE = $"Квест \"{qwest.NameOfProperty}\"", PRIORITY = 1, DUE_DATE = GetDateJSON(MainViewModel.selectedTime.AddHours(23).AddMinutes(59)), DUE_TIME_SET = 1, DUE_DATE_PROJECT = GetDateJSON(MainViewModel.selectedTime.AddHours(23).AddMinutes(59)), CREATED = GetDateJSON(MainViewModel.selectedTime), MODIFIED = GetDateJSON(MainViewModel.selectedTime), REMINDER = -1, START_DATE = GetDateJSON(DateTime.MinValue), HIDE = 0, HIDE_UNTIL = 0, REPEAT_FROM = 0, START_TIME_SET = 0, TYPE = 1, STATUS = status }; taskJson.TITLE = $"{counter.ToString().Remove(0,1)}) {taskJson.TITLE}"; counter++; List <object> tag = qwest.AbilitiLinksOf.Select(abilitiModel => root.TAG.First(n => n.UUID == abilitiModel.GUID).ID).Cast <object>().ToList(); foreach (var source in qwest.NeedsTasks.Select(n => n.TaskProperty)) { tag.AddRange(GetTagsForTask(root, source)); } tag = tag.Distinct().ToList(); taskJson.CONTEXT = root.CONTEXT[1].ID; taskJson.STATUS = status; taskJson.TAG = tag; root.TASK.Add(taskJson); id++; int counter2 = 100; //Задачи квеста foreach (var tsk in qwNeeds.OrderBy(n => n)) { var taskJson2 = new TASK { ID = id, NOTE = tsk.GUID, TITLE = tsk.NameOfProperty, PRIORITY = -1, CREATED = GetDateJSON(MainViewModel.selectedTime), MODIFIED = GetDateJSON(MainViewModel.selectedTime), REMINDER = -1, START_DATE = GetDateJSON(DateTime.MinValue), HIDE = 0, HIDE_UNTIL = 0, REPEAT_FROM = 0, START_TIME_SET = 0, PARENT = taskJson.ID, STATUS = status }; taskJson2.CONTEXT = root.CONTEXT[1].ID; taskJson2.TITLE = $"{counter2.ToString().Remove(0,1)}) {taskJson2.TITLE}"; counter2++; setDateAndro(taskJson2, tsk); root.TASK.Add(taskJson2); id++; } } }
public static RootObject SerializeToAndroidJSON(Pers pers, string path) { StaticMetods.Locator.MainVM.RefreshTasksPriority(false); // Задаем индекс для задач int i = 0; var ordered = pers.Tasks.OrderByDescending(n => n).ToList();//pers.Tasks.OrderBy(n => n).ToList(); foreach (var task in ordered) { task.TaskIndex = i; i++; } RootObject ro = new RootObject { PersName = pers.NameOfProperty, PersRang = pers.RangName, PersExp = pers.PersExpProperty, Is10AbLevels = pers.PersSettings.Is10AbLevels, Is5_5_50 = pers.PersSettings.Is5_5_50, IsFUDGE = pers.PersSettings.IsFUDGE, IsParetto = pers.IsParetto, DateOfLastUse = pers.DateOfLastUse.ToString("dd.MM.yyyy"), IsShowTasksByTimeAndroid = pers.PersSettings.IsShowTasksByTimeAndroid, TimeOfLastUse = string.Empty, IsSmartSort = pers.PersSettings.IsSmartTaskSort, IsSortByPrioryty = pers.IsSortByPrioryty, MaxGettedExp = pers.MaxGettedExp, HP = pers.HP, MaxHP = pers.MaxHP, BalanceIs50Levels = pers.BalanceIs50Levels, BalanceForFirstLevel = pers.BalanceForFirstLevel, BalanceForLastLevel = pers.BalanceForLastLevel, BalanceLevels = pers.BalanceLevels }; var tasks = pers.Tasks.Where(n => n.IsEnabled) .Where(n => !n.RelToQwests.Any() && !n.TaskInAbilitis.Any()) .OrderBy(n => n) .ToList(); List <Task> tsks = tasks.Select(GetTask).ToList(); ro.Tasks = new List <Task>(); ro.Qwests = new List <Qwest>(); ro.Abils = new List <AbilityAndroid>(); ro.Characts = new List <CharacteristicAndroid>(); foreach (var cha in pers.Characteristics) { CharacteristicAndroid chaA = new CharacteristicAndroid(cha.NameOfProperty, cha.CellValue, cha.RelayAbilitys.Select(n => new AbilityAndroid(n.AbilProperty.NameOfProperty, n.AbilProperty.CellValue)).ToList()); ro.Characts.Add(chaA); } // скиллы заполняем var ab = pers.Abilitis.Where(n => n.IsEnebledProperty).OrderBy(n => n).ToList(); foreach (var abilitiModel in ab) { ro.Abils.Add(new AbilityAndroid() { Guid = abilitiModel.GUID, Name = abilitiModel.NameOfProperty, Modificator = abilitiModel.Booster, Value = abilitiModel.ValueProperty, LastValue = abilitiModel.LastValue, ExpOneLevel = abilitiModel.getPriorOfAb(abilitiModel) }); Qwest qww = new Qwest(); qww.NotOneByOne = !pers.PersSettings.IsHideTasksOneByOneAndroid; qww.NameOfQwest = abilitiModel.NameOfProperty; qww.Guid = abilitiModel.GUID; var tskss = abilitiModel.NeedTasks .Where(n => n.TaskProperty.IsEnabled) .Where(n => { if (StaticMetods.PersProperty.IsParetto && n.TaskProperty.Recurrense.TypeInterval != TimeIntervals.Нет && n.TaskProperty.isSuper == false) { return(false); } return(true); }) .Select(n => n.TaskProperty) .OrderBy(n => n) .ToList(); var tsk = tskss.Select(GetTask).ToList(); //tsk.ForEach(n => n.LinksOf = abilitiModel.NameOfProperty); foreach (Task task in tsk) { task.SubTasksByQwests = GetSubTasksByQwests(abilitiModel, pers, task); } qww.Tasks = tsk; ro.Qwests.Add(qww); } // А теперь квесты заполняем var qw = pers.Aims.Where(QwestsActiveForAndroid()).OrderBy(n => n).ToList(); foreach (var qwest in qw) { Qwest qww = new Qwest(); qww.NameOfQwest = qwest.NameOfProperty; qww.Guid = qwest.GUID; var tskss = qwest.NeedsTasks.Where(n => !n.TaskProperty.IsDelProperty) .Select(n => n.TaskProperty) .OrderBy(n => n) .ToList(); qww.Tasks = tskss.Select(GetTask).ToList(); foreach (var task in qww.Tasks.Skip(1)) { var fod = qww.Tasks.FirstOrDefault(); if (fod != null) { if (getDateFromTaskAndroDateString(task.Date) < getDateFromTaskAndroDateString(fod.Date)) { task.Date = fod.Date; } } } //List<string> lnkLst = new List<string>(); //lnkLst.AddRange(qwest.AbilitiLinksOf.Select(n=>n.NameOfProperty)); string lnkOf = qwest.NameOfProperty; if (qwest.AbilitiLinksOf.Any()) { lnkOf = " ⇉ "; } // + " ⇉ " + string.Join(", ", lnkLst); qww.Tasks.ForEach(n => n.LinksOf = lnkOf); if (qwest.AbilitiLinksOf.Any()) { foreach (var task in qww.Tasks) { task.LinkedQwests = qwest.AbilitiLinksOf.Select(n => n.GUID).ToList(); } } foreach (var task in qww.Tasks) { task.SubTasksByQwests = GetSubTasksByQwests(null, pers, task); } ro.Qwests.Add(qww); } // Заполняем просто задачи, но запихиваем их в квест Qwest qw1 = new Qwest(); qw1.NameOfQwest = "Прочее"; qw1.Guid = Guid.NewGuid().ToString(); qw1.Tasks = tsks.Distinct().ToList(); qw1.NotOneByOne = true; foreach (var n in qw1.Tasks) { n.LinksOf = qw1.NameOfQwest; } ro.Qwests.Add(qw1); foreach (var task in ro.Tasks.ToList()) { AndroSub(pers, task, ro); AndroSetTask(task, path); } foreach (var qwest in ro.Qwests.ToList()) { foreach (var task in qwest.Tasks) { AndroSub(pers, task, ro); AndroSetTask(task, path); } } return(ro); }