private async Task <bool> SaveFolderDto(IKntService service, Guid?userId, CarpetaExport carpetaExport, Guid?parent, List <EtiquetaExport> etiquetas) { string r11 = "\r\n"; string r12 = "\n"; string r21 = "&#x"; string r22 = "$$$"; int nErrors = 0; #region Import customization //// afumfer //// ....... //string r31 = @"D:\KaNote\Resources\ImgsEditorHtml"; //string r32 = @"D:\Anotas\Docs\__Imgs_!!ANTHtmlEditor!!_"; //string r41 = @"D:\KaNote\Resources\ImgsEditorHtml"; //string r42 = @"C:\Anotas\Docs\__Imgs_!!ANTHtmlEditor!!_"; //string r51 = @"_KNTERRORTRAP"; //string r52 = @"_ANTERRORTRAP"; //string r61 = @"_KNTERRORCODE"; //string r62 = @"_ANTERRORCODE"; //string r71 = @"_KNTERRORDESCRIPTION"; //string r72 = @"_ANTERRORDESCRIPTION"; //string r81 = ""; //string r82 = "[!ExecuteAnTScriptBGroundThread]"; //string r91 = ""; //string r92 = "_ANTForm.Exit();"; #endregion string r31 = @"KntResCon/"; string r32 = @"\\educacion.org\Almacen\Pincel\TareasTM\Doc\"; string r41 = @"KntResCon/"; string r42 = @"\\educacion.org\Almacen\Pincel\tareasTM\Doc\"; string r51 = @"KntResCon/"; string r52 = @"\\Educacion.org\Almacen\Pincel\TareasTM\Doc\"; var newFolderDto = new FolderDto { FolderNumber = carpetaExport.IdCarpeta, //FolderNumber = 0, Name = carpetaExport.NombreCarpeta, Order = carpetaExport.Orden, OrderNotes = carpetaExport.OrdenNotas, ParentId = parent }; var resNewFolder = await service.Folders.SaveAsync(newFolderDto); label1.Text = $"Added folder: {resNewFolder.Entity?.Name}"; label1.Refresh(); var folder = resNewFolder.Entity; foreach (var n in carpetaExport.Notas) { try { if (n.DescripcionNota.Contains(r12)) { // Hack multiples CR LF n.DescripcionNota = n.DescripcionNota.Replace(r12, r11); // Hack for problems in deserialization n.DescripcionNota = n.DescripcionNota.Replace(r22, r21); } #region Import customization //// afumfer //// ....... //// Hack inserted resources change n.DescripcionNota = n.DescripcionNota.Replace(r32, r31); n.DescripcionNota = n.DescripcionNota.Replace(r42, r41); n.DescripcionNota = n.DescripcionNota.Replace(r52, r51); //n.DescripcionNota = n.DescripcionNota.Replace(r62, r61); //n.DescripcionNota = n.DescripcionNota.Replace(r72, r71); //n.DescripcionNota = n.DescripcionNota.Replace(r82, r81); //n.DescripcionNota = n.DescripcionNota.Replace(r92, r91); #endregion (string descriptionNew, string scriptCode) = ExtractAnTScriptCode(n.DescripcionNota); DateTime fecMod; if (n.FechaModificacion > n.FechaHoraCreacion) { fecMod = n.FechaModificacion; } else { fecMod = n.FechaHoraCreacion; } var newNote = new NoteExtendedDto { FolderId = folder.FolderId, NoteNumber = n.IdNota, //NoteNumber = 0, Description = descriptionNew, Script = scriptCode, Topic = n.Asunto, CreationDateTime = n.FechaHoraCreacion, ModificationDateTime = fecMod, Tags = n.PalabrasClave, InternalTags = n.Vinculo, Priority = n.Prioridad }; if (!newNote.Tags.Contains("UC=")) { if ("afumfer fdomher jurivmar sesther sleoare dgoddelw".Contains(n.Usuario)) { if (!string.IsNullOrEmpty(newNote.Tags)) { newNote.Tags += "; "; } newNote.Tags += "UC=" + n.Usuario; } } // Add task if (n.FechaInicio > new DateTime(1901, 1, 1) || n.FechaResolucion > new DateTime(1901, 1, 1) || n.FechaPrevistaInicio > new DateTime(1901, 1, 1) || n.FechaPrevistaFin > new DateTime(1901, 1, 1) || n.Resuelto == true) { NoteTaskDto task = new NoteTaskDto { NoteId = Guid.Empty, UserId = (Guid)userId, CreationDateTime = n.FechaHoraCreacion, ModificationDateTime = fecMod, Description = newNote.Topic, Tags = "(ANotas import)", Priority = 1, Resolved = n.Resuelto, EstimatedTime = n.TiempoEstimado, SpentTime = n.TiempoInvertido, DifficultyLevel = n.NivelDificultad, ExpectedEndDate = n.FechaPrevistaFin, ExpectedStartDate = n.FechaPrevistaInicio, EndDate = n.FechaResolucion, StartDate = n.FechaInicio }; newNote.Tasks.Add(task); } // Add alarm if (n.Alarma > new DateTime(1901, 1, 1)) { var message = new KMessageDto { NoteId = Guid.Empty, UserId = userId, AlarmActivated = n.ActivarAlarma, ActionType = EnumActionType.UserAlarm, Comment = "(import ANotas)", AlarmDateTime = n.Alarma }; // Alarm type switch (n.TipoAlarma) { case 0: // estandar message.AlarmType = EnumAlarmType.Standard; break; case 1: // diaria message.AlarmType = EnumAlarmType.Daily; break; case 2: // semanal message.AlarmType = EnumAlarmType.Weekly; break; case 3: // mensual message.AlarmType = EnumAlarmType.Monthly; break; case 4: // anual message.AlarmType = EnumAlarmType.Annual; break; case 5: // cada hora message.AlarmType = EnumAlarmType.InMinutes; message.AlarmMinutes = 60; break; case 6: // 4 horas message.AlarmType = EnumAlarmType.InMinutes; message.AlarmMinutes = 60 * 4; break; case 7: // 8 horas message.AlarmType = EnumAlarmType.InMinutes; message.AlarmMinutes = 60 * 8; break; case 8: // 12 diaria message.AlarmType = EnumAlarmType.InMinutes; message.AlarmMinutes = 60 * 12; break; default: message.AlarmType = EnumAlarmType.Standard; break; } newNote.Messages.Add(message); } // Add resource if (!string.IsNullOrEmpty(n.NotaEx)) { #region Import resources for ContendInDB = true //// TODO: Refactor this line //var root = @"D:\ANotas\Docs"; //var fileFullName = $"{root}{n.NotaEx}"; //if (File.Exists(fileFullName)) //{ // var fileArrayBytes = File.ReadAllBytes(fileFullName); // var contentBase64 = Convert.ToBase64String(fileArrayBytes); // ResourceDto resource = new ResourceDto // { // NoteId = Guid.Empty, // ContentInDB = true, // Order = 1, // Container = service.RepositoryRef.ResourcesContainer + "\\" + DateTime.Now.Year.ToString(), // Name = $"{Guid.NewGuid()}_{Path.GetFileName(fileFullName)}", // Description = $"(ANotas import {n.NotaEx})", // ContentArrayBytes = fileArrayBytes, // ContentBase64 = contentBase64, // FileType = _store.ExtensionFileToFileType(Path.GetExtension(fileFullName)) // }; // newNote.Resources.Add(resource); //} #endregion #region Import resources for ContendInDB = false if (n.NotaEx[0] == '\\') { n.NotaEx = n.NotaEx.Substring(1); } string fileImport = Path.Combine(new[] { service.RepositoryRef.ResourcesContainerCacheRootPath, service.RepositoryRef.ResourcesContainer, n.NotaEx }); ResourceDto resource = new ResourceDto { NoteId = Guid.Empty, ContentInDB = false, Order = 1, Container = service.RepositoryRef.ResourcesContainer, Name = n.NotaEx, Description = $"(ANotas import {n.NotaEx})", ContentArrayBytes = null, ContentBase64 = null, FileType = _store.ExtensionFileToFileType(Path.GetExtension(fileImport)) }; newNote.Resources.Add(resource); #endregion } // Save note and PostIt Result <NoteExtendedDto> resNewNote = null; if (newNote.IsValid()) { resNewNote = await service.Notes.SaveExtendedAsync(newNote); label2.Text = $"Added note: {resNewNote.Entity?.Topic} - {resNewNote.Entity?.NoteId.ToString()}"; // Add Window WindowDto windowPostIt = new WindowDto { NoteId = resNewNote.Entity.NoteId, UserId = (Guid)userId, Visible = false, //n.Visible, AlwaysOnTop = n.SiempreArriba, PosX = n.PosX, PosY = n.PosY, Width = n.Ancho, Height = n.Alto, FontName = n.FontName, FontSize = n.FontSize, FontBold = n.FontBold, FontItalic = n.FontItalic, FontUnderline = n.FontUnderline, FontStrikethru = n.FontStrikethru, ForeColor = ColorTranslator.ToHtml(ColorTranslator.FromOle(n.ForeColor)), TitleColor = ColorTranslator.ToHtml(ColorTranslator.FromOle(n.ColorBanda)), TextTitleColor = ColorTranslator.ToHtml(ColorTranslator.FromOle(n.ForeColor)), NoteColor = ColorTranslator.ToHtml(ColorTranslator.FromOle(n.ColorNota)), TextNoteColor = ColorTranslator.ToHtml(ColorTranslator.FromOle(n.ForeColor)) }; var resNewPostIt = await service.Notes.SaveWindowAsync(windowPostIt); } else { label2.Text = $"Added note: ERROR invalid note."; var msgErr = newNote.GetErrorMessage(); MessageBox.Show($"ERROR invalid note: {msgErr}"); } label2.Refresh(); } catch (Exception ex) { // TODO: hack, hay un registro erróneo en la exportación. nErrors++; if (nErrors > 1) { MessageBox.Show($"Más de error. Error: {ex.Message}"); } //throw; } } // For each folder child all recursively to this method foreach (var c in carpetaExport.CarpetasHijas) { await SaveFolderDto(service, userId, c, folder.FolderId, etiquetas); } return(await Task.FromResult <bool>(true)); }
public async Task <Result <NoteExtendedDto> > SaveExtendedAsync(NoteExtendedDto entity) { var result = new Result <NoteExtendedDto>(); entity.InternalTags = GetNoteStatus(entity.Tasks, entity.Messages); if (entity.IsDirty()) { var resNote = await SaveAsync(entity.GetSimpleDto <NoteDto>(), false); result.Entity = resNote.Entity.GetSimpleDto <NoteExtendedDto>(); } else { result.Entity = entity; } var noteEdited = result.Entity; foreach (var item in entity.Messages) { if (item.IsDeleted()) { var res = await DeleteMessageAsync(item.KMessageId); if (!res.IsValid) { CopyErrorList(res.ErrorList, result.ErrorList); } } else if (item.IsDirty()) { if (item.NoteId == Guid.Empty) { item.NoteId = noteEdited.NoteId; } var res = await SaveMessageAsync(item, true); if (!res.IsValid) { CopyErrorList(res.ErrorList, result.ErrorList); } else { result.Entity.Messages.Add(res.Entity); } } else { result.Entity.Messages.Add(item); } } entity.Messages.RemoveAll(m => m.IsDeleted()); foreach (var item in entity.Resources) { if (item.IsDeleted()) { var res = await DeleteResourceAsync(item.ResourceId); if (!res.IsValid) { CopyErrorList(res.ErrorList, result.ErrorList); } } else if (item.IsDirty()) { if (item.NoteId == Guid.Empty) { item.NoteId = noteEdited.NoteId; } var res = await SaveResourceAsync(item, true); if (!res.IsValid) { CopyErrorList(res.ErrorList, result.ErrorList); } else { result.Entity.Resources.Add(res.Entity); } } else { result.Entity.Resources.Add(item); } } entity.Resources.RemoveAll(r => r.IsDeleted()); foreach (var item in entity.Tasks) { if (item.IsDeleted()) { var res = await DeleteNoteTaskAsync(item.NoteTaskId); if (!res.IsValid) { CopyErrorList(res.ErrorList, result.ErrorList); } } else if (item.IsDirty()) { if (item.NoteId == Guid.Empty) { item.NoteId = noteEdited.NoteId; } var res = await SaveNoteTaskAsync(item, true); if (!res.IsValid) { CopyErrorList(res.ErrorList, result.ErrorList); } else { result.Entity.Tasks.Add(res.Entity); } } else { result.Entity.Tasks.Add(item); } } entity.Tasks.RemoveAll(t => t.IsDeleted()); return(result); }