Exemple #1
0
 public static TypedValue GetPropertyById(IVault vault, ObjVer obj, int id)
 {
     try
     {
         var res = vault.ObjectPropertyOperations.GetProperty(obj, id);
         return res.Value;
     }
     catch (COMException)
     {
         return null;
     }
 }
Exemple #2
0
 public ObjectVersionAndProperties MarkAssignmentComplete(ObjVer ObjVer)
 {
     throw new NotImplementedException();
 }
Exemple #3
0
 public PropertyValue GetProperty(ObjVer ObjVer, int Property)
 {
     throw new NotImplementedException();
 }
Exemple #4
0
 public VersionComments GetVersionCommentHistory(ObjVer ObjVer)
 {
     throw new NotImplementedException();
 }
Exemple #5
0
 public string GetPropertiesAsXML(ObjVer ObjVer, bool UpdateFromServer = false)
 {
     throw new NotImplementedException();
 }
Exemple #6
0
 public NamedValues GetPropertiesForMetadataSync(ObjVer ObjVer, MFMetadataSyncFormat Format)
 {
     throw new NotImplementedException();
 }
Exemple #7
0
 /// <summary>
 /// Removes a single property from a single object.
 /// </summary>
 /// <param name="objVer">The object to set the property on.</param>
 /// <param name="propertyDef">The property to remove.</param>
 /// <param name="token">A cancellation token for the request.</param>
 /// <returns>The new object version.</returns>
 /// <remarks>The object must be checked out to perform this action.</remarks>
 public Task <ExtendedObjectVersion> RemovePropertyAsync(ObjVer objVer, int propertyDef, CancellationToken token = default(CancellationToken))
 {
     // Use the other overload.
     return(this.RemovePropertyAsync(objVer.Type, objVer.ID, propertyDef, objVer.Version, token));
 }
Exemple #8
0
 public WorkflowAssignment GetAssignment_DEPRECATED(ObjVer ObjVer, bool UpdateFromServer = false)
 {
     throw new NotImplementedException();
 }
