private string AddItemToSequentialQueue(EventHandlerEnvironment env) { // Sanity. if (string.IsNullOrWhiteSpace(env?.Input)) { return("No item provided."); } if (false == ObjVerEx.TryParse(env.Vault, env.Input, out ObjVerEx item)) { return($"Input '{env.Input}' not in expected format."); } SysUtils.ReportInfoToEventLog($"Adding {item.ToString()} to the queue."); // Create a task in the task queue. var itemId = this.TaskProcessor.CreateApplicationTaskSafe ( true, VaultApplication.SequentialTaskQueueId, VaultApplication.TaskTypeSequentialTask, new ObjVerExTaskQueueDirective { ObjVerEx = item.ToString() }.ToBytes() ); // Return the ID. return(itemId); }
/// <summary> /// Replaces the contents of an existing <paramref name="objectFile"/> with data from <paramref name="fileContents"/>. /// </summary> /// <param name="objVerEx">The object version that contains the file. Must already be checked out.</param> /// <param name="objectFile">The file to update.</param> /// <param name="fileContents">The contents of the file.</param> /// <param name="blockSize">The block size to use for transfers.</param> public static void ReplaceFileContent ( this ObjVerEx objVerEx, ObjectFile objectFile, Stream fileContents, int blockSize = FileTransfers.DefaultBlockSize ) { // Sanity. if (null == objVerEx) { throw new ArgumentNullException(nameof(objVerEx)); } if (null == objectFile) { throw new ArgumentNullException(nameof(objectFile)); } if (null == fileContents) { throw new ArgumentNullException(nameof(fileContents)); } // Use the other extension method. objectFile.ReplaceFileContent ( objVerEx.Vault, fileContents, blockSize ); }
/// <summary> /// Replaces the contents of an existing object with exactly one file, with data from <paramref name="fileContents"/>. /// </summary> /// <param name="objVerEx">The object version that contains exactly one file. Must already be checked out.</param> /// <param name="fileContents">The contents of the file.</param> /// <param name="blockSize">The block size to use for transfers.</param> public static void ReplaceFileContent ( this ObjVerEx objVerEx, Stream fileContents, int blockSize = FileTransfers.DefaultBlockSize ) { // Sanity. if (null == objVerEx) { throw new ArgumentNullException(nameof(objVerEx)); } if (null == objVerEx.Info?.Files) { throw new ArgumentException($"The object version does not contain information about its files.", nameof(objVerEx)); } if (null == fileContents) { throw new ArgumentNullException(nameof(fileContents)); } // Does it have exactly one file? if (1 != objVerEx.Info.FilesCount) { throw new ArgumentException($"The object version does not contain exactly one file.", nameof(objVerEx)); } // Use the other extension method. objVerEx.ReplaceFileContent ( objVerEx.Info.Files[1], fileContents, blockSize ); }
public static List <T?> GetMultiSelectValueListForPropertyDef <T>(this ObjVerEx objVerEx, int id, bool include_deleted = false) where T : struct { if (!typeof(T).IsEnum || !objVerEx.HasValue(id)) { return(new List <T?>()); } Lookups lookups = objVerEx.GetLookups(id); if (lookups.Count == 0) { return(null); } List <T?> Items = new List <T?>(); foreach (Lookup lookup in lookups) { if (lookup.Deleted && !include_deleted) { continue; } Items.Add((T)Enum.Parse(typeof(T), lookup.Item.ToString())); } return(Items); }
public static List <T> GetMultiSelectLookupValueForObject <T>(this ObjVerEx objVerEx, int object_id, bool include_deleted = false) where T : IObjVerEx, new() { List <T> Items = new List <T>(); Lookups lookups = objVerEx.GetIndirectReferences(null, object_id).ToLookups(); foreach (Lookup lookup in lookups) { if (lookup.Deleted && !include_deleted) { continue; } ObjVerEx objVEx = new ObjVerEx(objVerEx.Vault, lookup.ObjectType, lookup.Item, lookup.Version); T classObj = new T() { objVerEx = objVEx }; if (null == classObj) { continue; } if (!Items.Contains(classObj)) { Items.Add(classObj); } } return(Items); }
public static OT_Document create_multifile_doc(this OT_Document doc, int?createdby_mfuserid = null, params string[] files) { Vault vault = doc.objVerEx.Vault; ObjVerEx version = doc.objVerEx; SourceObjectFiles sourceFiles = new SourceObjectFiles(); foreach (string file in files) { FileInfo fi = new FileInfo(file); sourceFiles.AddFile(fi.Name.Replace(fi.Extension, ""), fi.Extension.Replace(".", ""), fi.FullName); } ObjectVersionAndProperties obj = vault.ObjectOperations.CreateNewObjectEx(OT_Document.TypeID, version.Properties, sourceFiles, false, createdby_mfuserid == null); if (createdby_mfuserid != null) { TypedValue created_by = new TypedValue(); created_by.SetValue(MFDataType.MFDatatypeLookup, createdby_mfuserid.Value); obj = doc.objVerEx.Vault.ObjectPropertyOperations.SetCreationInfoAdmin(obj.ObjVer, true, created_by, false, null); doc.objVerEx.Vault.ObjectOperations.CheckIn(obj.ObjVer); } return(new OT_Document() { objVerEx = new ObjVerEx(obj.Vault, obj) }); }
/// <summary> /// Adds all files on the given <paramref name="objVerEx"/> to the <paramref name="emailMessage"/>. /// </summary> /// <param name="emailMessage">The email message to add the files to.</param> /// <param name="objVerEx">The object version that has the files.</param> /// <param name="fileFormat">The format for the attached files.</param> public static void AddAllFiles ( this IEmailMessage emailMessage, ObjVerEx objVerEx, MFFileFormat fileFormat = MFFileFormat.MFFileFormatNative ) { // Sanity. if (null == emailMessage) { throw new ArgumentNullException(nameof(emailMessage)); } if (null == objVerEx) { throw new ArgumentNullException(nameof(objVerEx)); } if (null == objVerEx.Vault) { throw new ArgumentException("The objVerEx's vault reference is null.", nameof(objVerEx)); } if (null == objVerEx.Vault) { throw new ArgumentException("The objVerEx's info (ObjectVersion) reference is null.", nameof(objVerEx)); } // Use the base implementation. emailMessage.AddAllFiles(objVerEx.Info, objVerEx.Vault, fileFormat); }
public static bool create(this ObjVerEx objVerEx, int typeId, int?createdby_mfuserid = null) { try { ObjectVersionAndProperties objVerAndProps = objVerEx.Vault.ObjectOperations.CreateNewObjectEx(typeId, objVerEx.Properties, null, false, createdby_mfuserid == null); int objVerID = objVerAndProps.ObjVer.ID; int objVersion = objVerAndProps.ObjVer.Version; if (createdby_mfuserid != null) { TypedValue created_by = new TypedValue(); created_by.SetValue(MFDataType.MFDatatypeLookup, createdby_mfuserid.Value); objVerAndProps = objVerEx.Vault.ObjectPropertyOperations.SetCreationInfoAdmin(objVerAndProps.ObjVer, true, created_by, false, null); ObjectVersion objver = objVerEx.Vault.ObjectOperations.CheckIn(objVerAndProps.ObjVer); objVerID = objver.ObjVer.ID; objVersion = objver.ObjVer.Version; } objVerEx.ObjVer.ID = objVerID; objVerEx.ObjVer.Version = objVersion; objVerEx.ObjVer.Type = objVerAndProps.ObjVer.Type; return(true); } catch (Exception exception) { throw exception; } }
public static bool GetYesOrNoAsBool(this ObjVerEx targetEx, MFIdentifier prop, out bool value) { value = false; // if the object doesn't have the property, return null if (!targetEx.HasProperty(prop)) { return(false); } // get the text version of the property var propText = targetEx.GetPropertyText(prop); // if the text version of the property is "Yes", return true if (propText.Equals("Yes")) { value = true; return(true); } // if the text version of the property is "No", return false if (propText.Equals("No")) { value = false; return(true); } // couldn't parse the text value, return null return(false); }
/// <summary> /// Expands a simple string using similar logic to the "concatenated properties" /// functionality in M-Files Admin. /// More lightweight than <see cref="ObjVerEx.ExpandPlaceholderText(string, bool, bool)"/> by only supporting /// simple property expressions (%PROPERTY_123%, %PROPERTY_{Alias}%, %PROPERTY_{Alias1}.PROPERTY_{Alias2}%, %EXTERNALID% and %INTERNALID%). /// </summary> /// <param name="objVerEx">The object containing information to use for the expansion.</param> /// <param name="concatenationString">The string containing the placeholders.</param> /// <returns>The expanded string.</returns> public static string ExpandSimpleConcatenation ( this ObjVerEx objVerEx, string concatenationString ) { // Sanity. if (null == objVerEx) { throw new ArgumentNullException(nameof(objVerEx)); } if (string.IsNullOrWhiteSpace(concatenationString)) { return(string.Empty); } // Use the internal implementation. return(objVerEx.ExpandSimpleConcatenation ( concatenationString, (o, id) => o.GetPropertyText(id), (o, id) => o.GetDirectReference(id), (o, platform) => UrlHelper.GetObjectUrl(o, platform) )); }
/// <summary> /// Get the value list item for the specified property def id. /// </summary> /// <param name="objVerEx">The child/owned object.</param> /// <param name="propDefId">The property definition id.</param> /// <returns>Value list item object if available</returns> /// <remarks>Can return null if the value list item is deleted or not set.</remarks> /// <exception cref="ArgumentException">Thrown if <paramref name="propDefId"/> does not point to a suitable property definition.</exception> public static ValueListItem GetPropertyAsValueListItem( this ObjVerEx objVerEx, int propDefId ) { // Sanity. if (null == objVerEx) { throw new ArgumentNullException(nameof(objVerEx)); } // Validity of the property def id if (0 > propDefId) { throw new ArgumentOutOfRangeException( nameof(propDefId), "Property Ids must be greater than -1; ensure that your property alias was resolved." ); } // Get the value list id of the property def PropertyDef propDef = objVerEx .Vault .PropertyDefOperations .GetPropertyDef(propDefId); // Exception if property was not found if (null == propDef) { throw new ArgumentException( $"The property could not be found.", nameof(propDefId) ); } // Does this have an owning type? if (false == propDef.BasedOnValueList || 0 > propDef.ValueList) { throw new ArgumentException( $"The property \"{propDef.Name}\" is not based on a value list.", nameof(propDefId) ); } // Get the lookup id of the property int lookupId = objVerEx.GetLookupID(propDefId); // Return null if lookup was not found if (lookupId < 0) { return(null); } // return the value list item for the lookup id return(objVerEx .Vault .ValueListItemOperations .GetValueListItemByID(propDef.ValueList, lookupId)); }
public static void replace_files(this OT_Document document, string singledoc_newfilepath = null, string[] multidoc_newfilespath = null) { Vault vault = document.objVerEx.Vault; var obj = document.objVerEx; bool isSingleFile = vault.ObjectOperations.IsSingleFileObject(obj.ObjVer); //singlefile document if (isSingleFile && string.IsNullOrEmpty(singledoc_newfilepath)) { throw new Exception("No file supplied for single-file document."); } //multifile document if (!isSingleFile && (multidoc_newfilespath == null || multidoc_newfilespath.Length == 0)) { throw new Exception("No file(s) supplied for multi-file document."); } ObjectVersion new_version = vault.ObjectOperations.CheckOut(obj.ObjID); try { ObjVerEx new_versionex = new ObjVerEx(vault, new_version); SourceObjectFiles files = new SourceObjectFiles(); if (isSingleFile) { FileInfo fi = new FileInfo(singledoc_newfilepath); files.AddFile(fi.Name.Replace(fi.Extension, ""), fi.Extension.Replace(".", ""), fi.FullName); //change the file type IEnumerator obfile_enumerator = vault.ObjectFileOperations.GetFiles(new_version.ObjVer).GetEnumerator(); obfile_enumerator.MoveNext(); ObjectFile single_fileobj = obfile_enumerator.Current as ObjectFile; if (single_fileobj == null) { throw new Exception("Single file for this document not found."); } vault.ObjectFileOperations.RenameFile(new_versionex.ObjVer, single_fileobj.FileVer, fi.Name.Replace(fi.Extension, ""), fi.Extension.Replace(".", ""), false); } else { foreach (string file in multidoc_newfilespath) { FileInfo fi = new FileInfo(file); files.AddFile(fi.Name.Replace(fi.Extension, ""), fi.Extension.Replace(".", ""), fi.FullName); } } new_versionex.ReplaceFiles(files); new_versionex.CheckIn(); document.objVerEx = new_versionex; } catch { if (new_version.ObjectCheckedOut) { vault.ObjectOperations.ForceUndoCheckout(new_version.ObjVer); } throw; } }
public void CheckIn(ObjVerEx objVerEx, string comments, int userId) { (objVerEx ?? throw new ArgumentNullException(nameof(objVerEx))) .CheckIn ( comments, userId ); }
public void SetSingleFileDocument(ObjVerEx objVerEx, bool value) { (objVerEx ?? throw new ArgumentNullException(nameof(objVerEx))) .SaveProperty ( (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefSingleFileObject, MFDataType.MFDatatypeBoolean, value ); }
/// <summary> /// Creates a <see cref="ObjVerExTaskQueueDirective"/> /// representing the provided <paramref name="objVerEx"/>. /// </summary> /// <param name="objVerEx">The object version to represent.</param> /// <returns>The task queue directive for the supplied object version.</returns> public static ObjVerExTaskQueueDirective FromObjVerEx(ObjVerEx objVerEx) { // Sanity. if (null == objVerEx) { throw new ArgumentNullException(nameof(objVerEx)); } // Use the other method. return(ObjVerExTaskQueueDirective.FromObjVer(objVerEx.ObjVer)); }
/// <summary> /// Creates a copy of this object in the vault. /// </summary> /// <param name="source">The source object to copy.</param> /// <param name="objectCopyOptions">Options defining how to copy the object.</param> /// <returns>The new object.</returns> /// <remarks>No attempt is made to roll back anything in case of an exception. /// It is recommended that the <paramref name="source"/> is loaded from a transactional vault reference /// so that the transaction is rolled back in case of issue.</remarks> public static ObjVerEx CreateCopy ( this ObjVerEx source, ObjectCopyOptions objectCopyOptions = null ) { return(source.CreateCopy ( objectCopyOptions ?? new ObjectCopyOptions(), new ObjectCopyCreator() )); }
/// <summary> /// Returns the <see cref="bool"/> value of the property specified in <paramref name="propertyDef"/>. /// </summary> /// <param name="objVerEx">The object version to check.</param> /// <param name="propertyDef">The property definition Id.</param> /// <returns>The value of the property, or null if not set.</returns> public static bool?GetPropertyAsBoolean ( this ObjVerEx objVerEx, int propertyDef ) { return(objVerEx.GetPropertyAs <bool?> ( propertyDef, MFDataType.MFDatatypeBoolean )); }
/// <summary> /// Returns the <see cref="double"/> value of the property specified in <paramref name="propertyDef"/>. /// </summary> /// <param name="objVerEx">The object version to check.</param> /// <param name="propertyDef">The property definition Id.</param> /// <returns>The value of the property, or null if not set.</returns> public static double?GetPropertyAsDouble ( this ObjVerEx objVerEx, int propertyDef ) { return(objVerEx.GetPropertyAs <double?> ( propertyDef, MFDataType.MFDatatypeFloating )); }
/// <summary> /// Returns the <see cref="int"/> value of the property specified in <paramref name="propertyDef"/>. /// </summary> /// <param name="objVerEx">The object version to check.</param> /// <param name="propertyDef">The property definition Id.</param> /// <returns>The value of the property, or null if not set.</returns> public static long?GetPropertyAsLong ( this ObjVerEx objVerEx, int propertyDef ) { return(objVerEx.GetPropertyAs <long?> ( propertyDef, MFDataType.MFDatatypeInteger64 )); }
/// <summary> /// Returns the <see cref="int"/> value of the property specified in <paramref name="propertyDef"/>. /// </summary> /// <param name="objVerEx">The object version to check.</param> /// <param name="propertyDef">The property definition Id.</param> /// <returns>The value of the property, or null if not set.</returns> public static int?GetPropertyAsInteger ( this ObjVerEx objVerEx, int propertyDef ) { return(objVerEx.GetPropertyAs <int?> ( propertyDef, MFDataType.MFDatatypeInteger )); }
/// <summary> /// Returns the <see cref="DateTime"/> value of the property specified in <paramref name="propertyDef"/>. /// </summary> /// <param name="objVerEx">The object to retrieve data from.</param> /// <param name="propertyDef">The property definition Id.</param> /// <returns>The value of the property, or null if not set.</returns> public static DateTime?GetPropertyAsDateTime ( this ObjVerEx objVerEx, int propertyDef ) { return(objVerEx.GetPropertyAs <DateTime?> ( propertyDef, MFDataType.MFDatatypeDate, MFDataType.MFDatatypeTimestamp )); }
public void AddFile(ObjVerEx addTo, string title, string extension, string localFilePath) { (addTo ?? throw new ArgumentNullException(nameof(addTo))) .Vault .ObjectFileOperations .AddFile ( addTo.ObjVer, title, extension, localFilePath ); }
public static bool?GetPropertyBooleanValue(this ObjVerEx objVerEx, int id) { if (objVerEx.HasProperty(id)) { PropertyValue pv = objVerEx.GetProperty(id); if (!pv.Value.IsNULL()) { return((bool)objVerEx.GetProperty(id).Value.Value); } } return(null); }
public static double GetPropertyDoubleValue(this ObjVerEx objVerEx, int id) { if (objVerEx.HasProperty(id)) { PropertyValue pv = objVerEx.GetProperty(id); if (!pv.Value.IsNULL()) { return((double)objVerEx.GetProperty(id).Value.Value); } } return(0.0); }
public static DateTime GetProperyDateTimeValue(this ObjVerEx objVerEx, int id) { if (objVerEx.HasProperty(id)) { PropertyValue pv = objVerEx.GetProperty(id); if (!pv.Value.IsNULL()) { return((DateTime)objVerEx.GetProperty(id).Value.Value); } } return(DateTime.MinValue); }
public static int GetPropertyIntValue(this ObjVerEx objVerEx, int id) { if (objVerEx.HasProperty(id)) { PropertyValue pv = objVerEx.GetProperty(id); if (!pv.Value.IsNULL()) { return((int)objVerEx.GetProperty(id).Value.Value); } } return(0); }
public void syncData(ObjVerEx objectToMove, string actionName, int actionTypeId) { var data = new { ObjectID = objectToMove.ID, ObjectType = objectToMove.Type, Objectver = objectToMove.Version, ClassID = objectToMove.Class, ActionName = actionName, ActionTypeID = actionTypeId }; this.PermanentVault.ExtensionMethodOperations.ExecuteVaultExtensionMethod("PerformActionMethod", JsonConvert.SerializeObject((object)data)); }
/// <summary> /// Creates a <see cref="ObjVerExTaskDirective"/> /// representing the provided <paramref name="objVerEx"/>. /// </summary> /// <param name="objVerEx">The object version to represent.</param> /// <param name="displayName">The name to display for this task.</param> /// <returns>The task directive for the supplied object version.</returns> public static ObjVerExTaskDirective ToObjVerExTaskDirective ( this ObjVerEx objVerEx, string displayName = null ) { // Sanity. if (null == objVerEx) { throw new ArgumentNullException(nameof(objVerEx)); } // Use the other method. return(objVerEx.ObjVer.ToObjVerExTaskDirective(displayName: displayName)); }
/// <summary> /// Adds a <see cref="SearchCondition"/> to the collection to find items with the given owner. /// </summary> /// <param name="searchBuilder">The <see cref="MFSearchBuilder"/> to add the condition to.</param> /// <param name="owner">The owner item.</param> /// <returns>The <paramref name="searchBuilder"/> provided, for chaining.</returns> public static MFSearchBuilder Owner ( this MFSearchBuilder searchBuilder, ObjVerEx owner ) { // Sanity. if (null == owner) { throw new ArgumentNullException(nameof(owner)); } // Use the other overload. return(searchBuilder.Owner(owner.ObjVer)); }
public static bool GetDouble(this ObjVerEx targetEx, MFIdentifier prop, out double value) { // set default value value = 0.0; // check if the property exists on the target if (!targetEx.HasProperty(prop)) { return(false); } // attempt to get the text value of the property var text = targetEx.GetPropertyText(prop); // attempt to parse it return(double.TryParse(text, out value)); }