/// <summary> /// tests etag refresh on an entry level /// </summary> [Test] public void ModelTestEntryETagRefresh() { RequestSettings settings = new RequestSettings(this.ApplicationName, this.userName, this.passWord); // settings.PageSize = 15; DocumentsRequest r = new DocumentsRequest(settings); // this returns the server default answer Feed <Document> feed = r.GetDocuments(); Document d = null; foreach (Document x in feed.Entries) { Assert.IsTrue(x != null, "We should have something"); d = x; } Assert.IsTrue(d != null, "We should have something"); // now this should result in a notmodified try { Document refresh = r.Retrieve(d); Assert.IsTrue(refresh == null, "we should not be here"); } catch (GDataNotModifiedException g) { Assert.IsTrue(g != null); } }
/// <summary> /// tests etag refresh on an entry level /// </summary> [Test] public void ModelTestEntryETagRefresh() { RequestSettings settings = new RequestSettings(this.ApplicationName, this.userName, this.passWord); // settings.PageSize = 15; DocumentsRequest r = new DocumentsRequest(settings); // this returns the server default answer Feed<Document> feed = r.GetDocuments(); Document d = null; foreach (Document x in feed.Entries ) { Assert.IsTrue(x != null, "We should have something"); d = x; } Assert.IsTrue(d != null, "We should have something"); // now this should result in a notmodified try { Document refresh = r.Retrieve(d); Assert.IsTrue(refresh == null, "we should not be here"); } catch (GDataNotModifiedException g) { Assert.IsTrue(g!=null); } }
/// <summary> /// Fetches a potential updated Document for syncing purposes. /// If the document hasn't been updated in Google Docs, will return null. /// </summary> /// <param name="document">Document to be updated.</param> /// <returns> /// Document if an updated entry is found. /// null if no updated item is found. /// </returns> public static Document GetUpdatedDocument(Document document) { var originalEtag = document.DocumentEntry.Etag; Document refreshed; try { var request = new DocumentsRequest(_settings); var reqFactory = (GDataRequestFactory)request.Service.RequestFactory; reqFactory.Proxy = GetProxy(); refreshed = request.Retrieve(document); } catch (GDataNotModifiedException) { // if response is 304 (NotModified) -> document hasn't changed Debug.WriteLine(string.Format("Document hasn't changed: {0} - {1} -> {2}", document.Title, originalEtag, document.ETag)); return(null); } catch (GDataRequestException exRequest) { var error = GetErrorMessage(exRequest); // if we encounter a ResourceNotFoundException, there's no need to add an error job, // the AutoFetchAll-worker will handle removing the tab if (error.ToLowerInvariant().Contains("resourcenotfoundexception")) { return(null); } if (exRequest.ResponseString == null && error.ToLowerInvariant().Contains("execution of request failed")) { throw new GDataRequestException("Couldn't sync document - internet down?"); } Trace.WriteLine(DateTime.Now + " - NocsService - couldn't check if doc updated: " + error); throw new GDataRequestException(string.Format("Couldn't check if document was updated: {0} - {1}", document.DocumentEntry.Title.Text, Tools.TrimErrorMessage(error))); } catch (Exception ex) { var error = GetErrorMessage(ex); Trace.WriteLine(DateTime.Now + " - NocsService - couldn't check if doc updated: " + ex.Message); throw new GDataRequestException(string.Format("Couldn't check if document was updated: {0} - {1}", document.DocumentEntry.Title.Text, error)); } if (refreshed != null) { Debug.WriteLine(string.Format("Found updated document: {0} - {1} -> {2}", refreshed.Title, originalEtag, refreshed.ETag)); // let's update our internal dictionary if (refreshed.Type == Document.DocumentType.Folder) { AllFolders[document.ResourceId] = refreshed; } else { AllDocuments[document.ResourceId] = refreshed; } return(refreshed); } // if we get here, the document hasn't updated return(null); }