private static DocumentsService getDocumentsService()
        {
            DocumentsService documentsService = new DocumentsService("Monitis2GoogleDocumentrService");
            documentsService.setUserCredentials(USERNAME, PASSWORD);

            return documentsService;
        }
        public void CreateTemplate()
        {
            DocumentsService service = new DocumentsService(applicationName);

            DocumentEntry entry = new DocumentEntry();

            // Set the document title
            entry.Title.Text = spreadsheetName;
            entry.IsSpreadsheet = true;

            // Set the media source
            entry.MediaSource = new MediaFileSource(GetStreamWithTemplate(), applicationName, "text/csv");

            // Define the resumable upload link
            Uri createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full");
            AtomLink link = new AtomLink(createUploadUrl.AbsoluteUri);
            link.Rel = ResumableUploader.CreateMediaRelation;
            entry.Links.Add(link);

            // Set the service to be used to parse the returned entry
            entry.Service = service;

            // Instantiate the ResumableUploader component.
            ResumableUploader uploader = new ResumableUploader();

            // Start the upload process
            uploader.Insert(new ClientLoginAuthenticator(applicationName,ServiceNames.Documents,userName,password), entry);
        }
Пример #3
0
 public void DeleteImageFile(Hashtable State,string url)
 {
     DocumentsService service = new DocumentsService("MobiFlexDocs");
     service.setUserCredentials( HttpRuntime.Cache["MobiFlexGDocsUsername"].ToString(),  HttpRuntime.Cache["MobiFlexGDocsPassword"].ToString());
     AtomEntry entry = service.Get(url);
     entry.Delete();
 }
        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);
        }
Пример #5
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());
                }
            }
        }
Пример #6
0
        public SpreadsheetProxy(Credentials credentials)
        {
            spreadsheetService = new SpreadsheetsService("groundfloor-svc1");
            spreadsheetService.setUserCredentials(credentials.username, credentials.password);

            documentService = new DocumentsService("groundfloor-svc2");
            documentService.setUserCredentials(credentials.username, credentials.password);
        }
Пример #7
0
		public DatabaseClient(string username, string password) {
			var docService = new DocumentsService("database");
			docService.setUserCredentials(username, password);
			documentService = docService;

			var ssService = new SpreadsheetsService("database");
			ssService.setUserCredentials(username, password);
			spreadsheetService = ssService;
		}
Пример #8
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; 
        }
Пример #10
0
        public DatabaseClient(string username, string password) {

            GOAuth2RequestFactory requestFactory = GDataDBRequestFactory.RefreshAuthenticate();

            var docService = new DocumentsService("database");
            docService.RequestFactory = requestFactory;
            
            //@kims
            //docService.setUserCredentials(username, password);
            documentService = docService;
             
            var ssService = new SpreadsheetsService("database");

            //@kims
            //ssService.setUserCredentials(username, password);
            
            ssService.RequestFactory = requestFactory;
            spreadsheetService = ssService;
        }
Пример #11
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;
        }
 public DocumentsFeedParser(DocumentsService myService) 
 {
     _myService = myService;
 }
        [Test] public void CreateSpreadsheetTest()
        {
            //set up a text/csv file
            string tempFile = Directory.GetCurrentDirectory();
            tempFile = tempFile + Path.DirectorySeparatorChar + "docs_live_test.csv";

            //Console.WriteLine("Creating temporary document at: " + tempFile);

            using (StreamWriter sw = File.CreateText(tempFile))
            {
                sw.WriteLine("foo,bar,baz");
                sw.WriteLine("1,2,3");
                sw.Close();
            }



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

            //pick a unique document name
            string documentTitle = "Simple " + Guid.NewGuid().ToString();

            DocumentEntry entry = service.UploadDocument(tempFile, documentTitle);

            Assert.IsNotNull(entry, "Should get a valid entry back from the server.");
            Assert.AreEqual(documentTitle, entry.Title.Text, "Title on document should be what we provided.");
            Assert.IsTrue(entry.IsSpreadsheet, "What we uploaded should come back as a spreadsheet document type.");

            //try to delete the document we created
            entry.Delete();

            //clean up the file we created
            File.Delete(tempFile);
        }
 /// <summary>
 /// Logs the user out of Google Docs.
 /// </summary>
 public void Logout()
 {
     loggedIn = false;
     service = 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;
     }
 }
        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:", "");
        }
        private WorksheetEntry createSpreadSheet(string sheetName)
        {
            DocumentsService docService = new DocumentsService(this.googleAppName);
            docService.RequestFactory = GoogleOauthAccess.getRequestFactory(this.googleAppName, this.parameters);

            DocumentEntry entry = new DocumentEntry();
            entry.Title.Text = sheetName;
            entry.Categories.Add(DocumentEntry.SPREADSHEET_CATEGORY);

            DocumentEntry newEntry = docService.Insert(DocumentsListQuery.documentsBaseUri, entry);

            return this.searchForSpreadsheet(entry.Title.Text);
        }