Exemple #9
0
        /// <summary>
        /// Executes the <see cref="ObjectSelector"/> rule against the <see cref="XNode"/>,
        /// importing matching objects.
        /// </summary>
        /// <param name="vault">The vault reference to use for processing the import.</param>
        /// <param name="node">The node to import data from.</param>
        /// <param name="objectSelector">The selector to execute.</param>
        /// <param name="xmlFile">The information about the XML file being imported.</param>
        /// <param name="parent">A parent object to create a relationship to, if appropriate.</param>
        /// <param name="xmlNamespaceManager">A namespace manager for using XML prefixes in XPath statements.</param>
        /// <returns>A list of files which were attached to the object, for deletion.</returns>
        public List <FileInfo> ImportXmlFile(
            Vault vault,
            XNode node,
            ObjectSelector objectSelector,
            FileInfo xmlFile = null,
            ObjVer parent    = null,
            XmlNamespaceManager xmlNamespaceManager = null)
        {
            // Sanity.
            if (vault == null)
            {
                throw new ArgumentNullException(nameof(vault));
            }
            if (null == node)
            {
                throw new ArgumentNullException(nameof(node));
            }
            if (null == objectSelector)
            {
                throw new ArgumentNullException(nameof(objectSelector));
            }
            if (string.IsNullOrWhiteSpace(objectSelector.XPathQuery))
            {
                throw new ArgumentException("The XPath query for the object was empty", nameof(objectSelector));
            }
            if (null == objectSelector.PropertySelectors)
            {
                throw new ArgumentException("The object selector contained no property selectors.", nameof(objectSelector));
            }
            if (false == objectSelector.ObjectType.IsResolved)
            {
                throw new InvalidOperationException("The object selector object type is not resolved");
            }
            if (false == objectSelector.Class.IsResolved)
            {
                throw new InvalidOperationException("The object selector class is not resolved");
            }

            // Create a list of attached files (which can then be deleted later).
            var attachedFilesToDelete = new List <FileInfo>();

            // Create the namespace manager.
            if (null != xmlNamespaceManager)
            {
                // Copy data from the other manager (so we don't accidentally affect other queries).
                var xmlNamespaceManager2 = new XmlNamespaceManager(new NameTable());
                foreach (string prefix in xmlNamespaceManager)
                {
                    // Don't add default.
                    if (string.IsNullOrWhiteSpace(prefix))
                    {
                        continue;
                    }
                    if (prefix == "xsi")
                    {
                        continue;
                    }
                    if (prefix == "xmlns")
                    {
                        continue;
                    }

                    // Add.
                    xmlNamespaceManager2.AddNamespace(prefix, xmlNamespaceManager.LookupNamespace(prefix));
                }
                xmlNamespaceManager = xmlNamespaceManager2;
            }
            else
            {
                xmlNamespaceManager = new XmlNamespaceManager(new NameTable());
            }

            // Populate the namespace manager.
            if (null != objectSelector.XmlNamespaces)
            {
                foreach (var ns in objectSelector.XmlNamespaces)
                {
                    // If the namespace manager already contains a prefix then remove it.
                    string existingPrefix = xmlNamespaceManager.LookupPrefix(ns.Uri);
                    if (false == string.IsNullOrEmpty(existingPrefix))
                    {
                        xmlNamespaceManager.RemoveNamespace(existingPrefix, ns.Uri);
                    }

                    xmlNamespaceManager.AddNamespace(ns.Prefix, ns.Uri);
                }
            }

            // Find matching nodes.
            foreach (var matchingElement in node.XPathSelectElements(objectSelector.XPathQuery, xmlNamespaceManager))
            {
                // Hold all the properties being read.
                var propertyValuesBuilder = new MFPropertyValuesBuilder(vault);

                // Add the class property value.
                propertyValuesBuilder.SetClass(objectSelector.Class.ID);

                // Retrieve the properties.
                foreach (var propertySelector in objectSelector.PropertySelectors)
                {
                    // Sanity.
                    if (string.IsNullOrWhiteSpace(propertySelector.XPathQuery))
                    {
                        throw new ArgumentException("The object selector contained no property selectors.", nameof(objectSelector));
                    }
                    if (false == propertySelector.PropertyDef.IsResolved)
                    {
                        throw new InvalidOperationException("The property value selector property definition is not resolved");
                    }

                    // Retrieve the element for the property value.
                    var matchingPropertyElement = matchingElement
                                                  .XPathSelectElement(propertySelector.XPathQuery, xmlNamespaceManager);
                    if (null == matchingPropertyElement)
                    {
                        continue;
                    }

                    // Find the property definition type.
                    var propertyDefType = vault
                                          .PropertyDefOperations
                                          .GetPropertyDef(propertySelector.PropertyDef.ID)
                                          .DataType;

                    // Add the property to the builder.
                    propertyValuesBuilder.Add(
                        propertySelector.PropertyDef.ID,
                        propertyDefType,
                        matchingPropertyElement.Value);
                }

                // Set the static values
                foreach (var staticPropertyValue in objectSelector.StaticPropertyValues ?? new List <StaticPropertyValue>())
                {
                    // Sanity.
                    if (false == staticPropertyValue.PropertyDef.IsResolved)
                    {
                        throw new InvalidOperationException("The property value selector property definition is not resolved");
                    }

                    // Find the property definition type.
                    var propertyDefType = vault
                                          .PropertyDefOperations
                                          .GetPropertyDef(staticPropertyValue.PropertyDef.ID)
                                          .DataType;

                    // Add the property to the builder.
                    propertyValuesBuilder.Add(
                        staticPropertyValue.PropertyDef.ID,
                        propertyDefType,
                        staticPropertyValue.Value);
                }


                // Create a reference to the parent?
                if (null != parent)
                {
                    // If the property definition to use was configured then use that.
                    if (true == objectSelector.ParentRelationshipPropertyDef?.IsResolved)
                    {
                        // Check that this property is a list and is for the correct object type.
                        var parentRelationshipPropertyDef = vault
                                                            .PropertyDefOperations
                                                            .GetPropertyDef(objectSelector.ParentRelationshipPropertyDef.ID);
                        if (false == parentRelationshipPropertyDef.BasedOnValueList ||
                            parentRelationshipPropertyDef.ValueList != parent.Type)
                        {
                            throw new InvalidOperationException(
                                      $"The property def {parentRelationshipPropertyDef.Name} ({parentRelationshipPropertyDef.ID}) is not based on value list {parent.Type}.");
                        }

                        // Use the configured property definition.
                        propertyValuesBuilder.Add(
                            parentRelationshipPropertyDef.ID,
                            parentRelationshipPropertyDef.DataType,
                            parent.ID);
                    }
                    else
                    {
                        // Retrieve data about the parent object type.
                        var parentObjectType = vault
                                               .ObjectTypeOperations
                                               .GetObjectType(parent.Type);

                        // Retrieve data about the child object type.
                        var childObjectType = vault
                                              .ObjectTypeOperations
                                              .GetObjectType(objectSelector.ObjectType.ID);

                        // Is there an owner for this child type?
                        if (childObjectType.HasOwnerType)
                        {
                            // Use the "owner" property definition.
                            propertyValuesBuilder.Add(
                                parentObjectType.OwnerPropertyDef,
                                MFDataType.MFDatatypeLookup,
                                parent.ID);
                        }
                        else
                        {
                            // Use the default property definition.
                            propertyValuesBuilder.Add(
                                parentObjectType.DefaultPropertyDef,
                                MFDataType.MFDatatypeMultiSelectLookup,
                                parent.ID);
                        }
                    }
                }

                // Create a container for any attached files.
                var sourceObjectFiles = new SourceObjectFiles();

                // Should we attach the file to this object?
                if (objectSelector.AttachFileToThisObject)
                {
                    // Locate the files to retrieve.
                    sourceObjectFiles = this.FindFilesToAttach(objectSelector, xmlFile, matchingElement, xmlNamespaceManager);

                    // If we were supposed to attach a file but no files were found then throw an exception.
                    if (objectSelector.AttachedFileConfiguration?.FileNotFoundHandlingStrategy == FileNotFoundHandlingStrategy.Fail &&
                        0 == sourceObjectFiles.Count)
                    {
                        throw new InvalidOperationException("Attached file expected but not found.");
                    }

                    if (objectSelector.AttachedFileConfiguration?.AttachedFileHandlingStrategy
                        == AttachedFileHandlingStrategy.AttachToCurrentObject)
                    {
                        // Retrieve information about the object type from the vault.
                        var objectType = vault
                                         .ObjectTypeOperations
                                         .GetObjectType(objectSelector.ObjectType.ID);

                        // If the object type cannot have files but we are meant to attach a file, then fail.
                        if (false == objectType.CanHaveFiles)
                        {
                            throw new InvalidOperationException(
                                      $"The object type {objectType.NameSingular} cannot have files, but the configuration states to attach a file.");
                        }
                    }
                }

                // Which source object files should we use for the new object?
                var sourceObjectFilesForNewObject = objectSelector.AttachedFileConfiguration?.AttachedFileHandlingStrategy
                                                    == AttachedFileHandlingStrategy.AttachToCurrentObject
                                        ? sourceObjectFiles
                                        : new SourceObjectFiles();

                // Add the object to the vault.
                var createdObject = vault
                                    .ObjectOperations
                                    .CreateNewObjectEx(
                    objectSelector.ObjectType.ID,
                    propertyValuesBuilder.Values,
                    sourceObjectFilesForNewObject,
                    SFD: objectSelector.ObjectType.ID == (int)MFBuiltInObjectType.MFBuiltInObjectTypeDocument &&
                    sourceObjectFilesForNewObject.Count == 1
                    );

                // The files which need to be deleted.
                attachedFilesToDelete.AddRange(
                    sourceObjectFiles
                    .Cast <SourceObjectFile>()
                    .Select(sof => new FileInfo(sof.SourceFilePath))
                    );

                // Are there any related objects (e.g. children) to create?
                foreach (var childObjectSelector in objectSelector.ChildObjectSelectors)
                {
                    attachedFilesToDelete.AddRange(this.ImportXmlFile(vault,
                                                                      matchingElement,
                                                                      childObjectSelector,
                                                                      xmlFile: xmlFile,
                                                                      parent: createdObject.ObjVer,
                                                                      xmlNamespaceManager: xmlNamespaceManager));
                }

                // Clean up the collections we were using.
                propertyValuesBuilder = new MFPropertyValuesBuilder(vault);

                // Handle creating a new object for the file.
                if (
                    objectSelector.AttachFileToThisObject &&
                    objectSelector.AttachedFileConfiguration?.AttachedFileHandlingStrategy
                    == AttachedFileHandlingStrategy.CreateNewObject)
                {
                    // Set the static values
                    foreach (var staticPropertyValue in objectSelector.AttachedFileConfiguration?.StaticPropertyValues ?? new List <StaticPropertyValue>())
                    {
                        // Sanity.
                        if (false == staticPropertyValue.PropertyDef.IsResolved)
                        {
                            throw new InvalidOperationException("The property value selector property definition is not resolved");
                        }

                        // Find the property definition type.
                        var propertyDefType = vault
                                              .PropertyDefOperations
                                              .GetPropertyDef(staticPropertyValue.PropertyDef.ID)
                                              .DataType;

                        // Add the property to the builder.
                        propertyValuesBuilder.Add(
                            staticPropertyValue.PropertyDef.ID,
                            propertyDefType,
                            staticPropertyValue.Value);
                    }

                    // Add the class property value.
                    propertyValuesBuilder.SetClass(objectSelector.AttachedFileConfiguration.Class.ID);

                    // Add a reference from this new object to the one we created earlier.
                    {
                        // Retrieve data about the parent object type.
                        var parentObjectType = vault
                                               .ObjectTypeOperations
                                               .GetObjectType(createdObject.ObjVer.Type);

                        // Set the relationship.
                        propertyValuesBuilder.Add(
                            parentObjectType.DefaultPropertyDef,
                            MFDataType.MFDatatypeMultiSelectLookup,
                            createdObject.ObjVer.ID);
                    }

                    // Add the object to the vault.
                    var createdDocumentObject = vault
                                                .ObjectOperations
                                                .CreateNewObjectEx(
                        objectSelector.AttachedFileConfiguration.ObjectType.ID,
                        propertyValuesBuilder.Values,
                        sourceObjectFiles,
                        SFD: objectSelector.AttachedFileConfiguration.ObjectType.ID == (int)MFBuiltInObjectType.MFBuiltInObjectTypeDocument &&
                        sourceObjectFiles.Count == 1
                        );
                }
            }

            // Return the files to remove.
            return(attachedFilesToDelete);
        }
