示例#1
0
 public Workspace(Note note)
 {
     id = note.ID;
     title = note.Title;
     var encryptedContent = note.Content;
     this.content = string.IsNullOrEmpty(encryptedContent) ? string.Empty : this.crypto.Decrypt(encryptedContent);
     datePublished = note.DatePublished;
     isSaved = true;
 }
示例#2
0
 /// <summary>
 ///     Performs the export.
 /// </summary>
 /// <param name="fileName">Name of the file to which the note will be exported.</param>
 /// <param name="note">The note that is being exported.</param>
 /// <param name="options">The options for the exporting.</param>
 /// <remarks>
 ///     When the <c>OptionDialog</c> is not null, the <paramref name="options" /> value
 ///     represents the options collected from the <c>OptionDialog</c>. Otherwise the options
 ///     value will be null.
 /// </remarks>
 protected override void DoExport(string fileName, Note note, object options)
 {
     var content = HtmlUtilities.ReplaceFileSystemImages(note.Content);
     File.WriteAllText(fileName, content, Encoding.UTF8);
 }
 /// <summary>
 /// Creates the note asynchronously.
 /// </summary>
 /// <param name="note">The note object to be created.</param>
 /// <returns>
 /// The <see cref="Task" /> that returns the <see cref="Guid" /> value which represents the ID of the note that is newly created.
 /// </returns>
 public async override Task<Guid> CreateNoteAsync(Note note)
 {
     var result =
         await
             this.serviceProxy.PostAsJsonAsync(
                 "api/notes/create",
                 new {note.Title, Content = note.Content, Weather = "Unspecified"});
     result.EnsureSuccessStatusCode();
     return new Guid((await result.Content.ReadAsStringAsync()).Trim('\"'));
 }
 public async override Task UpdateNoteAsync(Note note)
 {
     var result =
                 await
                     serviceProxy.PostAsJsonAsync(
                         "api/notes/update",
                         new
                         {
                             note.ID,
                             note.Title,
                             note.Content,
                             Weather = "Unspecified"
                         });
     result.EnsureSuccessStatusCode();
 }
示例#5
0
 /// <summary>
 ///     Adds a <see cref="TreeNodeExItem" /> object to the specified tree node collection.
 /// </summary>
 /// <param name="collection">The tree node collection to which the item should be added.</param>
 /// <param name="title">The title of the item.</param>
 /// <param name="description">The description of the item.</param>
 /// <param name="data">The data of the item.</param>
 /// <param name="image">The image of the data.</param>
 /// <returns>A <see cref="TreeNode" /> which contains the <see cref="TreeNodeExItem" /> data.</returns>
 public TreeNode AddItem(TreeNodeCollection collection, string title, string description, Note data,
     Image image = null)
 {
     return AddItem(collection, new TreeNodeExItem
     {
         Data = data,
         Description = description,
         Image = image,
         Title = title
     });
 }
 public override Task UpdateNoteAsync(Note note)
 {
     throw new NotImplementedException();
 }
示例#7
0
        private async Task DoNewAsync()
        {
            await SafeExecutionContext.ExecuteAsync(
                this,
                async () =>
                {
                    //var newNoteForm = new TextInputBox(Resources.NewNoteTitleText,
                    //    Resources.NewNotePrompt, new[]
                    //    {
                    //        new Tuple<Func<string, bool>, string>(string.IsNullOrEmpty, Resources.TitleRequired),
                    //        new Tuple<Func<string, bool>, string>(this.ExistingNotesTitle.Contains,
                    //            Resources.TitleExists)
                    //    });

                    var newNoteForm = new FrmCreateNote(Resources.NewNotePrompt, this.styleManager, this.settings, new[]
                    {
                        new Tuple<Func<string, bool>, string>(string.IsNullOrEmpty, Resources.TitleRequired),
                        new Tuple<Func<string, bool>, string>(this.ExistingNotesTitle.Contains,
                            Resources.TitleExists)
                    });

                    if (newNoteForm.ShowDialog() == DialogResult.OK)
                    {
                        var title = newNoteForm.SelectedTitle;
                        var note =
                            new Note
                            {
                                ID = Guid.Empty,
                                Title = title,
                                Content = newNoteForm.SelectedEmptyHtml,
                                DatePublished = DateTime.UtcNow
                            };
                        await this.ImportNote(note);
                    }
                });
        }
示例#8
0
 /// <summary>
 ///     Performs the export.
 /// </summary>
 /// <param name="fileName">Name of the file to which the note will be exported.</param>
 /// <param name="note">The note that is being exported.</param>
 /// <param name="options">The options for the exporting.</param>
 /// <remarks>
 ///     When the <c>OptionDialog</c> is not null, the <paramref name="options" /> value
 ///     represents the options collected from the <c>OptionDialog</c>. Otherwise the options
 ///     value will be null.
 /// </remarks>
 protected override void DoExport(string fileName, Note note, object options)
 {
     var encodingInfo = (EncodingInfo) options;
     File.WriteAllText(fileName, HtmlUtilities.RemoveHtmlTags(note.Content),
         Encoding.GetEncoding(encodingInfo.CodePage));
 }
