Inheritance: Thrift.Transport.TTransport
 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);
 }
Beispiel #2
0
 public static UserStore.Client GetUserStore()
 {
     var userStoreUrl = new Uri(Configuration.EvernoteUrl + "/edam/user");
     var userStoreTransport = new THttpClient(userStoreUrl);
     var userStoreProtocol = new TBinaryProtocol(userStoreTransport);
     return new UserStore.Client(userStoreProtocol);
 }
        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;
        }
        public EvernoteServiceSDK1(EFDbEvernoteCredentials credentials)
        {
            this.credentials = credentials;

            THttpClient noteStoreTransport = new THttpClient(new Uri(credentials.NotebookUrl));
            TBinaryProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport);
            noteStore = new NoteStore.Client(noteStoreProtocol);
        }
Beispiel #5
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;
 }
Beispiel #6
0
 internal static NoteStore.Client GetNoteStoreClient(String edamBaseUrl, User user)
 {
     Uri noteStoreUrl = new Uri(edamBaseUrl + "/edam/note/" + user.ShardId);
     TTransport noteStoreTransport = new THttpClient(noteStoreUrl);
     TProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport);
     NoteStore.Client noteStore = new NoteStore.Client(noteStoreProtocol);
     return noteStore;
 }
 /// <summary>
 /// UserStoreの取得
 /// </summary>
 /// <returns></returns>
 private UserStore.Client GetUserStore()
 {
     Uri userStoreUrl = new Uri("https://" + mEvernoteHost + "/edam/user");
     TTransport userStoreTransport = new THttpClient(userStoreUrl);
     TProtocol userStoreProtocol = new TBinaryProtocol(userStoreTransport);
     UserStore.Client userStore = new UserStore.Client(userStoreProtocol);
     return userStore;
 }
Beispiel #8
0
        ClientService.Iface Create(string uriString)
        {
            var uri = new Uri(uriString);
            var httpClient = new THttpClient(uri);
            var jsonProtocol = new TJSONProtocol(httpClient);
            var client = new ClientService.Client(jsonProtocol);

            return client;
        }
			// ! 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;
			}
        private static Calculator.Iface CreateCalculatorClient()
        {
            var uri = new Uri("http://localhost:43857/any-url.thrift");
            var httpClient = new THttpClient(uri);
            var jsonProtocol = new TJSONProtocol(httpClient);
            var calculator = new Calculator.Client(jsonProtocol);

            return calculator;
        }
Beispiel #11
0
        public static NoteStore.Client GetNoteStore(string token)
        {
            if (string.IsNullOrEmpty(_noteStoreUrl))
            {
                var userStore = GetUserStore();
                _noteStoreUrl = userStore.getNoteStoreUrl(token);
            }

            var noteStoreTransport = new THttpClient(new Uri(_noteStoreUrl));
            var noteStoreProtocol = new TBinaryProtocol(noteStoreTransport);
            return new NoteStore.Client(noteStoreProtocol);
        }
        private void Init(string evernoteHost, string devToken)
        {
            // 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";
            String authToken = devToken;

            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");
                throw new ApplicationException("ディベロッパートークンが指定されていません。");
            }

            // 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)
            {
                throw new ApplicationException("バージョンチェックに失敗しました。"
                    + "MAJOR=" + Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MAJOR
                    + ",MINOR=" + Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MINOR);
            }

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

            mAuthToken = authToken;
            mEvernoteHost = evernoteHost;
            mNoteStore = noteStore;
        }
Beispiel #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EvernoteOAuthTest.UserAuth"/> class.
        /// </summary>
        public UserAuth()
        {
            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 OAuth Test",
                                       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;
            }
        }
