/// <summary> /// Create a new note in the account of the user with the specified developer token. /// </summary> /// <returns>true if the note was created successfully, false otherwise.</returns> public bool createNote(String developerToken) { try { try { if (!auth(developerToken)) { // This is an unrecoverable error - our protocol version is out of date return false; } } catch (EDAMUserException eux) { // TODO - do proper error handling return false; } THttpClient noteStoreTransport = new THttpClient(new Uri(noteStoreUrl)); noteStoreTransport.CustomHeaders[HttpRequestHeader.UserAgent.ToString()] = USER_AGENT; TProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport); NoteStore.Client noteStore = new NoteStore.Client(noteStoreProtocol); // The bytes of the image we want to send up to the service // In this test, we use an image hardcoded as a base64-encoded string IBuffer imageBuffer = CryptographicBuffer.DecodeFromBase64String(imgBase64); byte[] imageBytes = WindowsRuntimeBufferExtensions.ToArray(imageBuffer); HashAlgorithmProvider provider = HashAlgorithmProvider.OpenAlgorithm("MD5"); IBuffer hashBuffer = provider.HashData(imageBuffer); byte[] hash = WindowsRuntimeBufferExtensions.ToArray(hashBuffer); String hashHex = CryptographicBuffer.EncodeToHexString(hashBuffer); Data data = new Data(); data.Size = imageBytes.Length; data.BodyHash = hash; data.Body = imageBytes; Resource resource = new Resource(); resource.Mime = "image/png"; resource.Data = data; Note note = new Note(); note.Title = "Hello, World!"; note.Content = EDAM_NOTE_PREAMBLE + "<h2>This note is created by the Evernote sample code for Windows Store applications!</h2>" + "<br />" + "<en-media type=\"image/png\" hash=\"" + hashHex + "\"/>" + EDAM_NOTE_POSTAMBLE; note.Resources = new List<Resource>(); note.Resources.Add(resource); try { noteStore.createNote(authToken, note); return true; } catch (EDAMUserException ex) { // Handle note creation failure } } catch (TApplicationException tax) { // Handle generic Thrift error } catch (TTransportException ttx) { // Handle networking error } catch (EDAMSystemException esx) { // Handle unrecoverable Evernote error (i.e., error not caused by bad user input) } return false; }
/// <summary> /// Create a new note in the account of the user with the specified Evernote username and password. /// </summary> /// <returns>true if the note was created successfully, false otherwise.</returns> public bool createNote(String username, String password) { try { try { if (!auth(username, password)) { // This is an unrecoverable error - our protocol version is out of date return false; } } catch (EDAMUserException eux) { // I'm showing some of the most common error codes here that we might want to handle separately. // For the full list, see // http://dev.evernote.com/documentation/reference/UserStore.html#Fn_UserStore_authenticate if (eux.ErrorCode == EDAMErrorCode.INVALID_AUTH) { if (eux.Parameter == "username" || eux.Parameter == "password") { // We failed to authenticate because the username or password was invalid // This is a recoverable error that the user can fix } else { // Our API key was invalid, or something else wonky happened // The user can't help us recover from this } } else if (eux.ErrorCode == EDAMErrorCode.PERMISSION_DENIED) { if (eux.Parameter == "User.active") { // The credentials were correct, but this user account is not active } } else { // We failed to authenticate for some other reason } return false; } THttpClient noteStoreTransport = new THttpClient(new Uri(noteStoreUrl)); noteStoreTransport.CustomHeaders[HttpRequestHeader.UserAgent.ToString()] = USER_AGENT; TProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport); NoteStore.Client noteStore = new NoteStore.Client(noteStoreProtocol); // The bytes of the image we want to send up to the service // In this test, we use an image hardcoded as a base64-encoded string IBuffer imageBuffer = CryptographicBuffer.DecodeFromBase64String(imgBase64); byte[] imageBytes = WindowsRuntimeBufferExtensions.ToArray(imageBuffer); HashAlgorithmProvider provider = HashAlgorithmProvider.OpenAlgorithm("MD5"); IBuffer hashBuffer = provider.HashData(imageBuffer); byte[] hash = WindowsRuntimeBufferExtensions.ToArray(hashBuffer); String hashHex = CryptographicBuffer.EncodeToHexString(hashBuffer); Data data = new Data(); data.Size = imageBytes.Length; data.BodyHash = hash; data.Body = imageBytes; Resource resource = new Resource(); resource.Mime = "image/png"; resource.Data = data; Note note = new Note(); note.Title = "Hello, World!"; note.Content = EDAM_NOTE_PREAMBLE + "<h2>This note is created by Skitch for Metro!</h2>" + "<br />" + "<en-media type=\"image/png\" hash=\"" + hashHex + "\"/>" + EDAM_NOTE_POSTAMBLE; note.Resources = new List<Resource>(); note.Resources.Add(resource); try { noteStore.createNote(authToken, note); return true; } catch (EDAMUserException ex) { // Handle note creation failure } } catch (TApplicationException tax) { // Handle generic Thrift error } catch (TTransportException ttx) { // Handle networking error } catch (EDAMSystemException esx) { // Handle unrecoverable Evernote error (i.e., error not caused by bad user input) } return false; }
public void Read (TProtocol iprot) { TField field; iprot.ReadStructBegin(); while (true) { field = iprot.ReadFieldBegin(); if (field.Type == TType.Stop) { break; } switch (field.ID) { case 1: if (field.Type == TType.String) { Guid = iprot.ReadString(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 2: if (field.Type == TType.String) { NoteGuid = iprot.ReadString(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 3: if (field.Type == TType.Struct) { Data = new Data(); Data.Read(iprot); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 4: if (field.Type == TType.String) { Mime = iprot.ReadString(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 5: if (field.Type == TType.I16) { Width = iprot.ReadI16(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 6: if (field.Type == TType.I16) { Height = iprot.ReadI16(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 7: if (field.Type == TType.I16) { Duration = iprot.ReadI16(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 8: if (field.Type == TType.Bool) { Active = iprot.ReadBool(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 9: if (field.Type == TType.Struct) { Recognition = new Data(); Recognition.Read(iprot); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 11: if (field.Type == TType.Struct) { Attributes = new ResourceAttributes(); Attributes.Read(iprot); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 12: if (field.Type == TType.I32) { UpdateSequenceNum = iprot.ReadI32(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 13: if (field.Type == TType.Struct) { AlternateData = new Data(); AlternateData.Read(iprot); } else { TProtocolUtil.Skip(iprot, field.Type); } break; default: TProtocolUtil.Skip(iprot, field.Type); break; } iprot.ReadFieldEnd(); } iprot.ReadStructEnd(); }
public void Read(TProtocol iprot) { TField field; iprot.ReadStructBegin(); while (true) { field = iprot.ReadFieldBegin(); if (field.Type == TType.Stop) { break; } switch (field.ID) { case 1: if (field.Type == TType.String) { this.guid = iprot.ReadString(); this.__isset.guid = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 2: if (field.Type == TType.String) { this.noteGuid = iprot.ReadString(); this.__isset.noteGuid = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 3: if (field.Type == TType.Struct) { this.data = new Data(); this.data.Read(iprot); this.__isset.data = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 4: if (field.Type == TType.String) { this.mime = iprot.ReadString(); this.__isset.mime = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 5: if (field.Type == TType.I16) { this.width = iprot.ReadI16(); this.__isset.width = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 6: if (field.Type == TType.I16) { this.height = iprot.ReadI16(); this.__isset.height = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 7: if (field.Type == TType.I16) { this.duration = iprot.ReadI16(); this.__isset.duration = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 8: if (field.Type == TType.Bool) { this.active = iprot.ReadBool(); this.__isset.active = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 9: if (field.Type == TType.Struct) { this.recognition = new Data(); this.recognition.Read(iprot); this.__isset.recognition = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 11: if (field.Type == TType.Struct) { this.attributes = new ResourceAttributes(); this.attributes.Read(iprot); this.__isset.attributes = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 12: if (field.Type == TType.I32) { this.updateSequenceNum = iprot.ReadI32(); this.__isset.updateSequenceNum = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 13: if (field.Type == TType.Struct) { this.alternateData = new Data(); this.alternateData.Read(iprot); this.__isset.alternateData = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; default: TProtocolUtil.Skip(iprot, field.Type); break; } iprot.ReadFieldEnd(); } iprot.ReadStructEnd(); }
private void launch(BackgroundWorker worker, DoWorkEventArgs e) { //this.pbProgress.Value = 0; //SetProgress(0); //frmMain frmMainE = (frmMain)e.Argument; myParams = (Parameters)e.Argument; ProgressStatusClass myProgress = new ProgressStatusClass(); // List of listed extensions when Only Music Files is Checked List<string> sExtOK = new List<string>(); sExtOK.Add(".flac"); sExtOK.Add(".mp3"); sExtOK.Add(".ogg"); sExtOK.Add(".wma"); sExtOK.Add(".alac"); foreach (Notebook notebook in notebooks) { if (notebook.Name == myParams.Notebook) { musicNotebook = notebook; } } // Liste des M-0Top if (chkRegenLists.Checked) { //TextWriter tw_lst = new StreamWriter(myParams.Folder + "\\camuma-top.lst", false, Encoding.Default); TextWriter tw_lst = new StreamWriter(myParams.Folder + "\\camuma-top.lst", false, Encoding.GetEncoding(850)); NoteFilter filter = new NoteFilter(); filter.NotebookGuid = musicNotebook.Guid; //filter.Words = "intitle:\"" + dir.Name + "\""; //any: "Camuma ID: 153266" intitle:"Muse - 1999 - Showbiz" //filter.Words = "\"CaMuMa ID: " + sId + "\""; // Recherche par CaMuMa ID ou Titre //filter.Words = "any: \"CaMuMa ID: " + sId + "\" intitle:\"" + dir.Name + "\""; filter.Words = "tag:M-0Top"; NotesMetadataResultSpec spec = new NotesMetadataResultSpec(); spec.IncludeTitle = true; int pageSize = 10; int offset = 0; NotesMetadataList notes = noteStore.findNotesMetadata(authToken, filter, 0, pageSize, spec); do { notes = noteStore.findNotesMetadata(authToken, filter, offset, pageSize, spec); foreach (NoteMetadata note in notes.Notes) { Console.WriteLine("M-0Top : " + note.Title); tw_lst.WriteLine(note.Title); } offset = offset + notes.Notes.Count; } while (notes.TotalNotes > offset); tw_lst.Close(); } //Liste des M-0Top /*if (chkPdf.Checked) { PdfDocument pdf = new PdfDocument(); pdf.PageLayout = PdfPageLayout.TwoColumnLeft; //pdf.PageMode = PdfPageMode. pdf.Info.Title = "CaMuMa List"; //pdf.Info.Producer = "Calexo CaMuMa"; pdf.Info.Creator = "Calexo CaMuMa"; }*/ // Listing all directories DirectoryInfo dir = new DirectoryInfo(myParams.Folder); DirectoryInfo dir2; //String sMsg=""; Int32 i = 0; foreach (DirectoryInfo f in dir.GetDirectories()) { this.sFolderList[i] = f.FullName; dir2 = new DirectoryInfo(this.sFolderList[i]); foreach (DirectoryInfo f2 in dir2.GetDirectories()) { i++; this.sFolderList[i] = f2.FullName; } i++; myProgress.Info = i + " directories..."; worker.ReportProgress(0, myProgress); } //TextWriter tw = new StreamWriter(myParams.Folder + "\\camuma.lst", false, System.Text.Encoding.Unicode); //TextWriter tw = new StreamWriter(myParams.Folder + "\\camuma.lst", false, Encoding.GetEncoding(65001)); //TextWriter tw = new StreamWriter(myParams.Folder + "\\camuma.lst", false, Encoding.BigEndianUnicode); TextWriter tw = new StreamWriter(myParams.Folder + "\\camuma.lst", false, Encoding.Default); // Checking each directory // Checking if MP3 or Flac is here // Adding note bool isFlac, isMP3, isAlac, isWma; bool isFolderJPG; bool isSpotify; String sFileList; String sContent = ""; String sFolderJPG = ""; Int32 j = 0; String sId = ""; List<string> lTagNames; String sArtist, sAlbum, sYear; //, sGenre; Boolean isParsed; Regex oRegex; MatchCollection oMatchCollection; String regArtist = @"^(?<ARTIST>([\w\'\(\)\&\, -])*([\w\'\(\)\&\,]))"; String regAlbum = @"(?<ALBUM>([\w\'\(\)\-\&\,\. ])+)$"; String regYear = @"(?<YEAR>([0-9]{4}))"; String regDash = "[ ]+-[ ]+"; foreach (String sDirName in sFolderList) { if (worker.CancellationPending == true) { e.Cancel = true; break; } if (sDirName != null) { dir = new DirectoryInfo(sDirName); isFlac = false; isMP3 = false; isWma = false; isAlac = false; isSpotify = false; isFolderJPG = false; sFolderJPG = ""; sFileList = "<div ><ul>";// "<div><b>" + WebUtility.HtmlEncode("Liste des fichiers :") + "</b></div>"; sContent = ""; sArtist = ""; sAlbum = ""; sYear = ""; //sGenre = ""; isParsed = false; if (chkAddIdTags.Checked) { if (File.Exists(dir.FullName + "\\camuma.id")) { TextReader tr = new StreamReader(dir.FullName + "\\camuma.id"); sId = tr.ReadLine().Trim(); } else { Random rRnd = new Random(); int iRnd = rRnd.Next(1001, 999999); sId = iRnd.ToString().PadLeft(6,'0'); System.IO.File.WriteAllText(@dir.FullName + "\\camuma.id", sId); } // Ajout au camuma.lst tw.WriteLine(sId + ":" + dir.FullName.Replace(myParams.Folder+"\\","")); //tw.Flush(); if (!File.Exists(dir.FullName + "\\camuma.png")) { QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.M); QrCode qrCode = new QrCode(); //QrCode qrCode = qrEncoder.Encode(sId, out qrCode); qrEncoder.TryEncode("camuma://" + sId, out qrCode); //GraphicsRenderer renderer = new GraphicsRenderer(5, Brushes.Black, Brushes.White); GraphicsRenderer renderer = new GraphicsRenderer(new FixedModuleSize(5, QuietZoneModules.Zero), Brushes.Black, Brushes.White); //int pixelSize = renderer.Measure( qrCode.Matrix.Width).Width; //WriteableBitmap wBitmap = new WriteableBitmap(pixelSize, pixelSize, 96, 96, PixelFormats.Gray8, null); //renderer.CreateImageFile(qrCode.Matrix, @dir.FullName + "\\camuma.png", ImageFormat.Png); using (FileStream stream = new FileStream(@dir.FullName + "\\camuma.png", FileMode.Create)) { renderer.WriteToStream(qrCode.Matrix, ImageFormat.Png, stream); } SizeF size; Font f = new Font(FontFamily.GenericSansSerif,20); // creates 1Kx1K image buffer and uses it to find out how bit the image needs to be to fit the text using (Image imageg = (Image)new Bitmap(1000, 1000)) size = Graphics.FromImage(imageg).MeasureString(sId, f); using (Bitmap image = new Bitmap((int)size.Width, (int)size.Height)) //,, PixelFormat.Format32bppArgb)) { Graphics g = Graphics.FromImage((Image)image); //g.TranslateTransform(image.Width, image.Height); //g.RotateTransform(180.0F); //note that we need the rotation as the default is down //Color colBG = new Color(); //colBG. g.Clear(ColorTranslator.FromHtml("#ABDA4C")); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; // draw text g.DrawString(sId, f, Brushes.Black, 0f, 0f); //note that this image has to be a PNG, as GDI+'s gif handling renders any transparency as black. //context.Response.AddHeader("ContentType", "image/png"); using (MemoryStream memStream = new MemoryStream()) { //note that context.Response.OutputStream doesn't support the Save, but does support WriteTo image.Save(memStream, ImageFormat.Png); //memStream.WriteTo(context.Response.OutputStream); System.IO.File.WriteAllBytes(@dir.FullName + "\\camumaid.png", memStream.ToArray()); } } } } foreach (FileInfo f in dir.GetFiles()) { //if (f.Extension.Equals("flac", StringComparison.CurrentCultureIgnoreCase) if (f.Extension.Equals(".flac", StringComparison.CurrentCultureIgnoreCase)) isFlac = true; else if (f.Extension.Equals(".mp3", StringComparison.CurrentCultureIgnoreCase)) isMP3 = true; else if (f.Extension.Equals(".wma", StringComparison.CurrentCultureIgnoreCase)) isWma = true; else if (f.Extension.Equals(".alac", StringComparison.CurrentCultureIgnoreCase)) isAlac = true; else if (f.Name.Equals("folder.jpg", StringComparison.CurrentCultureIgnoreCase)) { isFolderJPG = true; sFolderJPG = f.FullName; } if (!chkMusicFiles.Checked || sExtOK.Contains(f.Extension.ToLower())) { sFileList += "<li>" + WebUtility.HtmlEncode(f.Name) + "</li>"; } } sContent = "<h1>" + WebUtility.HtmlEncode(dir.Name) + "</h1>"; sContent += sFileList + "</ul></div>"; if (isMP3 || isFlac || isWma || isAlac) { j++; myProgress.ProgressValue = j; myProgress.Info = j + "/" + i +" \nAlbum..."; worker.ReportProgress(j, myProgress); //Info("Creating Note... " + j + "/" + i); lTagNames = new List<string>(); lTagNames.Add("M-Support:Cowon"); lTagNames.Add("M-Support:NAS2"); lTagNames.Add("M-Support:WD"); lTagNames.Add("M-Album"); if (isMP3) lTagNames.Add("M-MP3"); if (isFlac) lTagNames.Add("M-FLAC"); if (isAlac) lTagNames.Add("M-ALAC"); if (isWma) lTagNames.Add("M-WMA"); if (isFolderJPG) lTagNames.Add("M-Cover"); else lTagNames.Add("M-NoCover"); Console.WriteLine(dir.Name + "..."); // ARTIST - YEAR - ALBUM oRegex = new Regex(regArtist + regDash + regYear + regDash + regAlbum); oMatchCollection = oRegex.Matches(dir.Name); foreach (Match oMatch in oMatchCollection) { Console.WriteLine(" * " + oMatch.Groups["ARTIST"] + ":" + oMatch.Groups["ALBUM"] + "(" + oMatch.Groups["YEAR"] + ")"); sArtist = oMatch.Groups["ARTIST"].ToString(); sYear = oMatch.Groups["YEAR"].ToString(); sAlbum = oMatch.Groups["ALBUM"].ToString(); isParsed = true; } // ARTIST - ALBUM - YEAR if (!isParsed) { oRegex = new Regex(regArtist + regDash + regAlbum + regDash + regYear); oMatchCollection = oRegex.Matches(dir.Name); foreach (Match oMatch in oMatchCollection) { Console.WriteLine(" * " + oMatch.Groups["ARTIST"] + ":" + oMatch.Groups["ALBUM"] + "(" + oMatch.Groups["YEAR"] + ")"); sArtist = oMatch.Groups["ARTIST"].ToString(); sYear = oMatch.Groups["YEAR"].ToString(); sAlbum = oMatch.Groups["ALBUM"].ToString(); isParsed = true; } } // ARTIST - ALBUM if (!isParsed) { oRegex = new Regex(regArtist + regDash + regAlbum); oMatchCollection = oRegex.Matches(dir.Name); foreach (Match oMatch in oMatchCollection) { //lTagNames.Add (oMatch.Groups["ARTIST"].ToString()); Console.WriteLine(" * " + oMatch.Groups["ARTIST"] + ":" + oMatch.Groups["ALBUM"]); sArtist = oMatch.Groups["ARTIST"].ToString(); sAlbum = oMatch.Groups["ALBUM"].ToString(); isParsed = true; } } if (isParsed) { sArtist = sArtist.Trim(); sYear = sYear.Trim(); sAlbum = sAlbum.Trim(); if (!String.IsNullOrWhiteSpace(sArtist)) lTagNames.Add("M-Artist:" + sArtist); if (!String.IsNullOrWhiteSpace(sYear)) lTagNames.Add("M-Year:" + sYear); else lTagNames.Add("M-Year:None"); //if (!String.IsNullOrWhiteSpace(sAlbum)) lTagNames.Add("M-Album:" + sAlbum); myProgress.Info = j + "/" + i + "\n" + "Album : " + sArtist + ":" + sAlbum + "... "; worker.ReportProgress(j, myProgress); } else lTagNames.Add("M-NotParsed"); // Spotify if (chkSpotify.Checked) { try { SearchResults<Album> spoRes = Search.SearchAlbums(dir.Name); if (spoRes.SearchResultsPage.Length > 0) { Album album = spoRes.SearchResultsPage.First(); Console.WriteLine(" * Spotify : " + album.Artist + " - " + album.Name + " (" + album.Url + ")"); sContent += "<div><br/></div>"; sContent += "<h2>Liens</h2>"; sContent += "<div><strong>Spotify</strong> : "; sContent += "<a href=\"" + album.Url + "\">"; sContent += WebUtility.HtmlEncode(album.Artist + " - " + album.Name + " : " + album.Url); sContent += "</a>"; sContent += "</div>"; lTagNames.Add("M-Spotify"); isSpotify = true; } } catch (WebException we) { Console.WriteLine(" * Spotify : " + we.Message); } catch (System.FormatException we) { Console.WriteLine(" * Spotify : " + we.Message); } } // chkSpotify true /*foreach (Album album in spoRes.SearchResultsPage) { Console.WriteLine(" * Spotify : " + album.Artist + " - " + album.Name + " (" + album.Url + ")"); }*/ // Add CaMuMa Id sContent += "<div><p><i>CaMuMa ID:</i> <a href=\"camuma://" + sId + "\">" + sId + "</a></p>"; byte[] image = ReadFully(File.OpenRead(@dir.FullName + "\\camuma.png")); byte[] hashQR = new MD5CryptoServiceProvider().ComputeHash(image); String hashHexQR = BitConverter.ToString(hashQR).Replace("-", "").ToLower(); //sContent += "<a href=\"camuma://" + sId + "\">"; sContent += "<en-media type=\"image/png\" hash=\"" + hashHexQR + "\"/>"; sContent += "</div>"; Data data = new Data(); data.Size = image.Length; data.BodyHash = hashQR; data.Body = image; Resource imgQR = new Resource(); imgQR.Mime = "image/png"; imgQR.Data = data; Console.WriteLine(@dir.FullName + "\\camuma.png -> " + hashHexQR); // On ajoute si on n'est pas dans le Action AddSpotify // ou si il y a effectivement du Spotify if (chkEvernote.Checked) { if (!rbActSpotify.Checked || isSpotify) { // On recherche la note avec le même titre NoteFilter filter = new NoteFilter(); filter.NotebookGuid = musicNotebook.Guid; //filter.Words = "intitle:\"" + dir.Name + "\""; //any: "Camuma ID: 153266" intitle:"Muse - 1999 - Showbiz" //filter.Words = "\"CaMuMa ID: " + sId + "\""; // Recherche par CaMuMa ID ou Titre //filter.Words = "any: \"CaMuMa ID: " + sId + "\" intitle:\"" + dir.Name + "\""; filter.Words = "\"CaMuMa ID: " + sId; NotesMetadataResultSpec spec = new NotesMetadataResultSpec(); spec.IncludeTitle = true; int pageSize = 10; NotesMetadataList notes = noteStore.findNotesMetadata(authToken, filter, 0, pageSize, spec); // Non existing Note if (notes.TotalNotes == 0) { // If Adding ou Replacing if (rbAdd.Checked || rbReplace.Checked) { // Creating new note createNote(sFolderJPG, sContent, dir.Name, lTagNames, imgQR); Console.WriteLine(" * Creation"); } } else if (notes.TotalNotes == 1) { NoteMetadata noteToMod = notes.Notes.First(); Console.WriteLine(" * Existing..."); if (rbReplace.Checked) { Note note = noteStore.getNote(authToken, noteToMod.Guid, true, true, false, false); String hashHex = ""; // Suppr tags négatifs (NotParsed, ...) note.TagGuids.Remove(getTagGuid("M-NotParsed")); note.TagGuids.Remove(getTagGuid("M-NoCover")); // Adding new tags note.TagNames = lTagNames; byte[] hash = null; if (sFolderJPG != "") { Console.WriteLine(" * folder.jpg exists"); image = ReadFully(File.OpenRead(sFolderJPG)); hash = new MD5CryptoServiceProvider().ComputeHash(image); hashHex = BitConverter.ToString(hash).Replace("-", "").ToLower(); } if (note.Content != nodeContentEnrich(sContent, hashHex)) { Console.WriteLine(" * Different contents"); note.Content = nodeContentEnrich(sContent, hashHex); note.Resources = new List<Resource>(); if (hash != null) { Console.WriteLine(" * Adding folder image"); Data dataF = new Data(); dataF.Size = image.Length; dataF.BodyHash = hash; dataF.Body = image; Resource resource = new Resource(); resource.Mime = "image/jpg"; resource.Data = dataF; note.Resources.Add(resource); } note.Resources.Add(imgQR); Console.WriteLine("Res : " + note.Resources.Count); note.UpdateSequenceNum = 0; note.Updated = 0; Note newNote = noteStore.updateNote(authToken, note); if (newNote != null) { Console.WriteLine(" * Modified"); Console.WriteLine("Res : " + newNote.Resources.Count); //Console.WriteLine(newNote.Title); //Console.WriteLine(newNote.Updated); //Console.WriteLine(note.UpdateSequenceNum + " -> " + newNote.UpdateSequenceNum); } else { Console.WriteLine(" * Modification failed"); } } } } // TotalNotes=1 else // More than 1 matches { createNote(sFolderJPG, sContent, dir.Name, lTagNames, imgQR); Console.WriteLine(" * ERROR - Multiple found"); } } // ActSpotify } // chkEvernote } else { i--; } } //this.pbProgress.Maximum = i; //pbProgress.Value = j; myProgress.ProgressMax = i; myProgress.ProgressValue = j; worker.ReportProgress(j, myProgress); } //Info("OK"); tw.Close(); }
private Note createNote(String sImageFile, String sContent, String sTitle, List<string> sTags, Resource resQR) { if (isConnexionOK()) { Note note = new Note(); note.NotebookGuid = musicNotebook.Guid; note.Title = sTitle; /*note.Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">" + "<en-note>";*/ string hashHex=""; note.Resources = new List<Resource>(); if (sImageFile != "") { byte[] image = ReadFully(File.OpenRead(sImageFile)); byte[] hash = new MD5CryptoServiceProvider().ComputeHash(image); hashHex = BitConverter.ToString(hash).Replace("-", "").ToLower(); Data data = new Data(); data.Size = image.Length; data.BodyHash = hash; data.Body = image; Resource resource = new Resource(); resource.Mime = "image/jpg"; resource.Data = data; // folder.jpg note.Resources.Add(resource); //note.Content += "<en-media type=\"image/jpg\" hash=\"" + hashHex + "\"/>"; } // camuma.png note.Resources.Add(resQR); //note.Content += sContent + "<br/>"; //note.Content += "</en-note>"; note.Content = nodeContentEnrich(sContent, hashHex); Console.WriteLine(note.Content); note.TagNames = sTags; // Gestion du Read-Only /*if (this.chkReadOnly.Checked) {*/ note.Attributes = new NoteAttributes(); note.Attributes.ContentClass = "calexo.camuma"; //} return noteStore.createNote(authToken, note); } else return null; }