Exemple #10
0
 /// <summary>
 /// Sets a single property on a single object.
 /// </summary>
 /// <param name="objVer">The object to set the property on.</param>
 /// <param name="newPropertyValue">The new (or updated) property vlaue.</param>
 /// <param name="token">A cancellation token for the request.</param>
 /// <returns>The new object version.</returns>
 /// <remarks>The object must be checked out to perform this action.</remarks>
 public Task <ExtendedObjectVersion> SetPropertyAsync(ObjVer objVer, PropertyValue newPropertyValue, CancellationToken token = default(CancellationToken))
 {
     // Use the other overload.
     return(this.SetPropertyAsync(objVer.Type, objVer.ID, newPropertyValue, objVer.Version, token));
 }
 /// <summary>
 /// Set multiple properties on a single object.
 /// </summary>
 /// <param name="objVer">The object to set the property on.</param>
 /// <param name="propertyValues">The property values for the object.</param>
 /// <param name="replaceAllProperties">If true, <see paramref="propertyValues"/> contains all properties for the object (and others will be removed).</param>
 /// <param name="token">A cancellation token for the request.</param>
 /// <returns>The new object version.</returns>
 /// <remarks>If <see paramref="replaceAllProperties"/> is true then <see paramref="propertyValues"/> must contain values for property 0 (name or title), property 100 (class), property 22 (is single file), and any other mandatory properties for the given class.</remarks>
 public Task <ExtendedObjectVersion> SetPropertiesAsync(ObjVer objVer, PropertyValue[] propertyValues, bool replaceAllProperties, CancellationToken token = default(CancellationToken))
 {
     // Use the other overload.
     return(this.SetPropertiesAsync(objVer.Type, objVer.ID, propertyValues, replaceAllProperties, objVer.Version, token));
 }
 public int GetScoreOfObject(ObjVer objVer)
 {
     throw new NotImplementedException();
 }
