Beispiel #1
0
        static void offp()
        {
            var pid            = 1;
            var rid            = 1;
            var sdate          = "2016/01/01";
            var edate          = "2016/08/08";
            var input          = "{\"principal\":" + pid + ",\"receiver\":" + rid + ",\"startdate\":\"" + sdate + "\",\"enddate\":\"" + edate + "\"}";
            var app            = new MFilesClientApplication();
            var vault          = app.BindToVault("8211", IntPtr.Zero, true, true);
            var FilterReceiver = vault.ExtensionMethodOperations.ExecuteVaultExtensionMethod("GetSecureNotice", input);

            Console.WriteLine(FilterReceiver);
            //  var filedata = eval('(' + FilterReceiver + ')');
            var filedata = JsonConvert.DeserializeObject <ReportPrintData>(FilterReceiver);
            // alert(filedata.objver.id);
            // var ObjID  = MFiles.CreateInstance("ObjID");
            //   ObjID.SetIDs (0,filedata);
            var objver = new ObjVer();

            objver.SetIDs(filedata.objtype, filedata.objid, filedata.objversion);
            var filever = new FileVer();

            filever.ID      = filedata.fileid;
            filever.Version = filedata.fileversion;
            vault.ObjectFileOperations.OpenFileInDefaultApplication(IntPtr.Zero, objver, filever,
                                                                    MFFileOpenMethod.MFFileOpenMethodOpen);
        }
        protected virtual Mock <ObjectVersionAndProperties> CreateObjectVersionAndPropertiesMock
        (
            Vault vault,
            int objectType = 0,
            PropertyValues propertyValues = null,
            ObjectFiles objectFiles       = null
        )
        {
            // Sanity.
            propertyValues = propertyValues ?? new PropertyValues();

            // Create a new object version.
            var objVer = new ObjVer();

            objVer.SetIDs(objectType, ++count, 1);

            // Create the object version mock.
            var objectVersionMock = new Mock <ObjectVersion>();

            objectVersionMock.Setup(m => m.ObjVer).Returns(objVer);
            objectVersionMock.Setup(m => m.Files).Returns(objectFiles ?? new Mock <ObjectFiles>().Object);
            objectVersionMock.Setup(m => m.FilesCount).Returns(objectFiles?.Count ?? 0);

            // Create the mock for the object version and properties.
            var objectVersionAndPropertiesMock = new Mock <ObjectVersionAndProperties>();

            objectVersionAndPropertiesMock.SetupAllProperties();
            objectVersionAndPropertiesMock.Setup(m => m.ObjVer).Returns(objVer);
            objectVersionAndPropertiesMock.Setup(m => m.Vault).Returns(vault);
            objectVersionAndPropertiesMock.Setup(m => m.VersionData).Returns(objectVersionMock.Object);
            objectVersionAndPropertiesMock.Setup(m => m.Properties).Returns(propertyValues);
            return(objectVersionAndPropertiesMock);
        }
Beispiel #3
0
        public void FromObjVerCorrectString()
        {
            var objVer = new ObjVer();

            objVer.SetIDs(0, 1, 2);
            Assert.AreEqual
            (
                "(0-1-2)",
                objVer.ToObjVerExTaskDirective().ObjVerEx
            );
        }
