Esempio n. 1
0
        protected override void Execute(NativeActivityContext context)
        {
            var width    = DialogWidth.Get(context);
            var height   = DialogHeight.Get(context);
            var workings = WorkingProp.Get(context);

            if (workings == null)
            {
                workings = new List <Working>();
            }

            var vm = (InputPlPosListViewModel)IoC.Instance.Resolve(typeof(InputPlPosListViewModel));

            vm.PanelCaption       = Title.Get(context);
            vm.ActionWorkflowCode = ActionWorkflowCode.Get(context);

            var source = Source.Get(context);

            if (source != null)
            {
                source.ForEach(p => p.AcceptChanges());
            }
            ((IModelHandler)vm).SetSource(new ObservableCollection <InputPlPos>(source));

            var viewService  = IoC.Instance.Resolve <IViewService>();
            var dialogResult = viewService.ShowDialogWindow(viewModel: vm, isRestoredLayout: true, isNotNeededClosingOnOkResult: true, width: width, height: height);

            if (dialogResult == true)
            {
                var result = ((IModelHandler)vm).GetSource() as IEnumerable <InputPlPos>;
                if (result == null)
                {
                    throw new DeveloperException("Source type is not IEnumerable.");
                }

                Result.Set(context, result.ToList());
            }
            DialogResult.Set(context, dialogResult);

            workings.Clear();
            if (vm.Workings != null)
            {
                foreach (var w in vm.Workings)
                {
                    var working = new Working();

                    try
                    {
                        working.SuspendNotifications();
                        WMSBusinessObject.Copy(w, working);
                        working.AcceptChanges();
                    }
                    finally
                    {
                        working.ResumeNotifications();
                    }
                    workings.Add(working);
                }
            }
            WorkingProp.Set(context, workings);

            var disposable = vm as IDisposable;

            if (disposable != null)
            {
                disposable.Dispose();
            }
        }