public void BeforeTest() { NoteVm = new NoteVm(); NoteHandler = new NoteHandler(NoteVm); DateConverter = new DateConverter(); Collection = new Collections(); }
public IActionResult Post([FromBody] Note content) { var sub = int.Parse(User.Claims.FirstOrDefault(c => c.Type == "sub").Value.ToString()); var user = Database.GlobalDatabase.Users.FirstOrDefault(u => u.AuthorId == sub); //MVC Auto serialized the json into the object, however if the content is null //then there was a problem with the serializing of the object //Because our model has required field we need to make sure the client respected // those conditions. if (content != null && ModelState.IsValid) { content.AuthorId = user.AuthorId; content.AuthorName = user.Name; if (NoteHandler.AddNote(content)) { return(StatusCode(201)); } else { return(StatusCode(500)); } } //Bad Request format. return(StatusCode(400)); }
public bool DoKeyboardEvents(Rect rect, NoteHandler noteHandler) { Event evt = Event.current; hoveredKey = GetHoveredKey(evt.mousePosition, rect); if (evt.type == EventType.MouseUp) { if (currentKey >= 0) { noteHandler.NoteOff(currentKey); } currentKey = -1; return(true); } else if (rect.Contains(evt.mousePosition) && (evt.type == EventType.MouseDrag || evt.type == EventType.MouseDown)) { if (hoveredKey != currentKey) { if (currentKey >= 0) { noteHandler.NoteOff(currentKey); } noteHandler.NoteOn(hoveredKey, 1.0f); currentKey = hoveredKey; return(true); } } return(false); }
// Start is called before the first frame update void Start() { nh = this.GetComponent <NoteHandler>(); NoteList = nh.NoteList; createNote(); }
public IActionResult Delete(int id) { var removed = NoteHandler.RemoveNote(id); if (removed) { return(StatusCode(204)); } else { return(StatusCode(400)); } }
public IActionResult Put(int id, [FromBody] Note content) { if (content != null) { if (NoteHandler.UpdateNote(content)) { return(new CreatedAtActionResult("notes", "GET", id, content)); } else { return(StatusCode(500)); } } //Bad Request format. return(StatusCode(400)); }
void useSendFile(File file, string contents) { Note remoteNote = new Note(); if(file.Path.EndsWith(".note") && contents.StartsWith("<?xml")) { // xml note file try { // Parsing // XML // Get a SAXParser from the SAXPArserFactory SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); // Get the XMLReader of the SAXParser we created XMLReader xr = sp.getXMLReader(); // Create a new ContentHandler, send it this note to fill and apply it to the XML-Reader NoteHandler xmlHandler = new NoteHandler(remoteNote); xr.setContentHandler(xmlHandler); // Create the proper input source stringReader sr = new stringReader(contents); InputSource inputSource = new InputSource(sr); TLog.d(TAG, "parsing note"); xr.parse(inputSource); // TODO wrap and throw a new exception here } catch (Exception e) { e.PrintStackTrace(); if(e as TimeFormatException) TLog.e(TAG, "Problem parsing the note's date and time"); Finish(); } // the note guid is not stored in the xml but in the filename remoteNote.setGuid(file.Name.Replace(".note", "")); Java.Util.Regex.Pattern note_content = Java.Util.Regex.Pattern.Compile("<note-content[^>]+>(.*)<\\/note-content>", Pattern.CASE_INSENSITIVE+Pattern.DOTALL); // FIXME here we are re-reading the whole note just to grab note-content out, there is probably a better way to do this (I'm talking to you xmlpull.org!) Matcher m = note_content.Matcher(contents); if (m.Find()) { remoteNote.setXmlContent(NoteManager.stripTitleFromContent(m.Group(1),remoteNote.getTitle())); } else { TLog.w(TAG, "Something went wrong trying to grab the note-content out of a note"); return; } } else { // ordinary text file remoteNote = NewNote.createNewNote(this, file.getName().replaceFirst("\\.[^.]+$", ""), XmlUtils.escape(contents)); } remoteNote.setFileName(file.AbsolutePath); // check and see if the note already Exists; if so, send to conflict resolver Note localNote = NoteManager.getNoteByGuid(this, remoteNote.getGuid()); if(localNote != null) { int compareBoth = Time.Compare(localNote.getLastChangeDate(), remoteNote.getLastChangeDate()); TLog.v(TAG, "note conflict... showing resolution dialog TITLE:{0} GUID:{1}", localNote.getTitle(), localNote.getGuid()); // send everything to Tomdroid so it can show Sync Dialog Bundle bundle = new Bundle(); bundle.PutString("title",remoteNote.getTitle()); bundle.PutString("file",remoteNote.getFileName()); bundle.PutString("guid",remoteNote.getGuid()); bundle.PutString("date",remoteNote.getLastChangeDate().Format3339(false)); bundle.PutString("content", remoteNote.getXmlContent()); bundle.PutString("tags", remoteNote.getTags()); bundle.PutInt("datediff", compareBoth); bundle.PutBoolean("noRemote", true); Intent cintent = new Intent(ApplicationContext, typeof(CompareNotes)); cintent.PutExtras(bundle); StartActivityForResult(cintent, 0); return; } // note doesn't exist, just give it a new title if necessary remoteNote.setTitle(NoteManager.validateNoteTitle(this, remoteNote.getTitle(), remoteNote.getGuid())); // add to content provider Android.Net.Uri uri = NoteManager.putNote(this, remoteNote); // view new note Intent i = new Intent(Intent.ActionView, uri, this, typeof(Tomdroid)); i.PutExtra("view_note", true); i.AddFlags(ActivityFlags.ClearTop); StartActivity(i); Finish(); }