Beispiel #4
0
        /// <summary>
        /// 更新对象属性
        /// </summary>
        /// <param name="vault">库</param>
        /// <param name="typeId">类型ID</param>
        /// <param name="objId">对象ID</param>
        /// <param name="properties">属性列表</param>
        private static void UpdatePropertis(Vault vault, int typeId, int objId, PropertyValues properties)
        {
            var oObjVer = new ObjVer();

            oObjVer.SetIDs(typeId, objId, -1);
            var           oObjVn = vault.ObjectOperations.GetObjectInfo(oObjVer, true, true);
            ObjectVersion checkOutVn;

            if (!oObjVn.ObjectCheckedOut)
            {
                try
                {
                    checkOutVn = vault.ObjectOperations.CheckOut(oObjVer.ObjID);
                }
                catch (Exception ex)
                {
                    throw new Exception("当前账户无权限签出对象:" + oObjVn.Title + "\r\n" + ex.Message);
                }
            }
            else if (oObjVn.CheckedOutTo == vault.SessionInfo.UserID || oObjVn.CheckedOutTo == -103)
            {
                checkOutVn = oObjVn;
            }
            else
            {
                ObjVer oldObjVer;
                try
                {
                    oldObjVer = vault.ObjectOperations.ForceUndoCheckout(oObjVn.ObjVer).ObjVer;
                }
                catch (Exception ex)
                {
                    throw new Exception("当前账户无权限撤销对象:" + oObjVn.Title + " 的签出\r\n" + ex.Message);
                }
                try
                {
                    checkOutVn = vault.ObjectOperations.CheckOut(oldObjVer.ObjID);
                }
                catch (Exception ex)
                {
                    throw new Exception("当前账户无权限签出对象:" + oObjVn.Title + "\r\n" + ex.Message);
                }
            }
            vault.ObjectPropertyOperations.SetProperties(checkOutVn.ObjVer, properties);
            try
            {
                vault.ObjectOperations.CheckIn(checkOutVn.ObjVer);
            }
            catch (Exception ex)
            {
                vault.ObjectOperations.ForceUndoCheckout(checkOutVn.ObjVer);
                throw new Exception("签入修改对象:" + oObjVn.Title + "失败!\r\n" + ex.Message);;
            }
        }
Beispiel #5
0
        protected virtual Mock <ObjectVersionAndProperties> GetObjectVersionAndPropertiesMock
        (
            Mock <Vault> vaultMock,
            int objectTypeId  = 0,
            int objectId      = 123,
            int version       = 1,
            string externalId = "123ABCDEF123",
            ObjID originalId  = null,
            Guid?objectGuid   = null,
            params Tuple <int, MFDataType, object>[] propertyValues
        )
        {
            var objectVersionAndPropertiesMock = new Mock <ObjectVersionAndProperties>();

            objectVersionAndPropertiesMock
            .Setup(o => o.ObjVer)
            .Returns(() =>
            {
                var objVer = new ObjVer();
                objVer.SetIDs(objectTypeId, objectId, version);
                return(objVer);
            });
            objectVersionAndPropertiesMock
            .Setup(o => o.VersionData)
            .Returns(() =>
            {
                var data = new Mock <ObjectVersion>();
                data.Setup(o => o.DisplayIDAvailable).Returns(!string.IsNullOrWhiteSpace(externalId));
                data.Setup(o => o.DisplayID).Returns(externalId);
                data.Setup(o => o.OriginalObjID).Returns(originalId);
                if (objectGuid.HasValue)
                {
                    data.Setup(o => o.ObjectGUID).Returns(objectGuid.Value.ToString("B"));
                }
                return(data.Object);
            });
            objectVersionAndPropertiesMock
            .Setup(o => o.Properties)
            .Returns(() =>
            {
                var data = new PropertyValues();
                foreach (var tuple in propertyValues ?? new Tuple <int, MFDataType, object> [0])
                {
                    var pv = new PropertyValue {
                        PropertyDef = tuple.Item1
                    };
                    pv.Value.SetValue(tuple.Item2, tuple.Item3);
                    data.Add(-1, pv);
                }
                return(data);
            });
            return(objectVersionAndPropertiesMock);
        }
Beispiel #6
0
        public void ReturnsNullIfPropertyIsNull()
        {
            // IDs used.
            var propertyDefId = 1234;
            var valueListId   = 123;

            // 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 vault.
            var vaultMock = this.GetVaultMock();

            vaultMock.Setup(m => m.PropertyDefOperations).Returns(propertyDefinitionsMock.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.SetValueToNULL(MFDataType.MFDatatypeLookup);
                properties.Add(1, pv);
            }

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

            // Use the method.
            Assert.IsNull(objVerEx.GetPropertyAsValueListItem(propertyDefId));
        }
        public static ObjVer GetAsObjVer(this Lookup lookup, Vault vault)
        {
            int version = lookup.Version;

            if (version == -1)
            {
                return(vault.ObjectOperations.GetLatestObjVer(new ObjID {
                    ID = lookup.Item, Type = lookup.ObjectType
                }, true, true));
            }
            ObjVer objver = new ObjVer();

            objver.SetIDs(lookup.ObjectType, lookup.Item, lookup.Version);
            return(objver);
        }
