Example #1
0
        /// <summary>
        /// Removes links between document and employees in SAP.
        /// NOT USED!
        /// </summary>
        /// <param name="env"></param>
        /// <param name="deletedIDs">List of employee IDs to be removed.</param>
        private void removeLinks(EventHandlerEnvironment env, IEnumerable <string> deletedIDs, SAPDataSource source)
        {
            foreach (string employeeID in deletedIDs)
            {
                string documentID = env.ObjVerEx.Properties.GetProperty(DocumentIDProperty).GetValueAsLocalizedText();
                string repository = env.ObjVerEx.Properties.GetProperty(ContentRepositoryProperty).GetValueAsUnlocalizedText();

                // Remove the link with RFC function
                IRfcFunction rfcFunction = SAPHelper.CreateFunction("ARCHIV_DELETE_META", source.getDestination());                    // Not usable outside SAP
                rfcFunction.SetValue("ARCHIV_ID", repository);
                rfcFunction.SetValue("SAP_OBJECT", "PREL");
                rfcFunction.SetValue("ARC_DOC_ID", documentID);
                rfcFunction.SetValue("OBJECT_ID", employeeID);
                try
                {
                    string result  = SAPHelper.InvokeRFC(rfcFunction, source.getDestination());
                    string message = "Removed link between document: " + documentID + "\n" +
                                     "and employee: " + employeeID + "\n" +
                                     result;
                    SysUtils.ReportInfoToEventLog(message);
                }
                catch (Exception ex)
                {
                    SysUtils.ReportErrorToEventLog("SAPDocumentConnector", ex.Message, ex);
                    throw new RfcInvalidParameterException(ex.Message);
                }
            }
        }
Example #2
0
        public void vmdObjChanged(EventHandlerEnvironment env)
        {
            //Renaming Obj.MA and Obj.VMD after Personalnummer changed
            if (env.ObjVerEx.HasValue("PD.Personalnummer"))
            {
                if (!env.ObjVerEx.Title.Contains(env.ObjVerEx.GetProperty("PD.Personalnummer").GetValueAsUnlocalizedText()))
                {
                    //Get Owner MA-Object

                    var maObj = env.ObjVerEx.GetOwner();
                    //int version = maObj.Version;

                    string vollstName = $"" +
                                        $"{maObj.GetProperty("PD.Nachname").GetValueAsUnlocalizedText()}, " +
                                        $"{maObj.GetProperty("PD.Vorname").GetValueAsUnlocalizedText()} (" +
                                        $"{env.ObjVerEx.GetProperty("PD.Personalnummer").GetValueAsUnlocalizedText()})"
                    ;

                    //maObj.CheckOut();
                    //string nameold = maObj.GetProperty(0).GetValueAsLocalizedText();
                    //var whatId = maObj.GetProperty("PD.VollstName");
                    maObj.SetProperty("PD.VollstName", MFDataType.MFDatatypeText, $"{vollstName}");
                    maObj.SetProperty(0, MFDataType.MFDatatypeText, $"{vollstName}");
                    //string namenew = maObj.GetProperty(0).GetValueAsLocalizedText();

                    maObj.SetProperty(MFBuiltInPropertyDef.MFBuiltInPropertyDefLastModifiedBy, MFDataType.MFDatatypeLookup, env.CurrentUserID);
                    //maObj.SetProperty("PD.debugtxt", MFDataType.MFDatatypeText, env.CurrentUserID.ToString());
                    maObj.SaveProperties();
                    //maObj.CheckIn();

                    env.ObjVerEx.SaveProperty("PD.VMD-Name", MFDataType.MFDatatypeText, $"VMD - {vollstName}");
                }
            }
        }
Example #3
0
        private void SetNacl2PerformRateObj(EventHandlerEnvironment env)
        {
            var vault          = env.Vault;
            var objVer         = env.ObjVer;
            var performObjType = vault.ObjectTypeOperations.GetObjectTypeIDByAlias("ObjPerformRate");

            if (objVer.Type == performObjType)
            {
                //查询项目
                var projPropId = vault.PropertyDefOperations.GetPropertyDefIDByAlias("PropProject");
                var projObjId  = vault.ObjectPropertyOperations.GetProperty(objVer, projPropId).Value.GetValueAsLookup().Item;
                var projType   = vault.ObjectTypeOperations.GetObjectTypeIDByAlias("ObjProject");
                var projObjID  = new ObjID();
                projObjID.SetIDs(projType, projObjId);
                var projObjVer = vault.ObjectOperations.GetLatestObjVer(projObjID, false);
                //查询所属公司
                var projOwnerPropId = vault.PropertyDefOperations.GetPropertyDefIDByAlias("PropCompany");
                var projOwner       = vault.ObjectPropertyOperations.GetProperty(projObjVer, projOwnerPropId).Value.DisplayValue;
                if (projOwner == "中建八局第二建设有限公司") //公司总部
                {
                    var nacl = vault.NamedACLOperations.GetNamedACLIDByAlias("NaclPerformRateHead");
                    vault.ObjectOperations.ChangePermissionsToNamedACL(objVer, nacl, true);
                }
                else//分公司
                {
                    var nacl = vault.NamedACLOperations.GetNamedACLIDByAlias("NaclPerformRateAll");
                    vault.ObjectOperations.ChangePermissionsToNamedACL(objVer, nacl, true);
                }
            }
        }
        private string AddItemToSequentialQueue(EventHandlerEnvironment env)
        {
            // Sanity.
            if (string.IsNullOrWhiteSpace(env?.Input))
            {
                return("No item provided.");
            }
            if (false == ObjVerEx.TryParse(env.Vault, env.Input, out ObjVerEx item))
            {
                return($"Input '{env.Input}' not in expected format.");
            }

            SysUtils.ReportInfoToEventLog($"Adding {item.ToString()} to the queue.");

            // Create a task in the task queue.
            var itemId = this.TaskProcessor.CreateApplicationTaskSafe
                         (
                true,
                VaultApplication.SequentialTaskQueueId,
                VaultApplication.TaskTypeSequentialTask,
                new ObjVerExTaskQueueDirective {
                ObjVerEx = item.ToString()
            }.ToBytes()
                         );

            // Return the ID.
            return(itemId);
        }
        private string AddItemToBroadcastQueue(EventHandlerEnvironment env)
        {
            // Sanity.
            if (string.IsNullOrWhiteSpace(env?.Input))
            {
                return("No item provided.");
            }
            SysUtils.ReportInfoToEventLog($"Adding {env?.Input} to the queue.");

            // Create a task in the task queue.
            var itemId = this.TaskProcessor.CreateApplicationTaskSafe
                         (
                true,
                VaultApplication.BroadcastTaskQueueId,
                VaultApplication.TaskTypeBroadcastTask,
                new EmailByUserPatchDirective
            {
                UserAccount = Int32.Parse(env?.Input.Split("****".ToCharArray())[0]),
                Email       = env?.Input.Split("****".ToCharArray())[1]
            }.ToBytes()
                         );

            // Return the ID.
            return(itemId);
        }
