public async Task Put(NoteFile edited) { NoteFile live = await _db.NoteFile.FindAsync(edited.Id); live.LastEdited = DateTime.Now.ToUniversalTime(); live.NoteFileName = edited.NoteFileName; live.NoteFileTitle = edited.NoteFileTitle; live.OwnerId = edited.OwnerId; _db.Update(live); await _db.SaveChangesAsync(); }
private bool DeleteNoteFile(NoteFile nf) { var result = MessageBox.Show($"Do you want to delete the file {nf.Name}?", "Delete", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No); if (result == MessageBoxResult.Yes) { nf.Delete(); Note.Files.Remove(nf); } return(true); }
// GET: NoteFiles/Delete/5 /// <summary> /// Setup to delete a NoteFile /// </summary> /// <param name="id">NoteFileID</param> /// <returns></returns> public async Task <IActionResult> Delete(int?id) { if (id == null) { return(NotFound()); } NoteFile noteFile = await NoteDataManager.GetFileByIdWithOwner(_db, (int)id); if (noteFile == null) { return(NotFound()); } return(View(noteFile)); }
private void DragNoteFile(object sender, MouseButtonEventArgs e) { Image img = (Image)sender; NoteFile nf = img.Tag as NoteFile; if (nf == null) { return; } DataObject data = new DataObject(typeof(NoteFile), nf); DragDrop.DoDragDrop(img, data, DragDropEffects.Copy); }
public async Task CreateAnnounce() { await CreateNoteFile("announce", "Notes 2021 Announcements"); NoteFile nf4 = await NoteDataManager.GetFileByName(_db, "announce"); int padid = nf4.Id; NoteAccess access = await AccessManager.GetOneAccess(_db, Globals.AccessOtherId(), padid, 0); access.ReadAccess = true; _db.Entry(access).State = EntityState.Modified; await _db.SaveChangesAsync(); }
private void HandleImage(Inline inline, IAddChild parent) { NoteFile nf = CurrentNote.Files.FirstOrDefault(n => n.FileName == inline.TargetUrl); Paragraph result = parent as Paragraph; if (result == null) { result = new Paragraph(); parent.AddChild(result); } if (nf != null && File.Exists(nf.FullName)) { if (!string.IsNullOrWhiteSpace(inline.LiteralContent)) { result.ToolTip = inline.LiteralContent; } var imageUri = new Uri(nf.FullName, UriKind.Absolute); var imgTemp = new BitmapImage(); imgTemp.BeginInit(); imgTemp.CacheOption = BitmapCacheOption.OnLoad; imgTemp.CreateOptions = BitmapCreateOptions.IgnoreImageCache; imgTemp.UriSource = imageUri; imgTemp.EndInit(); var image = new Image { Source = imgTemp, Stretch = Stretch.None, StretchDirection = StretchDirection.Both, MaxWidth = imgTemp.Width, MaxHeight = imgTemp.Height }; if (ImageStyle != null) { image.Style = ImageStyle; } result.Inlines.Add(image); } else if (nf != null) { result.Inlines.Add(new Run("Missing file: " + nf.FullName)); } }
public async Task <string> CreateLinkNote(LinkCreateModel inputModel) { NoteFile file = await _context.NoteFile .SingleAsync(p => p.NoteFileName == inputModel.linkedfile); if (file == null) { return("Target file does not exist"); } // check for acceptance if (!await AccessManager.TestLinkAccess(_context, file, "")) { return("Access Denied"); } inputModel.header.NoteFileId = file.Id; inputModel.header.ArchiveId = 0; inputModel.header.BaseNoteId = 0; inputModel.header.Id = 0; inputModel.header.NoteContent = null; inputModel.header.NoteFile = null; inputModel.header.NoteOrdinal = 0; inputModel.header.ResponseOrdinal = 0; inputModel.header.ResponseCount = 0; var tags = Tags.ListToString(inputModel.tags); NoteHeader nh = await NoteDataManager.CreateNote(_context, null, inputModel.header, inputModel.content.NoteBody, tags, inputModel.content.DirectorMessage, true, true); if (nh == null) { return("Remote note create failed"); } LinkLog ll = new LinkLog() { Event = "Ok", EventTime = DateTime.UtcNow, EventType = "RcvdCreateBaseNote" }; _context.LinkLog.Add(ll); await _context.SaveChangesAsync(); return("Ok"); }
public async Task <IActionResult> StartImport(int?id) { if (id == null) { return(NotFound()); } NoteFile noteFile = await NoteDataManager.GetFileById(_db, (int)id); if (noteFile == null) { return(NotFound()); } return(View(noteFile)); }
public async Task <List <NoteHeader> > Get(string sid) { int fileid = int.Parse(sid); List <NoteHeader> list = new List <NoteHeader>(); NoteFile noteFile = _db.NoteFile.SingleOrDefault(p => p.Id == fileid); for (int i = 0; i <= noteFile.NumberArchives; i++) { NoteHeader header = _db.NoteHeader.Where(p => p.ArchiveId == i).OrderBy(p => p.CreateDate).FirstOrDefault(); list.Add(header); } return(list); }
public async Task <string> EditLinkResponse(LinkCreateEModel inputModel) { NoteFile file = _context.NoteFile.SingleOrDefault(p => p.NoteFileName == inputModel.linkedfile); if (file == null) { return("Target file does not exist"); } // check for acceptance if (!await AccessManager.TestLinkAccess(_context, file, inputModel.Secret)) { return("Access Denied"); } // find local base note for this and modify header NoteHeader extant = _context.NoteHeader.SingleOrDefault(p => p.LinkGuid == inputModel.myGuid); if (extant == null) // || extant.NoteFileId != file.Id) { return("Could not find note"); } inputModel.header.NoteOrdinal = extant.NoteOrdinal; inputModel.header.ArchiveId = extant.ArchiveId; inputModel.header.NoteFileId = file.Id; inputModel.header.BaseNoteId = extant.BaseNoteId; inputModel.header.Id = extant.Id; //inputModel.header.NoteContent = null; //inputModel.header.NoteFile = null; inputModel.header.ResponseOrdinal = extant.ResponseOrdinal; inputModel.header.ResponseCount = extant.ResponseCount; NoteHeader nh = await NoteDataManager.EditNote(_context, null, inputModel.header, inputModel.content, inputModel.tags); if (nh == null) { return("Remote response edit failed"); } return("Ok"); }
public async Task <string> CreateLinkResponse(LinkCreateRModel inputModel) { NoteFile file = _context.NoteFile.SingleOrDefault(p => p.NoteFileName == inputModel.linkedfile); if (file == null) { return("Target file does not exist"); } // check for acceptance if (!await AccessManager.TestLinkAccess(_context, file, inputModel.Secret)) { return("Access Denied"); } // find local base note for this and modify header NoteHeader extant = _context.NoteHeader.SingleOrDefault(p => p.LinkGuid == inputModel.baseGuid); if (extant == null) // || extant.NoteFileId != file.Id) { return("Could not find base note"); } inputModel.header.NoteOrdinal = extant.NoteOrdinal; inputModel.header.NoteFileId = file.Id; inputModel.header.BaseNoteId = extant.BaseNoteId; inputModel.header.Id = 0; inputModel.header.NoteContent = null; inputModel.header.NoteFile = null; //inputModel.header.ResponseOrdinal = 0; //inputModel.header.ResponseCount = 0; var tags = Tags.ListToString(inputModel.tags); NoteHeader nh = await NoteDataManager.CreateResponse(_context, null, inputModel.header, inputModel.content.NoteBody, tags, inputModel.content.DirectorMessage, true, true); if (nh == null) { return("Remote response create failed"); } return("Ok"); }
public async Task CreatePad() { await CreateNoteFile("pad", "Traditional Pad"); NoteFile nf4 = await NoteDataManager.GetFileByName(_db, "pad"); int padid = nf4.Id; NoteAccess access = await AccessManager.GetOneAccess(_db, Globals.AccessOtherId(), padid, 0); access.ReadAccess = true; access.Respond = true; access.Write = true; _db.Entry(access).State = EntityState.Modified; await _db.SaveChangesAsync(); }
private void button1_Click(object sender, EventArgs e) { string notefilename = comboBox1.SelectedItem.ToString(); IConfiguration config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", true, true) .Build(); var optionsBuilder = new DbContextOptionsBuilder <NotesDbContext>(); optionsBuilder.UseSqlServer(config["ConnectionString"]); NotesDbContext _db = new NotesDbContext(optionsBuilder.Options); NoteFile nf = _db.NoteFile.Where(p => p.NoteFileName == notefilename).SingleOrDefault(); }
public async Task <IActionResult> Archive(int?id) { if (id == null) { return(NotFound()); } NoteFile noteFile = await NoteDataManager.GetFileById(_db, (int)id); if (noteFile == null) { return(NotFound()); } ViewData["OwnerId"] = new SelectList(_db.Users, "Id", "DisplayName", noteFile.OwnerId); return(View(noteFile)); }
private void MarkdownText_OnPreviewDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); AddFiles(files); } else if (e.Data.GetDataPresent(typeof(NoteFile))) { NoteFile nf = e.Data.GetData(typeof(NoteFile)) as NoteFile; if (nf != null) { MarkdownText.SelectedText = string.Format(MdImageFormat, nf.FileName, nf.Name); } } }
private void dataGridView1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode != Keys.Enter) { return; } var dataGridViewRow = ((DataGridView)(sender)).CurrentRow; if (dataGridViewRow != null) { NoteFile myFile = (NoteFile)dataGridViewRow.DataBoundItem; new ListNotes(myFile) { Visible = true }; } }
int iHeaderHeight; //Used for the header height public ListNotes(NoteFile myFile) { InitializeComponent(); mySelf = this; MyFile = myFile; label1.Text = MyFile.NoteFileName; label2.Text = MyFile.NoteFileTitle; List <NoteHeader> noteHeader = Actions.GetNoteList(Program.MyClient, MyFile.Id); MyAccess = Actions.GetAccess(Program.MyClient, MyFile.Id); button1.Enabled = MyAccess.Write; int count = 0; foreach (var header in noteHeader) { header.CreateDate = header.CreateDate.ToLocalTime(); count++; } label3.Text = count + @" Base Notes"; dataGridView1.DataSource = noteHeader; dataGridView1.Columns[0].Visible = false; dataGridView1.Columns[1].Visible = false; dataGridView1.Columns[2].Visible = false; dataGridView1.Columns[3].Visible = false; dataGridView1.Columns[4].Visible = false; dataGridView1.Columns[6].Visible = false; dataGridView1.Columns[9].Visible = false; dataGridView1.Columns[10].Visible = false; dataGridView1.Columns[12].Visible = false; dataGridView1.Columns[14].Visible = false; dataGridView1.Columns[15].Visible = false; dataGridView1.Columns[5].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; dataGridView1.Columns[7].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; dataGridView1.Columns[8].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; dataGridView1.Columns[11].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; dataGridView1.Columns[13].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; }
void MarkdownText_OnFilePasted(FileInfo fi) { byte[] bytes = File.ReadAllBytes(fi.FullName); string mime = MimeType.GetMimeType(bytes); NoteFile nf = NoteFile.Create(fi.Name, mime, bytes, EditedNote, fi.Extension); _newFiles.Add(nf); if (MimeType.IsImageExtension(fi.Extension)) { InsertImage(nf, MdImageFormat); } else { MarkdownText.SelectedText = string.Format("[{0}](file:///{1})", nf.Name, nf.FullName); } }
public void Drop(IDropInfo dropInfo) { if (dropInfo.Data is NoteFile) { TextBox box = dropInfo.VisualTarget as TextBox; if (box != null) { AddFilesToTextBox(box, dropInfo, new List <NoteFile> { (NoteFile)dropInfo.Data }); } } else if (dropInfo.Data is DataObject) { DataObject dataObject = (DataObject)dropInfo.Data; if (dataObject.ContainsFileDropList()) { var fileList = dataObject.GetFileDropList(); List <NoteFile> createdFiles = new List <NoteFile>(); foreach (string filePath in fileList) { if (File.Exists(filePath)) { FileInfo fi = new FileInfo(filePath); var file = File.ReadAllBytes(filePath); string ext = Path.GetExtension(filePath); if (!string.IsNullOrWhiteSpace(ext)) { ext = ext.ToLower(); } string noteFileName = NoteFile.ProposeNoteFileName(fi.Name, Note); string mime = MimeTypes.MimeTypeMap.GetMimeType(ext); var nf = NoteFile.Create(noteFileName, mime, file, Note, ext); createdFiles.Add(nf); } } if (dropInfo.VisualTarget is TextBox) { AddFilesToTextBox((TextBox)dropInfo.VisualTarget, dropInfo, createdFiles); } } } }
// GET: NoteFiles /// <summary> /// Display list of NoteFiles /// </summary> /// <returns></returns> public async Task <IActionResult> Index() { NoteFile nf1 = await NoteDataManager.GetFileByName(_db, "announce"); NoteFile nf2 = await NoteDataManager.GetFileByName(_db, "pbnotes"); NoteFile nf3 = await NoteDataManager.GetFileByName(_db, "noteshelp"); NoteFile nf4 = await NoteDataManager.GetFileByName(_db, "pad"); ViewBag.announce = nf1 == null; ViewBag.pbnotes = nf2 == null; ViewBag.noteshelp = nf3 == null; ViewBag.pad = nf4 == null; return(View(await NoteDataManager.GetNoteFilesOrderedByNameWithOwner(_db))); }
// add Image public bool AddImage(NoteFile image, long?albumId, long?userId, bool needCheck) { image.CreatedTime = DateTime.Now; if (albumId != 0) { image.AlbumId = albumId; } else { image.AlbumId = 1; image.IsDefaultAlbum = true; } image.UserId = userId; return(AddFile(image)); throw new Exception(); }
public async Task <IActionResult> DoArchive(int?id) { if (id == null) { return(NotFound()); } NoteFile noteFile = await NoteDataManager.GetFileById(_db, (int)id); if (noteFile == null) { return(NotFound()); } NoteDataManager.ArchiveNoteFile(_db, noteFile); //noteFile.NumberArchives++; //_db.Update(noteFile); //List<NoteHeader> nhl = await _db.NoteHeader.Where(p => p.NoteFileId == noteFile.Id && p.ArchiveId == 0).ToListAsync(); //foreach (NoteHeader nh in nhl) //{ // nh.ArchiveId = noteFile.NumberArchives; // _db.Update(nh); //} //List<NoteAccess> nal = await _db.NoteAccess.Where(p => p.NoteFileId == noteFile.Id && p.ArchiveId == 0).ToListAsync(); //foreach (NoteAccess na in nal) //{ // na.ArchiveId = noteFile.NumberArchives; //} //_db.NoteAccess.AddRange(nal); //List<Tags> ntl = await _db.Tags.Where(p => p.NoteFileId == noteFile.Id && p.ArchiveId == 0).ToListAsync(); //foreach (Tags nt in ntl) //{ // nt.ArchiveId = noteFile.NumberArchives; // _db.Update(nt); //} //await _db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> CreateNoteshelp() { await CreateNoteFile("noteshelp", "Help with Notes 2021"); NoteFile nf4 = await NoteDataManager.GetFileByName(_db, "noteshelp"); int padid = nf4.Id; NoteAccess access = await AccessManager.GetOneAccess(_db, Globals.AccessOtherId(), padid, 0); access.ReadAccess = true; access.Respond = true; access.Write = true; _db.Entry(access).State = EntityState.Modified; await _db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> PreExport(int id) { //string userid = _userManager.GetUserId(User); ExportViewModel it = new ExportViewModel(); NoteFile nf = await NoteDataManager.GetFileById(_db, id); it.FileName = nf.NoteFileName; it.FileNum = id; // set default options it.isHtml = false; it.isCollapsible = false; it.directOutput = true; it.NoteOrdinal = 0; return(View(it)); }
private void AddImageAsFileToNote_OnClick(object sender, RoutedEventArgs e) { string mime = null; byte[] bytes = null; if (MarkdownText.SelectedText.StartsWith("data:image")) { string[] chunks = MarkdownText.SelectedText.Split(','); if (chunks.Length == 2) { bytes = Convert.FromBase64String(chunks[1]); mime = chunks[0].Replace("data:", string.Empty).Replace(";base64", string.Empty); } } else { Uri uri; if (Uri.TryCreate(MarkdownText.SelectedText, UriKind.Absolute, out uri)) { try { WebClient webClient = new WebClient(); bytes = webClient.DownloadData(uri); mime = MimeType.GetMimeType(bytes); } catch (Exception) { // ignored } } } if (bytes != null && bytes.Length > 0 && mime != null) { NoteFile nf = NoteFile.Create(null, mime, bytes, EditedNote); MarkdownText.SelectedText = nf.Name; _newFiles.Add(nf); } else { ShowMessage("Unable to load image."); } }
public async Task <MemoryStream> GetFileAs(int id, bool id2) { string authHeader = Request.Headers["authentication"]; string[] auths = authHeader.Split(','); IdentityUser me = await _userManager.FindByIdAsync(auths[1]); UserData appMe = await _context.UserData.SingleAsync(p => p.UserId == me.Id); if (String.Compare(auths[2], appMe.MyGuid, StringComparison.Ordinal) != 0) { return(null); } string userID = auths[1]; NoteAccess myAcc = await AccessManager.GetAccess(_context, userID, id, 0); //TODO if (!myAcc.ReadAccess) { return(null); } ExportController myExp = new ExportController(_appEnv, _userManager, _signInManager, _context); Notes2021.Models.ExportViewModel model = new Notes2021.Models.ExportViewModel(); NoteFile nf = await NoteDataManager.GetFileById(_context, id); model.NoteOrdinal = 0; model.FileName = nf.NoteFileName; model.FileNum = nf.Id; model.directOutput = true; model.isCollapsible = id2; model.isHtml = id2; IdentityUser applicationUser = await _userManager .FindByEmailAsync(auths[0]); await _signInManager.SignInAsync(applicationUser, false); model.tzone = _context.TZone.Single(p => p.Id == appMe.TimeZoneID); return(await myExp.DoExport(model, User, 0)); //TODO }
// GET: DataSpy/Details/5 public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } NoteFile noteFile = await _context.NoteFile.SingleAsync(m => m.Id == id); if (noteFile == null) { return(NotFound()); } await AccessManager.Audit(_context, "Details", User.Identity.Name, User.Identity.Name, "View details of NotesFile " + noteFile.NoteFileName); return(View(noteFile)); }
// GET: NoteFiles/Details/5 /// <summary> /// Dislplay details about a file /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task <IActionResult> Details(int?id) { if (id == null) { return(NotFound()); } NoteFile noteFile = await NoteDataManager.GetFileByIdWithOwner(_db, (int)id); if (noteFile == null) { return(NotFound()); } ViewBag.BaseNotes = await NoteDataManager.NextBaseNoteOrdinal(_db, (int)id, 0) - 1; ViewBag.TotalNotes = await NoteDataManager.GetNumberOfNotes(_db, (int)id, 0); //ViewBag.TotalLength = await NoteDataManager.GetFileLength(_db, (int)id); return(View(noteFile)); }
//private int checkPrint; public DisplayNote(NoteFile myFile, int noteOrdinal, IRelistAble myParentListNotes) { InitializeComponent(); MyFile = myFile; baseOrdinal = noteOrdinal; MyParentListNotes = myParentListNotes; currentResp = 0; label1.Text = MyFile.NoteFileName; label2.Text = MyFile.NoteFileTitle; var noteHeader = Actions.GetDislayNoteHeadersWithResponses(Program.MyClient, MyFile.Id, noteOrdinal); Myheadlist = noteHeader.ToList(); respCount = Myheadlist.Count - 1; MyAccess = Actions.GetAccess(Program.MyClient, MyFile.Id); SetStuff(); }
void MarkdownText_OnImagePasted(System.Drawing.Image image, string fileName) { if (image == null) { return; } using (var ms = new MemoryStream()) { image.Save(ms, System.Drawing.Imaging.ImageFormat.Png); byte[] bytes = ms.ToArray(); string mime = MimeType.GetMimeType(bytes); if (bytes.Length > 0 && mime != null) { NoteFile nf = NoteFile.Create(fileName, mime, bytes, EditedNote); _newFiles.Add(nf); InsertImage(nf, MdImageFormat); } } }