Beispiel #14
0
        protected void Dispose(bool disposing)
        {
            if (!disposed)
            {
                disposed = true;
                if (disposing)
                {
                    //dispose managed state
                    httpClient.Close();
                }
                else
                {
                    System.Diagnostics.Debug.Assert(false); // you MUST dispose this object explicitely or be doomed.
                }

                httpClient = null;
                protocol = null;

                GC.SuppressFinalize(this);
            }
        }
        public string GetNoteContent(string authToken, string noteId)
        {
            var noteStoreUrl = GetNoteStoreUrl(authToken);
            var transport = new THttpClient(new Uri(noteStoreUrl));
            var protocol = new TBinaryProtocol(transport);
            var noteStore = new NoteStore.Client(protocol);

            var note = noteStore.getNote(authToken, noteId, false, false, false, false);
            var body = noteStore.getNoteSearchText(authToken, noteId, false, false);

            if (!string.IsNullOrEmpty(body))
            {
                var index = body.LastIndexOf(note.Title);
                if (index > 0)
                {
                    body = body.Substring(0, index);
                }
                body = body.Trim();
            }

            return body;
        }
        public static void runHelloWorldExample()
        {
            Uri u = new Uri("http://localhost:9090");
            TTransport transport = new THttpClient(u);

            TProtocol protocol = new TBinaryProtocol(transport);
            HelloWorld.Client client = new HelloWorld.Client(protocol);

            transport.Open();

            client.ping();
            Console.WriteLine("ping()");

            string msg = client.sayHello();
            Console.WriteLine(msg);

            msg = client.sayMsg(Constants.HELLO_IN_KOREAN);
            Console.WriteLine(msg);

            HelloStruct hellostruct = client.structTest(Constants.HELLO_IN_JAPANESE);
            Console.WriteLine(hellostruct.Id);

            transport.Close();
        }
Beispiel #17
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();
    }
Beispiel #18
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);
        }
Beispiel #19
0
		public static void Execute(string[] args)
		{
			try
			{
				string host = "localhost";
				int port = 9090;
				string url = null;
				int numThreads = 1;
				bool buffered = false, framed = false;

				try
				{
					for (int i = 0; i < args.Length; i++)
					{
						if (args[i] == "-h")
						{
							string[] hostport = args[++i].Split(':');
							host = hostport[0];
							if (hostport.Length > 1)
							{
								port = Convert.ToInt32(hostport[1]);
							}
						}
						else if (args[i] == "-u")
						{
							url = args[++i];
						}
						else if (args[i] == "-n")
						{
							numIterations = Convert.ToInt32(args[++i]);
						}
						else if (args[i] == "-b" || args[i] == "-buffered")
						{
							buffered = true;
							Console.WriteLine("Using buffered sockets");
						}
						else if (args[i] == "-f" || args[i] == "-framed")
						{
							framed = true;
							Console.WriteLine("Using framed transport");
						}
						else if (args[i] == "-t")
						{
							numThreads = Convert.ToInt32(args[++i]);
						}
					}
				}
				catch (Exception e)
				{
					Console.WriteLine(e.StackTrace);
				}



				//issue tests on separate threads simultaneously
				Thread[] threads = new Thread[numThreads];
				DateTime start = DateTime.Now;
				for (int test = 0; test < numThreads; test++)
				{
					Thread t = new Thread(new ParameterizedThreadStart(ClientThread));
					threads[test] = t;
					if (url == null)
					{
						TTransport trans = new TSocket(host, port);
						if (buffered)
							trans = new TBufferedTransport(trans as TStreamTransport);
						if (framed)
							trans = new TFramedTransport(trans);
							
						t.Start(trans);
					}
					else
					{
						THttpClient http = new THttpClient(new Uri(url));
						t.Start(http);
					}
				}

				for (int test = 0; test < numThreads; test++)
				{
					threads[test].Join();
				}
				Console.Write("Total time: " + (DateTime.Now - start));
			}
			catch (Exception outerEx)
			{
				Console.WriteLine(outerEx.Message + " ST: " + outerEx.StackTrace);
			}

			Console.WriteLine();
			Console.WriteLine();
		}
