public EvernoteConnect()
 {
     FUserStoreUrl       = new Uri("https://" + FEvernoteHost + "/edam/user");
     FUserStoreTransport = new THttpClient(FUserStoreUrl);
     FUserStoreProtocol  = new TBinaryProtocol(FUserStoreTransport);
     FUserStore          = new UserStore.Client(FUserStoreProtocol);
 }
        public EvernoteSyncServer()
        {
            TTransport userStoreTransport = new THttpClient(UserStoreUrl);
            TProtocol  userStoreProtocol  = new TBinaryProtocol(userStoreTransport);

            _userStore = new UserStore.Client(userStoreProtocol);
        }
示例#3
0
        /// <summary>
        /// Evernoteのノートブック情報を取得する
        /// </summary>
        /// <param name="EvernoteToken">Evernoteトークン</param>
        /// <returns>ノートブック名とノートブックGuidのDictionary</returns>
        static public Dictionary <string, string> GetEvetnoteNotebook(string EvernoteToken)
        {
            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);

            List <Notebook> notebooks = noteStore.listNotebooks(authToken);

            Dictionary <string, string> notebookNames = new Dictionary <string, string>();

            foreach (var note in notebooks)
            {
                notebookNames.Add(note.Name, note.Guid);
            }

            return(notebookNames);
        }
示例#4
0
        public Wrapper()
        {
            Uri        userStoreUrl       = new Uri("https://" + evernoteHost + "/edam/user");
            TTransport userStoreTransport = new THttpClient(userStoreUrl);
            TProtocol  userStoreProtocol  = new TBinaryProtocol(userStoreTransport);

            userStore = new UserStore.Client(userStoreProtocol);
        }
示例#5
0
        public UserService(string authToken)
        {
            _authToken = authToken;

            if (_Instance == null)
            {
                _Instance = CreateInstance();
            }
        }
示例#6
0
        internal static UserStore.Client GetUserStoreClient(string edamBaseUrl)
        {
            Uri        userStoreUrl       = new Uri(edamBaseUrl + "/edam/user");
            TTransport userStoreTransport = new THttpClient(userStoreUrl);
            TProtocol  userStoreProtocol  = new TBinaryProtocol(userStoreTransport);

            UserStore.Client userStore = new UserStore.Client(userStoreProtocol);
            return(userStore);
        }
            // ! DO NOT INSTANTIATE THIS OBJECT DIRECTLY. GET ONE FROM AN AUTHENTICATED ENSESSION !

            internal ENUserStoreClient(string userStoreUrl, string authToken)
            {
                Uri url = new Uri(userStoreUrl);

                TTransport transport = new THttpClient(url);
                TProtocol  protocol  = new TBinaryProtocol(transport);

                Client = new UserStore.Client(protocol);
                AuthenticationToken = authToken;
            }
示例#8
0
        internal static bool VerifyEDAM(UserStore.Client userStore)
        {
            bool versionOK =
                userStore.checkVersion("C# EDAMTest",
                                       Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MAJOR,
                                       Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MINOR);

            Console.WriteLine("Is my EDAM protocol version up to date? " + versionOK);
            return(versionOK);
        }
示例#9
0
 private User GetUser(UserStore.Client userStore, string authToken)
 {
     try {
         return(userStore.getUser(authToken));
     }
     catch (Exception ex) {
         throw new EverpageException(
                   String.Format("Error occurred when getting user by authentication token '{0}': {1}", authToken, ex.Message),
                   ex);
     }
 }
示例#10
0
 private PublicUserInfo GetPublicUserInfo(UserStore.Client userStore, string username)
 {
     try {
         return(userStore.getPublicUserInfo(username));
     }
     catch (Exception ex) {
         throw new EverpageException(
                   String.Format("Error occurred when getting public info for user '{0}': {1}", username, ex.Message),
                   ex);
     }
 }
示例#11
0
        /// <summary>
        /// Evernoteのユーザー名を取得する
        /// </summary>
        /// <param name="EvernoteToken">Evernoteトークン</param>
        /// <returns>ユーザー名</returns>
        static public string GetEvernoteUserName(string EvernoteToken)
        {
            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);

            return(userStore.getUser(authToken).Username);
        }
