コード例 #1
0
ファイル: KntNoteService.cs プロジェクト: afumfer/KNote
        public async Task <Result <KMessageDto> > SaveMessageAsync(KMessageDto entity, bool forceNew = false)
        {
            Result <KMessageDto> resSavedEntity;

            if (entity.KMessageId == Guid.Empty)
            {
                entity.KMessageId = Guid.NewGuid();
                resSavedEntity    = await _repository.Notes.AddMessageAsync(entity);
            }
            else
            {
                if (!forceNew)
                {
                    resSavedEntity = await _repository.Notes.UpdateMessageAsync(entity);
                }
                else
                {
                    var checkExist = await GetMessageAsync(entity.KMessageId);

                    if (checkExist.IsValid)
                    {
                        resSavedEntity = await _repository.Notes.UpdateMessageAsync(entity);
                    }
                    else
                    {
                        resSavedEntity = await _repository.Notes.AddMessageAsync(entity);
                    }
                }
            }

            resSavedEntity.Entity.UserFullName = entity.UserFullName;
            return(resSavedEntity);
        }
コード例 #2
0
    public async Task <bool> DeleteMessage(Guid messageId)
    {
        var messageEditor = new MessageEditorComponent(Store);

        messageEditor.AutoDBSave = false;  // don't save automatically

        var res = await messageEditor.DeleteModel(Service, messageId);

        if (res)
        {
            KMessageDto msgDel = null;
            foreach (var item in Model.Messages)
            {
                if (item.KMessageId == messageId)
                {
                    msgDel = item;
                    break;
                }
            }

            if (msgDel != null)
            {
                if (msgDel.IsNew())
                {
                    Model.Messages.Remove(msgDel);
                }
                else
                {
                    msgDel.SetIsDeleted(true);
                }
            }
        }

        return(res);
    }
コード例 #3
0
ファイル: NoteEditorForm.cs プロジェクト: afumfer/KNote
    private void UpdateMessage(KMessageDto message)
    {
        var item = listViewAlarms.Items[message.KMessageId.ToString()];

        item.SubItems[1].Text = message.AlarmActivated.ToString();
        item.SubItems[2].Text = message.AlarmDateTime.ToString();
        item.SubItems[3].Text = message.AlarmType.ToString();
        item.SubItems[4].Text = message.AlarmMinutes.ToString();
        item.SubItems[5].Text = message.NotificationType.ToString();
        item.SubItems[6].Text = message.Comment.ToString();
    }
コード例 #4
0
ファイル: NoteEditorForm.cs プロジェクト: afumfer/KNote
    private ListViewItem MessageDtoToListViewItem(KMessageDto message)
    {
        var itemList = new ListViewItem(message.UserFullName);

        itemList.Name = message.KMessageId.ToString();
        itemList.SubItems.Add(message.AlarmActivated.ToString());
        itemList.SubItems.Add(message.AlarmDateTime.ToString());
        itemList.SubItems.Add(message.AlarmType.ToString());
        itemList.SubItems.Add(message.AlarmMinutes.ToString());
        itemList.SubItems.Add(message.NotificationType.ToString());
        itemList.SubItems.Add(message.Comment.ToString());
        return(itemList);
    }
コード例 #5
0
    private async Task <bool> SaveFastModelAlarm(string unitTime, int value)
    {
        DateTime?alarmDateTime = null;

        switch (unitTime)
        {
        case "m":
            alarmDateTime = DateTime.Now.AddMinutes(value);
            break;

        case "h":
            alarmDateTime = DateTime.Now.AddMinutes(value * 60);
            break;

        case "week":
            alarmDateTime = DateTime.Now.AddDays(7);
            break;

        case "month":
            alarmDateTime = DateTime.Now.AddMonths(1);
            break;

        case "year":
            alarmDateTime = DateTime.Now.AddYears(1);
            break;

        default:
            break;
        }

        var alarm = new KMessageDto
        {
            NoteId           = Model.NoteId,
            UserId           = await PostItGetUserId(),
            ActionType       = EnumActionType.NoteAlarm,
            NotificationType = EnumNotificationType.PostIt,
            AlarmType        = EnumAlarmType.Standard,
            AlarmDateTime    = alarmDateTime,
            AlarmMinutes     = 0,
            Comment          = "(Fast alarm)",
            AlarmActivated   = true
        };

        var resSaveMsg = await Service.Notes.SaveMessageAsync(alarm, true);

        return(await Task.FromResult <bool>(resSaveMsg.IsValid));
    }
コード例 #6
0
ファイル: LabForm.cs プロジェクト: afumfer/KNote
    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));
    }