/// <summary>Creates new documents from the given documents, unless there is already a document with the _key given. /// </summary> /// <remarks> /// Creates new documents from the given documents, unless there is already a document with the _key given. If no /// _key is given, a new unique _key is generated automatically. /// </remarks> /// <seealso><a href="https://docs.arangodb.com/current/HTTP/Document/WorkingWithDocuments.html#create-document">API /// * Documentation</a></seealso> /// <param name="values">A List of documents (POJO, VPackSlice or String for Json)</param> /// <returns>information about the documents</returns> /// <exception cref="ArangoDBException"/> /// <exception cref="ArangoDBException"/> public virtual MultiDocumentEntity <DocumentCreateEntity <T> > insertDocuments <T>(System.Collections.Generic.ICollection <T> values) { DocumentCreateOptions @params = new DocumentCreateOptions (); return(this.executor.execute(this.insertDocumentsRequest(values, @params), this.insertDocumentsResponseDeserializer (values, @params))); }
public virtual Request insertDocumentRequest <T>(T value , DocumentCreateOptions options) { Request request = new Request (this.db, RequestType.POST, this.executor.createPath(ArangoDBConstants .PATH_API_DOCUMENT, name)); DocumentCreateOptions @params = options != null ? options : new DocumentCreateOptions(); request.putQueryParam(ArangoDBConstants.WAIT_FOR_SYNC, @params .getWaitForSync()); request.putQueryParam(ArangoDBConstants.RETURN_NEW, @params .getReturnNew()); request.setBody(this.executor.Serialize(value)); return(request); }
public Document Create(Guid applicationId, string name, [Documentation(Name = "Data", Type = typeof(byte[]), Description = "File Data"), Documentation(Name = "DataUrl", Type = typeof(string), Description = "Base64 encoded Data"), Documentation(Name = "Url", Type = typeof(string), Description = "CFS File Url (use $core_v2_uploadedFile.Get() method to get a file url)"), Documentation(Name = "FolderPath", Type = typeof(string), Description = "Folder server relative Url"), Documentation(Name = "Overwrite", Type = typeof(bool))] IDictionary options) { var document = new Document(); try { DocumentCreateOptions documentCreateOptions = null; if (options["Data"] is byte[]) { documentCreateOptions = new DocumentCreateOptions(name, (byte[])options["Data"]); } else if (options["DataUrl"] != null && !string.IsNullOrEmpty(options["DataUrl"].ToString())) { var data = options["DataUrl"].ToString(); const string base64Prefix = "base64,"; var startIndex = data.IndexOf(base64Prefix, StringComparison.InvariantCultureIgnoreCase); if (startIndex != -1) { data = data.Substring(startIndex + base64Prefix.Length); } documentCreateOptions = new DocumentCreateOptions(name, Convert.FromBase64String(data)); } else if (options["Url"] != null) { var cfsOptions = CFSOptions.Get(options["Url"].ToString()); if (!cfsOptions.HasErrors()) { documentCreateOptions = new DocumentCreateOptions(name, cfsOptions.FileStore, cfsOptions.FilePath, cfsOptions.FileName); } else { foreach (var error in cfsOptions.Errors) { document.Errors.Add(error); } } } else { document.Errors.Add(new Error(typeof(ArgumentNullException).ToString(), "The Data or Url parameters have not been specified for a new document uploading.")); } if (!document.Errors.Any() && documentCreateOptions != null) { if (options["FolderPath"] != null) { documentCreateOptions.FolderPath = options["FolderPath"].ToString(); } bool overwrite; if (options["Overwrite"] != null && bool.TryParse(options["Overwrite"].ToString(), out overwrite)) { documentCreateOptions.Overwrite = overwrite; } document = PublicApi.Documents.Create(applicationId, documentCreateOptions); } } catch (InvalidOperationException ex) { document.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.InvalidCreateOptions, applicationId, name))); } catch (SPFileAlreadyExistsException ex) { document.Warnings.Add(new Warning(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.AlreadyExists, applicationId, name))); } catch (SPInternalException ex) { document.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.CannotBeCreated, applicationId, name))); } catch (Exception ex) { string message = string.Format("An exception of type {0} occurred in the WidgetApi.V2.SharePointFile.Create() method while uploading a new document LibraryId:{1} Name:{2}. The exception message is: {3}", ex.GetType(), applicationId, name, ex.Message); SPLog.UnKnownError(ex, message); document.Errors.Add(new Error(ex.GetType().ToString(), plugin.Translate(SharePointFileExtension.Translations.UnknownError))); } return(document); }
/// <summary>Creates a new document from the given document, unless there is already a document with the _key given. /// </summary> /// <remarks> /// Creates a new document from the given document, unless there is already a document with the _key given. If no /// _key is given, a new unique _key is generated automatically. /// </remarks> /// <seealso><a href="https://docs.arangodb.com/current/HTTP/Document/WorkingWithDocuments.html#create-document">API /// * Documentation</a></seealso> /// <param name="value">A representation of a single document (POJO, VPackSlice or String for Json) /// </param> /// <param name="options">Additional options, can be null</param> /// <returns>information about the document</returns> /// <exception cref="ArangoDBException"/> /// <exception cref="ArangoDBException"/> public virtual DocumentCreateEntity <T> insertDocument <T>(T value , DocumentCreateOptions options) { return(this.executor.execute(this.insertDocumentRequest(value, options), this.insertDocumentResponseDeserializer (value))); }