Пример #18
0
 public string UploadImageFile(Hashtable State, string local_file_path)
 {
     DocumentsService service = new DocumentsService("MobiFlexDocs");
     service.setUserCredentials( HttpRuntime.Cache["MobiFlexGDocsUsername"].ToString(),  HttpRuntime.Cache["MobiFlexGDocsPassword"].ToString());
     string name = local_file_path.Substring(local_file_path.IndexOf(@"media\") + 6).Replace(@"\", ".");
     DocumentEntry newEntry = service.UploadFile(local_file_path, name,"text/html",true);
     return newEntry.AlternateUri.ToString();
 }
Пример #19
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;
        }
Пример #20
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);
        }
Пример #21
0
        /// <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(APP_NAME);
                GDataGAuthRequestFactory reqFactory = (GDataGAuthRequestFactory)service.RequestFactory;
                reqFactory.KeepAlive = false;
                reqFactory.ProtocolMajor = 3;

                service.setUserCredentials(username, password);

                loggedIn = true;
            }
            catch (AuthenticationException e)
            {
                loggedIn = false;
                service = null;
                throw e;
            }
        }
        /////////////////////////////////////////////////////////////////////////////


        /// <summary>
        /// Tests word processor document creation and deletion
        /// </summary>
        [Test] public void CreateDocumentTest()
        {
            //set up a text/plain file
            string tempFile = Directory.GetCurrentDirectory();
            tempFile = tempFile + Path.DirectorySeparatorChar + "docs_live_test.txt";

            //Console.WriteLine("Creating temporary document at: " + tempFile);

            using (StreamWriter sw = File.CreateText(tempFile))
            {
                sw.WriteLine("My name is Ozymandias, king of kings:");
                sw.WriteLine("Look on my works, ye mighty, and despair!");
                sw.Close();
            }
            


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

            //pick a unique document name
            string documentTitle = "Ozy " + Guid.NewGuid().ToString();

            DocumentEntry entry = service.UploadDocument(tempFile, documentTitle);

            Assert.IsNotNull(entry, "Should get a valid entry back from the server.");
            Assert.AreEqual(documentTitle, entry.Title.Text, "Title on document should be what we provided.");
            Assert.IsTrue(entry.IsDocument, "What we uploaded should come back as a text document type.");
            Assert.IsTrue(entry.AccessControlList != null, "We should get an ACL list back");

            try
            {
                Uri uri = new Uri(entry.AccessControlList);
                Assert.IsTrue(uri.AbsoluteUri == entry.AccessControlList);
    
            } catch (Exception e)
            {
                throw e;
            }
            
            
            //try to delete the document we created
            entry.Delete();

            //clean up the file we created
            File.Delete(tempFile);
            
        }
Пример #23
0
 public static bool Connect(string username, string password)
 {
     try {
         service = new DocumentsService (GAppName);
         service.setUserCredentials (username, password);
     } catch (Exception e) {
         Log<GDocs>.Error (e.Message);
         return false;
     }
     return true;
 }
Пример #24
0
        public void DoWorkbookUpload(object in_instance)
        {
            var instance = in_instance as Google2uData;
            if (instance == null)
                return;

            if (!string.IsNullOrEmpty(instance.WorkbookUploadPath))
            {
                try
                {
                    // We need a DocumentService
                    var service = new DocumentsService("Google2Unity");
                    var mimeType = Google2uMimeType.GetMimeType(instance.WorkbookUploadPath);

                    var authenticator = new OAuth2Authenticator("Google2Unity", _authParameters);

                    // Instantiate a DocumentEntry object to be inserted.
                    var entry = new DocumentEntry
                    {
                        MediaSource = new MediaFileSource(instance.WorkbookUploadPath, mimeType)
                    };

                    // Define the resumable upload link
                    var createUploadUrl =
                        new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full");
                    var link = new AtomLink(createUploadUrl.AbsoluteUri)
                    {
                        Rel = ResumableUploader.CreateMediaRelation
                    };

                    entry.Links.Add(link);

                    // Set the service to be used to parse the returned entry
                    entry.Service = service;


                    // Instantiate the ResumableUploader component.
                    var uploader = new ResumableUploader();

                    // Set the handlers for the completion and progress events
                    uploader.AsyncOperationCompleted += OnSpreadsheetUploadDone;
                    uploader.AsyncOperationProgress += OnSpreadsheetUploadProgress;

                    // Start the upload process
                    uploader.InsertAsync(authenticator, entry, instance);
                }
                catch (Exception)
                {
                    PushNotification(
                        "There is a problem with your credentials. Clear the credentials and Re-Authorize G2U");
                    //instance.Messages.Add(new G2GUIMessage(GFGUIMessageType.InvalidLogin, ex.Message));
                    instance.Commands.Remove(GFCommand.WaitingForUpload);
                }
            }
        }
Пример #25
0
 public DocumentsService GetDocumentsService()
 {
     DocumentsService service = new DocumentsService("code.google.com/p/exult/");
     service.Credentials = GetDataCredentials();
     return service;
 }