/// <summary> /// リソースを出力する。 /// </summary> /// <param name="res"></param> private void WriteResource(Resource res) { Console.WriteLine(" * Mime: " + res.Mime); Console.WriteLine(" * ToString: " + res.ToString()); Data data = res.Data; byte[] body = data.Body; Console.WriteLine(" * Data.Size: " + data.Size); if (body == null) { Console.WriteLine(" * Data.Body: null"); } else { String fname = res.NoteGuid + "_" + res.Guid; if (res.Mime.Equals("image/png")) { fname += ".png"; } else { fname += ".dat"; } FileStream fs = new FileStream(fname, FileMode.Create); fs.Write(body, 0, body.Length); fs.Close(); Console.WriteLine(" * Data.Body: " + fname + "へ出力しました。"); } Console.WriteLine(" * Data.ToString: " + data.ToString()); }
public void TestSaveNote_Normal_0002() { // 準備 Resource resource = new Resource(); resource.Data = new Data(); resource.Data.Body = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 }; Note note = new Note(); note.Content = "content"; note.Resources = new List<Resource>(); note.Resources.Add(resource); string baseName = "TestSaveNote_Normal_0002"; // テスト実行 mTarget.SaveNote(note, baseName, 1); // 検証 Assert.True(File.Exists(baseName + "_00001.txt")); }
public static string GetExtenstion(Resource res) { Console.WriteLine("Mime:" + res.Mime); string ext; switch (res.Mime) { case "image/gif": ext = ".gif"; break; case "image/jpeg": ext = ".jpg"; break; case "image/png": ext = ".png"; break; default: ext = ".dat"; break; } return ext; }
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) { Title = iprot.ReadString(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 3: if (field.Type == TType.String) { Content = iprot.ReadString(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 4: if (field.Type == TType.String) { ContentHash = iprot.ReadBinary(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 5: if (field.Type == TType.I32) { ContentLength = iprot.ReadI32(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 6: if (field.Type == TType.I64) { Created = iprot.ReadI64(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 7: if (field.Type == TType.I64) { Updated = iprot.ReadI64(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 8: if (field.Type == TType.I64) { Deleted = iprot.ReadI64(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 9: if (field.Type == TType.Bool) { Active = iprot.ReadBool(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 10: if (field.Type == TType.I32) { UpdateSequenceNum = iprot.ReadI32(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 11: if (field.Type == TType.String) { NotebookGuid = iprot.ReadString(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 12: if (field.Type == TType.List) { { TagGuids = new List<string>(); TList _list17 = iprot.ReadListBegin(); for( int _i18 = 0; _i18 < _list17.Count; ++_i18) { string _elem19 = null; _elem19 = iprot.ReadString(); TagGuids.Add(_elem19); } iprot.ReadListEnd(); } } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 13: if (field.Type == TType.List) { { Resources = new List<Resource>(); TList _list20 = iprot.ReadListBegin(); for( int _i21 = 0; _i21 < _list20.Count; ++_i21) { Resource _elem22 = new Resource(); _elem22 = new Resource(); _elem22.Read(iprot); Resources.Add(_elem22); } iprot.ReadListEnd(); } } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 14: if (field.Type == TType.Struct) { Attributes = new NoteAttributes(); Attributes.Read(iprot); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 15: if (field.Type == TType.List) { { TagNames = new List<string>(); TList _list23 = iprot.ReadListBegin(); for( int _i24 = 0; _i24 < _list23.Count; ++_i24) { string _elem25 = null; _elem25 = iprot.ReadString(); TagNames.Add(_elem25); } iprot.ReadListEnd(); } } else { TProtocolUtil.Skip(iprot, field.Type); } break; default: TProtocolUtil.Skip(iprot, field.Type); break; } iprot.ReadFieldEnd(); } iprot.ReadStructEnd(); }
/// <summary> /// Updates the metadata for a single Resource. (Not its binary contents.) /// </summary> public int UpdateResource(Resource r) { lock (this) using (var httpClient = GetHttpClient()) { return GetNoteStoreClient(httpClient).updateResource(this.authToken, r); } }
internal static ENResource ResourceWithServiceResource(Resource serviceResource) { if (serviceResource.Data.Body == null) { ENSDKLogger.ENSDKLogError("Can't create an ENResource from an EDAMResource with no body"); return null; } var resource = new ENResource(); resource.Data = serviceResource.Data.Body; resource.MimeType = serviceResource.Mime; resource.Filename = serviceResource.Attributes.FileName; resource.SourceUrl = serviceResource.Attributes.SourceURL; return resource; }
internal Resource EDAMResource() { if (Data == null) { return null; } Resource resource = new Resource(); resource.Guid = Guid; if (resource.Guid == null && Data != null) { resource.Data = new Data(); resource.Data.BodyHash = DataHash; resource.Data.Size = Data.Length; resource.Data.Body = Data; } resource.Mime = MimeType; ResourceAttributes attributes = new ResourceAttributes(); if (Filename != null) { attributes.FileName = Filename; } if (SourceUrl != null) { attributes.SourceURL = SourceUrl; } resource.Attributes = attributes; return resource; }
/// <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; }
public void WriteResource(Resource resource) { Data resourceData = resource.Data; WriteResourceWithDataHash(resourceData.BodyHash, resource.Mime, null); }
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.title = iprot.ReadString(); this.__isset.title = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 3: if (field.Type == TType.String) { this.content = iprot.ReadString(); this.__isset.content = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 4: if (field.Type == TType.String) { this.contentHash = iprot.ReadBinary(); this.__isset.contentHash = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 5: if (field.Type == TType.I32) { this.contentLength = iprot.ReadI32(); this.__isset.contentLength = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 6: if (field.Type == TType.I64) { this.created = iprot.ReadI64(); this.__isset.created = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 7: if (field.Type == TType.I64) { this.updated = iprot.ReadI64(); this.__isset.updated = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 8: if (field.Type == TType.I64) { this.deleted = iprot.ReadI64(); this.__isset.deleted = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 9: if (field.Type == TType.Bool) { this.active = iprot.ReadBool(); this.__isset.active = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 10: if (field.Type == TType.I32) { this.updateSequenceNum = iprot.ReadI32(); this.__isset.updateSequenceNum = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 11: if (field.Type == TType.String) { this.notebookGuid = iprot.ReadString(); this.__isset.notebookGuid = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 12: if (field.Type == TType.List) { { this.tagGuids = new List<string>(); TList _list8 = iprot.ReadListBegin(); for( int _i9 = 0; _i9 < _list8.Count; ++_i9) { string _elem10 = null; _elem10 = iprot.ReadString(); this.tagGuids.Add(_elem10); } iprot.ReadListEnd(); } this.__isset.tagGuids = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 13: if (field.Type == TType.List) { { this.resources = new List<Resource>(); TList _list11 = iprot.ReadListBegin(); for( int _i12 = 0; _i12 < _list11.Count; ++_i12) { Resource _elem13 = new Resource(); _elem13 = new Resource(); _elem13.Read(iprot); this.resources.Add(_elem13); } iprot.ReadListEnd(); } this.__isset.resources = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 14: if (field.Type == TType.Struct) { this.attributes = new NoteAttributes(); this.attributes.Read(iprot); this.__isset.attributes = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 15: if (field.Type == TType.List) { { this.tagNames = new List<string>(); TList _list14 = iprot.ReadListBegin(); for( int _i15 = 0; _i15 < _list14.Count; ++_i15) { string _elem16 = null; _elem16 = iprot.ReadString(); this.tagNames.Add(_elem16); } iprot.ReadListEnd(); } this.__isset.tagNames = true; } else { TProtocolUtil.Skip(iprot, field.Type); } break; default: TProtocolUtil.Skip(iprot, field.Type); break; } iprot.ReadFieldEnd(); } iprot.ReadStructEnd(); }
/// <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; }
///** Submit a set of changes to a resource to the service. // This can be used to update the meta-data about the resource, but cannot be used to change the binary contents of the resource (including the length and hash). These cannot be changed directly without creating a new resource and removing the old one via updateNote. // @param resource A Resource object containing the desired fields to be populated on the service. The service will attempt to update the resource with the following fields from the client: guid(must be provided to identify the resource),mime,width,height,duration,attributes(optional. if present, the set of attributes will be replaced). // */ public int UpdateResource(Resource resource) { return Client.updateResource(AuthenticationToken(), resource); }
public OutputNoteResource(Resource res, string path) { this.mRes = res; this.mPath = path; }
private string GetResPath(Resource res, string noteBaseName, int resCount) { return noteBaseName + "_res_" + GetSeq(resCount) + OutputNoteResource.GetExtenstion(res); }
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; }