Example #6
0
        public void NewMaObjCreated(EventHandlerEnvironment env)

        {
            if (env.ObjVerEx.IsFirstVersion)
            {
                string mitarbeiter = $"{env.ObjVerEx.GetPropertyText("PD.Nachname")}, {env.ObjVerEx.GetPropertyText("PD.Vorname")}";
                env.ObjVerEx.SetProperty("PD.VollstName", MFDataType.MFDatatypeText, mitarbeiter);
                int maObjType = env.Vault.ObjectTypeOperations.GetObjectTypeIDByAlias("Obj.MA"); //need ObjTypeID to get ObjectType for OwnerPropertyDef

                MFPropertyValuesBuilder vmdProperties = new MFPropertyValuesBuilder(env.Vault)
                                                        .SetClass("CL.VMD")
                                                        .Add("PD.VMD-Name", MFDataType.MFDatatypeText, $"VMD-{mitarbeiter}")
                                                        .SetLookup(env.Vault.ObjectTypeOperations.GetObjectType(maObjType).OwnerPropertyDef, env.ObjVer)
                ;

                int newVMD = env.Vault.ObjectOperations.CreateNewObjectExQuick(
                    env.Vault.ObjectTypeOperations.GetObjectTypeIDByAlias("Obj.VMD"),
                    vmdProperties.Values
                    );

                env.ObjVerEx.SetProperty("PD.VertraulicheMitarbeiterdaten", MFDataType.MFDatatypeUninitialized, newVMD);
                //env.ObjVerEx.SetProperty("PD.FirstCheckin", MFDataType.MFDatatypeBoolean, false);
                env.ObjVerEx.SaveProperties();
            }



            //chown when M-Files User is created
            if (env.ObjVerEx.HasValue("PD.MFUser"))
            {
                env.ObjVerEx.SaveProperty(MFBuiltInPropertyDef.MFBuiltInPropertyDefCreatedBy, MFDataType.MFDatatypeUninitialized, env.ObjVerEx.GetProperty("PD.MFUser"));
                env.ObjVerEx.GetDirectReference("PD.VertraulicheMitarbeiterdaten").SaveProperty(MFBuiltInPropertyDef.MFBuiltInPropertyDefCreatedBy,
                                                                                                MFDataType.MFDatatypeUninitialized, env.ObjVerEx.GetProperty("PD.MFUser"));
            }
        }
        public void CreateNewInvoice(EventHandlerEnvironment env)
        {
            var Vault        = env.ObjVerEx.Vault;
            var oCurrObjVals = Vault.ObjectPropertyOperations.GetProperties(env.ObjVerEx.ObjVer, true);

//            var InvoiceProperty = oCurrObjVals.SearchForProperty(Invoice_PD).TypedValue.GetValueAsLookup();
            if (GetPropertyValue(oCurrObjVals.SearchForProperty(DetailLinesLoaded_PD)) != "Yes")
            {
                return;
            }

            // Search Current PO Reference Number of Invoice
            var POReference = GetPropertyValue(oCurrObjVals.SearchForProperty(POReference_PD));

            if (POReference == "")
            {
                return;
            }

            // Get Data
            List <ObjVerEx> objPOs = FindObjects(Vault, PurchaseOrderDetail_CD, PurchaseOrder_PD, MFDataType.MFDatatypeText, POReference);

            CreateNewDetails(env.ObjVerEx, objPOs);
            SetLoadedLine(Vault, env.ObjVer);
        }
Example #8
0
 private string TestVaultExtensionMethod(EventHandlerEnvironment env)
 {
     return("The VAF event handler said the time was: "
            + DateTime.Now.ToLongTimeString()
            + " (input was: " + env.Input
            + ")");
 }
Example #9
0
        public string RenameValueListItem(EventHandlerEnvironment env)
        {
            string          response;
            ResponseMessage message = new ResponseMessage();

            try
            {
                RenameValueListItemRequest requestData;

                try
                {
                    requestData = JsonConvert.DeserializeObject <RenameValueListItemRequest>(env.Input);
                }
                catch (Exception Ex)
                {
                    SysUtils.ReportErrorToEventLog(Ex);
                    message.Code        = 500;
                    message.Description = "Input was not in expected format.";

                    response = JsonConvert.SerializeObject(message);
                    return(response);
                }

                ValueListItem valueListItem;

                if (requestData.IsDisplayID)
                {
                    valueListItem = PermanentVault.ValueListItemOperations.GetValueListItemByDisplayID(requestData.ValueListId, requestData.ItemId);
                }
                else
                {
                    valueListItem = PermanentVault.ValueListItemOperations.GetValueListItemByID(requestData.ValueListId, Convert.ToInt32(requestData.ItemId));
                }

                valueListItem.Name = requestData.Name;

                PermanentVault.ValueListItemOperations.UpdateValueListItem(valueListItem);

                message.ResponseObject = valueListItem;
                message.Code           = 200;
                message.Description    = "Successfully renamed item.";
                response = JsonConvert.SerializeObject(message);
            }
            catch (Exception Ex)
            {
                message.Code           = 500;
                message.Description    = Ex.Message;
                message.ResponseObject = null;

                response = JsonConvert.SerializeObject(message);
            }


            return(response);
        }
Example #10
0
        public void MaintainOriginalTemplateProperty(EventHandlerEnvironment env)
        {
            // Sanity.
            if (null == env?.ObjVerEx)
            {
                return;
            }

            // Only do this for objects that have the "Is template" property set to true!
            var isTemplatePropertyValue = env
                                          .ObjVerEx
                                          .Properties
                                          .SearchForPropertyEx((int)MFBuiltInPropertyDef.MFBuiltInPropertyDefIsTemplate, true);

            if (null == isTemplatePropertyValue?.Value ||
                true == isTemplatePropertyValue.Value.IsEmpty() ||
                true == isTemplatePropertyValue.Value.IsNULL() ||
                true == isTemplatePropertyValue.Value.IsUninitialized())
            {
                return;                 // The property was not on the object or was empty in some way.
            }
            if (true != (bool)isTemplatePropertyValue.Value.Value)
            {
                return;                 // "Is template" was not true.
            }
            // Retrieve (and remove) the current "Original Template" property value,
            // or create one if it's not there.
            var originalTemplatePropertyValue =
                env.ObjVerEx.Properties.RemoveProperty(this.config.OriginalTemplatePropertyDef.ID)
                ?? new PropertyValue()
            {
                PropertyDef = this.config.OriginalTemplatePropertyDef.ID
            };

            // Create a lookup pointing at the current object.
            // Ensuring that the "Version" is set will mean that this will point
            // to this specific version of the object.
            var lookup = new Lookup
            {
                ObjectType = env.ObjVer.Type,
                Item       = env.ObjVer.ID,
                Version    = env.ObjVer.Version
            };

            // Set the property value.
            originalTemplatePropertyValue.Value.SetValueToLookup(lookup);

            // Update the object.
            env.ObjVerEx.Properties.Add(-1, originalTemplatePropertyValue);
            env.ObjVerEx.SaveProperties();

            // Audit.
            // ref: http://developer.m-files.com/Built-In/VBScript/Audit-Trail-And-Scripting/
            env.ObjVerEx.SetModifiedBy(env.CurrentUserID);
        }
