Пример #1
0
        private void DeleteTestNotes()
        {
            sync.LoadNotes();

            //Outlook.NoteItem outlookNote = sync.OutlookNotes.Find("[Body] = '" + body + "'") as Outlook.NoteItem;
            foreach (Outlook.NoteItem outlookNote in sync.OutlookNotes)
            {
                if (outlookNote != null &&
                    outlookNote.Body != null && outlookNote.Body == body)
                {
                    DeleteTestNote(outlookNote);
                }
            }

            foreach (Document googleNote in sync.GoogleNotes)
            {
                try
                {
                    string noteBody = NotePropertiesUtils.GetBody(sync, googleNote);
                    if (googleNote != null &&
                        noteBody != null && noteBody == body)
                    {
                        DeleteTestNote(googleNote);
                    }
                }
                catch (System.Exception ex)
                {
                    throw new System.Exception("Error deleting Google note '" + (googleNote == null?null:googleNote.Title), ex);
                }
            }

            //Delete empty Google note folders
            sync.CleanUpGoogleCategories();
        }
Пример #2
0
        private void DeleteTestNote(Document googleNote)
        {
            if (googleNote != null)
            {
                sync.DocumentsRequest.Delete(new Uri(Google.GData.Documents.DocumentsListQuery.documentsBaseUri + "/" + googleNote.ResourceId), googleNote.ETag);
                //sync.DocumentsRequest.Delete(googleNote);

                ////ToDo: Currently, the Delete only removes the Notes label from the document but keeps the document in the root folder, therefore the following workaround
                //Document deletedNote = sync.LoadGoogleNotes(googleNote.DocumentEntry.Id);
                //if (deletedNote != null)
                //    sync.DocumentsRequest.Delete(deletedNote);

                try
                {//Delete also the according temporary NoteFile
                    File.Delete(NotePropertiesUtils.GetFileName(googleNote.Id, sync.SyncProfile));
                }
                catch (System.Exception)
                { }
            }
        }
Пример #3
0
        public void CreateNewNote()
        {
            string gmailUsername;
            string syncProfile;

            GoogleAPITests.LoadSettings(out gmailUsername, out syncProfile);

            DocumentsRequest service;

            var scopes = new List <string>();

            //Contacts-Scope
            scopes.Add("https://www.google.com/m8/feeds");
            //Notes-Scope
            scopes.Add("https://docs.google.com/feeds/");
            //scopes.Add("https://docs.googleusercontent.com/");
            //scopes.Add("https://spreadsheets.google.com/feeds/");
            //Calendar-Scope
            //scopes.Add("https://www.googleapis.com/auth/calendar");
            scopes.Add(CalendarService.Scope.Calendar);

            UserCredential credential;

            byte[] jsonSecrets = Properties.Resources.client_secrets;

            using (var stream = new MemoryStream(jsonSecrets))
            {
                FileDataStore fDS = new FileDataStore(Logger.AuthFolder, true);

                GoogleClientSecrets clientSecrets = GoogleClientSecrets.Load(stream);

                credential = GCSMOAuth2WebAuthorizationBroker.AuthorizeAsync(
                    clientSecrets.Secrets,
                    scopes.ToArray(),
                    gmailUsername,
                    CancellationToken.None,
                    fDS).
                             Result;

                OAuth2Parameters parameters = new OAuth2Parameters
                {
                    ClientId     = clientSecrets.Secrets.ClientId,
                    ClientSecret = clientSecrets.Secrets.ClientSecret,

                    // Note: AccessToken is valid only for 60 minutes
                    AccessToken  = credential.Token.AccessToken,
                    RefreshToken = credential.Token.RefreshToken
                };

                RequestSettings settings = new RequestSettings("GoContactSyncMod", parameters);

                service = new DocumentsRequest(settings);

                //Instantiate an Authenticator object according to your authentication, to use ResumableUploader
                _authenticator = new OAuth2Authenticator("GCSM Unit Tests", parameters);
            }



            //Delete previously created test note.
            DeleteTestNote(service);

            Document newEntry = new Document();

            newEntry.Type  = Document.DocumentType.Document;
            newEntry.Title = "AN_OUTLOOK_TEST_NOTE";

            string file = NotePropertiesUtils.CreateNoteFile("AN_OUTLOOK_TEST_NOTE", "This is just a test note to test GoContactSyncMod", null);

            newEntry.MediaSource = new MediaFileSource(file, MediaFileSource.GetContentTypeForFileName(file));

            #region normal flow, only working to create documents without content (metadata only), e.g. for Notes folder

            Document createdEntry = Synchronizer.SaveGoogleNote(null, newEntry, service);

            Assert.IsNotNull(createdEntry.DocumentEntry.Id.Uri);

            Logger.Log("Created Google note", EventType.Information);

            //Wait 5 seconds to give the testcase the chance to finish
            System.Threading.Thread.Sleep(5000);

            //delete test note
            DeleteTestNote(service);
            #endregion

            #region workaround flow to use UploadDocument, not needed anymore because of new approach to use ResumableUploader
            //Google.GData.Documents.DocumentEntry createdEntry2 = service.Service.UploadDocument(file, newEntry.Title);

            //Assert.IsNotNull(createdEntry2.Id.Uri);

            ////delete test note
            //DeleteTestNote(service);
            #endregion

            #region New approach how to update an existing document: https://developers.google.com/google-apps/documents-list/#updatingchanging_documents_and_files
            //Instantiate the ResumableUploader component.
            ResumableUploader uploader = new ResumableUploader();
            uploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(OnGoogleNoteCreated);
            Synchronizer.CreateGoogleNote(newEntry, file, service, uploader, _authenticator);
            #endregion

            //Wait 5 seconds to give the testcase the chance to finish the Async events
            System.Threading.Thread.Sleep(5000);

            DeleteTestNote(service);
        }
