コード例 #1
0
        /// <summary>
        /// returns all items the user has viewed recently
        /// </summary>
        /// <returns></returns>
        public Feed <Document> GetViewed()
        {
            DocumentsListQuery q = PrepareQuery <DocumentsListQuery>(this.BaseUri);

            q.Categories.Add(DocumentsListQuery.VIEWED);
            return(PrepareFeed <Document>(q));
        }
コード例 #2
0
        /// <summary>
        /// returns all forms for the authorized user
        ///  </summary>
        /// <returns></returns>
        public Feed <Document> GetForms()
        {
            DocumentsListQuery q = PrepareQuery <DocumentsListQuery>(this.BaseUri);

            q.Categories.Add(DocumentsListQuery.FORMS);
            return(PrepareFeed <Document>(q));
        }
コード例 #3
0
        /// <summary>
        /// returns a Feed of all documents and folders for the authorized user
        /// </summary>
        /// <returns>a feed of everyting</returns>
        public Feed <Document> GetEverything()
        {
            DocumentsListQuery q = PrepareQuery <DocumentsListQuery>(this.BaseUri);

            q.ShowFolders = true;
            return(PrepareFeed <Document>(q));
        }
コード例 #4
0
        public static void UpdateDocs()
        {
            lock (docs_lock) {
                DocumentsFeed      docsFeed;
                DocumentsListQuery query = new DocumentsListQuery();
                query.Uri = new Uri(FeedUri);

                try {
                    docsFeed = service.Query(query);
                } catch (Exception e) {
                    docsFeed = null;
                    Log <GDocs> .Error(e.Message);

                    return;
                }

                docs.Clear();
                foreach (DocumentEntry doc in docsFeed.Entries)
                {
                    GDocsAbstractItem item = MaybeItemFromEntry(doc);
                    if (item != null)
                    {
                        docs.Add(item);
                    }
                }
            }
        }
コード例 #5
0
        public User Login(string login, string password)
        {
            try
            {
                var service = new DocumentsService("Idea Provider");
                ((GDataRequestFactory)service.RequestFactory).KeepAlive = false;
                service.setUserCredentials(login, password);
                //force the service to authenticate
                DocumentsListQuery query = new DocumentsListQuery();
                query.NumberToRetrieve = 1;
                service.Query(query);

                Service = service;
                _user   = new User
                {
                    Email    = login,
                    Login    = login,
                    Password = password
                };
                return(_user);
            }
            catch (AuthenticationException)
            {
                return(null);
            }
        }
コード例 #6
0
            public Feed <Document> GetFolderContent(string resourceId)
            {
                string             uri = String.Format(DocumentsListQuery.foldersUriTemplate, resourceId);
                DocumentsListQuery q   = PrepareQuery <DocumentsListQuery>(uri);

                return(PrepareFeed <Document>(q));
            }