Exemple #13
0
        public void ReturnsCorrectValueListItem()
        {
            // IDs used.
            var propertyDefId   = 1234;
            var valueListId     = 123;
            var valueListItemId = 1;

            // Mock the property definition operations object.
            var propertyDefinitionsMock = new Mock <VaultPropertyDefOperations>();

            propertyDefinitionsMock.Setup(m => m.GetPropertyDef(It.IsAny <int>()))
            .Returns((int propertyDef) =>
            {
                // Ensure that the property definition Id is correct.
                Assert.AreEqual(propertyDefId, propertyDef);

                // Return a property definition that is not based on a value list.
                return(new PropertyDef()
                {
                    ID = propertyDefId,
                    DataType = MFDataType.MFDatatypeLookup,
                    BasedOnValueList = true,
                    ValueList = valueListId
                });
            })
            .Verifiable();

            // Mock the value list item operations object.
            var valueListItemsMock = new Mock <VaultValueListItemOperations>();

            valueListItemsMock.Setup(m => m.GetValueListItemByID(It.IsAny <int>(), It.IsAny <int>()))
            .Returns((int vlid, int vliid) =>
            {
                // Did we get the right list and item ids?
                Assert.AreEqual(valueListId, vlid);
                Assert.AreEqual(valueListItemId, vliid);

                // Return an undeleted item.
                return(Mock.Of <ValueListItem>(i => i.ID == valueListItemId && i.ValueListID == valueListId && i.Deleted == false));
            });

            // Mock the vault.
            var vaultMock = this.GetVaultMock();

            vaultMock.Setup(m => m.PropertyDefOperations).Returns(propertyDefinitionsMock.Object);
            vaultMock.Setup(m => m.ValueListItemOperations).Returns(valueListItemsMock.Object);

            // Set up the data for the ObjVerEx.
            var objVer = new ObjVer();

            objVer.SetIDs(0, 1, 1);
            var objectVersionMock = new Mock <ObjectVersion>();

            objectVersionMock.SetupGet(m => m.ObjVer)
            .Returns(objVer);
            var properties = new PropertyValues();
            {
                var pv = new PropertyValue();
                pv.PropertyDef = propertyDefId;
                pv.TypedValue.SetValue(MFDataType.MFDatatypeLookup, valueListItemId);
                properties.Add(1, pv);
            }

            // Create the ObjVerEx.
            var objVerEx = new Common.ObjVerEx(vaultMock.Object, objectVersionMock.Object, properties);

            // Use the method.
            var item = objVerEx.GetPropertyAsValueListItem(propertyDefId);

            Assert.IsNotNull(item);
            Assert.AreEqual(valueListItemId, item.ID);
            Assert.AreEqual(valueListId, item.ValueListID);
            Assert.IsFalse(item.Deleted);
        }
