protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            if (string.IsNullOrEmpty(this.DocName))
            {
                base.Render(writer);
                return;
            }
            string username = "******";
            string password = "******";

            DocumentsService service = new DocumentsService("MyDocumentsListIntegration-v1");
            service.setUserCredentials(username, password);

            //DocumentsListQuery query = new DocumentsListQuery();
            TextDocumentQuery query = new TextDocumentQuery();

            // Make a request to the API and get all documents.
            DocumentsFeed feed = service.Query(query);

            // Iterate through all of the documents returned
            foreach (DocumentEntry entry in feed.Entries)
            {
                if (entry.Title.Text == this.DocName)
                {
                    writer.Write("<div class='gdoc'>");
                    Stream stream = service.Query(new Uri(entry.Content.Src.ToString()));
                    StreamReader reader = new StreamReader(stream);
                    writer.Write(reader.ReadToEnd());
                    writer.Write("</div>");
                    break;
                }
            }

            base.Render(writer);
        }
Пример #2
0
        static void Main(string[] args)
        {
            string username = "******";
            string password = "******";

            DocumentsService service = new DocumentsService("MyDocumentsListIntegration-v1");
            service.setUserCredentials(username, password);

            //DocumentsListQuery query = new DocumentsListQuery();
            TextDocumentQuery query = new TextDocumentQuery();

            // Make a request to the API and get all documents.
            DocumentsFeed feed = service.Query(query);

            // Iterate through all of the documents returned
            foreach (DocumentEntry entry in feed.Entries)
            {
                if (entry.Title.Text == "Rufo-Resume.doc")
                {
                    // Print the title of this document to the screen
                    Console.WriteLine(entry.Title.Text);
                    var stream = service.Query(new Uri(entry.Content.Src.ToString()));
                    var reader = new StreamReader(stream);
                    Console.WriteLine(reader.ReadToEnd());
                }
            }
        }
Пример #3
0
 void printDocumentList(OAuth2Parameters parameters)
 {
     GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, "MyDocumentsListIntegration-v1", parameters);
     DocumentsService service = new DocumentsService("MyDocumentsListIntegration-v1");
     service.RequestFactory = requestFactory;
     DocumentsListQuery query = new DocumentsListQuery();
     DocumentsFeed feed = service.Query(query);
     foreach (DocumentEntry entry in feed.Entries)
     {
         Console.WriteLine(entry.Title.Text);
     }
     Console.ReadKey();
 }
        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void GoogleAuthenticationTest()
        {
            Tracing.TraceMsg("Entering Documents List Authentication Test");

            DocumentsListQuery query = new DocumentsListQuery();
            DocumentsService service = new DocumentsService(this.ApplicationName);
            if (this.userName != null)
            {
                service.Credentials = new GDataCredentials(this.userName, this.passWord);
            }
            service.RequestFactory = this.factory; 

            DocumentsFeed feed = service.Query(query) as DocumentsFeed;

            ObjectModelHelper.DumpAtomObject(feed,CreateDumpFileName("AuthenticationTest")); 
                service.Credentials = null; 
        }
 /// <summary>
 /// Authenticates to Google servers
 /// </summary>
 /// <param name="username">The user's username (e-mail)</param>
 /// <param name="password">The user's password</param>
 /// <exception cref="AuthenticationException">Thrown on invalid credentials.</exception>
 public void Login(string username, string password)
 {
     if(loggedIn) {
         throw new ApplicationException("Already logged in.");
     }
     try
     {
         service = new DocumentsService("DocListUploader");
         ((GDataRequestFactory) service.RequestFactory).KeepAlive = false;
         service.setUserCredentials(username, password);
         //force the service to authenticate
         DocumentsListQuery query = new DocumentsListQuery();
         query.NumberToRetrieve = 1;
         service.Query(query);
         loggedIn = true;
     }
     catch(AuthenticationException e)
     {
         loggedIn = false;
         service = null;
         throw e;
     }
 }