Beispiel #8
0
        private bool DealTaskDone(MfTask otask, Vault vault, ObjVer objver, string server)
        {
            try
            {
                if (objver.Version < 2)
                {
                    return(false);
                }

                var pvs = vault.ObjectPropertyOperations.GetProperties(objver);
                var taskdoneuserlist = pvs.SearchForProperty((int)MFBuiltInPropertyDef.MFBuiltInPropertyDefCompletedBy);
                if (PropertyIsNull(taskdoneuserlist))
                {
                    return(false);
                }

                var lastobjver = new ObjVer();
                lastobjver.SetIDs(objver.Type, objver.ID, objver.Version - 1);
                var pvslast = vault.ObjectPropertyOperations.GetProperties(lastobjver);
                var taskdoneuserlistlast =
                    pvslast.SearchForProperty((int)MFBuiltInPropertyDef.MFBuiltInPropertyDefCompletedBy);
                //Writelog(
                //    string.Format(
                //        "in dealTaskDone,debug,MFBuiltInPropertyDefCompletedBy={0},taskdoneuserlist={1},taskdoneuserlistlast={2}",
                //        (int) MFBuiltInPropertyDef.MFBuiltInPropertyDefCompletedBy, taskdoneuserlist.Value.DisplayValue,
                //        taskdoneuserlistlast.Value.DisplayValue));
                if (PropertyIsNull(taskdoneuserlistlast) || taskdoneuserlist.Value.DisplayValue != taskdoneuserlistlast.Value.DisplayValue)
                {
                    var monitor = pvs.SearchForProperty((int)MFBuiltInPropertyDef.MFBuiltInPropertyDefMonitoredBy);
                    otask.UserIds.Add(monitor.TypedValue.GetValueAsLookup().Item.ToString(CultureInfo.InvariantCulture));
                    otask.NotificationType = NotificationTypeEnum.TaskDone;
                    Logonenotice(vault, otask, server);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Writelog(string.Format("dealtaskdone error : objver.ID={0},type={1},version={2},message={3}", objver.ID, objver.Type, objver.Version, ex.Message));
            }
            return(false);
        }
Beispiel #9
0
        private bool UpdateApprovalFormPostConditions(StateEnvironment env, out string message)
        {
            var vault      = env.Vault;
            var objver     = env.ObjVer;
            var lastobjver = new ObjVer();

            lastobjver.SetIDs(objver.Type, objver.ID, objver.Version - 2);
            var last =
                vault.ObjectOperations.GetObjectVersionAndProperties(lastobjver)
                .Properties.SearchForProperty((int)MFBuiltInPropertyDef.MFBuiltInPropertyDefState);
            var laststate = last.Value.GetLookupID();
            var next      =
                vault.ObjectOperations.GetObjectVersionAndProperties(objver)
                .Properties.SearchForProperty((int)MFBuiltInPropertyDef.MFBuiltInPropertyDefState);
            var nextstate = next.Value.GetLookupID();

            Writelog(string.Format("---- {0}, {1},{2}", laststate, env.StateID, nextstate));
            env.InitialNextStateID = laststate;
            message = "会签不通过返回修改后,再发起会签流程,需跳过会签通过的部门直接提交会签不通过的部门->" + last.GetValueAsLocalizedText();
            return(nextstate == laststate);
        }
Beispiel #10
0
        public void ReturnsEmptyCollectionIfPropertyNotInCollection()
        {
            // IDs used.
            var propertyDefId = 1234;
            var valueListId   = 123;

            // 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.MFDatatypeMultiSelectLookup,
                    BasedOnValueList = true,
                    ValueList = valueListId
                });
            })
            .Verifiable();

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

            objectTypeOperationsMock.Setup(m => m.GetObjectType(It.IsAny <int>()))
            .Returns((int objectTypeId) =>
            {
                return(new ObjType()
                {
                    ID = 101
                });
            });

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

            vaultMock.Setup(m => m.PropertyDefOperations).Returns(propertyDefinitionsMock.Object);
            vaultMock.Setup(m => m.ObjectTypeOperations).Returns(objectTypeOperationsMock.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();

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

            // Use the method.
            var items = objVerEx.GetPropertyAsValueListItems(propertyDefId);

            Assert.IsNotNull(items);
            Assert.AreEqual(0, items.Count);
        }
