Beispiel #1
0
        public void OAuth2LeggedDocumentsTest()
        {
            Tracing.TraceMsg("Entering OAuth2LeggedDocumentsTest");

            RequestSettings rs = new RequestSettings(this.ApplicationName, this.oAuthConsumerKey,
                                                     this.oAuthConsumerSecret, this.oAuthUser, this.oAuthDomain);

            DocumentsRequest dr = new DocumentsRequest(rs);

            Feed <Document> f = dr.GetDocuments();

            // modify one
            foreach (Document d in f.Entries)
            {
                string s = d.AtomEntry.EditUri.ToString();
                d.AtomEntry.EditUri = new AtomUri(s.Replace("@", "%40"));

                dr.Update(d);
                AclQuery q = new AclQuery();
                q.Uri = d.AccessControlList;
                Feed <Google.AccessControl.Acl> facl = dr.Get <Google.AccessControl.Acl>(q);

                foreach (Google.AccessControl.Acl a in facl.Entries)
                {
                    s = a.AclEntry.EditUri.ToString();
                    a.AclEntry.EditUri = new AtomUri(s.Replace("@", "%40"));
                    dr.Update(a);
                }
            }
        }
        public void OAuth2LeggedDocumentsTest() {
            Tracing.TraceMsg("Entering OAuth2LeggedDocumentsTest");

            RequestSettings rs = new RequestSettings(this.ApplicationName, this.oAuthConsumerKey,
                this.oAuthConsumerSecret, this.oAuthUser, this.oAuthDomain);

            DocumentsRequest dr = new DocumentsRequest(rs);

            Feed<Document> f = dr.GetDocuments();

            // modify one
            foreach (Document d in f.Entries) {
                string s = d.AtomEntry.EditUri.ToString();
                d.AtomEntry.EditUri = new AtomUri(s.Replace("@", "%40"));

                dr.Update(d);
                AclQuery q = new AclQuery();
                q.Uri = d.AccessControlList;
                Feed<Google.AccessControl.Acl> facl = dr.Get<Google.AccessControl.Acl>(q);

                foreach (Google.AccessControl.Acl a in facl.Entries) {
                    s = a.AclEntry.EditUri.ToString();
                    a.AclEntry.EditUri = new AtomUri(s.Replace("@", "%40"));
                    dr.Update(a);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// save the google note
        /// </summary>
        /// <param name="googleNote"></param>
        public static Document SaveGoogleNote(Document parentFolder, Document googleNote, DocumentsRequest documentsRequest)
        {
            //check if this contact was not yet inserted on google.
            if (googleNote.DocumentEntry.Id.Uri == null)
            {
                //insert contact.
                Uri feedUri = null;

                if (parentFolder != null)
                {
                    try
                    {//In case of Notes folder creation, the GoogleNotesFolder.DocumentEntry.Content.AbsoluteUri throws a NullReferenceException
                        feedUri = new Uri(parentFolder.DocumentEntry.Content.AbsoluteUri);
                    }
                    catch (Exception)
                    { }
                }

                if (feedUri == null)
                    feedUri = new Uri(documentsRequest.BaseUri);

                try
                {
                    Document createdEntry = documentsRequest.Insert(feedUri, googleNote);
                    //ToDo: Workaround also doesn't help: Utilities.SaveGoogleNoteContent(this, createdEntry, googleNote);
                    Logger.Log("Created new Google folder: " + createdEntry.Title, EventType.Information);
                    return createdEntry;
                }
                catch (Exception ex)
                {
                    string responseString = "";
                    if (ex is GDataRequestException)
                        responseString = EscapeXml(((GDataRequestException)ex).ResponseString);
                    string xml = GetXml(googleNote);
                    string newEx = String.Format("Error saving NEW Google note: {0}. \n{1}\n{2}", responseString, ex.Message, xml);
                    throw new ApplicationException(newEx, ex);
                }
            }
            else
            {
                try
                {
                    //note already present in google. just update
                    Document updated = documentsRequest.Update(googleNote);

                    //ToDo: Workaround also doesn't help: Utilities.SaveGoogleNoteContent(this, updated, googleNote);

                    return updated;
                }
                catch (Exception ex)
                {
                    string responseString = "";
                    if (ex is GDataRequestException)
                        responseString = EscapeXml(((GDataRequestException)ex).ResponseString);
                    string xml = GetXml(googleNote);
                    string newEx = String.Format("Error saving EXISTING Google note: {0}. \n{1}\n{2}", responseString, ex.Message, xml);
                    throw new ApplicationException(newEx, ex);
                }
            }
        }