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);
        }
        public List <ObjVerEx> SearchForObjects(StateEnvironment env, MFIdentifier ClassAlias, List <InvoiceValue> Criteria)
        {
            var Vault = env.ObjVerEx.Vault;
            // Create our search builder.
            var searchBuilder = new MFSearchBuilder(Vault);

            // Add an object type filter.
            searchBuilder.Class(ClassAlias);
            // Add a "not deleted" filter.
            searchBuilder.Deleted(false);
            List <ObjVerEx> searchResults;

            foreach (var CriteriaData in Criteria)
            {
                var PropertyType = Vault.PropertyDefOperations.GetPropertyDef(CriteriaData.PropertyID.ID).DataType;
                searchBuilder.Conditions.AddPropertyCondition(
                    CriteriaData.PropertyID.ID,
                    CriteriaData.ConditionType,
                    PropertyType,
                    CriteriaData.TypedValue);
            }

            searchResults = searchBuilder.FindEx();

            return((searchResults.Count != 0) ? searchResults : null);
        }
 public PropertyDefTestEnvironment(MFIdentifier prop, Common.ObjVerEx objverEx)
 {
     Ident      = prop;
     IsResolved = prop?.IsResolved ?? false;
     IsAssigned = IsResolved && null != objverEx && objverEx.HasProperty(prop);
     Value      = IsResolved ? objverEx.GetPropertyText(prop) : null;
 }
        public string SearchPropertyValue(PropertyValues ppvs, MFIdentifier def, PropertyValue defaultPpt = null)
        {
            var ppt = defaultPpt;

            if (ppt == null)
            {
                ppt = ppvs.SearchForProperty(def);
            }


            return((ppt.TypedValue.DataType == MFDataType.MFDatatypeLookup) ?
                   ppt.TypedValue.GetLookupID().ToString() : ppt.TypedValue.DisplayValue);
        }
        public PropertyValue GetPropertyValue(PropertyValues ppvs, MFIdentifier PropertyDef, MFIdentifier SetDef = null)
        {
            var ppValue = new PropertyValue();

            ppValue.PropertyDef = PropertyDef;

            if (SetDef == null)
            {
                SetDef = PropertyDef;
            }
            var ppt = ppvs.SearchForProperty(SetDef);

            ppValue.Value.SetValue(ppt.TypedValue.DataType, SearchPropertyValue(ppvs, SetDef, ppt));

            return(ppValue);
        }
        public List <ObjVerEx> FindObjects(Vault vault, MFIdentifier ClassAlias, MFIdentifier PDAlias, MFDataType PDType, String findValue)
        {
            // Create our search builder.
            var searchBuilder = new MFSearchBuilder(vault);

            // Add an object type filter.
            searchBuilder.Class(ClassAlias);
            // Add a "not deleted" filter.
            searchBuilder.Deleted(false);
            List <ObjVerEx> searchResults;

            searchBuilder.Property(PDAlias, PDType, findValue);

            searchResults = searchBuilder.FindEx();

            return((searchResults.Count != 0) ? searchResults : null);
        }
        public PropertyValue GetPropertyValue(Vault vault, PropertyValues POPpvs, MFIdentifier PODef, MFIdentifier InvDef)
        {
            var ppValue = new PropertyValue();

            ppValue.PropertyDef = InvDef.ID;

            string strVal = GetPropertyValue(POPpvs.SearchForProperty(PODef));

            if (InvDef == ItemNumber_PD)
            {
                string[] displayValues = strVal.Split('=');
                strVal = displayValues[0];
            }
            ppValue.Value.SetValue(vault.PropertyDefOperations.GetPropertyDef(InvDef.ID).DataType, strVal);

            return(ppValue);
        }
        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));
        }
        /// <summary>
        /// Enhanced method for <see cref="ObjVerEx.GetPropertyText(MFIdentifier)"/>
        /// to return a <see langword="null"/> value even if the property was not set or could not be resolved,
        /// otherwise the value which was set or <see cref="string.Empty"/>.
        /// </summary>
        ///
        /// <param name="objVerEx">
        /// The <see cref="ObjVerEx"/> object to be used as base for calling <see cref="ObjVerEx.GetPropertyText(MFIdentifier)"/>.
        /// </param>
        /// <param name="prop">
        /// The <see cref="MFIdentifier"/> object for the property which can be <see langword="null"/> or not resolved.
        /// </param>
        /// <param name="result">
        /// The <see cref="string"/> value to be returned as output parameter.
        /// </param>
        ///
        /// <returns>
        /// <list type="table">
        /// <item>
        /// <term><see cref="true"/></term>
        /// <description>if <paramref name="prop"/> is not <see langword="null"/> and can be resolved</description>
        /// </item>
        /// <item>
        /// <term><see cref="false"/></term>
        /// <description>if <paramref name="prop"/> is <see langword="null"/> or cannot be resolved</description>
        /// </item>
        /// </list>
        /// </returns>
        public static bool TryGetPropertyText(
            this ObjVerEx objVerEx,
            MFIdentifier prop,
            out string result)
        {
            // Sanity
            if (null == objVerEx)
            {
                throw new ArgumentNullException(nameof(objVerEx));
            }

            // return the nullValue specified if not set or not resolved as result and false as return value
            if (null == prop || !prop.IsResolved)
            {
                result = null;
                return(false);
            }

            // return value and return that all is ok
            result = objVerEx.GetPropertyText(prop);
            return(true);
        }
        public void TryGetPropertyText_Setup()
        {
            // Mock the property definition operations object.
            Mock <VaultPropertyDefOperations> propertyDefinitionsMock = new Mock <VaultPropertyDefOperations>();

            propertyDefinitionsMock.Setup(m => m.GetPropertyDefIDByAlias(It.IsAny <string>()))
            .Returns((string propertyAlias) =>
            {
                return(propertyAlias == aliasCustomProp ? idCustomProp : -1);
            })
            .Verifiable();

            propertyDefinitionsMock.Setup(m => m.GetPropertyDef(It.IsAny <int>()))
            .Returns((int propertyDef) =>
            {
                switch (propertyDef)
                {
                case (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefNameOrTitle:
                case (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefKeywords:
                case (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefMessageID:
                case idCustomProp:
                    return(new PropertyDef
                    {
                        ID = propertyDef,
                        DataType = MFDataType.MFDatatypeText,
                        Name = $"Property_{propertyDef}",
                    });

                default:
                    return(null);
                }
            })
            .Verifiable();

            // Mock the vault.
            Mock <Vault> vaultMock = GetVaultMock();

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

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

            objVer.SetIDs((int)MFBuiltInObjectType.MFBuiltInObjectTypeDocument, ID: 1, Version: 1);
            Mock <ObjectVersion> objectVersionMock = new Mock <ObjectVersion>();

            objectVersionMock.SetupGet(m => m.ObjVer).Returns(objVer);

            // Setup properties for NameOrTitle and MessageID (NOT: Keywords)
            PropertyValue  pv;
            PropertyValues properties = new PropertyValues();

            {
                // NameOrTitle
                pv = new PropertyValue
                {
                    PropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefNameOrTitle,
                };
                pv.TypedValue.SetValue(MFDataType.MFDatatypeText, "valueNameOrTitle");
                properties.Add(1, pv);

                // MessageID
                pv = new PropertyValue
                {
                    PropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefMessageID,
                };
                pv.TypedValue.SetValue(MFDataType.MFDatatypeText, null);
                properties.Add(2, pv);

                // CustomProp
                pv = new PropertyValue
                {
                    PropertyDef = idCustomProp,
                };
                pv.TypedValue.SetValue(MFDataType.MFDatatypeText, "valueCustomProp");
                properties.Add(3, pv);
            }

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

            // Get the test property params object
            MFIdentifier identCurrent = null;

            envNull = new PropertyDefTestEnvironment(identCurrent, objVerEx);

            identCurrent = new MFIdentifier((int)MFBuiltInPropertyDef.MFBuiltInPropertyDefNameOrTitle);
            identCurrent.Resolve(vaultMock.Object, typeof(PropertyDef));
            envNameOrTitle = new PropertyDefTestEnvironment(identCurrent, objVerEx);

            identCurrent = new MFIdentifier((int)MFBuiltInPropertyDef.MFBuiltInPropertyDefKeywords);
            identCurrent.Resolve(vaultMock.Object, typeof(PropertyDef));
            envKeywords = new PropertyDefTestEnvironment(identCurrent, objVerEx);

            identCurrent = new MFIdentifier((int)MFBuiltInPropertyDef.MFBuiltInPropertyDefMessageID);
            identCurrent.Resolve(vaultMock.Object, typeof(PropertyDef));
            envMessageID = new PropertyDefTestEnvironment(identCurrent, objVerEx);

            identCurrent = new MFIdentifier(aliasCustomProp);
            identCurrent.Resolve(vaultMock.Object, typeof(PropertyDef));
            envCustomProp = new PropertyDefTestEnvironment(identCurrent, objVerEx);

            identCurrent = new MFIdentifier("incorrectAlias");
            identCurrent.Resolve(vaultMock.Object, typeof(PropertyDef));
            envNotResolved = new PropertyDefTestEnvironment(identCurrent, objVerEx);
        }
Пример #11
0
 public object this[MFIdentifier key]
 {
     get => GetPropertyText(key);