Пример #4
0
        public void TestResetMatches()
        {
            sync.SyncOption = SyncOption.MergeOutlookWins;

            // create new Note to sync
            Outlook.NoteItem outlookNote = Synchronizer.CreateOutlookNoteItem(Synchronizer.SyncNotesFolder);
            outlookNote.Body = body;
            outlookNote.Save();

            Document googleNote = new Document();

            googleNote.Type = Document.DocumentType.Document;
            sync.UpdateNote(outlookNote, googleNote);
            NoteMatch match = new NoteMatch(outlookNote, googleNote);

            //save Note to google.
            sync.SaveNote(match);

            for (int i = 0; match.AsyncUpdateCompleted.HasValue && !match.AsyncUpdateCompleted.Value && i < 10; i++)
            {
                Thread.Sleep(1000);//DoNothing, until the Async Update is complete, but only wait maximum 10 seconds
            }
            //load the same Note from google.
            sync.MatchNotes();
            match = FindMatch(outlookNote);
            NotesMatcher.SyncNote(match, sync);

            // delete outlook Note
            outlookNote.Delete();
            match.OutlookNote = null;

            //load the same Note from google
            sync.MatchNotes();
            match = FindMatch(match.GoogleNote);
            NotesMatcher.SyncNote(match, sync);

            Assert.IsNull(match.OutlookNote);

            // reset matches
            System.IO.File.Delete(NotePropertiesUtils.GetFileName(match.GoogleNote.Id, sync.SyncProfile));
            //Not, because NULL: sync.ResetMatch(match.OutlookNote.GetOriginalItemFromOutlook(sync));

            // load same Note match
            sync.MatchNotes();
            match = FindMatch(match.GoogleNote);
            NotesMatcher.SyncNote(match, sync);

            // google Note should still be present and OutlookNote should be filled
            Assert.IsNotNull(match.GoogleNote);
            Assert.IsNotNull(match.OutlookNote);

            DeleteTestNotes();

            // create new Note to sync
            outlookNote      = Synchronizer.CreateOutlookNoteItem(Synchronizer.SyncNotesFolder);
            outlookNote.Body = body;
            outlookNote.Save();

            // same test for delete google Note...
            googleNote      = new Document();
            googleNote.Type = Document.DocumentType.Document;
            sync.UpdateNote(outlookNote, googleNote);
            match = new NoteMatch(outlookNote, googleNote);

            //save Note to google.
            sync.SaveNote(match);

            for (int i = 0; match.AsyncUpdateCompleted.HasValue && !match.AsyncUpdateCompleted.Value && i < 10; i++)
            {
                Thread.Sleep(1000);//DoNothing, until the Async Update is complete, but only wait maximum 10 seconds
            }
            //load the same Note from google.
            sync.MatchNotes();
            match = FindMatch(outlookNote);
            NotesMatcher.SyncNote(match, sync);

            // delete google Note
            //sync.DocumentsRequest.Delete(match.GoogleNote);
            DeleteTestNote(match.GoogleNote);
            match.GoogleNote = null;

            //load the same Note from google.
            sync.MatchNotes();
            match = FindMatch(outlookNote);
            NotesMatcher.SyncNote(match, sync);

            Assert.IsNull(match.GoogleNote);

            // reset matches
            //Not, because null: sync.ResetMatch(match.GoogleNote);
            sync.ResetMatch(match.OutlookNote);

            // load same Note match
            sync.MatchNotes();
            match = FindMatch(outlookNote);
            NotesMatcher.SyncNote(match, sync);

            // Outlook Note should still be present and GoogleNote should be filled
            Assert.IsNotNull(match.OutlookNote);
            Assert.IsNotNull(match.GoogleNote);

            System.IO.File.Delete(NotePropertiesUtils.GetFileName(outlookNote.EntryID, sync.SyncProfile));
            outlookNote.Delete();
        }