Пример #6
0
        public override bool Execute()
        {
            GDataCredentials credentials = GetDataCredentials();
            RequestSettings settings = new RequestSettings("code.google.com/p/exult/", credentials);
            settings.AutoPaging = true;
            settings.PageSize = 100;

            DocumentsService service = new DocumentsService("Exult");
            service.Credentials = credentials;

            // Instantiate a ChangesQuery object to retrieve changes.
            ChangesQuery query = new ChangesQuery();

            // Make a request to the API and get all changes.
            ChangesFeed feed = service.Query(query);

            // Iterate through all of the changes returned
            foreach (ChangeEntry entry in feed.Entries)
            {
                //if (Pattern == null || PatternExpression.IsMatch(entry.TitlePath))
                //{
                //    Log.LogMessage(MessageImportance.High, "Matched \"{0}\"", path.TitlePath);
                //    outputs.Add(BuildFolder(entry, path));
                //}
                //else
                //{
                //    Log.LogMessage(MessageImportance.Low, "Skipped \"{0}\"", path.TitlePath);
                //}

                // Print the title and changestamp of this document to the screen
                Log.LogMessage(MessageImportance.Normal, entry.Title.Text);
                Log.LogMessage(MessageImportance.Normal, entry.Changestamp);
            }

            return true;
        }
Пример #7
0
        static void Main(string[] args)
        {
            var localHtmlDocname = "docContents.htm";

            //Get credentials
            Console.Write("Enter your username:"******"Enter your password:"******"my-service");
            service.setUserCredentials(user, password);
            DocumentsFeed listFeed = null;
            AtomFeed feed = null;
            DocumentsListQuery query = null;
            IProgress<string> p = new Progress<string>(Console.WriteLine);

            //Get list of documents
            var getList = Task.Run(() =>
            {
                p.Report("Reading list of documents");
                query = new DocumentsListQuery();
                feed = service.Query(query);
            });

            getList.Wait();

            foreach (DocumentEntry entry in feed.Entries.OrderBy(x => x.Title.Text))
            {
                if (entry.IsDocument)
                    Console.WriteLine(entry.Title.Text);
            }

            Console.WriteLine("Type the name of the document you would like to open:");
            var openDocTitle = Console.ReadLine();
            string contents = string.Empty;

            //Get list of documents
            var openDoc = Task.Run(() =>
            {
                p.Report("Reading document contents");
                query.Title = openDocTitle;
                feed = service.Query(query);

                var openMe = feed.Entries[0] as DocumentEntry;
                var stream = service.Query(new Uri(openMe.Content.Src.ToString()));
                var reader = new StreamReader(stream);
                contents = reader.ReadToEnd();

                using (var fs = File.Create(localHtmlDocname))
                {
                    using (var writer = new StreamWriter(fs))
                    {
                        contents += Environment.UserName + " was here - " + DateTime.Now.ToString() + "<br/>";
                        writer.Write(contents);
                        writer.Flush();
                        writer.Close();
                    }

                    fs.Close();
                }

                //OPTIONAL: Uncomment to save changes BACK to the google doc
                /*
                openMe.MediaSource = new MediaFileSource(localHtmlDocname, "text/html");
                var uploader = new ResumableUploader();

                //Get an authenticator
                var authenticator = new ClientLoginAuthenticator("document-access-test", ServiceNames.Documents, service.Credentials);

                //Perform the upload...
                Console.WriteLine("Saving to Google Drive...");
                uploader.Update(authenticator, openMe);
                */
            });

            openDoc.Wait();
            Console.WriteLine("Opening contents of Google doc file...");
            System.Diagnostics.Process.Start(localHtmlDocname);
        }