Beispiel #11
0
        public void ReturnsCorrectValueListItems_OneInvalid()
        {
            // IDs used.
            var propertyDefId = 1234;
            var valueListId   = 123;

            // 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.MFDatatypeMultiSelectLookup,
                    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);

                if (vliid == 456)
                {
                    throw new COMException();
                }

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

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

            objectTypeOperationsMock.Setup(m => m.GetObjectType(It.IsAny <int>()))
            .Returns((int objectTypeId) =>
            {
                return(new ObjType()
                {
                    ID = 101
                });
            });

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

            vaultMock.Setup(m => m.PropertyDefOperations).Returns(propertyDefinitionsMock.Object);
            vaultMock.Setup(m => m.ValueListItemOperations).Returns(valueListItemsMock.Object);
            vaultMock.Setup(m => m.ObjectTypeOperations).Returns(objectTypeOperationsMock.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.MFDatatypeMultiSelectLookup, new object[] {
                    123,
                    456,
                    789
                });
                properties.Add(1, pv);
            }

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

            // Use the method.
            var items = objVerEx.GetPropertyAsValueListItems(propertyDefId);

            Assert.IsNotNull(items);
            Assert.AreEqual(2, items.Count);
            Assert.AreEqual(123, items[0].ID);
            Assert.AreEqual(789, items[1].ID);
            Assert.IsFalse(items[0].Deleted);
            Assert.IsFalse(items[1].Deleted);
        }