コード例 #7
0
        private bool SendFile(string uriUpload, string htmlBuf)
        {
            try
            {
                Uri uri = new Uri(uriUpload);
                Console.WriteLine("uri in send: " + uri);
                string[]         token        = uri.UserInfo.Split(':');
                string           filename     = "Report Floading " + DateTime.Now.ToString("dd-MM-yyyy hh.ss") + ".html";
                string           fullPathName = StorageManager.getEnvValue("wrDirectory") + filename;
                DocumentsService service      = new DocumentsService("Floading report");
                Console.WriteLine("token[0] in send: " + token[0] + " token[1] in send: " + token[1]);
                service.setUserCredentials(token[0], token[1]);
                FileStream stream    = new FileStream(fullPathName, FileMode.CreateNew, FileAccess.Write);
                byte[]     htmlBytes = new System.Text.ASCIIEncoding().GetBytes(htmlBuf);
                stream.Write(htmlBytes, 0, htmlBytes.Length);
                stream.Close();
                DocumentsListQuery query = new DocumentsListQuery();
                DocumentsFeed      feed  = service.Query(query);

                DocumentEntry newEntry = service.UploadDocument(fullPathName, filename);

                File.Delete(fullPathName);
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }
コード例 #8
0
        public List <ISPCItem> GetItems(EUSiteSetting siteSetting, ISPCFolder parentFolder)
        {
            Login(siteSetting.User, siteSetting.Password);
            List <ISPCItem> items = new List <ISPCItem>();

            DocumentsListQuery query = new DocumentsListQuery();

            if (parentFolder.UniqueIdentifier != String.Empty)
            {
                query = new FolderQuery(parentFolder.UniqueIdentifier);
            }
            DocumentsFeed feed = service.Query(query);

            foreach (DocumentEntry entry in feed.Entries)
            {
                if (entry.IsFolder == false)
                {
                    if (parentFolder == null || parentFolder.UniqueIdentifier == String.Empty)
                    {
                        if (entry.ParentFolders.Count > 0)
                        {
                            continue;
                        }
                    }
                    ISPCItem item = new GItem(siteSetting, entry.ResourceId, entry.Title.Text, entry.AlternateUri.ToString());
                    items.Add(item);
                }
            }
            return(items);
        }
コード例 #9
0
        public List <IItem> GetListItems(ISiteSetting siteSetting, string webUrl, string listName, bool isRecursive)
        {
            Login(siteSetting.Username, siteSetting.Password);
            List <IItem> items = new List <IItem>();

            DocumentsListQuery query = new DocumentsListQuery();

            if (string.IsNullOrEmpty(webUrl) == false)
            {
                query = new FolderQuery(webUrl);
            }
            DocumentsFeed feed = service.Query(query);

            foreach (DocumentEntry entry in feed.Entries)
            {
                if (entry.IsFolder == false)
                {
                    if (String.IsNullOrEmpty(webUrl) == true)
                    {
                        if (entry.ParentFolders.Count > 0)
                        {
                            continue;
                        }
                    }
                    IItem item = new GItem(siteSetting.ID, entry.ResourceId, entry.Title.Text, entry.AlternateUri.ToString());
                    item.Properties.Add("ows_Editor", entry.LastModified.Name);
                    item.Properties.Add("ows_Modified", entry.Edited.DateValue.ToString());
                    items.Add(item);
                }
            }
            return(items);
        }
コード例 #10
0
        public List <ISPCFolder> GetFolders(EUSiteSetting siteSetting, ISPCFolder parentFolder)
        {
            Login(siteSetting.User, siteSetting.Password);
            List <ISPCFolder>  folders = new List <ISPCFolder>();
            DocumentsListQuery query   = new DocumentsListQuery();

            if (parentFolder.UniqueIdentifier != String.Empty)
            {
                query = new FolderQuery(parentFolder.UniqueIdentifier);
            }
            query.ShowFolders = true;
            DocumentsFeed feed = service.Query(query);

            foreach (DocumentEntry entry in feed.Entries)
            {
                if (entry.IsFolder)
                {
                    if (parentFolder == null || parentFolder.UniqueIdentifier == String.Empty)
                    {
                        if (entry.ParentFolders.Count > 0)
                        {
                            continue;
                        }
                    }
                    ISPCFolder folder = new GFolder(siteSetting, entry.ResourceId, entry.Title.Text, entry.Id.AbsoluteUri);
                    folders.Add(folder);
                }
            }
            return(folders);
        }
コード例 #11
0
        /// <summary>
        /// Retrieves a list of documents from the server.
        /// </summary>
        /// <returns>The list of documents as a DocumentsFeed.</returns>
        public DocumentsFeed GetDocs()
        {
            DocumentsListQuery query = new DocumentsListQuery();
            DocumentsFeed      feed  = service.Query(query);

            return(feed);
        }
コード例 #12
0
        /// <summary>
        /// Fetches list of documents in Google Drive.
        /// </summary>
        /// <returns></returns>
        public static DocumentsFeed GetGDriveDocList()
        {
            //Waiting for the service authentication to complete.
            _autoEvent.WaitOne();
            DocumentsFeed documents = null;

            try
            {
                //In case an error was encountered go back.
                if (_parameters == null || _exception != null)
                {
                    return(documents);
                }
                //Creating the request factory for the Drive service.
                GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, APPLICATION_NAME, _parameters);
                //Creating a service instance.
                DocumentsService service = new DocumentsService(APPLICATION_NAME);
                //Assigning the factory instance to the service.
                service.RequestFactory = requestFactory;
                DocumentsListQuery query = new DocumentsListQuery();
                //Sending a query to the service to fetch list of all documents on the drive.
                documents = service.Query(query);
            }
            catch (Exception Ex)
            {
                _exception = Ex;
            }
            finally
            {
                //Can now signal other threads to continue accessing/refreshing services.
                _autoEvent.Set();
            }
            return(documents);
        }