Exemple #14
0
        public string FindMultifile(Vault env)
        {
            var searchMultiFile = new MFSearchBuilder(env);

            searchMultiFile.Deleted(false);
            searchMultiFile.ObjType(MFBuiltInObjectType.MFBuiltInObjectTypeDocument);
            searchMultiFile.Conditions.AddPropertyCondition(22, MFConditionType.MFConditionTypeEqual, MFDataType.MFDatatypeBoolean, false);
            searchMultiFile.Class(this.Configuration.CurrentConfiguration.ProposalClass);

            var searchMFResults = searchMultiFile.FindEx();

            foreach (var searchResult in searchMFResults)
            {
                // If it is an MFD with one file then convert back.
                if (searchResult.Info.FilesCount == 1)
                {
                    // Set to SFD.
                    searchResult.SaveProperty(
                        (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefSingleFileObject,
                        MFDataType.MFDatatypeBoolean,
                        true);

                    // Audit trail.


                    // Done.
                    return("");
                }

                try
                {
                    //Get multifile name
                    var MFTitle = searchResult.Title;


                    // Get a collection of documents for the document collection.
                    var createdItems = new Lookups();

                    // Get a copy of the current object's properties.
                    var propertiesCopy = this.GetNewObjectPropertyValues(searchResult.Properties);

                    // For each file, create a new object.
                    foreach (var file in searchResult.Info.Files.Cast <ObjectFile>())
                    {
                        // Add Component Type based on Title
                        if (file.Title.Contains("NPA"))
                        {
                            propertiesCopy.SetProperty(this.Configuration.CurrentConfiguration.ComponentTypeProperty, MFDataType.MFDatatypeLookup, 2);
                        }
                        else if (file.Title.Contains("EOI"))
                        {
                            propertiesCopy.SetProperty(this.Configuration.CurrentConfiguration.ComponentTypeProperty, MFDataType.MFDatatypeLookup, 3);
                        }
                        else if (file.Title.Contains("Price"))
                        {
                            propertiesCopy.SetProperty(this.Configuration.CurrentConfiguration.ComponentTypeProperty, MFDataType.MFDatatypeLookup, 4);
                        }
                        else if (file.Title.Contains("RFT"))
                        {
                            propertiesCopy.SetProperty(this.Configuration.CurrentConfiguration.ComponentTypeProperty, MFDataType.MFDatatypeLookup, 1);
                        }
                        else if (file.Title.Contains("RFP"))
                        {
                            propertiesCopy.SetProperty(this.Configuration.CurrentConfiguration.ComponentTypeProperty, MFDataType.MFDatatypeLookup, 1);
                        }

                        // Download the file.
                        var sourceObjectFiles = this.GetNewObjectSourceFiles(env, file);
                        propertiesCopy.SetProperty(0, MFDataType.MFDatatypeText, file.Title);
                        // Create the new object.
                        var createdObjectId = env.ObjectOperations
                                              .CreateNewObjectExQuick(
                            (int)MFBuiltInObjectType.MFBuiltInObjectTypeDocument,
                            propertiesCopy.Clone(),
                            sourceObjectFiles,
                            SFD: true);

                        createdItems.Add(-1, new Lookup
                        {
                            ObjectType = (int)MFBuiltInObjectType.MFBuiltInObjectTypeDocument,
                            Item       = createdObjectId,
                            // TODO: Version???
                        });
                    }

                    // Add the created documents to a property for the collection.
                    {
                        var collectionMembersPropertyValue = new PropertyValue
                        {
                            PropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefCollectionMemberDocuments
                        };
                        collectionMembersPropertyValue.Value.SetValueToMultiSelectLookup(createdItems);
                        propertiesCopy.Add(-1, collectionMembersPropertyValue);
                    }

                    propertiesCopy.SetProperty(0, MFDataType.MFDatatypeText, MFTitle);
                    propertiesCopy.RemoveProperty(this.Configuration.CurrentConfiguration.ComponentTypeProperty);
                    propertiesCopy.SetProperty(100, MFDataType.MFDatatypeLookup, this.Configuration.CurrentConfiguration.ProposalCollectionClass);
                    // Create the document collection.
                    var documentCollectionObjVer = new ObjVer
                    {
                        Type = (int)MFBuiltInObjectType.MFBuiltInObjectTypeDocumentCollection,
                        ID   = env.ObjectOperations.CreateNewObjectExQuick(
                            (int)MFBuiltInObjectType.MFBuiltInObjectTypeDocumentCollection,
                            propertiesCopy)
                    };

                    // Can we reference the collection?
                    if (this.Configuration.CurrentConfiguration.DocumentCollectionReference.IsResolved)
                    {
                        // Find items which referenced this (old) document and instead reference the collection.
                        foreach (var objVerEx in env
                                 .ObjectOperations
                                 .GetRelationships(searchResult.ObjVer, MFRelationshipsMode.MFRelationshipsModeToThisObject)
                                 .Cast <ObjectVersion>()
                                 .Select(ov => new ObjVerEx(env, ov)))
                        {
                            var checkout = objVerEx.StartRequireCheckedOut();
                            objVerEx.AddLookup(
                                this.Configuration.CurrentConfiguration.DocumentCollectionReference.ID,
                                documentCollectionObjVer,
                                exactVersion: false);
                            objVerEx.SaveProperties();
                            objVerEx.EndRequireCheckedOut(checkout);
                        }
                    }

                    //Remove orignal File
                    {
                        searchResult.Delete();
                    }
                }
                catch (Exception e)
                {
                    SysUtils.ReportErrorToEventLog(e);

                    // Throw.
                    throw;
                }
            }
            return("");
        }
Exemple #15
0
        public void ReturnsParentObjectIfDataCorrect()
        {
            // Set up our configuration.
            var childObjectType  = 102;
            var parentObjectType = 101;
            var ownerPropertyDef = 1020;

            // Unfortunately this requires mocking deep into the vault because we can't override the default ObjVerEx behaviour for GetDirectReference...

            // Set up the property definitions mock.
            var propertyDefOperationsMock = new Mock <VaultPropertyDefOperations>();

            propertyDefOperationsMock
            .Setup(m => m.GetPropertyDef(It.IsAny <int>()))
            .Returns((int propertyDefId) => new PropertyDef()
            {
                BasedOnValueList = true,
                ValueList        = parentObjectType,
                ID       = propertyDefId,
                DataType = MFDataType.MFDatatypeLookup
            });

            // Set up the object type operations mock.
            var objectTypeOperationsMock = new Mock <VaultObjectTypeOperations>();

            objectTypeOperationsMock
            .Setup(m => m.GetObjectType(It.IsAny <int>()))
            .Returns((int objectTypeId) =>
            {
                // Is it a child?
                if (objectTypeId == childObjectType)
                {
                    return(new ObjType()
                    {
                        ID = childObjectType,
                        NamePlural = "Children",
                        NameSingular = "Child",
                        HasOwnerType = true,
                        OwnerType = parentObjectType,
                        RealObjectType = true
                    });
                }

                // Is it a parent?
                if (objectTypeId == parentObjectType)
                {
                    return(new ObjType()
                    {
                        ID = parentObjectType,
                        NamePlural = "Parents",
                        NameSingular = "Parent",
                        HasOwnerType = false,
                        OwnerPropertyDef = ownerPropertyDef,
                        RealObjectType = true
                    });
                }

                // Unexpected object type.
                throw new InvalidOperationException("Unexpected object type");
            });

            // Set up the vault mock.
            var vaultMock = this.GetVaultMock();

            vaultMock.Setup(v => v.ObjectTypeOperations).Returns(objectTypeOperationsMock.Object);
            vaultMock.Setup(v => v.PropertyDefOperations).Returns(propertyDefOperationsMock.Object);

            // Set up the expected object.
            var expectedParent = new Common.ObjVerEx(vaultMock.Object, parentObjectType, 1234, -1);

            // Set up the ObjVerEx.
            var objectVersion = new Mock <ObjectVersion>();

            objectVersion
            .Setup(m => m.ObjVer)
            .Returns(() =>
            {
                var objVer = new ObjVer();
                objVer.SetIDs(childObjectType, 1, 2);
                return(objVer);
            });
            var objVerEx = new Common.ObjVerEx
                           (
                vaultMock.Object,
                objectVersion.Object,
                new PropertyValues()
                           );

            // Set up the owner property.
            {
                var ownerProperty = new PropertyValue()
                {
                    PropertyDef = ownerPropertyDef
                };
                ownerProperty.TypedValue.SetValue(MFDataType.MFDatatypeLookup, new Lookup()
                {
                    Item       = 1234,
                    Deleted    = false,
                    ObjectType = parentObjectType
                });
                objVerEx.Properties.Add(-1, ownerProperty);
            }

            // Run.
            var owner = objVerEx.GetOwner();

            // Did we get the right object back?
            Assert.IsNotNull(owner);
            Assert.AreEqual(expectedParent.Type, owner.Type);
            Assert.AreEqual(expectedParent.ID, owner.ID);
        }
Exemple #16
0
 public ObjectVersionAndProperties SetWorkflowState(ObjVer ObjVer, ObjectVersionWorkflowState WorkflowState)
 {
     throw new NotImplementedException();
 }
Exemple #17
0
 public ObjectFile GetObjectFile(ObjVer objVer)
 {
     return(Vault.ObjectFileOperations.GetFiles(objVer)[1]);
 }
Exemple #18
0
 public ObjectVersionAndProperties SetWorkflowStateEx(ObjVer ObjVer, ObjectVersionWorkflowState WorkflowState, [System.Runtime.InteropServices.OptionalAttribute][System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.IDispatch)][System.Runtime.CompilerServices.IDispatchConstantAttribute] object ElectronicSignature)
 {
     throw new NotImplementedException();
 }
