findNotes() публичный Метод

public findNotes ( string authenticationToken, NoteFilter filter, int offset, int maxNotes ) : NoteList
authenticationToken string
filter NoteFilter
offset int
maxNotes int
Результат NoteList
        public IEnumerable<EverNote> GetDefaultNoteBookNotes(string authToken)
        {
            var noteStoreUrl = GetNoteStoreUrl(authToken);
            var transport = new THttpClient(new Uri(noteStoreUrl));
            var protocol = new TBinaryProtocol(transport);
            var noteStore = new NoteStore.Client(protocol);
            var notes = new List<EverNote>();

            var notebooks = noteStore.listNotebooks(authToken);

            foreach (Notebook notebook in notebooks)
            {
                if (notebook.DefaultNotebook)
                {
                    var findResult = noteStore.findNotes(authToken, new NoteFilter { NotebookGuid = notebook.Guid }, 0, int.MaxValue);
                    foreach (var note in findResult.Notes)
                    {
                        notes.Add(new EverNote(note.Guid, note.Title));
                    }
                    break;
                }
            }

            return notes;
        }
Пример #2
0
        /// <summary>
        /// Fetches the first n suitable notes to tweet.
        /// </summary>
        public static List<Note> GetNotesToTweet( int numNotesWanted )
        {
            if ( LoginNeeded )
                Login( );

            // Connect to the note store.  
            log.Info( "Fetching notebooks..." );
            NoteStore.Client noteClient = new NoteStore.Client( new TBinaryProtocol( new THttpClient( new Uri( BaseUrl + "/edam/note/" + authentication.User.ShardId ) ) ) );

            // Find the specified notebook.
            List<Notebook> notebooks = noteClient.listNotebooks( authentication.AuthenticationToken );
            Notebook notebook = notebooks.Find( delegate( Notebook n ) { return n.Name == "Users in Hell"; } );

            // Get a list of the most recent notes.
            NoteList notes = noteClient.findNotes( authentication.AuthenticationToken, new NoteFilter { Ascending = true, Order = 1, NotebookGuid = notebook.Guid }, 0, 300 );
            log.Info( "Found " + notes.Notes.Count + " notes in the notebook." );
            
            // Filter down to the first n untweeted notes. Download the attached images. And return!
            return FetchResources( FilterNotes( notes.Notes, numNotesWanted), noteClient );
        }