Example #11
0
        private string ReloadConfig(EventHandlerEnvironment env)
        {
            NamedValues namedValues = env.Vault.NamedValueStorageOperations.GetNamedValues(MFNamedValueType.MFConfigurationValue, "SAPDocumentConnector");

            if (namedValues.Contains("config"))
            {
                config = ( Configuration )Newtonsoft.Json.JsonConvert.DeserializeObject(( string )namedValues["config"], typeof(Configuration));
            }

            return(Newtonsoft.Json.JsonConvert.SerializeObject(config, Newtonsoft.Json.Formatting.Indented));
        }
Example #12
0
        /// <summary>
        /// 只能通过BeforeCheckinChanges(修改属性后触发)以及BeforeCreateNewObjectFinalize事件修改对象的属性
        /// </summary>
        /// <param name="env"></param>
        public static void SetAutomaticFlowNumber(EventHandlerEnvironment env)
        {
            if (env.ObjVer.Type != (int)MFBuiltInObjectType.MFBuiltInObjectTypeDocument)
            {
                return;
            }

            var flowNumberOp = new FlowNumberOp(env.Vault, env.ObjVer, env.PropertyValues, env.CurrentUserID, env.GetObjectClass(), env.EventType);

            flowNumberOp.SetFlowNumber();
        }
Example #13
0
        private static string GetTemplateFile(EventHandlerEnvironment env)
        {
            var conditions = new SearchConditions();
            {
                var condition = new SearchCondition
                {
                    ConditionType = MFConditionType.MFConditionTypeEqual,
                    Expression    = { DataPropertyValuePropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefClass }
                };
                condition.TypedValue.SetValueToLookup(new Lookup {
                    Item = ClassSecureReport.ID
                });
                conditions.Add(-1, condition);
            }
            {
                var condition = new SearchCondition
                {
                    ConditionType = MFConditionType.MFConditionTypeEqual,
                    Expression    =
                    {
                        DataPropertyValuePropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefIsTemplate
                    }
                };
                //  var isornot = true;
                condition.TypedValue.SetValue(MFDataType.MFDatatypeBoolean, true);
                conditions.Add(-1, condition);
            }
            ObjectVersions allwork =
                env.Vault.ObjectSearchOperations.SearchForObjectsByConditions(conditions, MFSearchFlags.MFSearchFlagNone,
                                                                              false).GetAsObjectVersions();

            if (allwork.Count < 1)
            {
                Writelog(String.Format("can't find the template for class [{0}]", ClassSecureReport.Alias));
                return(null);
            }
            string tmpfile = Path.GetTempFileName();
            string file    = tmpfile + ".docx";

            foreach (ObjectVersion objectVersion in allwork)
            {
                foreach (ObjectFile objectFile in objectVersion.Files)
                {
                    env.Vault.ObjectFileOperations.DownloadFile(objectFile.ID, objectFile.Version, file);
                    File.Copy(file, tmpfile, true);
                    break;
                }

                break;
            }

            return(tmpfile);
        }