Exemple #19
0
 public ObjectVersionAndProperties SetAssignment_DEPRECATED(ObjVer ObjVer, WorkflowAssignment Assignment)
 {
     throw new NotImplementedException();
 }
Exemple #20
0
 public PropertyValuesForDisplay GetPropertiesForDisplay(ObjVer ObjVer, bool UpdateFromServer = false)
 {
     throw new NotImplementedException();
 }
Exemple #21
0
 public ObjectVersionAndProperties SetLastModificationInfoAdmin(ObjVer ObjVer, bool UpdateLastModifiedBy, TypedValue LastModifiedBy, bool UpdateLastModified, TypedValue LastModifiedUtc)
 {
     throw new NotImplementedException();
 }
Exemple #22
0
 public PropertyValuesWithIconClues GetPropertiesWithIconClues(ObjVer ObjVer, bool UpdateFromServer = false)
 {
     throw new NotImplementedException();
 }
Exemple #23
0
 public ObjectVersionAndProperties SetProperties(ObjVer ObjVer, PropertyValues PropertyValues)
 {
     throw new NotImplementedException();
 }
Exemple #24
0
 public VersionComment GetVersionComment(ObjVer ObjVer)
 {
     throw new NotImplementedException();
 }
Exemple #25
0
 public ObjectVersionAndProperties SetPropertiesWithPermissionsEx(ObjVer ObjVer, PropertyValues PropertyValues, MFACLEnforcingMode ACLEnforcingMode, AccessControlList ACLProvided, [System.Runtime.InteropServices.OptionalAttribute][System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.IDispatch)][System.Runtime.CompilerServices.IDispatchConstantAttribute] object ElectronicSignature)
 {
     throw new NotImplementedException();
 }
