public override void Execute(IServiceProvider serviceProvider)
        {
            base.Execute(serviceProvider);

            try
            {
                lys_communication    createdCommunication = GetTargetAs <Entity>().ToEntity <lys_communication>();
                IOrganizationService currentUserService   = CreateService();

                NavCommunicationHandler communicationHandler = new NavCommunicationHandler(currentUserService, TraceService);

                // 5.6
                communicationHandler.CheckMultipleMainCommunications(createdCommunication);
            }
            catch (EntityHandlerException e)
            {
                TraceService.Trace(e.ToString());
                throw new InvalidPluginExecutionException(e.Message);
            }
            catch (Exception e)
            {
                TraceService.Trace(e.ToString());
                throw new InvalidPluginExecutionException("Возникла ошибка, см. журнал для подробностей.");
            }
        }
Esempio n. 2
0
        public override void Execute(IServiceProvider serviceProvider)
        {
            base.Execute(serviceProvider);

            try
            {
                lys_invoice          createdInvoice     = GetTargetAs <Entity>().ToEntity <lys_invoice>();
                IOrganizationService currentUserService = CreateService();

                // 5.1
                if (createdInvoice.lys_type == null)
                {
                    createdInvoice.lys_type = lys_invoice_lys_type.Ruchnoe_sozdanie;
                }

                NavInvoiceHandler invoiceHandler = new NavInvoiceHandler(currentUserService, TraceService);

                // 5.4
                invoiceHandler.UpdateInvoiceDate(createdInvoice, true);
            }
            catch (EntityHandlerException e)
            {
                TraceService.Trace(e.ToString());
                throw new InvalidPluginExecutionException(e.Message);
            }
            catch (Exception e)
            {
                TraceService.Trace(e.ToString());
                throw new InvalidPluginExecutionException("Возникла ошибка, см. журнал для подробностей.");
            }
        }
Esempio n. 3
0
        public override void Execute(IServiceProvider serviceProvider)
        {
            base.Execute(serviceProvider);

            if (PluginExecutionContext.Depth > 1)
            {
                // Recursive update.
                return;
            }

            try
            {
                lys_agreement        updatedAgreement   = GetTargetAs <Entity>().ToEntity <lys_agreement>();
                IOrganizationService currentUserService = CreateService();

                NavAgreementHandler agreementHandler = new NavAgreementHandler(currentUserService, TraceService);

                // 5.5
                agreementHandler.UpdateFact(updatedAgreement);
            }
            catch (EntityHandlerException e)
            {
                TraceService.Trace(e.ToString());
                throw new InvalidPluginExecutionException(e.Message);
            }
            catch (Exception e)
            {
                TraceService.Trace(e.ToString());
                throw new InvalidPluginExecutionException("Возникла ошибка, см. журнал для подробностей.");
            }
        }
Esempio n. 4
0
        public override void Execute(IServiceProvider serviceProvider)
        {
            base.Execute(serviceProvider);

            try
            {
                lys_invoice          createdInvoice     = GetTargetAs <Entity>().ToEntity <lys_invoice>();
                IOrganizationService currentUserService = CreateService();

                NavInvoiceHandler invoiceHandler = new NavInvoiceHandler(currentUserService, TraceService);

                // 5.3
                // 5.5
                invoiceHandler.UpdateRelatedAgreementFactData(createdInvoice);
            }
            catch (EntityHandlerException e)
            {
                TraceService.Trace(e.ToString());
                throw new InvalidPluginExecutionException(e.Message);
            }
            catch (Exception e)
            {
                TraceService.Trace(e.ToString());
                throw new InvalidPluginExecutionException("Возникла ошибка, см. журнал для подробностей.");
            }
        }
        protected override void Execute(CodeActivityContext context)
        {
            Init(context);

            try
            {
                IOrganizationService currentUserService = CreateService();
                NavAgreementHandler  agreementHandler   = new NavAgreementHandler(currentUserService, TraceService);

                lys_agreement agreement = new lys_agreement
                {
                    Id = Agreement.Get(context).Id
                };

                // 6.1
                agreementHandler.CreateFirstRelatedInvoice(agreement, WorkflowContext.UserId);
            }
            catch (EntityHandlerException e)
            {
                TraceService.Trace(e.ToString());
                throw new InvalidWorkflowException(e.Message);
            }
            catch (Exception e)
            {
                TraceService.Trace(e.ToString());
                throw new InvalidWorkflowException("Возникла ошибка, см. журнал для подробностей.");
            }
        }
        private Dictionary <string, String> GetStaticParameters(CodeActivityContext executionContext)
        {
            TraceService.Trace("Getting Static Parameters");
            string jsonTypeFormattersString;

            if (this.WorkflowContext.InputParameters.Contains("StaticParameters"))
            {
                jsonTypeFormattersString = this.WorkflowContext.InputParameters["StaticParameters"] as string;
            }
            else
            {
                jsonTypeFormattersString = this.StaticParameters.Get <String>(executionContext);
            }

            if (!string.IsNullOrEmpty(jsonTypeFormattersString))
            {
                TraceService.Trace("Static Parameters (JSON string): {0}", jsonTypeFormattersString);
                try
                {
                    Dictionary <string, String> staticParameters = JsonConvert.DeserializeObject(jsonTypeFormattersString, typeof(Dictionary <string, String>)) as Dictionary <string, String>;

                    TraceService.Trace("Static Parameters have been deserialised. Count: {0}", staticParameters == null ? "Null" : staticParameters.Count.ToString());

                    return(staticParameters);
                }
                catch (Exception exc)
                {
                    throw new InvalidPluginExecutionException(string.Format("There was an exception deserialising the Static Parameters '{0}'. Error Message: {1}. Exception type: {2}", jsonTypeFormattersString, exc.Message, exc.GetType()));
                }
            }
            else
            {
                return(null);
            }
        }
