Пример #1
0
        private static void OnApportion(IStartAddin msg)
        {
            DocSetId.Value = msg.Entity.Id;

            EventMessageBus.Current.GetEvent <IEntitySetWithChangesLoaded>(
                new StateEventInfo(msg.Process, Entity.Events.EntitySetLoaded, Source.SourceId), Source).Where(x => x.EntityType.Name == "AsycudaDocumentSetExpenses" && x.Process.Id == msg.Process.Id)
            .Where(x => x.ProcessInfo.EventKey == Source.SourceId)
            .Subscribe(x => OnSetExpensesReceived(x));

            EventMessageBus.Current.Publish(new GetEntitySetWithChanges("ExactMatch",
                                                                        DynamicEntityTypeExtensions.GetOrAddDynamicEntityType("AsycudaDocumentSetExpenses"), new Dictionary <string, dynamic>()
            {
                { "AsycudaDocumentSetId", msg.Entity.Id }
            },
                                                                        process: msg.Process,
                                                                        processInfo: new StateCommandInfo(msg.Process, RevolutionData.Context.CommandFunctions.UpdateCommandData("AsycudaDocumentSetExpenses", Entity.Commands.LoadEntitySetWithChanges), Source.SourceId),
                                                                        source: Source));


            EventMessageBus.Current.GetEvent <IEntitySetWithChangesLoaded>(
                new StateEventInfo(msg.Process, Entity.Events.EntitySetLoaded, Source.SourceId), Source).Where(x => x.EntityType.Name == "xcuda_Item" && x.Process.Id == msg.Process.Id)
            .Where(x => x.ProcessInfo.EventKey == Source.SourceId)
            .Subscribe(x => OnDocumentItemsReceived(x));



            // get Documents with value for documentSet

            // get document expenses for document set
            // Sum documents to get Total document value
            // Apportion expenes to document Expenses based on factor
            // publish document expenses
            // for each document in document set
            // get document expenses
            // get document items statistical value
            // sum document item statistical value to get document total
            // apportion document expenses to document items
            // publish document item expenses
        }
Пример #2
0
        private static void OnImport(IStartAddin msg)
        {
            //StatusModel.Timer("Importing Documents");
            //import asycuda xml id and details
            if (msg.Entity == null || msg.Entity.Id == 0)
            {
                MessageBox.Show("Please Select Asycuda Document Set");
                return;
            }


            var od = new OpenFileDialog();

            od.DefaultExt  = ".xml";
            od.Filter      = "Xml Documents (.xml)|*.xml";
            od.Multiselect = true;
            var result = od.ShowDialog();

            if (result == true)
            {
                //StatusModel.Timer(string.Format("Importing {0} files", od.FileNames.Count()));
                //StatusModel.StartStatusUpdate("Importing files", od.FileNames.Count());
                //StatusModel.RefreshNow();
                foreach (var f in od.FileNames)
                {
                    if (ASYCUDA.CanLoadFromFile(f))
                    {
                        var a   = Asycuda421.ASYCUDA.LoadFromFile(f);
                        var res = AsycudaToDataBase421.Instance.Import(a, msg.Entity);
                        var de  = new DynamicEntity(
                            new DynamicEntityType("xcuda_ASYCUDA", "xcuda_ASYCUDA",
                                                  new List <IEntityKeyValuePair>(), new Dictionary <string, List <dynamic> >(),
                                                  new ObservableDictionary <string, Dictionary <int, dynamic> >(),
                                                  new List <IDynamicRelationshipType>(), new List <IDynamicRelationshipType>(),
                                                  DynamicEntityType.NullEntityType(),
                                                  new ObservableList <IAddinAction>()), 0,
                            new Dictionary <string, object>());

                        EventMessageBus.Current.Publish(new UpdateEntityWithChanges(de,
                                                                                    res.Properties.ToDictionary(x => x.Key, x => x.Value),
                                                                                    new StateCommandInfo(msg.Process,
                                                                                                         RevolutionData.Context.CommandFunctions.UpdateCommandData(de.EntityType.Name,
                                                                                                                                                                   RevolutionData.Context.Entity.Commands.CreateEntity)), msg.Process, Source));
                    }
                    else
                    {
                        throw new ApplicationException(string.Format("Can not Load file '{0}'", f));
                    }
                }

                var cnt = od.FileNames.Length;
                var t   = 0;
                EventMessageBus.Current.GetEvent <IEntityWithChangesUpdated>(
                    new StateEventInfo(msg.Process, Entity.Events.EntityUpdated), Source)
                .Where(x => x.EntityType.Name == "xcuda_ASYCUDA" && x.Process.Id == msg.Process.Id)
                .Subscribe(x =>
                {
                    t += 1;
                    if (t == cnt)
                    {
                        MessageBox.Show("Complete");
                    }
                });


                //StatusModel.StopStatusUpdate();
            }
            // StatusModel.StopStatusUpdate();
        }