Пример #3
0
    public static void Main(string[] args)
    {
        // Developer token for Evernote API
        String authToken = "S=s1:U=2261f:E=13eccfa5d71:C=13775493171:P=1cd:A=en-devtoken:H=fe7ee8dac619c7d380a0f9f3731a8698";

        String evernoteHost = "sandbox.evernote.com";

        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);

        FNHSessionManager<NoteEntry> sessionManager = new FNHSessionManager<NoteEntry>(FNHSessionManager<NoteEntry>.DatabaseType.MySQL);
        FNHRepository<NoteEntry> repository = new FNHRepository<NoteEntry>(sessionManager);

        bool versionOK =
            userStore.checkVersion("Evernote EDAMTest (C#)",
               Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MAJOR,
               Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MINOR);
        Console.WriteLine("Is my Evernote API version up to date? " + versionOK);
        if (!versionOK) {
            return;
        }

        // Get the URL used to interact with the contents of the user's account
        // When your application authenticates using OAuth, the NoteStore URL will
        // be returned along with the auth token in the final OAuth request.
        // In that case, you don't need to make this call.
        String noteStoreUrl = userStore.getNoteStoreUrl(authToken);

        TTransport noteStoreTransport = new THttpClient(new Uri(noteStoreUrl));
        TProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport);
        NoteStore.Client noteStore = new NoteStore.Client(noteStoreProtocol);

        // Lists all of the notebooks in the user's account with a notebook count
        List<Notebook> notebooks = noteStore.listNotebooks(authToken);
        Console.WriteLine("Found " + notebooks.Count + " notebooks:");
        foreach (Notebook notebook in notebooks) {
            Console.WriteLine("  * " + notebook.Name);
        }

        //The offset represents the index of the first note that is to be returned
        int offset = 0;

        //maxNotes represents the number of note that is to be returned
        int maxNotes = 15;

        //NoteFilter is a struct that contains a list of criteria you can search notes for.
        //In this app, NoteFilter.Words will be used to return notes containing a certain string.
        NoteFilter filter = new NoteFilter();

        Console.WriteLine();
        Console.WriteLine("What word do you want to search through the notes for?");
        Console.WriteLine("Enter word: ");
        filter.Words = Console.ReadLine();
        //filter.Words = "business";

        //Creates a new NoteList struct, which returns a list of individual notes out of a larger set of them
        NoteList noteList = new NoteList();

        //This finds all notes containing the word that was given by the user
        noteList = noteStore.findNotes(authToken, filter, offset, maxNotes);

        //This stores the Guids of the notes containing the word
        ArrayList guidList = new ArrayList();

        // For each note in the list of notes...
        foreach (Note fetchedNote in noteList.Notes)
        {
            //Console.WriteLine("  * " + fetchedNote.Guid);

            // Add guid to list
            guidList.Add(fetchedNote.Guid);
        }

        // For each guid in the list...
        foreach (String Guid in guidList)
        {
            // Get the contents of the matching notes
            String text = noteStore.getNoteContent(authToken, Guid);

            // Then split the contents by line
            string[] split = Regex.Split(text, "\\n");

            Console.WriteLine();

            int MAX = split.Length;

            String line1;
            String line2;
            String line3;

            // This for-loop cycles through each line in the array of lines and tests if the line contains the word.
            // If so, it sets the note Guid as well as the surrounding lines as properties to a new Entry object.

            for (int n = 0; n < MAX; n++)
            {
                Boolean b = split[n].Contains(filter.Words);

                if (b == true)
                {
                    line2 = split[n];
                    line1 = split[n - 1];
                    line3 = split[n + 1];

                    Entry postgresEntry = new Entry();
                    postgresEntry.setGuid(Guid);
                    postgresEntry.setLine1(line1);
                    postgresEntry.setLine2(line2);
                    postgresEntry.setLine3(line3);

                    Console.WriteLine("Note GUID: " + postgresEntry.getGuid());
                    Console.WriteLine();
                    postgresEntry.displayLines();
                    postgresEntry.InsertRow();
                    Console.WriteLine();
                    //postgresEntry.getLastInsertedRow();

                    NoteEntry mysqlNote = new NoteEntry();
                    mysqlNote.Guid = Guid;
                    mysqlNote.Line1 = line1;
                    mysqlNote.Line2 = line2;
                    mysqlNote.Line3 = line3;

                    repository.Create(mysqlNote);
                }
            }
        }

        Console.WriteLine();
        Console.WriteLine("These lines have been saved to a Postgresql database using ODBC.");
        Console.WriteLine("They have also been saved to a MySQL database using Fluent NHibernate.");
        Console.WriteLine();
        Console.WriteLine("Which row do you want to retrieve from the MySQL database?");
        String id = Console.ReadLine();
        int num = int.Parse(id);
        NoteEntry noteEntry = repository.RetrieveById(num);

        Console.WriteLine("This is entry " + num + " retrieved from the MySQL database...");
        Console.WriteLine();
        Console.WriteLine("GUID: " + noteEntry.Guid);
        Console.WriteLine("Line 1: " + noteEntry.Line1);
        Console.WriteLine("Line 2: " + noteEntry.Line2);
        Console.WriteLine("Line 3: " + noteEntry.Line3);
        Console.WriteLine();

        Console.WriteLine("Click ENTER to continue...");
        Console.ReadLine();
    }
Пример #4
0
        public static void RunImpl(object state)
        {
            // Username and password of the Evernote user account to access
            const string username = ""; // Enter your username here
            const string password = ""; // Enter your password here

            if ((ConsumerKey == String.Empty) || (ConsumerSecret == String.Empty))
            {
                ShowMessage("Please provide your API key in Sample.cs");
                return;
            }
            if ((username == String.Empty) || (password == String.Empty))
            {
                ShowMessage("Please provide your username and password in Sample.cs");
                return;
            }

            // Instantiate the libraries to connect the service
            TTransport userStoreTransport = new THttpClient(new Uri(UserStoreUrl));
            TProtocol userStoreProtocol = new TBinaryProtocol(userStoreTransport);
            UserStore.Client userStore = new UserStore.Client(userStoreProtocol);

            // Check that the version is correct
            bool versionOK =
                userStore.checkVersion("C# EDAMTest",
                   Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MAJOR,
                   Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MINOR);
            InvokeOnUIThread(() => ViewModel.TheViewModel.VersionOK = versionOK);
            Debug.WriteLine("Is my EDAM protocol version up to date? " + versionOK);
            if (!versionOK)
            {
                return;
            }

            // Now we are going to authenticate
            AuthenticationResult authResult;
            try
            {
                authResult = userStore.authenticate(username, password, ConsumerKey, ConsumerSecret);
            }
            catch (EDAMUserException ex)
            {
                HandleAuthenticateException(EvernoteHost, ConsumerKey, ex);
                return;
            }
            Debug.WriteLine("We are connected to the service");

            // User object received after authentication
            User user = authResult.User;
            String authToken = authResult.AuthenticationToken;
            InvokeOnUIThread(() => ViewModel.TheViewModel.AuthToken = authToken);

            Debug.WriteLine("Authentication successful for: " + user.Username);
            Debug.WriteLine("Authentication token = " + authToken);

            // Creating the URL of the NoteStore based on the user object received
            String noteStoreUrl = EDAMBaseUrl + "/edam/note/" + user.ShardId;

            TTransport noteStoreTransport = new THttpClient(new Uri(noteStoreUrl));
            TProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport);
            NoteStore.Client noteStore = new NoteStore.Client(noteStoreProtocol);

            // Listing all the user's notebook
            List<Notebook> notebooks = noteStore.listNotebooks(authToken);
            Debug.WriteLine("Found " + notebooks.Count + " notebooks:");
            InvokeOnUIThread(() => notebooks.ForEach(notebook => ViewModel.TheViewModel.Notebooks.Add(notebook)));

            // Find the default notebook
            Notebook defaultNotebook = notebooks.Single(notebook => notebook.DefaultNotebook);

            // Printing the names of the notebooks
            foreach (Notebook notebook in notebooks)
            {
                Debug.WriteLine("  * " + notebook.Name);
            }

            // Listing the first 10 notes in the default notebook
            NoteFilter filter = new NoteFilter { NotebookGuid = defaultNotebook.Guid };
            NoteList notes = noteStore.findNotes(authToken, filter, 0, 10);
            InvokeOnUIThread(() => notes.Notes.ForEach(note => ViewModel.TheViewModel.Notes.Add(note)));
            foreach (Note note in notes.Notes)
            {
                Debug.WriteLine("  * " + note.Title);
            }

            // Creating a new note in the default notebook
            Debug.WriteLine("Creating a note in the default notebook: " + defaultNotebook.Name);

            Note newNote = new Note
                            {
                                NotebookGuid = defaultNotebook.Guid,
                                Title = "Test note from EDAMTest.cs",
                                Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                                          "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">" +
                                          "<en-note>Here's an Evernote test note<br/>" +
                                          "</en-note>"
                            };

            Note createdNote = noteStore.createNote(authToken, newNote);

            ShowMessage("Successfully created new note with GUID: " + createdNote.Guid);
        }