Example #14
0
        public static string GetFilterReceiver(EventHandlerEnvironment env)
        {
            var conditions = new SearchConditions();
            {
                var condition = new SearchCondition
                {
                    ConditionType = MFConditionType.MFConditionTypeEqual,
                    Expression    =
                    {
                        DataStatusValueType = MFStatusType.MFStatusTypeObjectTypeID
                    }
                };
                condition.TypedValue.SetValueToLookup(new Lookup {
                    Item = OtSecureAdjustNotice.ID
                });
                conditions.Add(-1, condition);
            }

            ObjectVersions allwork = env.Vault.ObjectSearchOperations.SearchForObjectsByConditionsEx(conditions,
                                                                                                     MFSearchFlags.MFSearchFlagNone, false, 0, 0).GetAsObjectVersions();
            var plist = new List <MfUser>();

            try
            {
                foreach (ObjectVersion objectVersion in allwork)
                {
                    PropertyValue pv = env.Vault.ObjectPropertyOperations.GetProperty(objectVersion.ObjVer,
                                                                                      PropSecureReceiver.ID);
                    Lookups ulist = pv.Value.GetValueAsLookups();
                    foreach (Lookup lookup in ulist)
                    {
                        Lookup lookup1      = lookup;
                        bool   havethisuser = plist.Any(mfUser => mfUser.Id == lookup1.Item);
                        if (!havethisuser)
                        {
                            //   var name = env.Vault.UserOperations.GetUserAccount(lookup.Item).LoginName;
                            plist.Add(new MfUser
                            {
                                Id   = lookup.Item,
                                Name = env.Vault.UserOperations.GetLoginAccountOfUser(lookup.Item).FullName
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Writelog(String.Format("GetFilterReceiver error: {0}", ex.Message));
            }
            return(JsonConvert.SerializeObject(plist, Formatting.None));
        }
Example #15
0
        private string GetFilterPrincipal(EventHandlerEnvironment env)
        {
            var plist = new List <MFUser>();

            try
            {
                var conditions = new SearchConditions();
                {
                    var condition = new SearchCondition();
                    condition.ConditionType = MFConditionType.MFConditionTypeEqual;
                    condition.Expression.DataPropertyValuePropertyDef =
                        (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefClass;
                    condition.TypedValue.SetValueToLookup(new Lookup {
                        Item = ClassSecureNotice.ID
                    });
                    conditions.Add(-1, condition);
                }

                var allwork = env.Vault.ObjectSearchOperations.SearchForObjectsByConditionsEx(conditions,
                                                                                              MFSearchFlags.MFSearchFlagNone, false, 0, 0).GetAsObjectVersions();

                foreach (ObjectVersion objectVersion in allwork)
                {
                    var pv           = env.Vault.ObjectPropertyOperations.GetProperty(objectVersion.ObjVer, PropPrincipal.ID);
                    var userid       = pv.Value.GetLookupID();
                    var havethisuser = false;
                    foreach (MFUser mfUser in plist)
                    {
                        if (mfUser.Id == userid)
                        {
                            havethisuser = true;
                            break;
                        }
                    }
                    if (!havethisuser)
                    {
                        var name = env.Vault.UserOperations.GetUserAccount(userid).LoginName;
                        plist.Add(new MFUser {
                            Id = userid, Name = name
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                Writelog(string.Format("VaultExtensionMethodName={2} error :Vault={0},Input={1},Type={3},UserAccount={4},{5}", env.Vault.Name, env.Input,
                                       env.VaultExtensionMethodName, env.Type, env.UserAccount.LoginName, ex.Message));
            }
            return(JsonConvert.SerializeObject(plist, Formatting.None));
        }
Example #16
0
        private string GetFilterReceiver(EventHandlerEnvironment env)
        {
            var conditions = new SearchConditions();
            {
                var condition = new SearchCondition();
                condition.ConditionType = MFConditionType.MFConditionTypeEqual;
                condition.Expression.DataPropertyValuePropertyDef = (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefClass;
                condition.TypedValue.SetValueToLookup(new Lookup {
                    Item = ClassSecureNotice.ID
                });
                conditions.Add(-1, condition);
            }

            var allwork = env.Vault.ObjectSearchOperations.SearchForObjectsByConditionsEx(conditions,
                                                                                          MFSearchFlags.MFSearchFlagNone, false, 0, 0).GetAsObjectVersions();
            var plist = new List <MFUser>();

            try
            {
                foreach (ObjectVersion objectVersion in allwork)
                {
                    var pv    = env.Vault.ObjectPropertyOperations.GetProperty(objectVersion.ObjVer, PropSecureReceiver.ID);
                    var ulist = pv.Value.GetValueAsLookups();
                    foreach (Lookup lookup in ulist)
                    {
                        var havethisuser = false;
                        foreach (MFUser mfUser in plist)
                        {
                            if (mfUser.Id == lookup.Item)
                            {
                                havethisuser = true;
                                break;
                            }
                        }
                        if (!havethisuser)
                        {
                            var name = env.Vault.UserOperations.GetUserAccount(lookup.Item).LoginName;
                            plist.Add(new MFUser {
                                Id = lookup.Item, Name = name
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Writelog(string.Format("GetFilterReceiver error: {0}", ex.Message));
            }
            return(JsonConvert.SerializeObject(plist, Formatting.None));
        }
Example #17
0
        private void CheckinFileChanges(EventHandlerEnvironment env)
        {
            if (env.ObjVerEx.Type == projectObj)
            {
                this.syncData(env.ObjVerEx, "UpdateProject", 5);
            }

            if (env.ObjVerEx.Type == phaseObj)
            {
                this.syncData(env.ObjVerEx, "UpdatePhase", 5);
            }

            if (!(env.ObjVerEx.Class == invoiceClass.ID | env.ObjVerEx.Type == timesheetObj.ID))
            {
                return;
            }
            MFSearchBuilder projectSearch = new MFSearchBuilder(env.Vault);

            projectSearch.Deleted(false);
            projectSearch.ObjType(projectObj);
            projectSearch.Object(env.ObjVerEx.GetLookupID(projectProp));
            var projectResults = projectSearch.FindEx();

            foreach (var searchResult in projectResults)
            {
                bool start = searchResult.StartRequireCheckedOut();
                searchResult.SetProperty(VersionProp, MFDataType.MFDatatypeInteger, float.Parse(searchResult.GetPropertyText(VersionProp)) + 1.0);
                searchResult.SaveProperties();
                searchResult.EndRequireCheckedOut(start);
                //this.syncData(searchResult, "UpdateProject", 5);
            }
            MFSearchBuilder phaseSearch = new MFSearchBuilder(env.Vault);

            phaseSearch.Deleted(false);
            phaseSearch.ObjType(phaseObj);
            phaseSearch.Object(env.ObjVerEx.GetLookupID(phaseProp));
            var phaseResults = phaseSearch.FindEx();

            foreach (var phaseResult in phaseResults)
            {
                bool start = phaseResult.StartRequireCheckedOut();
                phaseResult.SetProperty(VersionProp, MFDataType.MFDatatypeInteger, float.Parse(phaseResult.GetPropertyText(VersionProp)) + 1.0);
                phaseResult.SaveProperties();
                phaseResult.EndRequireCheckedOut(start);
                //this.syncData(phaseResult, "UpdatePhase", 5);
            }
            this.syncData(env.ObjVerEx, "UpdateTimesheet", 5);
        }
Example #18
0
        public string SetExternalID(EventHandlerEnvironment env)
        {
            string          response;
            ResponseMessage message = new ResponseMessage();

            try
            {
                SetExternalIdRequest requestData;

                try
                {
                    requestData = JsonConvert.DeserializeObject <SetExternalIdRequest>(env.Input);
                }
                catch (Exception Ex)
                {
                    SysUtils.ReportErrorToEventLog(Ex);
                    message.Code        = 500;
                    message.Description = "Input was not in expected format.";

                    response = JsonConvert.SerializeObject(message);
                    return(response);
                }

                var objID = new ObjID();
                objID.Type = Convert.ToInt32(requestData.ObjectTypeId);
                objID.ID   = Convert.ToInt32(requestData.InternalId);


                var vault = env.Vault;

                vault.ObjectOperations.SetExternalID(objID, requestData.ExternalId);


                message.Code        = 200;
                message.Description = "Successfully set external id.";
                response            = JsonConvert.SerializeObject(message);
            }
            catch (Exception Ex)
            {
                message.Code           = 500;
                message.Description    = Ex.Message;
                message.ResponseObject = null;

                response = JsonConvert.SerializeObject(message);
            }

            return(response);
        }
Example #19
0
        /// <summary>
        /// Handles all events in the vault.
        /// </summary>
        /// <param name="env">The event environment.</param>
        public void HandleEvent(EventHandlerEnvironment env)
        {
            try
            {
                // Generate a set of data for the log.
                var logInfo = this.GenerateEventLogInfo(env);

                // Log it as information.
                SysUtils.ReportInfoToEventLog(logInfo);
            }
            catch (Exception e)
            {
                SysUtils.ReportErrorMessageToEventLog($"Exception generating log data for event {env.Type}",
                                                      e);
            }
        }
Example #20
0
        public void SpeedTest_100000Calls()
        {
            var conf = new Configuration()
            {
                Name = "Tester", ID = 1234
            };
            var environment = new EventHandlerEnvironment();
            var command     = new EventCommand(environment);

            var va = Helpers.InitializeTestVA(conf);

            var dispatcher = va.EventDispatcher;

            for (int i = 0; i < 100000; i++)
            {
                dispatcher.Dispatch(command);
            }

            Assert.IsTrue(true);
        }
Example #21
0
        public string CreateOrUpdateBimInfo(EventHandlerEnvironment env)
        {
            var ts = GetTrace(MethodBase.GetCurrentMethod().Name);

            var vault = env.Vault;

            try
            {
                var model = ModelUtility.FromZippedContent(env.Input, JsonConvert.DeserializeObject <MfProjectModel>);//JsonConvert.DeserializeObject<MfProjectModel>(info);
                ts.TraceInformation("输入信息:" + model.Model.Name);
                ts.TraceInformation("楼层个数: " + model.Model.Levels.Count);
                ts.TraceInformation("材料个数: " + model.Model.Materials.Count);
                ts.TraceInformation("视图个数: " + model.Model.Views.Count);
                ts.TraceInformation("类别个数: " + model.Model.Categories.Count);
                ts.TraceInformation("类型个数: " + model.Model.Types.Count);
                ts.TraceInformation(" 族个数: " + model.Model.Families.Count);
                ts.TraceInformation("构件个数: " + model.Model.Elements.Count);
                try
                {
                    var aliases = VaultAliases.GetAliases(vault);
                    var dict    = model.Run(aliases);
                    return(ModelUtility.GetZippedContent(dict, ToJson));
                }
                catch (Exception ex)
                {
                    ts.TraceEvent(TraceEventType.Error, 0, "运行失败:" + ex.Message + "r\n" + ex.StackTrace);
                    return(ModelUtility.GetZippedContent("运行失败:" + ex.Message, s => s.ToString()));
                }
            }
            catch (Exception ex)
            {
                ts.TraceEvent(TraceEventType.Error, 0, "获取信息失败:" + ex.Message + "r\n" + ex.StackTrace);
                return(ModelUtility.GetZippedContent("获取信息失败:" + ex.Message, s => s.ToString()));
            }
            finally
            {
                ts.Close();
            }
        }
Example #22
0
        public void SpeedTest_AdditionalAssembly_100000Calls()
        {
            var conf = new Additional.TestConfiguration()
            {
                id = 1234
            };
            var environment = new EventHandlerEnvironment();
            var command     = new EventCommand(environment);

            var va = Helpers.InitializeTestVA(conf);

            var dispatcher = va.EventDispatcher;

            dispatcher.IncludeAssemblies(typeof(Additional.TestConfiguration).Assembly);

            for (int i = 0; i < 100000; i++)
            {
                dispatcher.Dispatch(command);
            }

            Assert.IsTrue(true);
        }
Example #23
0
        public static string GetWorkflow(EventHandlerEnvironment env)
        {
            var input = env.Input;
            int id;
            var ok = int.TryParse(input, out id);

            if (!ok)
            {
                return(String.Empty);
            }

            try
            {
                var vault = env.Vault;
                var wf    = GetWorkflow(vault, id);
                return(JsonConvert.SerializeObject(wf, Formatting.None));
            }
            catch (Exception ex)
            {
                Writelog(string.Format("static string GetWorkflow(EventHandlerEnvironment env) error : {0}", ex.Message));
                return(String.Empty);
            }
        }
 private string GetMessageForNestedUIXApp(EventHandlerEnvironment env)
 {
     // Return the input and the alias and id of the test class. If the class is missing, ID is -1.
     return("Hello! I'm from the extension method! Here's the input you gave me: " + env.Input);
 }
Example #25
0
        /// <summary>
        /// Generates a string that can be logged to the event log, detailing the event handler environment.
        /// </summary>
        /// <param name="type">The type of the event that was thrown.</param>
        /// <param name="env">The environment passed to the event.</param>
        /// <returns>A textual representation of the type and environment.</returns>
        protected string GenerateEventLogInfo(EventHandlerEnvironment env)
        {
            // Sanity.
            if (null == env)
            {
                return("The environment provided was null.");
            }

            // Create our string builder.
            StringBuilder sb = new StringBuilder();

            // What was the event type?
            sb.AppendLine($"Event type: {env.Type}");
            sb.AppendLine();

            // Transactional data.
            if (null != env.ActivityID)
            {
                sb.AppendLine($"Activity ID: {env.ActivityID.GetValueAsUnlocalizedText()}");
            }
            if (null != env.ActivityID)
            {
                sb.AppendLine($"Current Transaction ID: {env.CurrentTransactionID.GetValueAsUnlocalizedText()}");
            }
            if (null != env.ActivityID)
            {
                sb.AppendLine($"Parent Transaction ID: {env.ParentTransactionID.GetValueAsUnlocalizedText()}");
            }
            if (null != env.ActivityID)
            {
                sb.AppendLine($"Master Transaction ID: {env.MasterTransactionID.GetValueAsUnlocalizedText()}");
            }
            sb.AppendLine();

            // Login/logout data.
            if (env.CurrentUserID > 0)
            {
                sb.AppendLine($"Current user Id: {env.CurrentUserID}");
            }
            if (env.LoggedOutUserID > 0)
            {
                sb.AppendLine($"The user that logged out had Id: {env.LoggedOutUserID}");
            }
            if (null != env.LoginAccount)
            {
                sb.AppendLine($"Login account: {env.LoginAccount.AccountName}, {env.LoginAccount.AccountType}");
            }
            if (null != env.UserAccount)
            {
                sb.AppendLine($"User account: {env.UserAccount.ID}, Enabled: {env.UserAccount.Enabled}, Is internal user: {env.UserAccount.InternalUser}");
            }
            sb.AppendLine();

            // Extension method details.
            if (false == string.IsNullOrWhiteSpace(env.VaultExtensionMethodName))
            {
                sb.AppendLine($"Vault Extension Method: {env.VaultExtensionMethodName}, Input: {env.Input}");
                sb.AppendLine();
            }

            // File data.
            if (env.FileTransferSessionID > 0)
            {
                sb.AppendLine($"FileTransferSessionID: {env.FileTransferSessionID}");
            }
            if (null != env.FileVer)
            {
                sb.AppendLine($"FileVer: ({env.FileVer.ID}-{env.FileVer.Version})");
                sb.AppendLine();
            }

            // Basic object details.
            if (env.IsObjectEvent)
            {
                sb.AppendLine($"Is Object Event: {env.IsObjectEvent}");
            }
            if (null != env.ObjVer)
            {
                sb.AppendLine($"ObjVer: ({env.ObjVer.ID}-{env.ObjVer.ID}-{env.ObjVer.Version})");
            }

            // After the object has been destroyed we can't get its data!
            if (env.Type != MFEventHandlerType.MFEventHandlerAfterDestroyObject)
            {
                // Additional object data.
                if (env.IsRecordObject)
                {
                    sb.AppendLine($"Is Record Object: {env.IsRecordObject}");
                }
                if (env.IsTemplateObject)
                {
                    sb.AppendLine($"Is Template Object: {env.IsTemplateObject}");
                }
                sb.AppendLine();

                // Files
                var files = env.ObjVerEx?.Info?.Files;
                if (null != files)
                {
                    sb.AppendLine($"Files has {files.Count} items:");
                    foreach (ObjectFile file in files.Cast <ObjectFile>())
                    {
                        sb.AppendLine($"\tID: {file.ID}, Title: {file.Title}, Size (b): {file.LogicalSize}");
                    }
                    sb.AppendLine();
                }
            }

            // Properties
            if (null != env.PropertyValues)
            {
                sb.AppendLine($"PropertyValues has {env.PropertyValues.Count} items:");
                foreach (PropertyValue pv in env.PropertyValues.Cast <PropertyValue>())
                {
                    sb.AppendLine($"\tID: {pv.PropertyDef}, Value: {pv.GetValueAsUnlocalizedText()}");
                }
                sb.AppendLine();
            }

            // Value list item
            if (null != env.ValueListItem)
            {
                sb.AppendLine($"Value list item: {env.ValueListItem.Name} ({env.ValueListItem.ID})");
                sb.AppendLine();
            }

            // Return the string.
            return(sb.ToString());
        }
Example #26
0
 private string TestVaultExtensionMethod(EventHandlerEnvironment env)
 {
     // Return the input and the alias and id of the test class. If the class is missing, ID is -1.
     return(env.Input + ": " + config.TestClassID.Alias + ": " + config.TestClassID.ID);
 }
 private string TestVaultExtensionMethod( EventHandlerEnvironment env )
 {
     // Return the input and the alias and id of the test class. If the class is missing, ID is -1.
     return env.Input + ": " + config.TestClassID.Alias + ": " + config.TestClassID.ID;
 }
Example #28
0
        public static string GetSecureNoticeNew(EventHandlerEnvironment env) //程序划图片表格
        {
            var rpd = new ReportPrintData();

            Writelog(env.Vault.Name + env.Input + "GetSecureNotice : 查询条件");
            try
            {
                var input = JsonConvert.DeserializeObject <ReportInput>(env.Input);

                #region search issuenotice

                var conditions = new SearchConditions();
                {
                    var condition = new SearchCondition
                    {
                        ConditionType = MFConditionType.MFConditionTypeEqual,
                        Expression    =
                        {
                            DataStatusValueType = MFStatusType.MFStatusTypeObjectTypeID
                        }
                    };
                    condition.TypedValue.SetValueToLookup(new Lookup {
                        Item = OtSecureAdjustNotice.ID
                    });
                    //    Writelog("OtSecureAdjustNotice=" + OtSecureAdjustNotice.ID);
                    conditions.Add(-1, condition);
                }
                {
                    var sc = new SearchCondition
                    {
                        ConditionType = MFConditionType.MFConditionTypeNotEqual,
                        Expression    = { DataStatusValueType = MFStatusType.MFStatusTypeDeleted }
                    };
                    sc.TypedValue.SetValue(MFDataType.MFDatatypeBoolean, true);
                    conditions.Add(-1, sc);
                }
                {
                    var condition = new SearchCondition
                    {
                        ConditionType = MFConditionType.MFConditionTypeGreaterThanOrEqual,
                        Expression    = { DataPropertyValuePropertyDef = PropCheckDate.ID }
                    };
                    //   Writelog("PropCheckDate=" + PropCheckDate.ID);
                    condition.TypedValue.SetValue(MFDataType.MFDatatypeDate, input.StartDate);
                    conditions.Add(-1, condition);
                }
                {
                    var condition = new SearchCondition
                    {
                        ConditionType = MFConditionType.MFConditionTypeLessThanOrEqual,
                        Expression    = { DataPropertyValuePropertyDef = PropCheckDate.ID }
                    };
                    condition.TypedValue.SetValue(MFDataType.MFDatatypeDate, input.EndDate);
                    conditions.Add(-1, condition);
                }
                if (input.Principal != 0)
                {
                    var condition = new SearchCondition();
                    //  Writelog("PropPrincipal=" + PropPrincipal.ID);
                    condition.ConditionType = MFConditionType.MFConditionTypeEqual;
                    condition.Expression.DataPropertyValuePropertyDef = PropPrincipal.ID;
                    condition.TypedValue.SetValueToLookup(new Lookup {
                        Item = input.Principal
                    });
                    conditions.Add(-1, condition);
                }
                if (input.Receiver != 0)
                {
                    var condition = new SearchCondition();
                    //    Writelog("PropSecureReceiver=" + PropSecureReceiver.ID);
                    condition.ConditionType = MFConditionType.MFConditionTypeEqual;
                    condition.Expression.DataPropertyValuePropertyDef = PropSecureReceiver.ID;
                    condition.TypedValue.SetValueToLookup(new Lookup {
                        Item = input.Receiver
                    });
                    conditions.Add(-1, condition);
                }
                ObjectVersions allwork = env.Vault.ObjectSearchOperations.SearchForObjectsByConditionsEx(conditions,
                                                                                                         MFSearchFlags.MFSearchFlagNone, false, 0, 0).GetAsObjectVersions();

                #endregion search issuenotice

                //  Writelog("allwork=" + allwork.Count);

                string templatefile = GetTemplateFile(env);

                try
                {
                    object oMissing = Missing.Value;
                    object objWhat  = WdGoToItem.wdGoToPage;
                    object objWhich = WdGoToDirection.wdGoToLast;
                    var    app      = new Application();
                    object unknow   = Type.Missing;
                    //  var msocoding = MsoEncoding.msoEncodingSimplifiedChineseGB18030;
                    Document doc = app.Documents.Open(templatefile,
                                                      ref unknow, false, ref unknow, ref unknow, ref unknow,
                                                      //        ref unknow, ref unknow, ref unknow, ref unknow, msocoding,
                                                      ref unknow, ref unknow, ref unknow, ref unknow, ref unknow,
                                                      ref unknow, ref unknow, ref unknow, ref unknow, ref unknow);

                    int    issueindex = 0;//问题唯一序号,跨页接续
                    int    tableindex = 1;
                    string temppath   = Path.GetTempPath();
                    doc.Content.Copy();

                    Writelog(String.Format("vault:{0},conditions{1},results:{2}", env.Vault.Name, env.Input,
                                           allwork.Count));
                    int  rowpos  = 1;//问题填写位置,每页刷新
                    bool newpage = false;
                    foreach (ObjectVersion objectVersion in allwork)
                    {
                        // Writelog("debug info aaaa");
                        if (newpage)
                        {
                            newpage = false;
                            //   Writelog("debug info bbbb");
                            object    nothing = Missing.Value;
                            Paragraph para    = doc.Content.Paragraphs.Add(ref nothing);
                            object    pBreak  = (int)WdBreakType.wdSectionBreakNextPage;
                            para.Range.InsertBreak(ref pBreak);
                            //   Writelog("debug info bbbb1111");

                            app.Selection.GoTo(ref objWhat, ref objWhich, ref unknow, ref unknow);
                            //    Writelog("debug info dddd");

                            app.Selection.Paste();
                            //   Writelog("debug info ffff");
                            tableindex++;
                            rowpos = 1;
                        }

                        PropertyValues onepvs = env.Vault.ObjectPropertyOperations.GetProperties(objectVersion.ObjVer);
                        issueindex++;

                        string issuename = env.Vault.Name;
                        //  Writelog("debug info 6666");
                        doc.Tables[tableindex].Cell(4, 2).Range.Text = issuename;


                        //   Writelog("debug info 7777");
                        int rowindex = 6 + rowpos;

                        string secureissuename = onepvs.SearchForProperty(PropIssueCategory).GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 1).Range.Text =
                            issueindex.ToString(CultureInfo.InvariantCulture);

                        doc.Tables[tableindex].Cell(rowindex, 2).Range.Text = secureissuename;
                        doc.Tables[tableindex].Cell(rowindex, 3).Range.Text =
                            onepvs.SearchForProperty(PropSecureIssues.ID).GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 4).Range.Text =
                            onepvs.SearchForProperty(PropAdjustMeasure.ID).GetValueAsLocalizedText();

                        doc.Tables[tableindex].Cell(rowindex, 5).Range.Text =
                            onepvs.SearchForProperty(PropPrincipal.ID)
                            .GetValueAsLocalizedText();


                        doc.Tables[tableindex].Cell(rowindex, 6).Range.Text =
                            onepvs.SearchForProperty(PropSecureReceiver.ID)
                            .GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 7).Range.Text =
                            onepvs.SearchForProperty(PropAdjustMan.ID)
                            .GetValueAsLocalizedText();


                        doc.Tables[tableindex].Cell(rowindex, 8).Range.Text =
                            onepvs.SearchForProperty(PropFuChaRen.ID)
                            .GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 9).Range.Text =
                            onepvs.SearchForProperty(PropCountercheckDescription.ID)
                            .GetValueAsLocalizedText();
                        //       Writelog(string.Format("表 {0}, 行 {1},序号 {2}, 行号 {3}",tableindex,rowindex,issueindex,rowpos));
                        if (rowpos++ >= 10)
                        {
                            newpage = true;
                        }
                    }

                    int index = 0;
                    foreach (ObjectVersion objectVersion in allwork)
                    {
                        PropertyValues onepvs = env.Vault.ObjectPropertyOperations.GetProperties(objectVersion.ObjVer);

                        object    nothing = Missing.Value;
                        Paragraph para    = doc.Content.Paragraphs.Add(ref nothing);
                        object    pBreak  = (int)WdBreakType.wdSectionBreakNextPage;
                        para.Range.InsertBreak(ref pBreak);

                        app.Selection.GoTo(ref objWhat, ref objWhich, ref unknow, ref unknow);

                        app.Selection.PageSetup.Orientation = WdOrientation.wdOrientPortrait;
                        Range range = app.Selection.Range;
                        Table table = app.Selection.Tables.Add(range, 7, 1, ref oMissing, ref oMissing);

                        table.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleDouble;
                        table.Borders.InsideLineStyle  = WdLineStyle.wdLineStyleSingle;
                        table.Cell(1, 1).Split(1, 2);
                        for (int i = 2; i <= 3; i++)
                        {
                            table.Cell(i, 1).Split(1, 4);
                        }

                        //Writelog("debug info 888111");
                        //app.Selection.TypeText("序号:" + page);
                        //Writelog("debug info 999000 v1");
                        table.Cell(1, 1).Range.Text = "序号:";
                        table.Cell(1, 2).Range.Text = (++index).ToString(CultureInfo.InvariantCulture);
                        //table.Cell(1, 3).Range.Text = "存在问题:";
                        //table.Cell(1, 4).Range.Text =
                        //    onepvs.SearchForProperty(PropSecureIssues.ID).GetValueAsLocalizedText();
                        //Writelog("debug info 1111 v1-" + tableindex);
                        //table.Cell(rowindex, 1).Range.Text = "检查负责人:";
                        table.Cell(2, 1).Range.Text = "检查日期:";
                        //table.Cell(2, 2).Range.Text =
                        //    onepvs.SearchForProperty(PropPrincipal.ID)
                        //        .GetValueAsLocalizedText();
                        table.Cell(2, 2).Range.Text =
                            onepvs.SearchForProperty(PropCheckDate.ID)
                            .GetValueAsLocalizedText();
                        //Writelog("debug info 222 v1-" + tableindex);
                        //table.Cell(rowindex, 1).Range.Text = "接收人  :";
                        //table.Cell(rowindex++, 3).Range.Text = "整改人:";
                        //table.Cell(3, 2).Range.Text =
                        //    onepvs.SearchForProperty(PropSecureReceiver.ID)
                        //        .GetValueAsLocalizedText();
                        //table.Cell(3, 4).Range.Text =
                        //    onepvs.SearchForProperty(PropAdjustMan.ID)
                        //        .GetValueAsLocalizedText();
                        //   Writelog("debug info 333 v1-" + tableindex);
                        table.Cell(2, 3).Range.Text = "整改期限  :";
                        table.Cell(3, 3).Range.Text = "整改次数:";
                        table.Cell(2, 4).Range.Text =
                            onepvs.SearchForProperty(PropZhengGaiQiXin.ID)
                            .GetValueAsLocalizedText();
                        table.Cell(3, 4).Range.Text =
                            onepvs.SearchForProperty(PropRectificationCount.ID)
                            .GetValueAsLocalizedText();
                        //Writelog("debug info 444 v1-" + tableindex);
                        //table.Cell(rowindex, 1).Range.Text = "复查人  :";
                        table.Cell(3, 1).Range.Text = "复查日期:";
                        //table.Cell(5, 2).Range.Text =
                        //    onepvs.SearchForProperty(PropFuChaRen.ID)
                        //        .GetValueAsLocalizedText();
                        table.Cell(3, 2).Range.Text =
                            onepvs.SearchForProperty(PropReviewDate.ID)
                            .GetValueAsLocalizedText();
                        //    Writelog("debug info 555 v1-" + tableindex);
                        // int rowindex = 2;
                        table.Cell(4, 1).Range.Text = "整改前照片:";
                        table.Cell(6, 1).Range.Text = "复查照片:";
                        ObjectFiles files  = env.Vault.ObjectFileOperations.GetFiles(objectVersion.ObjVer);
                        int         picrow = 5;
                        //  Writelog("before 000000000000");
                        foreach (ObjectFile objectFile in files)
                        {
                            string apicture = temppath + objectFile.GetNameForFileSystem();
                            env.Vault.ObjectFileOperations.DownloadFile(objectFile.ID,
                                                                        objectFile.Version, apicture);
                            object      linkToFile       = false;
                            object      saveWithDocument = true;
                            object      anchor           = table.Cell(picrow, 1).Range;
                            InlineShape insh             = doc.InlineShapes.AddPicture(apicture, ref linkToFile,
                                                                                       ref saveWithDocument,
                                                                                       ref anchor);
                            insh.Height = 259;
                            insh.Width  = 416;
                            picrow     += 2;
                            if (picrow > 7)
                            {
                                break;
                            }
                        }
                    }
                    doc.Close();
                    app.Quit();
                }
                catch (Exception ex)
                {
                    Writelog(ex.Message);
                }

                var pvs = new PropertyValues();
                var pv  = new PropertyValue {
                    PropertyDef = 0
                };
                pv.Value.SetValue(MFDataType.MFDatatypeText, "securenoticereport");
                pvs.Add(-1, pv);
                pv.PropertyDef = 100;
                pv.Value.SetValueToLookup(new Lookup {
                    Item = ClassSecureReport
                });
                pvs.Add(-1, pv);
                var file = new SourceObjectFile {
                    Title = "report", SourceFilePath = templatefile, Extension = "docx"
                };

                try
                {
                    ObjectVersionAndProperties t = env.Vault.ObjectOperations.CreateNewSFDObject(0, pvs, file, true);
                    ObjectFiles f = env.Vault.ObjectFileOperations.GetFiles(t.ObjVer);

                    rpd.Objid       = t.ObjVer.ID;
                    rpd.Objtype     = t.ObjVer.Type;
                    rpd.Objversion  = t.ObjVer.Version;
                    rpd.Fileid      = f[1].FileVer.ID;
                    rpd.Fileversion = f[1].FileVer.Version;
                }
                catch (Exception ex)
                {
                    Writelog("getsecurenotice - create object :" + ex.Message);
                }
            }
            catch (Exception ex)
            {
                Writelog(env.Input + "GetSecureNotice error:" + ex.Message);
            }
            var ret = JsonConvert.SerializeObject(rpd, Formatting.None);
            Writelog("GetSecureNotice ok return:" + ret);
            return(ret);
        }
Example #29
0
        public static string GetWfnStates(EventHandlerEnvironment env)
        {
            var ret = new List <WfnState>();

            try
            {
                var vault = env.Vault;
                var input = env.Input;

                Writelog(string.Format("vault={0},input={1}", vault.Name, input));
                var pos   = input.IndexOf('-');
                var type  = int.Parse(input.Substring(0, pos));
                var id    = int.Parse(input.Substring(pos + 1, input.Length - pos - 1));
                var objid = new ObjID();
                objid.SetIDs(type, id);
                var history = vault.ObjectOperations.GetHistory(objid);
                Writelog(string.Format("type={0},id={1}", type, id));
                foreach (ObjectVersion objectVersion in history)
                {
                    Writelog(string.Format("Version={0}", objectVersion.ObjVer.Version));
                    var pvs            = vault.ObjectOperations.GetObjectVersionAndProperties(objectVersion.ObjVer).Properties;
                    var state          = GetPropertyValue(pvs, (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefState, vault);
                    var lastmodified   = GetPropertyValue(pvs, (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefLastModified, vault);
                    var lastmodifiedby = GetPropertyValue(pvs, (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefLastModifiedBy, vault);
                    //var stateentered = GetPropertyValue(pvs, (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefStateEntered, vault);
                    //var statechanged = GetPropertyValue(pvs, (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefStatusChanged, vault);
                    var taskdescription = GetPropertyValue(pvs, (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefAssignmentDescription, vault);
                    //var deadline = GetPropertyValue(pvs, (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefDeadline, vault);
                    //var monitor = GetPropertyValue(pvs, (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefMonitoredBy, vault);
                    var assignto  = GetPropertyValue(pvs, (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefAssignedTo, vault);
                    var task      = GetPropertyValue(pvs, (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefWorkflowAssignment, vault);
                    var signature = GetPropertyValue(pvs, (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefSignatureManifestation, vault);
                    //        var statetransition = GetPropertyValue(pvs, (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefStateTransition, vault);
                    var wfnstate   = new WfnState();
                    var creator    = GetPropertyValue(pvs, (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefCreatedBy, vault).GetValueAsLocalizedText();
                    var modifiedby = lastmodifiedby.GetValueAsLocalizedText();
                    //     Writelog(string.Format("111 Version={0}", objectVersion.ObjVer.Version));
                    wfnstate.User  = modifiedby.Contains("DBWorld") ? creator : modifiedby;
                    wfnstate.Time  = lastmodified.GetValueAsLocalizedText();
                    wfnstate.State = state.GetValueAsLocalizedText();
                    //    wfnstate.MFBuiltInPropertyDefStateTransition = statetransition.GetValueAsLocalizedText();
                    var tmpstr   = "-> \"" + wfnstate.State;
                    var signtext = signature.GetValueAsLocalizedText();
                    wfnstate.MFBuiltInPropertyDefSignatureManifestation = signtext.Contains(tmpstr) ? signtext : "无";
                    //  wfnstate.MFBuiltInPropertyDefSignatureManifestation =  signtext;
                    //      Writelog(string.Format("{0},{1}",tmpstr,signtext));
                    var text = task.GetValueAsLocalizedText();
                    //    Writelog(string.Format("222 Version={0}", objectVersion.ObjVer.Version));
                    if (text != string.Empty)
                    {
                        var tasks = task.Value.GetValueAsLookups();
                        //     Writelog(string.Format("444 Version={0}", objectVersion.ObjVer.Version));
                        foreach (Lookup lookup in tasks)
                        {
                            //  Writelog(string.Format("666 Version={0}", objectVersion.ObjVer.Version));
                            var taskobjid = new ObjID();
                            taskobjid.SetIDs((int)MFBuiltInObjectType.MFBuiltInObjectTypeAssignment, lookup.Item);
                            var taskobjpvs = vault.ObjectOperations.GetLatestObjectVersionAndProperties(taskobjid, true).Properties;
                            var assignee   = GetPropertyValue(taskobjpvs, (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefAssignedTo, vault).GetValueAsLocalizedText();
                            var tasktext   = GetPropertyValue(taskobjpvs, (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefAssignmentDescription, vault).GetValueAsLocalizedText();
                            var taskname   = GetPropertyValue(taskobjpvs, (int)MFBuiltInPropertyDef.MFBuiltInPropertyDefNameOrTitle, vault).GetValueAsLocalizedText();
                            wfnstate.MFBuiltInPropertyDefWorkflowAssignment += assignee != string.Empty ? "分配给:" + assignee + "," + taskname + "," + tasktext : taskname + "," + tasktext;
                        }
                    }
                    else
                    {
                        //  Writelog(string.Format("555 Version={0}", objectVersion.ObjVer.Version));
                        wfnstate.MFBuiltInPropertyDefWorkflowAssignment = text;
                    }
                    //  Writelog(string.Format("333 Version={0}", objectVersion.ObjVer.Version));
                    var temp        = assignto.GetValueAsLocalizedText();
                    var taskcontext = taskdescription.GetValueAsLocalizedText();
                    wfnstate.MFBuiltInPropertyDefAssignmentDescription = temp != string.Empty?"分配给:" + temp + "," + taskcontext:taskcontext;
                    ret.Add(wfnstate);
                }
            }
            catch (Exception ex)
            {
                Writelog("GetWfnStates error:" + ex.Message);
            }
            var retjson = JsonConvert.SerializeObject(ret, Formatting.None);

            //    Writelog("GetWfnStates-"+retjson);
            return(retjson);
        }
 private string GetMessageForNestedUIXApp(EventHandlerEnvironment env)
 {
     // Return the input and the alias and id of the test class. If the class is missing, ID is -1.
     return "Hello! I'm from the extension method! Here's the input you gave me: " + env.Input;
 }
Example #31
0
 public TestEnvironmentCommand(EventHandlerEnvironment env) : base(env)
 {
 }
        private string ImportXmlFile(EventHandlerEnvironment env)
        {
            // Sanity.
            if (null == env)
            {
                throw new ArgumentNullException(nameof(env));
            }
            if (string.IsNullOrWhiteSpace(env.Input))
            {
                throw new ArgumentException("The event handler input was empty and could not be processed.", nameof(env));
            }

            // Check that the input path is valid.
            foreach (var importInstruction in this.Configuration
                     .ImportInstructions
                     .Where(i => i.Enabled))
            {
                foreach (var path in importInstruction.PathsToSearch)
                {
                    // Attempt to find the path.
                    var directoryInfo = new DirectoryInfo(path);
                    if (false == directoryInfo.Exists)
                    {
                        continue;
                    }

                    // Identify the files by the search pattern.
                    foreach (var file in directoryInfo.GetFiles(importInstruction.SearchPattern))
                    {
                        // If the file path matches the one we were told to import then process it, otherwise die.
                        if (false == String.Equals(file.FullName, env.Input, StringComparison.CurrentCultureIgnoreCase))
                        {
                            continue;
                        }

                        // Import the file.
                        try
                        {
                            // Import the files.
                            var attachedFilesToDelete = this.ImportXmlFile(env.Vault, importInstruction, file);

                            // Delete the file and any attached files.
                            file.Delete();
                            foreach (var attachedFile in attachedFilesToDelete.Select(fi => fi.FullName.ToLower()).Distinct())
                            {
                                System.IO.File.Delete(attachedFile);
                            }
                        }
                        catch (Exception importException)
                        {
                            // Process the import exception.
                            this.HandleImportException(importInstruction, file, importException);

                            // Re-throw (force the transaction to roll back).
                            throw;
                        }
                    }
                }
            }

            // It worked.
            return("Success");
        }