/// <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)); }
/// <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)); }
/// <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)); }
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); } } } }
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); } }
public Feed <Document> GetFolderContent(string resourceId) { string uri = String.Format(DocumentsListQuery.foldersUriTemplate, resourceId); DocumentsListQuery q = PrepareQuery <DocumentsListQuery>(uri); return(PrepareFeed <Document>(q)); }
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); }
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); }
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); }
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); }
/// <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); }
/// <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); }
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)); }
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; } }
/// <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); }
/// <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)); }
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); } }
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()); }
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:", "")); }
////////////////////////////////////////////////////////////////////// /// <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) { 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; } }
/// <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)); }
/// <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); }
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); } }
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); }