private void SaveDocument() { RavenJObject doc; RavenJObject metadata; try { doc = RavenJObject.Parse(parentModel.JsonData); metadata = RavenJObject.Parse(parentModel.JsonMetadata); if (parentModel.Key != null && Separator != null && metadata.Value <string>(Constants.RavenEntityName) == null) { var entityName = parentModel.Key.Split(new[] { Separator }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(); if (entityName != null && entityName.Length > 1) { metadata[Constants.RavenEntityName] = char.ToUpper(entityName[0]) + entityName.Substring(1); } else { metadata[Constants.RavenEntityName] = parentModel.ExpireAt.Value; } } if (parentModel.EnableExpiration.Value) { metadata["Raven-Expiration-Date"] = parentModel.ExpireAt.Value.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffff"); } else if (metadata.ContainsKey("Raven-Expiration-Date")) { metadata.Remove("Raven-Expiration-Date"); } } catch (Exception ex) { ApplicationModel.Current.AddErrorNotification(ex, "Could not parse JSON"); return; } parentModel.UpdateMetadata(metadata); ApplicationModel.Current.AddInfoNotification("Saving document " + parentModel.Key + " ..."); Etag etag = string.Equals(parentModel.DocumentKey, parentModel.Key, StringComparison.InvariantCultureIgnoreCase) || parentModel.ResolvingConflict ? parentModel.Etag : Etag.Empty; DatabaseCommands.PutAsync(parentModel.Key, etag, doc, metadata) .ContinueOnSuccess(result => { parentModel.ResolvingConflict = false; ApplicationModel.Current.AddInfoNotification("Document " + result.Key + " saved"); parentModel.HasUnsavedChanges = false; parentModel.Etag = result.ETag; parentModel.PutDocumentKeyInUrl(result.Key, dontOpenNewTab: true); parentModel.SetCurrentDocumentKey(result.Key); }) .ContinueOnSuccess(() => new RefreshDocumentCommand(parentModel).Execute(null)) .Catch(exception => ApplicationModel.Current.AddErrorNotification(exception, "Could not save document.")); }
public override void Execute(object parameter) { RavenJObject metadata; try { metadata = RavenJObject.Parse(editableDocumentModel.JsonMetadata); editableDocumentModel.JsonData = RavenJObject.Parse(editableDocumentModel.JsonData).ToString(Formatting.Indented); editableDocumentModel.JsonMetadata = metadata.ToString(Formatting.Indented); } catch (JsonReaderException ex) { ErrorPresenter.Show(ex.Message, string.Empty); return; } editableDocumentModel.UpdateMetadata(metadata); }
private void SaveDocument() { RavenJObject doc; RavenJObject metadata; try { doc = RavenJObject.Parse(document.JsonData); metadata = RavenJObject.Parse(document.JsonMetadata); if (document.Key != null && Seperator != null && metadata.Value <string>(Constants.RavenEntityName) == null) { var entityName = document.Key.Split(new[] { Seperator }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(); if (entityName != null && entityName.Length > 1) { metadata[Constants.RavenEntityName] = char.ToUpper(entityName[0]) + entityName.Substring(1); } else { metadata[Constants.RavenEntityName] = entityName; } } } catch (JsonReaderException ex) { ErrorPresenter.Show(ex.Message); return; } document.UpdateMetadata(metadata); ApplicationModel.Current.AddNotification(new Notification("Saving document " + document.Key + " ...")); var url = new UrlParser(UrlUtil.Url); var docId = url.GetQueryParam("id"); Guid?etag = string.Equals(docId, document.Key, StringComparison.InvariantCultureIgnoreCase) ? document.Etag : Guid.Empty; DatabaseCommands.PutAsync(document.Key, etag, doc, metadata) .ContinueOnSuccess(result => { ApplicationModel.Current.AddNotification(new Notification("Document " + result.Key + " saved")); document.Etag = result.ETag; document.SetCurrentDocumentKey(result.Key, dontOpenNewTag: true); }) .ContinueOnSuccess(() => new RefreshDocumentCommand(document).Execute(null)) .Catch(exception => ApplicationModel.Current.AddNotification(new Notification(exception.Message))); }
private void SaveDocument() { RavenJObject doc; RavenJObject metadata; try { doc = RavenJObject.Parse(document.JsonData); metadata = RavenJObject.Parse(document.JsonMetadata); if (document.Key != null && document.Key.Contains("/") && metadata.Value <string>(Constants.RavenEntityName) == null) { var entityName = document.Key.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(); if (entityName != null && entityName.Length > 1) { metadata[Constants.RavenEntityName] = char.ToUpper(entityName[0]) + entityName.Substring(1); } else { metadata[Constants.RavenEntityName] = entityName; } } } catch (JsonReaderException ex) { ErrorPresenter.Show(ex.Message, string.Empty); return; } document.UpdateMetadata(metadata); ApplicationModel.Current.AddNotification(new Notification("Saving document " + document.Key + " ...")); DatabaseCommands.PutAsync(document.Key, document.Etag, doc, metadata) .ContinueOnSuccess(result => { ApplicationModel.Current.AddNotification(new Notification("Document " + result.Key + " saved")); document.Etag = result.ETag; document.SetCurrentDocumentKey(result.Key); }) .ContinueOnSuccess(() => new RefreshDocumentCommand(document).Execute(null)) .Catch(exception => ApplicationModel.Current.AddNotification(new Notification(exception.Message))); }