Пример #8
0
        // this method creates the spreadsheet, deletes the old one if overwrite is on and there's already on with the same name,
        // and adds the worksheets if they've been specified. Wrapped in a static method so other components (like WriteToSpreadsheet)
        // can make use of it and create new spreadsheets.
        public static SpreadsheetEntry createNewSpreadsheet(GH_ActiveObject activeObj, AuthToken authToken, string sheetName, List<string> worksheets, bool overwrite)
        {
            SpreadsheetEntry matchingEntry = null;
            //setup OAuth Parameters
            OAuth2Parameters parameters = GDriveUtil.GetParameters(authToken);

            // It seems clunky to need both a SpreadsheetService and a DocumentService - but
            // DocumentService is necessary to add/delete spreadsheets, and SpreadsheetService
            // is needed to manipulate the worksheets.

            //setup auth and factory for documentsService

            GOAuth2RequestFactory requestFactory =
              new GOAuth2RequestFactory(null, "MyDocumentsListIntegration-v1", parameters);
            DocumentsService docService = new DocumentsService("MyDocumentsListIntegration-v1");
            docService.RequestFactory = requestFactory;

            //setup SpreadsheetsService
            SpreadsheetsService service = GDriveUtil.GetSpreadsheetsService(parameters);

            //make spreadsheet documentquery
            Google.GData.Documents.SpreadsheetQuery dQuery = new Google.GData.Documents.SpreadsheetQuery();

            DocumentsFeed dFeed = docService.Query(dQuery);

            //if user has opted to overwrite, find first matching spreadsheet and delete. If no matching spreadsheet found, nothing happens.
            if (overwrite)
            {

                foreach (DocumentEntry entry in dFeed.Entries)
                {
                    if (entry.Title.Text.Equals(sheetName))
                    {
                        docService.Delete(entry);
                        break;
                    }
                }
            }

            //create new spreadsheet object
            DocumentEntry dEntry = new DocumentEntry();
            dEntry.Title.Text = sheetName;
            dEntry.Categories.Add(DocumentEntry.SPREADSHEET_CATEGORY);
            docService.Insert(DocumentsListQuery.documentsBaseUri, dEntry);

            //find the spreadsheet we just created as a SpreadsheetEntry

            matchingEntry = GDriveUtil.findSpreadsheetByName(sheetName, service);
            //if worksheets specified, add worksheets
            if (worksheets.Count > 0)
            {

                if (matchingEntry == null) //this shouldn't ever happen, since we just created a new spreadsheet called sheetName.
                {
                    activeObj.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Something went wrong with spreadsheet creation.");
                    return null;
                }

                WorksheetFeed wsFeed = matchingEntry.Worksheets;

                //first, we find the existing worksheets, store them, add new ones, and then delete the old.

                List<WorksheetEntry> entriesToDelete = new List<WorksheetEntry>();
                foreach (WorksheetEntry entry in wsFeed.Entries)
                {
                    entriesToDelete.Add(entry);
                }

                // find the dimensions of the first worksheet, to use for other worksheet creation
                uint rows = ((WorksheetEntry)wsFeed.Entries[0]).Rows;
                uint cols = ((WorksheetEntry)wsFeed.Entries[0]).Cols;

                for (int i = 0; i < worksheets.Count; i++)
                {
                    {
                        string wsName = worksheets[i];

                        WorksheetEntry entry = new WorksheetEntry(rows, cols, wsName);
                        service.Insert(wsFeed, entry);
                    }
                }

                foreach (WorksheetEntry entryToDelete in entriesToDelete)
                {
                    entryToDelete.Delete();
                }

            }

            //end if worksheets...

            return matchingEntry;
        }
        public string getSpreadsheetURL(string sheetName)
        {
            DocumentsService docService = new DocumentsService(this.googleAppName);
            docService.RequestFactory = GoogleOauthAccess.getRequestFactory(this.googleAppName, this.parameters);

            Google.GData.Spreadsheets.SpreadsheetQuery query = new Google.GData.Spreadsheets.SpreadsheetQuery();

            DocumentsListQuery docQuery = new DocumentsListQuery();
            docQuery.Title = sheetName;

            DocumentsFeed feed = docService.Query(docQuery);
            DocumentEntry entry = (DocumentEntry)feed.Entries[0];

            return "https://docs.google.com/spreadsheet/ccc?key=" + entry.ResourceId.Replace("spreadsheet:", "");
        }