コード例 #13
0
        public static void TrashDocument(GDocsAbstractItem item)
        {
            // Search for document(s) having exactly the title,
            // Delete the one with matching AlternateUri
            DocumentsListQuery query = new DocumentsListQuery();

            query.Title      = item.Name;
            query.TitleExact = true;
            DocumentsFeed docFeed  = service.Query(query);
            DocumentEntry document =
                docFeed.Entries.FirstOrDefault(e => e.AlternateUri == item.URL) as DocumentEntry;

            if (document == null)
            {
                return;
            }

            try {
                document.Delete();
            } catch (Exception e) {
                Log.Error(e.Message);
                Services.Notifications.Notify(GetDeleteDocumentFailedNotification());
                return;
            }

            Services.Notifications.Notify(GetDocumentDeletedNotification(item.Name));
        }
コード例 #14
0
 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;
         if (!string.IsNullOrEmpty(hapConfig.Current.ProxyServer.Address) && hapConfig.Current.ProxyServer.Enabled)
         {
             ((GDataRequestFactory)service.RequestFactory).Proxy = new WebProxy(hapConfig.Current.ProxyServer.Address, hapConfig.Current.ProxyServer.Port);
         }
         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;
     }
 }
コード例 #15
0
        /// <summary>
        /// Retrieves a list of documents from the server.
        /// </summary>
        /// <returns>The list of documents as a DocumentsFeed.</returns>
        public DocumentsFeed GetDocs()
        {
            DocumentsListQuery query = new DocumentsListQuery();

            query.ShowFolders = true;

            DocumentsFeed feed = service.Query(query);

            return(feed);
        }
コード例 #16
0
        /// <summary>
        /// returns a feed of documents for the specified folder
        /// </summary>
        /// <param name="folder"></param>
        /// <returns></returns>
        public Feed <Document> GetFolderContent(Document folder)
        {
            if (folder.Type != Document.DocumentType.Folder)
            {
                throw new ArgumentException("The parameter folder is not a folder");
            }

            string             uri = String.Format(DocumentsListQuery.foldersUriTemplate, folder.ResourceId);
            DocumentsListQuery q   = PrepareQuery <DocumentsListQuery>(uri);

            return(PrepareFeed <Document>(q));
        }
コード例 #17
0
        public void GoogleDocsList()
        {
            DocumentsListQuery query     = new DocumentsListQuery();
            DocumentsService   myService = new DocumentsService("exampleCo-exampleApp-1");

            myService.setUserCredentials("gianpieroradano", "");
            DocumentsFeed feed = myService.Query(query);

            foreach (DocumentEntry entry in feed.Entries)
            {
                Console.WriteLine(entry.Title.Text);
            }
        }
コード例 #18
0
        static public void send(String email, String password)
        {
            DocumentsService service = new DocumentsService("servizioEsempio");

            service.setUserCredentials(email, password);
            DocumentsListQuery query = new DocumentsListQuery();
            DocumentsFeed      feed  = service.Query(query);

            foreach (DocumentEntry entry in feed.Entries)
            {
                Console.WriteLine(entry.Title.Text);
            }
            System.Console.ReadLine();

            // DocumentEntry newEntry = service.UploadDocument("C:\\Users\\gianpy\\Desktop\\specifiche.txt", "New Document Title.txt");
            // Console.WriteLine("Now accessible at: " + newEntry.AlternateUri.ToString());
        }