Esempio n. 7
0
 private void AttemptToTraceTracingException(string format, object[] args, Exception ex)
 {
     try
     {
         if (args == null)
         {
             TraceService.Trace((format == null
                                    ? "Exception occured attempting to trace null and null args."
                                    : $@"Exception occured attempting to trace: ""{format}"" and null args.") + Environment.NewLine + ex);
         }
         else
         {
             try
             {
                 format = args.Length == 0 ? format : string.Format(format ?? "NULL", args);
                 TraceService.Trace($"Exception occured attempting to trace {format}.{Environment.NewLine + ex}");
             }
             catch
             {
                 var argsText = $"[{string.Join(", ", args)}]";
                 TraceService.Trace($"Exception occured attempting to trace and then handle format for {format} with {argsText}.{Environment.NewLine + ex}");
             }
         }
     }
     // ReSharper disable once EmptyGeneralCatchClause
     catch
     {
         // Attempted to trace a message, and had an exception, and then had another exception attempting to trace the exception that occured when tracing.
         // Better to give up rather than stopping the entire program when attempting to write a Trace message
     }
 }
        private void SendEmail(EntityReference newEmailReference, CodeActivityContext executionContext)
        {
            TraceService.Trace("Entering SendEmail method");
            if ((this.WorkflowContext.InputParameters.Contains("SendInstantly") &&
                 ((bool)this.WorkflowContext.InputParameters["SendInstantly"]) == true)
                ||
                (this.SendInstantly != null
                 &&
                 this.SendInstantly.Get <Boolean>(executionContext) == true)
                )
            {
                TraceService.Trace("Email is going to be sent");

                SendEmailRequest sendRequest = new SendEmailRequest()
                {
                    EmailId = newEmailReference.Id
                    ,
                    IssueSend = GetIssueSend(executionContext)
                    ,
                    TrackingToken = GetTrackingToken(executionContext)
                };

                SendEmailResponse sendEmailResponse = this.OrganizationService.Execute(sendRequest) as SendEmailResponse;

                this.Subject.Set(executionContext, sendEmailResponse.Subject);

                TraceService.Trace("Email has been sent correclty with subject " + sendEmailResponse.Subject);
            }
            else
            {
                this.Subject.Set(executionContext, string.Empty);
            }
        }
 private EntityReference GetRegarding(CodeActivityContext executionContext)
 {
     TraceService.Trace("Getting Regarding");
     if (this.WorkflowContext.InputParameters.Contains("Regarding"))
     {
         EntityReference regarding = this.WorkflowContext.InputParameters["Regarding"] as EntityReference;
         if (regarding.Id.Equals(Guid.Empty))
         {
             return(null);
         }
         else
         {
             return(regarding);
         }
     }
     else
     {
         string regardingRecordURL = this.EmailRegardingRecordURL.Get <String>(executionContext);
         if (string.IsNullOrEmpty(regardingRecordURL))
         {
             return(null);
         }
         else
         {
             return(ConvertURLtoEntityReference(regardingRecordURL));
         }
     }
 }
        protected override void ExecuteActivity(System.Activities.CodeActivityContext executionContext)
        {
            TraceService.Trace("Entering GetProcessPropertiesActivity");

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Worflow Category: " + WorkflowContext.WorkflowCategory);

            sb.AppendLine("The following Values were in the InputParameters:");
            foreach (KeyValuePair <string, object> pair in WorkflowContext.InputParameters)
            {
                sb.AppendLine(pair.Key);
            }

            sb.AppendLine("The following Values were in the OutputParameters:");
            foreach (KeyValuePair <string, object> pair in WorkflowContext.OutputParameters)
            {
                sb.AppendLine(pair.Key);
            }


            sb.AppendLine("End of GetProcessPropertiesActivity");

            throw new Exception(sb.ToString());
        }
        private EntityReferenceCollection GetRecipient(CodeActivityContext executionContext)
        {
            TraceService.Trace("Getting Recipient");
            EntityReferenceCollection toRecipient = new EntityReferenceCollection();

            if (this.WorkflowContext.InputParameters.Contains("ToRecipient"))
            {
                EntityCollection toRecipientEntityCollection = this.WorkflowContext.InputParameters["ToRecipient"] as EntityCollection;
                foreach (Entity toRecipientEntity in toRecipientEntityCollection.Entities)
                {
                    toRecipient.Add(toRecipientEntity.ToEntityReference());
                }
                return(toRecipient);
            }
            else
            {
                string toRecipientRecordURL = this.ToRecipientRecordURL.Get <String>(executionContext);
                if (string.IsNullOrEmpty(toRecipientRecordURL))
                {
                    return(null);
                }
                else
                {
                    toRecipient.Add(ConvertURLtoEntityReference(toRecipientRecordURL));
                    return(toRecipient);
                }
            }
        }
 private Boolean GetIssueSend(CodeActivityContext executionContext)
 {
     TraceService.Trace("Getting IssueSend input argument");
     if (this.WorkflowContext.InputParameters.Contains("IssueSend"))
     {
         return((Boolean)this.WorkflowContext.InputParameters["IssueSend"]);
     }
     else
     {
         return(this.IssueSend.Get <Boolean>(executionContext));
     }
 }
 private string GetTrackingToken(CodeActivityContext executionContext)
 {
     TraceService.Trace("Getting TrackingToken input argument");
     if (this.WorkflowContext.InputParameters.Contains("TrackingToken"))
     {
         return(this.WorkflowContext.InputParameters["TrackingToken"] as string);
     }
     else
     {
         return(this.TrackingToken.Get <String>(executionContext));
     }
 }
 private bool GetAllowDuplicateAttachments(CodeActivityContext executionContext)
 {
     TraceService.Trace("Getting AllowDuplicateAttachments argument");
     if (this.WorkflowContext.InputParameters.Contains("AllowDuplicateAttachments"))
     {
         return((Boolean)this.WorkflowContext.InputParameters["AllowDuplicateAttachments"]);
     }
     else
     {
         return(this.AllowDuplicateAttachments.Get <Boolean>(executionContext));
     }
 }
 private bool GetOnlyUseAttachmentsInTemplate(CodeActivityContext executionContext)
 {
     TraceService.Trace("Getting OnlyUseAttachmentsInTemplate argument");
     if (this.WorkflowContext.InputParameters.Contains("OnlyUseAttachmentsInTemplate"))
     {
         return((Boolean)this.WorkflowContext.InputParameters["OnlyUseAttachmentsInTemplate"]);
     }
     else
     {
         return(this.OnlyUseAttachmentsInTemplate.Get <Boolean>(executionContext));
     }
 }
 private string GetEmailTemplateName(CodeActivityContext executionContext)
 {
     TraceService.Trace("Getting Email Template Name");
     if (this.WorkflowContext.InputParameters.Contains("EmailTemplateName"))
     {
         return(this.WorkflowContext.InputParameters["EmailTemplateName"] as string);
     }
     else
     {
         return(this.EmailTemplateName.Get <String>(executionContext));
     }
 }