示例#9
0
        public async Task ImportNote(Note note, bool rethrow = false)
        {
            Type[] exceptionTypes = null;
            if (rethrow)
            {
                exceptionTypes = new[] {typeof (NoteAlreadyExistsException)};
            }
            await SafeExecutionContext.ExecuteAsync(this, async () =>
            {
                var existingNoteTitles = this.ExistingNotesTitle;
                if (existingNoteTitles.Contains(note.Title))
                {
                    throw new NoteAlreadyExistsException(Resources.TitleExists);
                }

                var canceled = await this.SaveWorkspaceAsync();
                if (!canceled)
                {
                    this.ClearWorkspace();
                    note.Content = string.IsNullOrEmpty(note.Content) ? string.Empty : crypto.Encrypt(note.Content);
                    this.workspace = new Workspace(note);
                    this.workspace.PropertyChanged += this.workspace_PropertyChanged;
                    await this.SaveWorkspaceSlientlyAsync();
                    await this.LoadNotesAsync();
                }
            },
                () =>
                {
                    this.slblStatus.Text = Resources.Importing;
                    this.sp.Visible = true;
                },
                () => this.sp.Visible = false, exceptionTypes);
        }
示例#10
0
 private async Task LoadNoteAsync(Guid id)
 {
     using (var dataAccessProxy = this.CreateDataAccessProxy())
     {
         this.currentNote = await dataAccessProxy.GetNoteAsync(id);
     }
     this.ClearWorkspace();
     this.workspace = new Workspace(this.currentNote);
     this.workspace.PropertyChanged += this.workspace_PropertyChanged;
     this.lblTitle.Text = this.workspace.Title;
     var datePublished = this.workspace.DatePublished;
     this.lblDatePublished.Text = datePublished.ToLocalTime()
         .ToString("F", new CultureInfo(this.settings.General.Language));
     this.htmlEditor.Html = this.workspace.Content;
     this.htmlEditor.Enabled = true;
     this.tbtnSave.Enabled = false;
     this.mnuSave.Enabled = false;
     this.mnuPrint.Enabled = true;
     if (this.mnuSaveAs != null)
     {
         this.mnuSaveAs.Enabled = true;
     }
 }
示例#11
0
 private async void tvNotes_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
 {
     if (!e.CancelEdit)
     {
         await SafeExecutionContext.ExecuteAsync(
             this,
             async () =>
             {
                 var title = e.Label;
                 if (string.IsNullOrEmpty(title))
                 {
                     return;
                 }
                 this.slblStatus.Text = Resources.Renaming;
                 this.sp.Visible = true;
                 if (this.notesNode.Nodes.Cast<TreeNode>().Any(n => n != e.Node && n.Text == title))
                 {
                     MessageBox.Show(
                         Resources.TitleExists,
                         Resources.Error,
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Warning);
                     e.CancelEdit = true;
                 }
                 else
                 {
                     var item = GetItem(e.Node);
                     var nodeMetadata = item.Data;
                     using (var dataAccessProxy = this.CreateDataAccessProxy())
                     {
                         var selectedNote = await dataAccessProxy.GetNoteAsync(nodeMetadata.ID);
                         var noteUpdate = new Note
                         {
                             ID = nodeMetadata.ID,
                             Title = title,
                             Content = selectedNote.Content
                         };
                         await dataAccessProxy.UpdateNoteAsync(noteUpdate);
                         this.lblTitle.Text = title;
                         this.workspace.Title = title;
                         item.Title = title;
                         this.tvNotes.Refresh();
                     }
                 }
             },
             null,
             () => this.sp.Visible = false);
     }
 }
示例#12
0
 private async Task DoNewAsync()
 {
     await SafeExecutionContext.ExecuteAsync(
         this,
         async () =>
         {
             var newNoteForm = new TextInputBox(Resources.NewNotePrompt, new Tuple<Func<string, bool>, string>[]
             {
                 new Tuple<Func<string, bool>, string>(string.IsNullOrEmpty, Resources.TitleRequired),
                 new Tuple<Func<string, bool>, string>(this.ExistingNotesTitle.Contains, Resources.TitleExists)
             });
             if (newNoteForm.ShowDialog() == DialogResult.OK)
             {
                 var title = newNoteForm.InputText;
                 var note =
                     new Note
                     {
                         ID = Guid.Empty,
                         Title = title,
                         Content = string.Empty,
                         DatePublished = DateTime.UtcNow
                     };
                 await this.ImportNote(note);
             }
         });
 }
示例#13
0
 /// <summary>
 /// Performs the export.
 /// </summary>
 /// <param name="fileName">Name of the file to which the note will be exported.</param>
 /// <param name="note">The note that is being exported.</param>
 /// <param name="options">The options for the exporting.</param>
 /// <remarks>
 /// When the <c>OptionDialog</c> is not null, the <paramref name="options"/> value
 /// represents the options collected from the <c>OptionDialog</c>. Otherwise the options
 /// value will be null.
 /// </remarks>
 protected abstract void DoExport(string fileName, Note note, object options);
示例#14
0
 /// <summary>
 /// Creates the note asynchronously.
 /// </summary>
 /// <param name="note">The note object to be created.</param>
 /// <returns>The <see cref="Task"/> that returns the <see cref="Guid"/> value which represents the ID of the note that is newly created.</returns>
 public abstract Task<Guid> CreateNoteAsync(Note note);
示例#15
0
 /// <summary>
 /// Updates the note asynchronously.
 /// </summary>
 /// <param name="note">The note to be updated.</param>
 /// <returns>The <see cref="Task"/> that is responsible for updating the note.</returns>
 public abstract Task UpdateNoteAsync(Note note);