示例#12
0
        public void GetNotebooks(object arguments)
        {
            string[] inputs      = (string[])arguments;
            string   username    = inputs[0];
            string   password    = inputs[1];
            string   savePath    = inputs[2];
            string   edamBaseUrl = @"https://www.evernote.com";

            UserStore.Client userStore = EvernoteHelper.GetUserStoreClient(edamBaseUrl);
            if (EvernoteHelper.VerifyEDAM(userStore) == false)
            {
                return;
            }

            try
            {
                AuthenticationResult authResult = EvernoteHelper.Authenticate(username, password, consumerKey, consumerSecret, "www.evernote.com", userStore);
                enNotebooks = ReadEvernoteNotebooks(edamBaseUrl, authResult);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                EnableControls(true);
                return;
            }

            if (rdoExportSelected.Checked)
            {
                NotebookSelection nbSelect = new NotebookSelection();
                nbSelect.ShowDialog(enNotebooks);
                enNotebooks = nbSelect.nbListKeep;
                if (enNotebooks.Count == 0)
                {
                    MessageBox.Show("There were no notebooks selected and will stop processing.", "Notebooks Not Selected", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    EnableControls(true);
                    return;
                }
            }

            try
            {
                AuthenticationResult authResult = EvernoteHelper.Authenticate(username, password, consumerKey, consumerSecret, "www.evernote.com", userStore);
                enNotebooks = ReadEvernoteNotes(edamBaseUrl, authResult);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                EnableControls(true);
                return;
            }
            Create(arguments);
        }
示例#13
0
 private NoteStore.Client GetNoteStore(UserStore.Client userStore, string authToken)
 {
     try {
         var noteStoreUrl       = userStore.getNoteStoreUrl(authToken);
         var noteStoreTransport = new THttpClient(new Uri(noteStoreUrl));
         var noteStoreProtocol  = new TBinaryProtocol(noteStoreTransport);
         return(new NoteStore.Client(noteStoreProtocol));
     }
     catch (Exception ex) {
         throw new EverpageException(
                   String.Format("Error occurred when getting note store: {0}", ex.Message),
                   ex);
     }
 }
示例#14
0
        public static void RunImpl(DependencyObject dispatcherOwner, ViewModel viewModel)
        {
            if (authToken == "your developer token")
            {
                ShowMessage(dispatcherOwner, "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(dispatcherOwner, () => viewModel.IsVersionOk = 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(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(dispatcherOwner, () =>
            {
                foreach (var notebook in notebooks)
                {
                    viewModel.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(dispatcherOwner, () =>
            {
                foreach (var note in notes.Notes)
                {
                    viewModel.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(dispatcherOwner, "Successfully created new note with GUID: " + createdNote.Guid);
        }
示例#15
0
        private async void ClickedCreateNoteButton(object sender, EventArgs e)
        {
            try
            {
                string authToken    = "authToken";
                string evernoteHost = "sandbox.evernote.com";

                string url = urlEntry.Text;
                if (string.IsNullOrWhiteSpace(url))
                {
                    throw new Exception("URLを入力してください。");
                }
                Debug.WriteLine("URL=" + url);

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

                bool versionOk = userStore.checkVersion("InstantEverClip",
                                                        Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MAJOR,
                                                        Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MINOR);
                if (!versionOk)
                {
                    throw new Exception("バージョン・チェックがエラーになりました。");
                }

                var noteTitle = "";
                var req       = WebRequest.Create(url);
                var res       = await req.GetResponseAsync();

                using (Stream s = res.GetResponseStream())
                {
                    var htmlDoc = new HtmlDocument();
                    var buf     = new byte[1024 * 1024];
                    var ms      = new MemoryStream();
                    var len     = 0;
                    while ((len = s.Read(buf, 0, buf.Length)) > 0)
                    {
                        ms.Write(buf, 0, len);
                    }

                    buf = ms.ToArray();
                    var html = "";
                    var enc  = Hnx8.ReadJEnc.ReadJEnc.JP.GetEncoding(buf, buf.Length, out html);
                    if (enc != null)
                    {
                        Debug.WriteLine("HTML Encoding=" + enc.ToString());
                        htmlDoc.LoadHtml(html);
                        HtmlNode titleNode = htmlDoc.DocumentNode.Descendants("title").First();
                        if (titleNode != null)
                        {
                            if (!string.IsNullOrWhiteSpace(titleNode.InnerText))
                            {
                                noteTitle = titleNode.InnerText;
                                Debug.WriteLine("noteTitle=" + noteTitle);
                            }
                            else
                            {
                                noteTitle = url;
                                Debug.WriteLine("title tag is empty.");
                            }
                        }
                        else
                        {
                            noteTitle = url;
                            Debug.WriteLine("title tag is not found.");
                        }
                    }
                    else
                    {
                        noteTitle = url;
                        Debug.WriteLine("url is not text/html.");
                    }
                }

                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      = noteTitle;
                note.Attributes = new NoteAttributes
                {
                    SourceURL = urlEntry.Text
                };
                note.Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
                               + "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">"
                               + "<en-note>" + noteTitle + "<br />" + urlEntry.Text + "</en-note>";

                noteStore.createNote(authToken, note);
                Debug.WriteLine("create note succeed.");
                App.ShowToast(ToastNotificationType.Success, noteTitle, "ノートを作成しました。");

                urlEntry.Text = string.Empty;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                App.ShowToast(ToastNotificationType.Error, "エラー", ex.ToString());
            }
        }
示例#16
0
        internal static AuthenticationResult Authenticate(String username, String password, String consumerKey, String consumerSecret, String evernoteHost, UserStore.Client userStore)
        {
            AuthenticationResult authResult;

            try
            {
                authResult = userStore.authenticate(username, password, consumerKey, consumerSecret);
            }
            catch (EDAMUserException ex)
            {
                String        parameter = ex.Parameter;
                EDAMErrorCode errorCode = ex.ErrorCode;

                if (parameter.ToLower() == "consumerkey")
                {
                    throw new ApplicationException("API Key Missing. \r\n Please download latest en2ki release from homepage");
                }
                else
                {
                    throw new ApplicationException(String.Format("Authentication Failed \r\n (Make sure {0} is correct)", parameter));
                }
            }
            return(authResult);
        }
示例#17
0
    public static void Main(string[] args)
    {
        // Real applications authenticate with Evernote using OAuth, but for the
        // purpose of exploring the API, you can get a developer token that allows
        // you to access your own Evernote account. To get a developer token, visit
        // https://sandbox.evernote.com/api/DeveloperToken.action
        String authToken = "your developer token";

        if (authToken == "your developer token")
        {
            Console.WriteLine("Please fill in your developer token");
            Console.WriteLine("To get a developer token, visit https://sandbox.evernote.com/api/DeveloperToken.action");
            return;
        }

        // Initial development is performed on our sandbox server. To use the production
        // service, change "sandbox.evernote.com" to "www.evernote.com" and replace your
        // developer token above with a token from
        // https://www.evernote.com/api/DeveloperToken.action
        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);

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

        // List all of the notebooks in the user's account
        List <Notebook> notebooks = noteStore.listNotebooks(authToken);

        Console.WriteLine("Found " + notebooks.Count + " notebooks:");
        foreach (Notebook notebook in notebooks)
        {
            Console.WriteLine("  * " + notebook.Name);
        }

        Console.WriteLine();
        Console.WriteLine("Creating a note in the default notebook");
        Console.WriteLine();

        // To create a new note, simply create a new Note object and fill in
        // attributes such as the note's title.
        Note note = new Note();

        note.Title = "Test note from EDAMTest.cs";

        // To include an attachment such as an image in a note, first create a Resource
        // for the attachment. At a minimum, the Resource contains the binary attachment
        // data, an MD5 hash of the binary data, and the attachment MIME type. It can also
        // include attributes such as filename and location.
        ImageConverter converter = new ImageConverter();

        byte[] image = (byte[])converter.ConvertTo(Resources.enlogo, 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;

        // Now, add the new Resource to the note's list of resources
        note.Resources = new List <Resource>();
        note.Resources.Add(resource);

        // To display the Resource as part of the note's content, include an <en-media>
        // tag in the note's ENML content. The en-media tag identifies the corresponding
        // Resource using the MD5 hash.
        string hashHex = BitConverter.ToString(hash).Replace("-", "").ToLower();

        // The content of an Evernote note is represented using Evernote Markup Language
        // (ENML). The full ENML specification can be found in the Evernote API Overview
        // at http://dev.evernote.com/documentation/cloud/chapters/ENML.php
        note.Content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                       "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">" +
                       "<en-note>Here's the Evernote logo:<br/>" +
                       "<en-media type=\"image/png\" hash=\"" + hashHex + "\"/>" +
                       "</en-note>";

        // Finally, send the new note to Evernote using the createNote method
        // The new Note object that is returned will contain server-generated
        // attributes such as the new note's unique GUID.
        Note createdNote = noteStore.createNote(authToken, note);

        Console.WriteLine("Successfully created new note with GUID: " + createdNote.Guid);
    }
示例#18
0
        /// <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);
        }