Esempio n. 17
0
        protected override void ConfigureServiceLocator()
        {
            base.ConfigureServiceLocator();
            string xs    = "\0\0\0\0\0";
            bool   empty = xs.All(c => c == '\0');

            Database db     = new Database(@"H:\X\MM.sqlite");
            var      tables = db.Tables;
            var      ts     = new TableSignature("ABPerson");

            var rs      = db.ReadTableRecords(ts, true);
            var deletes = rs.Where(r => r.Deleted == DeletedState.Deleted).ToList();

            foreach (var r in rs)
            {
                TraceService.Trace(TraceLevel.Info, $"{r["text"]?.Value}:{r.Deleted}");
            }



            PA.InfraLib.Services.Registor.RegAllServices(Container);
            PA.Logic.Services.Registor.RegAllServices(Container);

            //这个路径改成你们电脑上的实际案例路径

            //新的测试用法
            //1.在Bin/Plugins目录下找到config.dat,修改里面的内容,把你的脚本的配置加进去(如果没有加的话)
            //2.如果只需要跑你指定的脚本,将Bin/Plugins的其他脚本移走,只留下你要测试的脚本和其依赖脚本
            //3.测试
            //4.
            //这个路径改成你们电脑上的实际案例路径,支持多镜像案例(比如安卓的全盘包括data.img和external_data.img)
            string casePath = @"I:\Cases\HUAWEI NXT-AL10__201811201125_逻辑镜像(Root)\Manifest.PGFD";
            var    importer = new CaseImportService();
            var    pack     = CasePackage.FromPath(casePath);


            //演示如何从厂商备份构建
            //var pack = importer.FromExtenalEnvidence(@"H:\X\backup.ab", ImportType.AndroidBackup); //从*.ab文件构建
            //var pack = importer.FromExtenalEnvidence(@"H:\X\backup.ab", ImportType.AndroidBackup); //从*.ab文件构建
            //var pack = importer.FromExtenalEnvidence(@"H:\X\2019-01-16_16-32-21", ImportType.HuaweiBackup); //从华为自备份目录构建,注意华为可以设置密码,*.db会被解成*.dbx,优先使用*.dbx(明文数据库)
            if (pack != null && pack.RpcClient.Connect())
            {
                var task = pack.LoadData();
                task.Wait();
                Console.WriteLine("程序走到这里,表明脚本跑完了,程序将会退出");
            }
            else
            {
                Console.WriteLine("案例配置不正确,换个案例");
            }
        }
        public void TraceTestReferenceMethodTest()
        {
            var moduleDef   = Helpers.LoadTestModuleDef();
            var thisTypeDef = moduleDef.Find("Confuser.Core.Test.Services.TraceServiceTest", false);
            var refMethod   = thisTypeDef.FindMethod(nameof(TestReferenceMethod));

            var traceService = new TraceService();
            var methodTrace  = traceService.Trace(refMethod);

            var getMethodCall = refMethod.Body.Instructions.Single(i => i.OpCode == OpCodes.Call && i.Operand.ToString().Contains("GetMethod"));
            var arguments     = methodTrace.TraceArguments(getMethodCall);

            Assert.NotNull(arguments);
        }
        private EntityReference GetSender(CodeActivityContext executionContext)
        {
            TraceService.Trace("Getting Sender");
            if (this.WorkflowContext.InputParameters.Contains("FromSender"))
            {
                EntityReference fromSender = this.WorkflowContext.InputParameters["FromSender"] as EntityReference;
                if (fromSender.Id.Equals(Guid.Empty))
                {
                    return(null);
                }
                else
                {
                    return(fromSender);
                }
            }
            else
            {
                string senderEmailAddress = this.SenderEmailAddress.Get <String>(executionContext);
                if (string.IsNullOrEmpty(senderEmailAddress))
                {
                    throw new ArgumentNullException("Sender Email Address", "'Sender Email Address' cannot be null, a user or queue mail must be provided");
                }

                QueryExpression userQuery = new QueryExpression("systemuser");
                userQuery.NoLock = true;
                userQuery.Criteria.AddCondition("internalemailaddress", ConditionOperator.Equal, senderEmailAddress);

                EntityCollection results = OrganizationService.RetrieveMultiple(userQuery);
                if (results.Entities.Count > 0)
                {
                    return(results.Entities[0].ToEntityReference());
                }
                else
                {
                    QueryExpression queueQuery = new QueryExpression("queue");
                    queueQuery.NoLock = true;
                    queueQuery.Criteria.AddCondition("emailaddress", ConditionOperator.Equal, senderEmailAddress);

                    results = OrganizationService.RetrieveMultiple(queueQuery);
                    if (results.Entities.Count > 0)
                    {
                        return(results.Entities[0].ToEntityReference());
                    }
                    else
                    {
                        throw new Exception(string.Format("User or Queue couldn't be found with email address {0}", senderEmailAddress));
                    }
                }
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Executes the workflow activity.
        /// </summary>
        /// <param name="executionContext">The execution context.</param>
        protected override void Execute(CodeActivityContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("Code Activity Context is null");
            }

            ITracingService tracingService = executionContext.GetExtension <ITracingService>();

            DXTools.CRM.Solutions.CustomEmails.Common.TraceService.Initialise(tracingService);

            if (tracingService == null)
            {
                throw new InvalidPluginExecutionException("Failed to retrieve tracing service.");
            }

            IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>();

            this.WorkflowContext = context;

            if (context == null)
            {
                throw new InvalidPluginExecutionException("Failed to retrieve workflow context.");
            }

            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
            IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

            OrganizationServiceFactory = serviceFactory;
            OrganizationService        = service;

            tracingService.Trace("Entered custom activity, Correlation Id: {0}, Initiating User: {1}", context.CorrelationId, context.InitiatingUserId);

            try
            {
                TraceService.Trace("Entering ExecuteActivity {0}. Correlation Id: {1}", this.GetType().FullName, context.CorrelationId);
                this.ExecuteActivity(executionContext);
                TraceService.Trace("Ending ExecuteActivity {0}.  Correlation Id: {1}", this.GetType().FullName, context.CorrelationId);
            }
            catch (Exception e)
            {
                ExceptionOccured.Set(executionContext, true);
                ExceptionMessage.Set(executionContext, e.Message);

                if (FailOnException.Get <bool>(executionContext))
                {
                    throw new InvalidPluginExecutionException(e.Message, e);
                }
            }
        }
Esempio n. 21
0
 protected void OnModuleImported(PythonDataPlugin plugin, DataStore ds, ScriptWrapper sc)
 {
     try
     {
         //获取脚本方函数对象,函数的原型是请参考apple_apps.py里面的run
         var func = sc.GetScopeFunction <DataStore, bool, IDescriptiveProgress, CancellationToken, ParserResults>($"run");
         if (func != null)
         {
             //运行此函数(建议在脚本里断点调试)
             var results = func(ds, true, plugin.Progress, plugin.CancellationToken);
         }
     }
     catch (Exception e)
     {
         TraceService.Trace(TraceLevel.Error, e.Message);
     }
 }
Esempio n. 22
0
        /// <inheritdoc />
        public virtual void Trace(string format, params object[] args)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(format) || TraceService == null)
                {
                    return;
                }

                var trace = args.Length == 0
                    ? format
                    : string.Format(format, args);
                TraceHistory.AppendLine(trace);
                TraceService.Trace(trace);
            }
            catch (Exception ex)
            {
                AttemptToTraceTracingException(format, args, ex);
            }
        }