Beispiel #20
0
        /// <summary>
        ///  Thrift의 실제 Client instance를 반환하는 메서드.
        ///  
        /// 현재는 Transport와 Protocol이 각각 THttpClient와 TBinarnyProtocol로 명시되어 있음.
        /// 향후 Connection pooling등이 필요하게 될지도 모름.
        /// </summary>
        /// <returns></returns>
        private Outbound_ItemService.Client GetClient()
        {
            TTransport trans = new THttpClient(new Uri(ServiceUrl));
            try
            {
                trans.Open();
            }
            catch (Exception ex)
            {
                throw new ThriftClientException("연결을 생성할 수 없습니다.\n" + ex.Message);
            }

            TProtocol proto = new TBinaryProtocol(trans);
            Outbound_ItemService.Client client = new Outbound_ItemService.Client(proto);
            return client;
        }
    public static void Main(string[] args) {

        // --------------------------------------------------
        // UserStoreオブジェクト作成
        // --------------------------------------------------

        // 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;
        }

        // --------------------------------------------------
        // NoteStoreオブジェクト作成
        // --------------------------------------------------

        // 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);
    }
Beispiel #22
0
 private UserStore.Client GetUserStore()
 {
     var userStoreUrl = new Uri("https://www.evernote.com/edam/user");
     var userStoreTransport = new THttpClient(userStoreUrl);
     var userStoreProtocol = new TBinaryProtocol(userStoreTransport);
     return new UserStore.Client(userStoreProtocol);
 }
Beispiel #23
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");
          Console.ReadLine();
          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);
        }

        // Sample Code To Add A Notebook
        //Notebook newNoteBook = new Notebook();
        //newNoteBook.Name     = "Test Notebook";
        //noteStore.createNotebook(authToken, newNoteBook); 

        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 = "Evernote Logo";

        // 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();
        Console.WriteLine("Successfully created new note with GUID: " + createdNote.Guid);
        Console.WriteLine();
 
        // Share The Newly Created Note To Provide Access Using An Evernote URL
        // This Document Will Be Publicly Accessible.  
        string noteKey = noteStore.shareNote(authToken, createdNote.Guid);

        Console.WriteLine();
        Console.WriteLine("Successfully shared new note with Note Key: " + noteKey);
        Console.WriteLine();

        // Twitter Integration
        try
        {

            // You Can Find Your SharedId By Sharing A Document On Your Evernote Sandbox Account
            // The Evernote Generated URL Will Contain This Value
            string sharedId = "s1";
            string noteLink = "https://sandbox.evernote.com/shard/" + sharedId + "/sh/" + createdNote.Guid + "/" + noteKey;

            // You Will Need To Create A Twitter Developer Account For This Information.
            // All Of The Values Below Will Be Generated From Your Twitter Developer Account
            // Login In To Twitter And Use The Following URL:  https://dev.twitter.com/apps
            //   1. Create Twitter Developer Account
            //   2. Create A New Application
            //   2. Set Access Level To Read and Write On The Application Page
            //   3. Generate Access Token At Bottom Of The Application Page
            OAuthTokens oaTokens       = new OAuthTokens();
            oaTokens.AccessToken       = "Your Twitter Access Token Here";
            oaTokens.AccessTokenSecret = "Your Twitter Access Token Secret Here";
            oaTokens.ConsumerKey       = "Your Twitter ConsumerKey Here";
            oaTokens.ConsumerSecret    = "Your Twitter ConsumerKey Here";

            // Truncate Doc Title If It Is Longer Than 40 Characters
            string docTitle = createdNote.Title;
            if (docTitle.Length > 40)
            {
                docTitle.Substring(0, 40);
            }

            // Truncate Message If It Is Longer Than 140 Characters
            string message = "Evernote Doc - " + docTitle;
            if (message.Length > 140)
            {
                message = message.Substring(0, 140);
            }
            // Add URL To Tweet.  Twitter Will Shorten If Neccessary
            message += " " + noteLink;

            // Update Twitter Status And Check Result For Success
            TwitterResponse<TwitterStatus> twStatus = TwitterStatus.Update(oaTokens, message); 
            if (twStatus.Result.ToString().ToLower() != "success")
            {
                throw new Exception("Twitter Status Not Updated");
            }

            Console.WriteLine();
            Console.Write("Document Posted To Twitter");
            Console.WriteLine();

        }
        catch (Exception ex)
        {
            Console.Write(ex.ToString());
        }

        Console.ReadLine();
    }