Пример #5
0
        public void TestSyncDeletedGoogle()
        {
            //ToDo: Check for eache SyncOption and SyncDelete combination
            sync.SyncOption = SyncOption.MergeOutlookWins;
            sync.SyncDelete = true;

            // create new Note to sync
            Outlook.NoteItem outlookNote = Synchronizer.CreateOutlookNoteItem(Synchronizer.SyncNotesFolder);
            outlookNote.Body = body;
            outlookNote.Save();

            Document googleNote = new Document();

            googleNote.Type = Document.DocumentType.Document;
            sync.UpdateNote(outlookNote, googleNote);
            NoteMatch match = new NoteMatch(outlookNote, googleNote);

            //save Notes
            sync.SaveNote(match);

            for (int i = 0; match.AsyncUpdateCompleted.HasValue && !match.AsyncUpdateCompleted.Value && i < 100; i++)
            {
                Thread.Sleep(1000);//DoNothing, until the Async Update is complete, but only wait maximum 10 seconds
            }
            Document deletedNote = sync.LoadGoogleNotes(null, match.GoogleNote.DocumentEntry.Id);

            Assert.IsNotNull(deletedNote);
            AtomId deletedNoteAtomId = deletedNote.DocumentEntry.Id;
            string deletedNoteId     = deletedNote.Id;

            Assert.IsTrue(File.Exists(NotePropertiesUtils.GetFileName(deletedNoteId, sync.SyncProfile)));

            // delete google Note
            sync.DocumentsRequest.Delete(new Uri(Google.GData.Documents.DocumentsListQuery.documentsBaseUri + "/" + deletedNote.ResourceId), deletedNote.ETag);

            // sync
            sync.MatchNotes();
            match = FindMatch(outlookNote);
            NotesMatcher.SyncNote(match, sync);

            string id = outlookNote.EntryID;

            // delete
            sync.SaveNote(match);

            // sync
            sync.MatchNotes();
            NotesMatcher.SyncNotes(sync);
            match = FindMatch(id);

            // check if outlook Note still exists
            Assert.IsNull(match);

            deletedNote = sync.LoadGoogleNotes(null, deletedNoteAtomId);
            Assert.IsNull(deletedNote);

            Assert.IsFalse(File.Exists(NotePropertiesUtils.GetFileName(deletedNoteId, sync.SyncProfile)));
            Assert.IsFalse(File.Exists(NotePropertiesUtils.GetFileName(id, sync.SyncProfile)));

            DeleteTestNotes(match);
        }