public bool BeginSyncTransaction()
{
Logger.Debug("[Evernote] Begining Sync...");
if (ConsumerKey.Equals("your_key_here"))
{
throw new Exception("You need to Update the Evernote ConsumerKey!! Open up the EvernoteSyncServer.cs file and look at it!");
}
ServicePointManager.CertificatePolicy = new CertificateManager ();
//ServicePointManager.ServerCertificateValidationCallback += ValidateServerCertificate;
bool versionOK =
_userStore.checkVersion("Tomboy.EvernoteSyncAddin",
Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MAJOR,
Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MINOR);
if (!versionOK)
{
Logger.Error("[Evernote] EDAM protocol version not up to date: " +
Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MAJOR + "." +
Evernote.EDAM.UserStore.Constants.EDAM_VERSION_MINOR);
return false;
}
string username;
string password;
if (!EvernoteSyncServiceAddin.GetConfigSettings(out username, out password))
{
return false;
}
AuthenticationResult authResult =
_userStore.authenticate(username, password, ConsumerKey, ConsumerSecret);
User user = authResult.User;
_authToken = authResult.AuthenticationToken;
Logger.Debug("[Evernote] Authentication successful for: " + user.Username);
Logger.Debug("[Evernote] Authentication token = " + _authToken);
String noteStoreUrl = EdamBaseUrl + "/edam/note/" + user.ShardId;
TTransport noteStoreTransport = new THttpClient(noteStoreUrl);
TProtocol noteStoreProtocol = new TBinaryProtocol(noteStoreTransport);
_noteStore = new NoteStore.Client(noteStoreProtocol);
//TODO - check if the user has a 'Tomboy' Notebook. If not, add one
bool foundTomboyNotebook = false;
List<Notebook> notebooks = _noteStore.listNotebooks(_authToken);
foreach (Notebook notebook in notebooks)
{
if (notebook.Name.ToLowerInvariant().Trim().Equals("tomboy"))
{
foundTomboyNotebook = true;
_tomboyNotebook = notebook;
}
}
if (!foundTomboyNotebook)
{
// no tomboy notebook found, so try to add one
_tomboyNotebook = new Notebook();
_tomboyNotebook.Name = "Tomboy";
_tomboyNotebook.DefaultNotebook = false;
_tomboyNotebook.Guid = new Guid().ToString();
_tomboyNotebook = _noteStore.createNotebook(_authToken, _tomboyNotebook);
if (_tomboyNotebook == null)
{
Logger.Error("[Evernote] Could not create 'Tomboy' notebook in evernote");
return false;
}
Console.WriteLine("[Evernote] New Tomboy notebook with guid : " + _tomboyNotebook.Guid);
}
return true;
}