Exemple #26
0
 public ObjectVersionWorkflowState GetWorkflowState(ObjVer ObjVer, bool UpdateFromServer = false)
 {
     throw new NotImplementedException();
 }
Exemple #27
0
 public ObjectVersionAndProperties SetPropertiesWithPermissionsEx(ObjVer ObjVer, PropertyValues PropertyValues, MFACLEnforcingMode ACLEnforcingMode = MFACLEnforcingMode.MFACLEnforcingModeAutomatic, AccessControlList ACLProvided = null)
 {
     throw new NotImplementedException();
 }
Exemple #28
0
 public ObjectVersionAndProperties RemoveProperty(ObjVer ObjVer, int Property)
 {
     throw new NotImplementedException();
 }
Exemple #29
0
 public ObjectVersionAndProperties SetVersionComment(ObjVer ObjVer, PropertyValue VersionComment)
 {
     throw new NotImplementedException();
 }
Exemple #30
0
 public static ObjectFile GetFileByObject(IVault vault, ObjVer objVer)
 {
     var files = vault.ObjectFileOperations.GetFiles(objVer);
     return files.Count < 1 ? null : files[1];
 }
Exemple #31
0
        /// <summary>
        /// 更新邮件对象
        /// </summary>
        /// <param name="vault"></param>
        /// <param name="objVer"></param>
        /// <param name="properties"></param>
        /// <param name="sourceFiles"></param>
        private static bool UpdateMailToMf(Vault vault, ObjectVersion objVer, PropertyValues properties, SourceObjectFiles sourceFiles)
        {
            //签出对象邮件对象
            ObjectVersion checkOutVn = null;

            if (!objVer.ObjectCheckedOut)
            {
                try
                {
                    checkOutVn = vault.ObjectOperations.CheckOut(objVer.ObjVer.ObjID);
                }
                catch (Exception ex)
                {
                    Common.Logger.Log.ErrorFormat("exception. update email to mfiles error: {0}", ex.Message);
                    return(false);
                }
            }
            else if (objVer.CheckedOutTo == vault.SessionInfo.UserID || objVer.CheckedOutTo == -103)
            {
                checkOutVn = objVer;
            }
            else
            {
                ObjVer oldObjVer = null;
                try
                {
                    oldObjVer = vault.ObjectOperations.ForceUndoCheckout(objVer.ObjVer).ObjVer;
                }
                catch (Exception ex)
                {
                    Common.Logger.Log.ErrorFormat("exception. update email to mfiles error: {0}", ex.Message);
                    return(false);
                }

                try
                {
                    if (oldObjVer != null)
                    {
                        checkOutVn = vault.ObjectOperations.CheckOut(oldObjVer.ObjID);
                    }
                }
                catch (Exception ex)
                {
                    Common.Logger.Log.ErrorFormat("exception. update email to mfiles error: {0}", ex.Message);
                    return(false);
                }
            }

            try
            {
                //更新邮件对象属性
                if (checkOutVn != null)
                {
                    //获取邮件正文文件对象
                    var objFiles = vault.ObjectFileOperations.GetFiles(checkOutVn.ObjVer);
                    vault.ObjectPropertyOperations.SetProperties(checkOutVn.ObjVer, properties);
                    vault.ObjectOperations.SetSingleFileObject(checkOutVn.ObjVer, false);
                    vault.ObjectFileOperations.RemoveFile(checkOutVn.ObjVer, objFiles[1].FileVer);
                    vault.ObjectFileOperations.AddFile(checkOutVn.ObjVer,
                                                       sourceFiles[1].Title,
                                                       sourceFiles[1].Extension,
                                                       sourceFiles[1].SourceFilePath);
                    vault.ObjectOperations.SetSingleFileObject(checkOutVn.ObjVer, true);

                    //签入对象
                    vault.ObjectOperations.CheckIn(checkOutVn.ObjVer);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                if (checkOutVn != null)
                {
                    vault.ObjectOperations.ForceUndoCheckout(checkOutVn.ObjVer);
                }
                Common.Logger.Log.ErrorFormat("exception. update email to mfiles error: {0}", ex.Message);
                return(false);
            }

            return(false);
        }