private void loginLToolStripMenuItem_Click(object sender, EventArgs e) { EvernoteOA oauth = new EvernoteOA(EvernoteOA.HostService.Production); if (oauth.doAuth(consumerKey, consumerSecret)) { EverImage.Properties.Settings.Default.EvernoteToken = oauth.OAuthToken; EverImage.Properties.Settings.Default.Save(); StringBuilder sb = new StringBuilder(); List <string> evernotebooks = new List <string>(Evernote.GetEvetnoteNotebook(EvernoteToken).Keys); for (int i = evernotebooks.Count - 1; i >= 0; i--) { sb.Append(evernotebooks[i]); sb.Append(","); } sb.Remove(sb.Length - 1, 1); EverImage.Properties.Settings.Default.EvernoteBookNames = sb.ToString(); EverImage.Properties.Settings.Default.EvernoteUserName = Evernote.GetEvernoteUserName(EvernoteToken); EverImage.Properties.Settings.Default.Save(); loginLToolStripMenuItem.Enabled = false; logoutOToolStripMenuItem.Enabled = true; settingSToolStripMenuItem.Text = ResEverImage.EndGettingEvernoteInfo; reflesh(); } }
private void bgSendToEvernote_DoWork(object sender, DoWorkEventArgs e) { int count = 1; List <string> evernoteTags = new List <string>(tbEvernoteTags.Text.Split(',')); if (cbSendinOneNote.Checked == true) { List <Image> sendImages = new List <Image>(); foreach (var index in SendImagesIndex.Keys) { sendImages.Add(Images[index]); } try { Evernote.SendToEvernote(sendImages, EvernoteToken, EvernoteNotebookName, evernoteTags, tbUrl.Text); } catch (Exception ex) { foreach (var index in SendImagesIndex.Keys) { ErrorImageUrls.Add(SendImagesIndex[index]); } } } else { string sourceUrl = string.Empty; foreach (int index in SendImagesIndex.Keys) { try { Evernote.SendToEvernote(new List <Image>() { Images[index] }, EvernoteToken, EvernoteNotebookName, evernoteTags, Adresses[index]); } catch { ErrorImageUrls.Add(SendImagesIndex[index]); } bgSendToEvernote.ReportProgress(count); count++; } } }
/// <summary> /// Evernoteに画像を送信する /// </summary> /// <param name="sendImage">送信する画像</param> /// <param name="EvernoteToken">Evernoteトークン</param> static public void SendToEvernote(List <Image> sendImages, string EvernoteToken, string evernoteNotebookName, List <string> evernoteTags, string sourceUrl) { string authToken = EvernoteToken; Uri userStoreUrl = new Uri("https://" + evernoteHost + "/edam/user"); TTransport userStoreTransport = new THttpClient(userStoreUrl); TProtocol userStoreProtocol = new TBinaryProtocol(userStoreTransport); UserStore.Client userStore = new UserStore.Client(userStoreProtocol); String noteStoreUrl = userStore.getNoteStoreUrl(authToken); TTransport noteStoreTransport = new THttpClient(new Uri(noteStoreUrl)); TProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport); NoteStore.Client noteStore = new NoteStore.Client(noteStoreProtocol); Note note = new Note(); note.Title = DateTime.Now.ToShortDateString(); foreach (var notebook in Evernote.GetEvetnoteNotebook(EvernoteToken)) { if (notebook.Key == evernoteNotebookName) { note.NotebookGuid = notebook.Value; break; } } note.TagNames = evernoteTags; NoteAttributes attributes = new NoteAttributes(); attributes.SourceURL = sourceUrl; note.Attributes = attributes; StringBuilder content = new StringBuilder(); content.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); content.Append("<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">"); content.Append("<en-note>"); note.Resources = new List <Resource>(); foreach (var sendImage in sendImages) { ImageConverter converter = new ImageConverter(); byte[] image = (byte[])converter.ConvertTo(sendImage, typeof(byte[])); byte[] hash = new MD5CryptoServiceProvider().ComputeHash(image); Data data = new Data(); data.Size = image.Length; data.BodyHash = hash; data.Body = image; Resource resource = new Resource(); resource.Mime = "image/png"; resource.Data = data; note.Resources.Add(resource); string hashHex = BitConverter.ToString(hash).Replace("-", "").ToLower(); content.Append("<span>"); content.Append("<en-media type=\"image/png\" hash=\""); content.Append(hashHex); content.Append("\"/>"); content.Append("</span>"); content.Append("<br/>"); } content.Append("</en-note>"); note.Content = content.ToString(); Note createdNote = noteStore.createNote(authToken, note); }