Beispiel #12
0
        //Export Button
        private void button1_Click(object sender, EventArgs e, Vault currVault, MFilesClientApplication mFilesApp)
        {
            //MessageBox.Show(currVault.Name);

            SaveFileDialog saveFile = new SaveFileDialog();

            saveFile.Filter = "XML Files (*.xml)|*.xml";


            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                //pull invoices using search conditions
                var searchConditions = new SearchConditions();

                //is it not deleted
                var isNotDeleted = new SearchCondition();
                isNotDeleted.Expression.DataStatusValueType         = MFStatusType.MFStatusTypeDeleted;
                isNotDeleted.Expression.DataStatusValueDataFunction = MFDataFunction.MFDataFunctionNoOp;
                isNotDeleted.ConditionType = MFConditionType.MFConditionTypeNotEqual;
                isNotDeleted.TypedValue.SetValue(MFDataType.MFDatatypeBoolean, true);
                searchConditions.Add(-1, isNotDeleted);

                //is it part of the Invoice workflow
                var isInvoice = new SearchCondition();
                isInvoice.Expression.DataPropertyValuePropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefWorkflow;
                isInvoice.ConditionType = MFConditionType.MFConditionTypeEqual;
                isInvoice.TypedValue.SetValue(MFDataType.MFDatatypeLookup, Properties.Settings.Default.invoiceWorkflow);
                searchConditions.Add(-1, isInvoice);

                //is it in the accounting state
                var isAccounting = new SearchCondition();
                isAccounting.Expression.DataPropertyValuePropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefState;
                isAccounting.ConditionType = MFConditionType.MFConditionTypeEqual;
                isAccounting.TypedValue.SetValue(MFDataType.MFDatatypeLookup, Properties.Settings.Default.stateAccounting);
                searchConditions.Add(-1, isAccounting);

                //Perform search
                var invoices = currVault.ObjectSearchOperations.SearchForObjectsByConditions(searchConditions, MFSearchFlags.MFSearchFlagNone, false);


                //start output file
                XElement output   = new XElement("YsiTran");
                XElement payables = new XElement("Payables");

                //get post month
                var postMonthForm = new PostMonth();
                postMonthForm.ShowDialog();

                //loop through invoices collecting at import workflow state, build XML file from the inside out.
                int count = 0;
                foreach (ObjectVersion invoice in invoices)
                {
                    XElement payable     = new XElement("Payable");
                    double   totalAmount = 0;
                    count++;

                    var propValues        = new PropertyValues();
                    var currPropertyValue = new PropertyValue();
                    var objLedger         = new ObjectVersion();
                    propValues = currVault.ObjectPropertyOperations.GetProperties(invoice.ObjVer);

                    XElement details = new XElement("Details");

                    //Get Ledger Entry reference
                    currPropertyValue = propValues.SearchForProperty(Properties.Settings.Default.propLedgerEntry);

                    if (currPropertyValue.TypedValue.DataType == MFDataType.MFDatatypeMultiSelectLookup)
                    {
                        var lookups = new Lookups();

                        lookups = currPropertyValue.TypedValue.GetValueAsLookups();

                        int i = 0;
                        foreach (Lookup lookup in lookups)
                        {
                            XElement detail = new XElement("Detail");

                            var propDef = new PropertyDef();
                            propDef = currVault.PropertyDefOperations.GetPropertyDef(currPropertyValue.PropertyDef);
                            var valListObjType = new ObjType();
                            valListObjType = currVault.ValueListOperations.GetValueList(propDef.ValueList);

                            if (valListObjType.RealObjectType)
                            {
                                i++;
                                //Get Ledgery Entry Object
                                var objDetail = new ObjVer();
                                objDetail.SetIDs(valListObjType.ID, lookup.Item, lookup.Version);
                                var detailValues = new PropertyValues();
                                var detailValue  = new PropertyValue();
                                detailValues = currVault.ObjectPropertyOperations.GetProperties(objDetail);
                                //MessageBox.Show(i.ToString());
                                //Get Account
                                detailValue = detailValues.SearchForProperty(Properties.Settings.Default.propAccount);
                                if (detailValue.TypedValue.DataType == MFDataType.MFDatatypeMultiSelectLookup)
                                {
                                    Lookup lookupAccount = new Lookup();
                                    lookupAccount = detailValue.TypedValue.GetValueAsLookup();

                                    propDef        = currVault.PropertyDefOperations.GetPropertyDef(detailValue.PropertyDef);
                                    valListObjType = currVault.ValueListOperations.GetValueList(propDef.ValueList);

                                    if (valListObjType.RealObjectType)
                                    {
                                        //Get Account Number
                                        var objAccount = new ObjVer();
                                        objAccount.SetIDs(valListObjType.ID, lookupAccount.Item, lookupAccount.Version);
                                        var accountValues = new PropertyValues();
                                        var accountValue  = new PropertyValue();
                                        accountValues = currVault.ObjectPropertyOperations.GetProperties(objAccount);
                                        accountValue  = accountValues.SearchForProperty(Properties.Settings.Default.propGLCode);
                                        XElement account = new XElement("AccountId");
                                        account.SetValue(accountValue.GetValueAsLocalizedText());
                                        detail.Add(account);
                                    }
                                }

                                //get Description-Notes
                                detailValue = detailValues.SearchForProperty(Properties.Settings.Default.propDescription);
                                XElement notes = new XElement("Notes");
                                notes.SetValue(detailValue.GetValueAsLocalizedText());
                                detail.Add(notes);

                                //get Amount
                                detailValue = detailValues.SearchForProperty(Properties.Settings.Default.propGLAmount);
                                XElement amount = new XElement("Amount");
                                amount.SetValue(detailValue.GetValueAsLocalizedText());
                                detail.Add(amount);
                                totalAmount += Convert.ToDouble(detailValue.GetValueAsLocalizedText());
                            }

                            XElement propertyID = new XElement("PropertyId");
                            detail.Add(propertyID);
                            details.Add(detail);
                        }
                    }

                    //Get Property ID
                    currPropertyValue = propValues.SearchForProperty(Properties.Settings.Default.propProperty);
                    if (currPropertyValue.TypedValue.DataType == MFDataType.MFDatatypeMultiSelectLookup)
                    {
                        //Getlookup of property to find object
                        var lookup = new Lookup();
                        lookup = currPropertyValue.TypedValue.GetValueAsLookup();
                        var propDef = new PropertyDef();
                        propDef = currVault.PropertyDefOperations.GetPropertyDef(currPropertyValue.PropertyDef);
                        var valListObjType = new ObjType();
                        valListObjType = currVault.ValueListOperations.GetValueList(propDef.ValueList);

                        if (valListObjType.RealObjectType)
                        {
                            //Get property ID
                            var objProperty = new ObjVer();
                            objProperty.SetIDs(valListObjType.ID, lookup.Item, lookup.Version);
                            var propertyValues = new PropertyValues();
                            var propertyValue  = new PropertyValue();
                            propertyValues = currVault.ObjectPropertyOperations.GetProperties(objProperty);
                            propertyValue  = propertyValues.SearchForProperty(Properties.Settings.Default.propPropertyID);



                            IEnumerable <XElement> ieDetails = from el in details.Elements() select el;


                            //loop through items

                            foreach (XElement detail in ieDetails)
                            {
                                //Check that a check has been cut in Yardi.
                                if (detail.Elements("PropertyId").Any())
                                {
                                    detail.Element("PropertyId").SetValue(propertyValue.GetValueAsLocalizedText());
                                }
                            }
                        }
                    }

                    //Get Vendor ID
                    currPropertyValue = propValues.SearchForProperty(Properties.Settings.Default.propVendor);
                    if (currPropertyValue.TypedValue.DataType == MFDataType.MFDatatypeMultiSelectLookup)
                    {
                        //Getlookup of vendor to find object
                        var lookup = new Lookup();
                        lookup = currPropertyValue.TypedValue.GetValueAsLookup();
                        var propDef = new PropertyDef();
                        propDef = currVault.PropertyDefOperations.GetPropertyDef(currPropertyValue.PropertyDef);
                        var valListObjType = new ObjType();
                        valListObjType = currVault.ValueListOperations.GetValueList(propDef.ValueList);

                        if (valListObjType.RealObjectType)
                        {
                            //Get Vendor ID
                            var objProperty = new ObjVer();
                            objProperty.SetIDs(valListObjType.ID, lookup.Item, lookup.Version);
                            var vendorValues = new PropertyValues();
                            var vendorValue  = new PropertyValue();
                            vendorValues = currVault.ObjectPropertyOperations.GetProperties(objProperty);
                            vendorValue  = vendorValues.SearchForProperty(Properties.Settings.Default.propYardiCode);
                            XElement propertyID = new XElement("PersonId");
                            propertyID.SetValue(vendorValue.GetValueAsLocalizedText());
                            payable.Add(propertyID);
                        }
                    }

                    // Add details to payable
                    payable.Add(details);

                    //Add Post Month
                    XElement postMonth = new XElement("PostMonth");
                    postMonth.SetValue(postMonthForm.StrPostMonth);
                    payable.Add(postMonth);

                    //Get link to object
                    XElement link    = new XElement("Notes");
                    string   strLink = "m-files://show/" + Properties.Settings.Default.vaultGUID + "/" + invoice.ObjVer.Type.ToString() + "-" + invoice.ObjVer.ID.ToString();
                    link.SetValue(strLink);
                    payable.Add(link);

                    //get Invoice Number
                    currPropertyValue = propValues.SearchForProperty(Properties.Settings.Default.propInvoiceNumber);
                    XElement invoiceNumber = new XElement("InvoiceNumber");
                    invoiceNumber.SetValue(currPropertyValue.GetValueAsLocalizedText());
                    payable.Add(invoiceNumber);

                    //get Invoice date
                    currPropertyValue = propValues.SearchForProperty(Properties.Settings.Default.propInvoiceDate);
                    XElement invoiceDate = new XElement("InvoiceDate");
                    invoiceDate.SetValue(currPropertyValue.GetValueAsLocalizedText());
                    payable.Add(invoiceDate);

                    //get Due Date
                    currPropertyValue = propValues.SearchForProperty(Properties.Settings.Default.propDueDate);
                    XElement dueDate = new XElement("DueDate");
                    dueDate.SetValue(currPropertyValue.GetValueAsLocalizedText());
                    payable.Add(dueDate);

                    //Set Expense Type
                    XElement expenseType = new XElement("ExpenseType");
                    expenseType.SetValue("Contract");
                    payable.Add(expenseType);


                    //Set Total
                    XElement total = new XElement("TotalAmount");
                    total.SetValue(totalAmount.ToString());


                    payables.Add(payable);

                    //change workflow state
                    propValues.SearchForProperty((int)MFBuiltInPropertyDef.MFBuiltInPropertyDefState).TypedValue.SetValue(MFDataType.MFDatatypeLookup, Properties.Settings.Default.stateProcessing);
                    currVault.ObjectPropertyOperations.SetAllProperties(invoice.ObjVer, true, propValues);
                }



                output.Add(payables);
                output.Save(saveFile.FileName);
                MessageBox.Show(count.ToString() + " Files Exported!");
            }
        }
        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);
        }
Beispiel #14
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);
        }
Beispiel #15
0
        public void ReturnsValueListItemIfIsDeleted()
        {
            // 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);

                // Deleted is okay.
                return(Mock.Of <ValueListItem>(i => i.ID == valueListItemId && i.ValueListID == valueListId && i.Deleted == true));
            });

            // 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.IsTrue(item.Deleted);
        }