Esempio n. 23
0
        protected override void Execute(CodeActivityContext context)
        {
            Init(context);

            try
            {
                IOrganizationService currentUserService = CreateService();
                NavAgreementHandler  agreementHandler   = new NavAgreementHandler(currentUserService, TraceService);

                lys_agreement agreement = new lys_agreement
                {
                    Id = Agreement.Get(context).Id
                };

                // 6.2
                agreementHandler.CreateRelatedCreditInvoices(agreement);
            }
            catch (Exception e)
            {
                // Can't display any errors since it's a background activity.
                TraceService.Trace(e.ToString());
            }
        }
Esempio n. 24
0
        public override void Execute(IServiceProvider serviceProvider)
        {
            base.Execute(serviceProvider);

            if (PluginExecutionContext.Depth > 1)
            {
                // Recursive update.
                return;
            }

            try
            {
                lys_invoice          updatedInvoice     = GetTargetAs <Entity>().ToEntity <lys_invoice>();
                IOrganizationService currentUserService = CreateService();

                NavInvoiceHandler invoiceHandler = new NavInvoiceHandler(currentUserService, TraceService);

                // 5.3
                // 5.5.
                invoiceHandler.UpdateRelatedAgreementFactData(updatedInvoice);

                // 5.4
                invoiceHandler.UpdateInvoiceDate(updatedInvoice);
            }
            catch (EntityHandlerException e)
            {
                TraceService.Trace(e.ToString());
                throw new InvalidPluginExecutionException(e.Message);
            }
            catch (Exception e)
            {
                TraceService.Trace(e.ToString());
                throw;
                //throw new InvalidPluginExecutionException(Properties.strings.ErrorMessage);
            }
        }
        private string[] GetAttachments(CodeActivityContext executionContext)
        {
            TraceService.Trace("Getting attachments");

            string attachments = null;

            if (this.WorkflowContext.InputParameters.Contains("Attachments"))
            {
                attachments = this.WorkflowContext.InputParameters["Attachments"].ToString();
            }
            else
            {
                attachments = this.Attachments.Get <string>(executionContext);
            }

            if (string.IsNullOrEmpty(attachments))
            {
                return(null);
            }
            else
            {
                return(attachments.Split(','));
            }
        }
 public void Trace(string msg)
 {
     TraceService.Trace(msg);
 }