Beispiel #24
0
        /// <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;
        }
Beispiel #25
0
        public static bool Execute(string[] args)
        {
            try
            {
                string host = "localhost";
                int port = 9090;
                string url = null, pipe = null;
                int numThreads = 1;
                bool buffered = false, framed = false, encrypted = false;
                string certPath = "../../../../../keys/server.pem";

                try
                {
                    for (int i = 0; i < args.Length; i++)
                    {
                        if (args[i] == "-u")
                        {
                            url = args[++i];
                        }
                        else if (args[i] == "-n")
                        {
                            numIterations = Convert.ToInt32(args[++i]);
                        }
                        else if (args[i] == "-pipe")  // -pipe <name>
                        {
                            pipe = args[++i];
                            Console.WriteLine("Using named pipes transport");
                        }
                        else if (args[i].Contains("--host="))
                        {
                            host = args[i].Substring(args[i].IndexOf("=") + 1);
                        }
                        else if (args[i].Contains("--port="))
                        {
                            port = int.Parse(args[i].Substring(args[i].IndexOf("=")+1));
                        }
                        else if (args[i] == "-b" || args[i] == "--buffered" || args[i] == "--transport=buffered")
                        {
                            buffered = true;
                            Console.WriteLine("Using buffered sockets");
                        }
                        else if (args[i] == "-f" || args[i] == "--framed"  || args[i] == "--transport=framed")
                        {
                            framed = true;
                            Console.WriteLine("Using framed transport");
                        }
                        else if (args[i] == "-t")
                        {
                            numThreads = Convert.ToInt32(args[++i]);
                        }
                        else if (args[i] == "--compact" || args[i] == "--protocol=compact")
                        {
                            protocol = "compact";
                            Console.WriteLine("Using compact protocol");
                        }
                        else if (args[i] == "--json" || args[i] == "--protocol=json")
                        {
                            protocol = "json";
                            Console.WriteLine("Using JSON protocol");
                        }
                        else if (args[i] == "--ssl")
                        {
                            encrypted = true;
                            Console.WriteLine("Using encrypted transport");
                        }
                        else if (args[i].StartsWith("--cert="))
                        {
                            certPath = args[i].Substring("--cert=".Length);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                }

                //issue tests on separate threads simultaneously
                Thread[] threads = new Thread[numThreads];
                DateTime start = DateTime.Now;
                for (int test = 0; test < numThreads; test++)
                {
                    Thread t = new Thread(new ParameterizedThreadStart(ClientThread));
                    threads[test] = t;
                    if (url == null)
                    {
                        // endpoint transport
                        TTransport trans = null;
                        if (pipe != null)
                            trans = new TNamedPipeClientTransport(pipe);
                        else
                        {
                            if (encrypted)
                                trans = new TTLSSocket(host, port, certPath);
                            else
                                trans = new TSocket(host, port);
                        }

                        // layered transport
                        if (buffered)
                            trans = new TBufferedTransport(trans as TStreamTransport);
                        if (framed)
                            trans = new TFramedTransport(trans);

                        //ensure proper open/close of transport
                        trans.Open();
                        trans.Close();
                        t.Start(trans);
                    }
                    else
                    {
                        THttpClient http = new THttpClient(new Uri(url));
                        t.Start(http);
                    }
                }

                for (int test = 0; test < numThreads; test++)
                {
                    threads[test].Join();
                }
                Console.Write("Total time: " + (DateTime.Now - start));
            }
            catch (Exception outerEx)
            {
                Console.WriteLine(outerEx.Message + " ST: " + outerEx.StackTrace);
                return false;
            }

            Console.WriteLine();
            Console.WriteLine();
            return true;
        }
Beispiel #26
0
 public ThriftHttpClient(string uri)
 {
     this.httpClient = new THttpClient(uri);
     this.protocol= new TBinaryProtocol(httpClient);
 }
Beispiel #27
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);
     }
 }
Beispiel #28
0
        /// <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;
        }
Beispiel #29
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);
        }
