示例#1
0
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="arg">
        /// The SampleArgument argument.
        /// </param>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The <see cref="JobInfoArgument"/>.
        /// </returns>
        public override async Task <JobInfoArgument> Run(JobInfoArgument arg, CommercePipelineExecutionContext context)
        {
            if (arg == null || arg.JobConnection == null || !arg.JobConnection.Type.Equals("flat file", StringComparison.OrdinalIgnoreCase))
            {
                return(arg);
            }
            try
            {
                var customersFromERP = GetCustomersFromFlatFile(arg.JobConnection);
                var entityViewArg    = new EntityViewArgument();
                entityViewArg.ViewName  = "Details";
                entityViewArg.ForAction = "AddCustomer";
                var view = await _getEntityViewPipeline.Run(entityViewArg, context);

                view.Properties.FirstOrDefault(v => v.Name.Equals("FirstName", StringComparison.OrdinalIgnoreCase)).Value =
                    customersFromERP.FirstName;
                view.Properties.FirstOrDefault(v => v.Name.Equals("LastName", StringComparison.OrdinalIgnoreCase)).Value =
                    customersFromERP.LastName;
                view.Properties.FirstOrDefault(v => v.Name.Equals("email", StringComparison.OrdinalIgnoreCase)).Value =
                    customersFromERP.Email;
                view.Properties.FirstOrDefault(v => v.Name.Equals("AccountStatus", StringComparison.OrdinalIgnoreCase)).Value =
                    customersFromERP.AccountStatus;
                //view.Properties.FirstOrDefault(v => v.Name.Equals("Language", StringComparison.OrdinalIgnoreCase)).Value =context.CommerceContext.CurrentLanguage();
                view = await _doActionPipeline.Run(view, context);

                if (context.CommerceContext.HasErrors())
                {
                    arg.JobInstance.Status = "Failure";
                }
                else
                {
                    arg.JobInstance.Status = "Success";
                }
                //var messages = context.CommerceContext.GetMessages();
            }
            catch (Exception ex)
            {
                string str = await context.CommerceContext.AddMessage(context.GetPolicy <KnownResultCodes>().Error, "Error", new object[1]
                {
                    arg.JobInstance.FriendlyId,
                }, ex.Message);

                arg.JobInstance.Status = "Failure";
            }
            return(arg);
        }
        private async Task AddCustomer(ErpCustomer erpCustomer, CommercePipelineExecutionContext context)
        {
            var entityView = new EntityView();

            entityView.EntityId    = $"{(object)CommerceEntity.IdPrefix<Customer>()}{erpCustomer.AccountNumber}";
            entityView.Name        = "Details";
            entityView.DisplayName = "Details";
            entityView.Action      = "AddCustomer";
            entityView.ChildViews  = new List <Model>();
            entityView.DisplayRank = 500;
            entityView.UiHint      = "Flat";
            entityView.Icon        = "chart_column_stacked";
            entityView.Properties  = new List <ViewProperty>()
            {
                new ViewProperty()
                {
                    Name         = "Version",
                    DisplayName  = "Version",
                    Value        = "1",
                    IsHidden     = true,
                    OriginalType = "System.Int32",
                    IsRequired   = true,
                    IsReadOnly   = true,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                },
                new ViewProperty()
                {
                    Name         = "FirstName",
                    DisplayName  = "First Name",
                    Value        = erpCustomer.FirstName,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = false,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new MaxLengthPolicy()
                        {
                            MaxLengthAllow = 100,
                            Models         = new List <Model>(),
                            PolicyId       = "e9150513558d4ba080accc7fa84fad00"
                        }
                    }
                },
                new ViewProperty()
                {
                    Name         = "LastName",
                    DisplayName  = "Last Name",
                    Value        = erpCustomer.LastName,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = false,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new MaxLengthPolicy()
                        {
                            MaxLengthAllow = 100,
                            Models         = new List <Model>(),
                            PolicyId       = "70fdc77e288143c5ae050fe171ffffd3"
                        }
                    }
                },
                new ViewProperty()
                {
                    Name         = "Email",
                    DisplayName  = "Email",
                    Value        = erpCustomer.Email,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = true,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new MaxLengthPolicy()
                        {
                            MaxLengthAllow = 100,
                            Models         = new List <Model>(),
                            PolicyId       = "960bae42b5084ae48b3c0770260587aa"
                        }
                    }
                },
                new ViewProperty()
                {
                    Name         = "AccountStatus",
                    DisplayName  = "Account Status",
                    Value        = erpCustomer.AccountStatus,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = true,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new AvailableSelectionsPolicy()
                        {
                            Models           = new List <Model>(),
                            PolicyId         = "3250891c884c4ba08c5fff2835cdc914",
                            AllowMultiSelect = false,
                            List             = new List <Selection>()
                            {
                                new Selection()
                                {
                                    Name        = "ActiveAccount",
                                    Policies    = new List <Policy>(),
                                    DisplayName = "Active",
                                    IsDefault   = false
                                },
                                new Selection()
                                {
                                    Name        = "InactiveAccount",
                                    Policies    = new List <Policy>(),
                                    DisplayName = "Inactive",
                                    IsDefault   = false
                                },
                                new Selection()
                                {
                                    Name        = "RequiresApproval",
                                    Policies    = new List <Policy>(),
                                    DisplayName = "Requires Approval",
                                    IsDefault   = false
                                }
                            }
                        }
                    }
                },
                new ViewProperty()
                {
                    Name         = "PhoneNumber",
                    DisplayName  = "Phone",
                    Value        = erpCustomer.PhoneNumber,
                    IsHidden     = false,
                    OriginalType = "System.String",
                    IsRequired   = true,
                    UiType       = string.Empty,
                    Policies     = new List <Policy>()
                    {
                        new MaxLengthPolicy()
                        {
                            MaxLengthAllow = 50,
                            Models         = new List <Model>(),
                            PolicyId       = "30b9ad5b9e014b3a8697967280cd2596"
                        }
                    }
                }
                //new ViewProperty()
                //{
                //    Name = "Language",
                //    DisplayName = "Language",
                //    Value = "en",
                //    IsHidden = false,
                //    OriginalType = "System.String",
                //    IsRequired = true,
                //    UiType = string.Empty,
                //    Policies = new List<Policy>()
                //    {
                //        new AvailableSelectionsPolicy()
                //        {
                //            Models = new List<Model>(),
                //            PolicyId = "beaebd811a8747db8b0577c4165f4118",
                //            AllowMultiSelect = false,
                //            List = new List<Selection>()
                //            {
                //                new Selection()
                //                {
                //                    Name = "en",
                //                    Policies = new List<Policy>(),
                //                    DisplayName = "en",
                //                    IsDefault = false
                //                },
                //                new Selection()
                //                {
                //                    Name = "de-DE",
                //                    Policies = new List<Policy>(),
                //                    DisplayName = "de-DE",
                //                    IsDefault = false
                //                },
                //                new Selection()
                //                {
                //                    Name = "fr-FR",
                //                    Policies = new List<Policy>(),
                //                    DisplayName = "fr-FR",
                //                    IsDefault = false
                //                }
                //            }
                //        }
                //    }
                //}
            };

            var viewCustomer = await _doActionPipeline.Run(entityView, context);

            foreach (var erpCustomerAddress in erpCustomer.ErpCustomerAddressList)
            {
                await AddAddress(erpCustomerAddress, viewCustomer.EntityId, context);
            }
        }