Esempio n. 1
0
        public GasLog LogHistory(GasLog entity)
        {
            Guard.Against <ArgumentNullException>(entity == null, nameof(entity));

            // ReSharper disable once PossibleNullReferenceException
            entity.AuthorId   = DefaultAuthor.Id;
            entity.CreateDate = _dateProvider.UtcNow;

            if (!Validator.IsValidEntity(entity, ProcessResult))
            {
                return(null);
            }

            var note = entity.GetNote(NoteSerializer, DefaultAuthor);

            NoteManager.Create(note);

            switch (NoteManager.ProcessResult.Success)
            {
            case false:
                ProcessResult.PropagandaResult(NoteManager.ProcessResult);
                return(null);

            default:

                return(GetEntityById(note.Id));
            }
        }
Esempio n. 2
0
        public override GasLog Create(GasLog entity)
        {
            Guard.Against <ArgumentNullException>(entity == null, nameof(entity));

            // ReSharper disable once PossibleNullReferenceException
            entity.AuthorId   = DefaultAuthor.Id;
            entity.CreateDate = _dateProvider.UtcNow;

            // ToDo: validate current meter reader with auto meter reader
            if (!Validator.IsValidEntity(entity, ProcessResult))
            {
                return(null);
            }

            var auto = _autoManager.GetEntityById(entity.Car.Id);

            if (auto == null)
            {
                ProcessResult.AddErrorMessage("Cannot find automobile information");
                return(null);
            }

            var(isMeterValid, validationError) = MeterReadingValid(entity, auto);
            if (!isMeterValid)
            {
                ProcessResult.AddErrorMessage(validationError);
                return(null);
            }

            if (!string.IsNullOrEmpty(validationError))
            {
                ProcessResult.AddWaningMessage(validationError);
            }

            // Update automobile meter reader
            auto.MeterReading = (long)entity.CurrentMeterReading.TotalKilometre;
            var updatedAuto = _autoManager.Update(auto);

            if (updatedAuto == null)
            {
                ProcessResult.PropagandaResult(_autoManager.ProcessResult);
                return(null);
            }

            // ReSharper disable once PossibleNullReferenceException
            var note = entity.GetNote(NoteSerializer, DefaultAuthor);

            NoteManager.Create(note);

            switch (NoteManager.ProcessResult.Success)
            {
            case false:
                ProcessResult.PropagandaResult(NoteManager.ProcessResult);
                return(null);

            default:

                return(GetEntityById(note.Id));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Return the template Tomboy Note that corresponds with
        /// this Notebook.
        /// </summary>
        /// <returns>
        /// A <see cref="Note"/>
        /// </returns>
        public virtual Note GetTemplateNote()
        {
            NoteManager noteManager = Tomboy.DefaultNoteManager;
            Note        note        = noteManager.Find(templateNoteTitle);

            if (note == null)
            {
                note =
                    noteManager.Create(templateNoteTitle,
                                       NoteManager.GetNoteTemplateContent(templateNoteTitle));

                // Select the initial text
                NoteBuffer   buffer = note.Buffer;
                Gtk.TextIter iter   = buffer.GetIterAtLineOffset(2, 0);
                buffer.MoveMark(buffer.SelectionBound, iter);
                buffer.MoveMark(buffer.InsertMark, buffer.EndIter);

                // Flag this as a template note
                Tag tag = TagManager.GetOrCreateSystemTag(TagManager.TemplateNoteSystemTag);
                note.AddTag(tag);

                // Add on the notebook system tag so Tomboy
                // will persist the tag/notebook across sessions
                // if no other notes are added to the notebook.
                tag = TagManager.GetOrCreateSystemTag(NotebookTagPrefix + Name);
                note.AddTag(tag);

                note.QueueSave(ChangeType.ContentChanged);
            }

            return(note);
        }
Esempio n. 4
0
        public static Note Create(NoteManager manager, DateTime day)
        {
            string title = GetTitle(day);
            string xml   = GetContent(day, manager);

            Note notd = null;

            try {
                notd = manager.Create(title, xml);
            } catch (Exception e) {
                // Prevent blowup if note creation fails
                Logger.Error(
                    "NoteOfTheDay could not create \"{0}\": {1}",
                    title,
                    e.Message);
                notd = null;
            }

            if (notd != null)
            {
                // Automatically tag all new Note of the Day notes
                Tag notd_tag = TagManager.GetOrCreateSystemTag("NoteOfTheDay");
                notd.AddTag(notd_tag);

                // notd.AddTag queues a save so the following is no longer necessary
                //notd.Save ();
            }

            return(notd);
        }
        protected void OnActivated(object sender, EventArgs args)
        {
            if (notebook == null)
            {
                return;
            }

            // Look for the template note and create a new note
            Note templateNote = notebook.GetTemplateNote();
            Note note;

            NoteManager noteManager = Tomboy.DefaultNoteManager;

            note = noteManager.Create();
            if (templateNote != null)
            {
                // Use the body from the template note
                string xmlContent = templateNote.XmlContent.Replace(XmlEncoder.Encode(templateNote.Title),
                                                                    XmlEncoder.Encode(note.Title));
                xmlContent      = NoteManager.SanitizeXmlContent(xmlContent);
                note.XmlContent = xmlContent;
            }

            note.AddTag(notebook.Tag);
            note.Window.Show();
        }
        public static Note Create(NoteManager manager, DateTime day)
        {
            string title = GetTitle (day);
            string xml = GetContent (day, manager);

            Note notd = null;
            try {
                notd = manager.Create (title, xml);
            } catch (Exception e) {
                // Prevent blowup if note creation fails
                Logger.Error (
                        "NoteOfTheDay could not create \"{0}\": {1}",
                        title,
                        e.Message);
                notd = null;
            }

            if (notd != null) {
                // Automatically tag all new Note of the Day notes
                Tag notd_tag = TagManager.GetOrCreateSystemTag ("NoteOfTheDay");
                notd.AddTag (notd_tag);

                // notd.AddTag queues a save so the following is no longer necessary
                //notd.Save ();
            }

            return notd;
        }
Esempio n. 7
0
        void OpenTemplateButtonClicked(object sender, EventArgs args)
        {
            NoteManager manager       = Tomboy.DefaultNoteManager;
            Note        template_note = manager.Find(NoteOfTheDay.TemplateTitle);

            if (template_note == null)
            {
                // Create a new template note for the user
                try {
                    template_note = manager.Create(
                        NoteOfTheDay.TemplateTitle,
                        NoteOfTheDay.GetTemplateContent(
                            NoteOfTheDay.TemplateTitle));
                    template_note.QueueSave(ChangeType.ContentChanged);
                } catch (Exception e) {
                    Logger.Warn("Error creating Note of the Day Template note: {0}\n{1}",
                                e.Message, e.StackTrace);
                }
            }

            // Open the template note
            if (template_note != null)
            {
                template_note.Window.Show();
            }
        }
 public Note CreateNote(Note note)
 {
     Note result = null;
     using (NoteManager manager = new NoteManager())
     {
         result = manager.Create(note);
     }
     return result;
 }
Esempio n. 9
0
        /// <summary>
        /// Return the template Tomboy Note that corresponds with
        /// this Notebook.
        /// </summary>
        /// <returns>
        /// A <see cref="Note"/>
        /// </returns>
        public virtual Note GetTemplateNote()
        {
            NoteManager noteManager   = Tomboy.DefaultNoteManager;
            Note        template_note = null;
            Tag         template_tag  = TagManager.GetOrCreateSystemTag(TagManager.TemplateNoteSystemTag);
            Tag         notebook_tag  = TagManager.GetOrCreateSystemTag(NotebookTagPrefix + Name);

            foreach (Note note in template_tag.Notes)
            {
                if (note.ContainsTag(notebook_tag))
                {
                    template_note = note;
                    break;
                }
            }

            if (template_note == null)
            {
                // Check name does not exist
                String template_name = templateNoteTitle;
                if (noteManager.Find(template_name) != null)
                {
                    template_name = noteManager.GetUniqueName(template_name, 1);
                }

                template_note =
                    noteManager.Create(template_name,
                                       NoteManager.GetNoteTemplateContent(template_name));

                // Select the initial text
                NoteBuffer   buffer = template_note.Buffer;
                Gtk.TextIter iter   = buffer.GetIterAtLineOffset(2, 0);
                buffer.MoveMark(buffer.SelectionBound, iter);
                buffer.MoveMark(buffer.InsertMark, buffer.EndIter);

                // Flag this as a template note
                template_note.AddTag(template_tag);

                // Add on the notebook system tag so Tomboy
                // will persist the tag/notebook across sessions
                // if no other notes are added to the notebook.
                template_note.AddTag(notebook_tag);

                template_note.QueueSave(ChangeType.ContentChanged);
            }

            return(template_note);
        }
Esempio n. 10
0
        public IActionResult Post([FromBody] NoteViewModel model)
        {
            var dataModel = new Note
            {
                Content  = model.Content,
                Expiry   = model.Expiry,
                PIN      = model.PIN,
                MaxReads = model.MaxReads,
            };

            var response = noteManager.Create(dataModel);

            if (response?.Success ?? false && !string.IsNullOrEmpty(response?.Id))
            {
                return(Ok(new { response.Id }));
            }

            return(BadRequest());
        }
Esempio n. 11
0
        public override AutomobileInfo Create(AutomobileInfo entity)
        {
            Guard.Against <ArgumentNullException>(entity == null, nameof(entity));

            // ReSharper disable once PossibleNullReferenceException
            entity.AuthorId = DefaultAuthor.Id;
            if (!Validator.IsValidEntity(entity, ProcessResult))
            {
                return(null);
            }

            var note = entity.GetNote(NoteSerializer, DefaultAuthor);

            NoteManager.Create(note);
            if (NoteManager.ProcessResult.HasReturnedMessage())
            {
                ProcessResult.PropagandaResult(NoteManager.ProcessResult);
            }

            return(NoteManager.ProcessResult.Success switch
            {
                false => null,
                _ => GetEntityById(note.Id)
            });