コード例 #19
0
        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:", ""));
        }
コード例 #20
0
        //////////////////////////////////////////////////////////////////////
        /// <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;
        }
コード例 #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)
 {
     try
     {
         if (service == null)
         {
             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;
     }
 }
コード例 #22
0
        /// <summary>
        /// returns a Feed of all folders for the authorized user
        /// </summary>
        /// <returns>a feed of Documents</returns>
        public Feed <Document> GetFolders()
        {
            DocumentsListQuery q = PrepareQuery <DocumentsListQuery>(DocumentsListQuery.allFoldersUri);

            return(PrepareFeed <Document>(q));
        }
コード例 #23
0
 /// <summary>
 /// overloaded to create typed version of Query
 /// </summary>
 /// <param name="feedQuery"></param>
 /// <returns>EventFeed</returns>
 public DocumentsFeed Query(DocumentsListQuery feedQuery)
 {
     return(base.Query(feedQuery) as DocumentsFeed);
 }
コード例 #24
0
        public void parse()
        {
            //The date and time in this moment.
            DateTime timeNow = DateTime.Now;

            //Indicate if there are new updates in Google Docs.
            bool isNewUpdate = false;
            //The title of the most recent updated document.
            string latestEditedTitle = "";
            //The number of documents in total.
            int numOfDocuments = 0;
            //The number of unviewed documents.
            int unviewedDocuments = 0;

            //Inform the GUI to change the progress value.
            UpdateProgressBar(25);

            try
            {
                //Download the feed from Google Docs server.
                DocumentsListQuery query = new DocumentsListQuery();
                DocumentsFeed      feed  = _myService.Query(query);

                //Inform the GUI to change the progress value.
                UpdateProgressBar(50);

                foreach (DocumentEntry entry in feed.Entries)
                {
                    DateTime lastEditedTime = new DateTime(); //No use for now.
                    DateTime lastViewedTime = timeNow;
                    //Note: There are some Google Docs type has no lastViewed tag.
                    //      Hence, it is better to set the default value of the
                    //      lastViewedTime to be the current date and time.

                    //Retrieve lastEditedTime and lastViewedTime from
                    //the Extension Elements of the feeds.
                    HandleExtensionElements(entry, ref lastEditedTime, ref lastViewedTime);

                    //If the document is newly created document or unread updated document...
                    if (VerifyNewDocuments(entry) || VerifyUnviewedUpdatedDocuments(entry, lastViewedTime))
                    {
                        HandleNewOrUnreadUpdatedDocuments(
                            entry,
                            ref isNewUpdate, ref latestEditedTime,
                            ref latestEditedTitle, ref unviewedDocuments);
                    }

                    //Inform the GUI to change the progress value.
                    UpdateProgressBar(((int)(((double)numOfDocuments++ / feed.Entries.Count()) * 50)) + 50);
                }

                //Inform the GUI to change the status message.
                UpdateStatusMessage(unviewedDocuments.ToString() + " documents listed above.");

                //Inform the GUI to update and show the balloon tooltip.
                updateNotifyIcon(
                    "Your Google Docs is updated",
                    "Latest edited document: " + latestEditedTitle,
                    unviewedDocuments,
                    isNewUpdate);
            }
            catch (Google.GData.Client.InvalidCredentialsException)
            {
                throw;
            }
            catch (Google.GData.Client.CaptchaRequiredException)
            {
                throw;
            }
            catch (Google.GData.Client.AuthenticationException)
            {
                throw;
            }
            catch (Exception)
            {
                //Inform the GUI to change the status message.
                UpdateStatusMessage("Unable to connect to Google Docs server.");

                //Inform the GUI to UPDATE ONLY the balloon tooltip icon
                //and say there is no new update found.
                updateNotifyIcon(
                    "",
                    "",
                    0,
                    false);
            }
        }
コード例 #25
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);
        }