Пример #5
0
        public static void RunImpl(object state)
        {
            if (authToken == "your developer token") {
            {
                ShowMessage("Please fill in your devleoper token in Sample.cs");
                return;
            }

            // Instantiate the libraries to connect the service
            TTransport userStoreTransport = new THttpClient(new Uri(UserStoreUrl));
            TProtocol userStoreProtocol = new TBinaryProtocol(userStoreTransport);
            UserStore.Client userStore = new UserStore.Client(userStoreProtocol);

            // Check that the version is correct
            bool versionOK =
                userStore.checkVersion("Evernote EDAMTest (WP7)",
                   Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MAJOR,
                   Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MINOR);
            InvokeOnUIThread(() => ViewModel.TheViewModel.VersionOK = versionOK);
            Debug.WriteLine("Is my Evernote API version up to date? " + versionOK);
            if (!versionOK)
            {
                return;
            }

            // Get the URL used to interact with the contents of the user's account
            // When your application authenticates using OAuth, the NoteStore URL will
            // be returned along with the auth token in the final OAuth request.
            // In that case, you don't need to make this call.
            String noteStoreUrl = userStore.getNoteStoreUrl(authToken);

            TTransport noteStoreTransport = new THttpClient(new Uri(authResult.NoteStoreUrl));
            TProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport);
            NoteStore.Client noteStore = new NoteStore.Client(noteStoreProtocol);

            // Listing all the user's notebook
            List<Notebook> notebooks = noteStore.listNotebooks(authToken);
            Debug.WriteLine("Found " + notebooks.Count + " notebooks:");
            InvokeOnUIThread(() => notebooks.ForEach(notebook => ViewModel.TheViewModel.Notebooks.Add(notebook)));

            // Find the default notebook
            Notebook defaultNotebook = notebooks.Single(notebook => notebook.DefaultNotebook);

            // Printing the names of the notebooks
            foreach (Notebook notebook in notebooks)
            {
                Debug.WriteLine("  * " + notebook.Name);
            }

            // Listing the first 10 notes in the default notebook
            NoteFilter filter = new NoteFilter { NotebookGuid = defaultNotebook.Guid };
            NoteList notes = noteStore.findNotes(authToken, filter, 0, 10);
            InvokeOnUIThread(() => notes.Notes.ForEach(note => ViewModel.TheViewModel.Notes.Add(note)));
            foreach (Note note in notes.Notes)
            {
                Debug.WriteLine("  * " + note.Title);
            }

            // Creating a new note in the default notebook
            Debug.WriteLine("Creating a note in the default notebook: " + defaultNotebook.Name);

            Note newNote = new Note
                            {
                                NotebookGuid = defaultNotebook.Guid,
                                Title = "Test note from EDAMTest.cs",
                                Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                                          "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">" +
                                          "<en-note>Here's an Evernote test note<br/>" +
                                          "</en-note>"
                            };

            Note createdNote = noteStore.createNote(authToken, newNote);

            ShowMessage("Successfully created new note with GUID: " + createdNote.Guid);
        }