Beispiel #30
0
    public static void Main(string[] args) {

        if (args.Length < 2) {
            Console.WriteLine("Arguments:  <username> <password>");
            return;
        }
        String username = args[0];
        String password = args[1];

        // NOTE: You must change the consumer key and consumer secret to the 
        //       key and secret that you received from Evernote
        String consumerKey = "en-edamtest";
        String consumerSecret = "0123456789abcdef";
        
        String evernoteHost = "sandbox.evernote.com";
        String edamBaseUrl = "https://" + evernoteHost;
        // If using Mono, see http://www.mono-project.com/FAQ:_Security
        
        String userStoreUrl = edamBaseUrl + "/edam/user";
        TTransport userStoreTransport = new THttpClient(userStoreUrl);
        TProtocol userStoreProtocol = new TBinaryProtocol(userStoreTransport);
        UserStore.Client userStore = new UserStore.Client(userStoreProtocol);
        
        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);
        if (!versionOK) {
            return;
        }
        
        AuthenticationResult authResult = null;
        try {
            authResult = userStore.authenticate(username, password,
                                                consumerKey, consumerSecret);
        } catch (EDAMUserException ex) {
            String parameter = ex.Parameter;
            EDAMErrorCode errorCode = ex.ErrorCode;
            
            Console.WriteLine("Authentication failed (parameter: " + parameter + " errorCode: " + errorCode + ")");
            
            if (errorCode == EDAMErrorCode.INVALID_AUTH) {
                if (parameter == "consumerKey") {
                    if (consumerKey == "en-edamtest") {
                        Console.WriteLine("You must replace the variables consumerKey and consumerSecret with the values you received from Evernote.");
                    } else {
                        Console.WriteLine("Your consumer key was not accepted by " + evernoteHost);
                        Console.WriteLine("This sample client application requires a client API key. If you requested a web service API key, you must authenticate using OAuth");
                    }
                    Console.WriteLine("If you do not have an API Key from Evernote, you can request one from http://www.evernote.com/about/developer/api");
                } else if (parameter == "username") {
                    Console.WriteLine("You must authenticate using a username and password from " + evernoteHost);
                    if (evernoteHost == "www.evernote.com" == false) {
                        Console.WriteLine("Note that your production Evernote account will not work on " + evernoteHost + ",");
                        Console.WriteLine("you must register for a separate test account at https://" + evernoteHost + "/Registration.action");
                    }
                } else if (parameter == "password") {
                    Console.WriteLine("The password that you entered is incorrect");
                }
            }
            
            return;
        }
        
        User user = authResult.User;
        String authToken = authResult.AuthenticationToken;
        Console.WriteLine("Authentication successful for: " + user.Username);
        Console.WriteLine("Authentication token = " + authToken);
        
        String noteStoreUrl = edamBaseUrl + "/edam/note/" + user.ShardId;
        TTransport noteStoreTransport = new THttpClient(noteStoreUrl);
        TProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport);
        NoteStore.Client noteStore = new NoteStore.Client(noteStoreProtocol);
        
        List<Notebook> notebooks = noteStore.listNotebooks(authToken);
        Console.WriteLine("Found " + notebooks.Count + " notebooks:");
        Notebook defaultNotebook = notebooks[0];
        foreach (Notebook notebook in notebooks) {
            Console.WriteLine("  * " + notebook.Name);
            if (notebook.DefaultNotebook) {
                defaultNotebook = notebook;
            }
        }
        
        Console.WriteLine();
        Console.WriteLine("Creating a note in the default notebook: " +
                          defaultNotebook.Name);
        Console.WriteLine();
        
        byte[] image = ReadFully(File.OpenRead("enlogo.png"));
        byte[] hash = new MD5CryptoServiceProvider().ComputeHash(image);
        string 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/png";
        resource.Data = data;
        
        Note note = new Note();
        note.NotebookGuid = defaultNotebook.Guid;
        note.Title = "Test note from EDAMTest.cs";
        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>";

        note.Resources = new List<Resource>();
        note.Resources.Add(resource);
        
        Note createdNote = noteStore.createNote(authToken, note);
        
        Console.WriteLine("Successfully created new note with GUID: " + createdNote.Guid);
    }