public override void RowSelected(UITableView tableView, NSIndexPath indexPath) { var row = dataSource.RowAtIndexPath(indexPath); var doc = row.Document; // Toggle the document's 'checked' property var docContent = doc.Properties; object checkedVal; docContent.TryGetValue(RootViewController.CheckboxPropertyName, out checkedVal); var wasChecked = (bool)checkedVal; docContent[RootViewController.CheckboxPropertyName] = !wasChecked; SavedRevision newRevision = null; try { newRevision = doc.CurrentRevision.CreateRevision(docContent); } catch (Exception ex) { if (newRevision == null) { parent.ShowErrorAlert("Failed to update item", ex, false); } } }
//*** GetDocument ***// /// <summary> /// Returns the requested document. /// </summary> /// <param name="fullSyncDatatbase"></param> /// <param name="parameters"></param> /// <returns></returns> public async override Task <object> HandleGetDocumentRequest(string fullSyncDatatbaseName, string docid, IDictionary <string, object> parameters) { var fullSyncDatabase = await GetOrCreateFullSyncDatabase(fullSyncDatatbaseName); // Gets the document form the local database var document = fullSyncDatabase.Database.GetExistingDocument(docid); if (document != null) { // If there are attachments, compute for each one the url to local storage and add it to the attachment descriptor var attachmentsProperty = document.GetProperty(C8oFullSync.FULL_SYNC__ATTACHMENTS) as JObject; if (attachmentsProperty != null) { SavedRevision rev = document.CurrentRevision; Assembly couchbaseLiteAssembly = Assembly.GetAssembly(typeof(Attachment)); Type attachmentInternalType = couchbaseLiteAssembly.GetType(ATTACHMENT_INTERNAL_TYPE); ConstructorInfo attachmentInternalConstructor = attachmentInternalType.GetConstructor(new Type[] { typeof(String), typeof(IDictionary <string, object>) }); foreach (var attachmentProperty in attachmentsProperty) { string attachmentName = attachmentProperty.Key; Attachment attachment = rev.GetAttachment(attachmentName); if (!attachment.Metadata.Keys.Contains(ATTACHMENT_PROPERTY_KEY_CONTENT_URL)) { Object[] attachmentInternalConstructorParams = new Object[] { attachment.Name, attachment.Metadata }; object attachmentInternal = attachmentInternalConstructor.Invoke(attachmentInternalConstructorParams); PropertyInfo databaseProp = attachmentInternalType.GetProperty(ATTACHMENT_INTERNAL_PROPERTY_DATABASE); databaseProp.SetValue(attachmentInternal, fullSyncDatabase.Database); PropertyInfo urlProp = attachmentInternalType.GetProperty(ATTACHMENT_INTERNAL_PROPERTY_CONTENT_URL); object contentUrl = urlProp.GetValue(attachmentInternal, null); if (contentUrl != null && contentUrl is Uri) { Uri uri = (Uri)contentUrl; string absoluteUri = C8oUtils.UrlDecode(uri.AbsoluteUri); string absolutePath = C8oUtils.UrlDecode(uri.AbsolutePath); attachment.Metadata.Add(ATTACHMENT_PROPERTY_KEY_CONTENT_URL, absoluteUri); if (attachmentProperty.Value is JObject) { (attachmentProperty.Value as JObject)[ATTACHMENT_PROPERTY_KEY_CONTENT_URL] = absoluteUri; } attachment.Metadata.Add("content_path", absolutePath); if (attachmentProperty.Value is JObject) { (attachmentProperty.Value as JObject)["content_path"] = absolutePath; } } } } } } else { throw new C8oRessourceNotFoundException(C8oExceptionMessage.RessourceNotFound("requested document \"" + docid + "\"")); } return(document); }
public override async Task SaveResponseToLocalCache(string c8oCallRequestIdentifier, C8oLocalCacheResponse localCacheResponse) { C8oFullSyncDatabase fullSyncDatabase = await GetOrCreateFullSyncDatabase(C8o.LOCAL_CACHE_DATABASE_NAME); Document localCacheDocument = fullSyncDatabase.Database.GetDocument(c8oCallRequestIdentifier); IDictionary <string, object> properties = new Dictionary <string, object>(); properties[C8o.LOCAL_CACHE_DOCUMENT_KEY_RESPONSE] = localCacheResponse.Response; properties[C8o.LOCAL_CACHE_DOCUMENT_KEY_RESPONSE_TYPE] = localCacheResponse.ResponseType; if (localCacheResponse.ExpirationDate > 0) { properties[C8o.LOCAL_CACHE_DOCUMENT_KEY_EXPIRATION_DATE] = localCacheResponse.ExpirationDate; } SavedRevision currentRevision = localCacheDocument.CurrentRevision; if (currentRevision != null) { properties[FULL_SYNC__REV] = currentRevision.Id; } localCacheDocument.PutProperties(properties); }