Пример #1
0
        // Initialize a new ENNote from an EDAMNote.
        internal ENNote(Note edamNote)
        {
            // Copy the fields that can be edited at this level.
            _Title     = edamNote.Title;
            _Content   = ENNoteContent.NoteContentWithENML(edamNote.Content);
            IsReminder = edamNote.Attributes.ReminderOrder != 0;
            SourceUrl  = edamNote.Attributes.SourceURL;
            _TagNames  = edamNote.TagNames;            //This is usually null, unfortunately, on notes that come from the service.

            // Resources to ENResources
            _Resources = new List <ENResource>();
            if (edamNote.Resources != null)
            {
                foreach (Resource serviceResource in edamNote.Resources)
                {
                    ENResource resource = ENResource.ResourceWithServiceResource(serviceResource);
                    if (resource != null)
                    {
                        _Resources.Add(resource);
                    }
                }
            }

            // Keep a copy of the service note around with all of its extra properties
            // in case we have to convert back to an EDAMNote later.
            ServiceNote = edamNote;

            // Get rid of these references here; they take up memory and we can let them be potentially cleaned up.
            ServiceNote.Content   = null;
            ServiceNote.Resources = null;
        }
Пример #2
0
 public void AddResource(ENResource resource)
 {
     if (resource != null)
     {
         if (Resources.Count >= Evernote.EDAM.Limits.Constants.EDAM_NOTE_RESOURCES_MAX)
         {
             ENSDKLogger.ENSDKLogInfo(string.Format("Too many resources already on note. Ignoring {0}. Note {1}.", resource, this));
         }
         else
         {
             InvalidateCachedContent();
             Resources.Add(resource);
         }
     }
 }
Пример #3
0
        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);
        }
Пример #4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // Be sure to put your own consumer key and consumer secret here.
            ENSession.SetSharedSessionConsumerKey("your key", "your secret");

            if (ENSession.SharedSession.IsAuthenticated == false)
            {
                ENSession.SharedSession.AuthenticateToEvernote();
            }

            // Get a list of all notebooks in the user's account.
            List<ENNotebook> myNotebookList = ENSession.SharedSession.ListNotebooks();

            // Create a new note (in the user's default notebook) with some plain text content.
            ENNote myPlainNote = new ENNote();
            myPlainNote.Title = "My plain text note";
            myPlainNote.Content = ENNoteContent.NoteContentWithString("Hello, world!");
            ENNoteRef myPlainNoteRef = ENSession.SharedSession.UploadNote(myPlainNote, null);

            // Share this new note publicly.  "shareUrl" is the public URL to distribute to access the note.
            string shareUrl = ENSession.SharedSession.ShareNote(myPlainNoteRef);

            // Create a new note (in the user's default notebook) with some HTML content.
            ENNote myFancyNote = new ENNote();
            myFancyNote.Title = "My first note";
            myFancyNote.Content = ENNoteContent.NoteContentWithSanitizedHTML("<p>Hello, world - <i>this</i> is a <b>fancy</b> note - and here is a table:</p><br /> <br/><table border=\"1\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\"><tr><td>Red</td><td>Green</td></tr><tr><td>Blue</td><td>Yellow</td></tr></table>");
            ENNoteRef myFancyNoteRef = ENSession.SharedSession.UploadNote(myFancyNote, null);

            // Delete the HTML content note we just created.
            ENSession.SharedSession.DeleteNote(myFancyNoteRef);

            // Create a new note with a resource.
            ENNote myResourceNote = new ENNote();
            myResourceNote.Title = "My test note with a resource";
            myResourceNote.Content = ENNoteContent.NoteContentWithString("Hello, resource!");
            byte[] myFile = StreamFile("<complete path and filename of a JPG file on your computer>");    // Be sure to replace this with a real JPG file
            ENResource myResource = new ENResource(myFile, "image/jpg", "My First Picture.jpg");
            myResourceNote.Resources.Add(myResource);
            ENNoteRef myResourceRef = ENSession.SharedSession.UploadNote(myResourceNote, null);

            // Search for some text across all notes (i.e. personal, shared, and business).
            // Change the Search Scope parameter to limit the search to only personal, shared, business - or combine flags for some combination.
            string textToFind = "some text to find*";
            List<ENSessionFindNotesResult> myNotesList = ENSession.SharedSession.FindNotes(ENNoteSearch.NoteSearch(textToFind), null, ENSession.SearchScope.All, ENSession.SortOrder.RecentlyUpdated, 500);
            int personalCount = 0;
            int sharedCount = 0;
            int businessCount = 0;
            foreach (ENSessionFindNotesResult note in myNotesList)
            {
                if (note.NoteRef.Type == ENNoteRef.ENNoteRefType.TypePersonal)
                {
                    personalCount ++;
                }
                else if (note.NoteRef.Type == ENNoteRef.ENNoteRefType.TypeShared)
                {
                    sharedCount ++;
                }
                else if (note.NoteRef.Type == ENNoteRef.ENNoteRefType.TypeBusiness)
                {
                    businessCount ++;
                }
            }

            if (myNotesList.Count > 0)
            {
                // Given a NoteRef instance, download that note.
                ENNote myDownloadedNote = ENSession.SharedSession.DownloadNote(myNotesList[0].NoteRef);

                // Serialize a NoteRef.
                byte[] mySavedRef = myNotesList[0].NoteRef.AsData();
                // And deserialize it.
                ENNoteRef newRef = ENNoteRef.NoteRefFromData(mySavedRef);

                // Download the thumbnail for a note; then display it on this app's form.
                byte[] thumbnail = ENSession.SharedSession.DownloadThumbnailForNote(myNotesList[0].NoteRef, 120);
                try
                {
                    MemoryStream ms = new MemoryStream(thumbnail, 0, thumbnail.Length);
                    ms.Position = 0;
                    System.Drawing.Image image1 = System.Drawing.Image.FromStream(ms, false, false);
                    pictureBoxThumbnail.Image = image1;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }

            }

        }
		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;
		}
Пример #6
0
		public void AddResource(ENResource resource)
		{
			if (resource != null)
			{
				if (Resources.Count >= Evernote.EDAM.Limits.Constants.EDAM_NOTE_RESOURCES_MAX)
				{
					ENSDKLogger.ENSDKLogInfo(string.Format("Too many resources already on note. Ignoring {0}. Note {1}.", resource, this));
				}
				else
				{
					InvalidateCachedENML();
					Resources.Add(resource);
				}
			}
		}
        /// <summary>
        /// Evernoteにファイルをアップロードします
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uploadButton_Click(object sender, RoutedEventArgs e)
        {
            FileList list = this.DataContext as FileList;

              try
              {
            foreach (var f in list.FileNames)
            {
              ENNote resourceNote = new ENNote();
              resourceNote.Title = "My test note with a resource";
              resourceNote.Content = ENNoteContent.NoteContentWithString("Hello, resource!");
              byte[] file = File.ReadAllBytes(f);
              FileInfo fInfo = new FileInfo(f);
              ENResource resource = new ENResource(file, MimeTypeMap.GetMimeType(fInfo.Extension), fInfo.Name);
              resourceNote.Resources.Add(resource);
              ENNoteRef resourceRef = ENSession.SharedSession.UploadNote(resourceNote, null);
            }
              }
              catch (Exception ex)
              {
            ModernDialog.ShowMessage("アップロード中にエラーが発生しました。", "お知らせ", MessageBoxButton.OK);
            return;
              }
              ModernDialog.ShowMessage("アップロードが完了しました。", "お知らせ", MessageBoxButton.OK);
        }