/// <summary> /// Executes the local transaction. /// </summary> /// <param name="packageList">The list of packages belonging to one local transaction.</param> /// <param name="unitOfWork"></param> /// <returns> /// <c>true</c> if succeeded; otherwise, <c>false</c>. /// </returns> public bool ExecuteLocalTransaction(IEnumerable <ICommunicationPackage> packageList, IUnitOfWork unitOfWork) { bool result = true; Guid localTransactionId = Guid.NewGuid(); Guid currentPackageId = Guid.Empty; this.scriptFactory.UnitOfWork = unitOfWork; this.scriptFactory.LocalTransactionId = localTransactionId; this.scriptFactory.IsHeadquarter = this.isHeadquarter; this.scriptFactory.ExecutionController.IsDeffered = true; this.scriptFactory.ExecutionController.UnitOfWork = unitOfWork; CommunicationPackageRepository repo = new CommunicationPackageRepository(unitOfWork); Stopwatch timer = new Stopwatch(); timer.Start(); foreach (ICommunicationPackage communicationPackage in packageList) { var currentPackage = communicationPackage;//.Clone() as ICommunicationPackage; currentPackageId = communicationPackage.XmlData.Id; this.Log.Info("Wykonywanie paczki: " + communicationPackage.OrderNumber + "=" + currentPackageId); if (this.IsExecutionRequired(communicationPackage)) { XDocument commXml = XDocument.Parse(communicationPackage.XmlData.Content); IExecutingScript script = this.scriptFactory.CreateScript(communicationPackage.XmlData.XmlType, commXml); script.UnitOfWork = unitOfWork; script.Log = this.Log; try { this.BeforePackageExecution(unitOfWork); result = script.ExecutePackage(currentPackage); } catch (ConflictException) { this.Log.Error("Conflict was detected while executing package, id=" + currentPackageId); result = false; } } else { this.Log.Info("Pomijanie paczki: " + currentPackage.OrderNumber + "=" + currentPackageId); } if (result == false) { return(false); } } this.scriptFactory.ExecutionController.RunDefferedActions(); timer.Stop(); packageList.ToList().ForEach(p => p.ExecutionTime = timer.Elapsed.TotalSeconds); return(result); }
/// <summary> /// Creates object responsible for processing package of specified type. /// </summary> /// <param name="packageType">Type of the package to processed.</param> /// <param name="xmlPackage">The XML package to process.</param> /// <returns>Created package processing object.</returns> public IExecutingScript CreateScript(string packageType, XDocument xmlPackage) { if (packageType == null) { throw new ArgumentNullException("packageType"); } CommunicationPackageType packageTypeVal; try { packageTypeVal = (CommunicationPackageType)Enum.Parse(typeof(CommunicationPackageType), packageType); } catch (ArgumentException) { packageTypeVal = CommunicationPackageType.Unknown; } IExecutingScript script = null; switch (packageTypeVal) { case CommunicationPackageType.ComplaintDocumentSnapshot: script = new ComplaintDocumentSnapshot(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.Configuration: script = new ConfigurationScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.ContractorSnapshot: script = new ContractorScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.ContractorRelations: script = new ContractorRelationsScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.ContractorGroupMembership: script = new ContractorGroupMembershipScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.DictionaryPackage: script = new DictionarySnapshotScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.FileDescriptor: script = new FileDescriptorScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.FinancialReport: script = new FinancialReportScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.FinancialDocumentSnapshot: script = new FinancialDocumentScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.InventoryDocumentSnapshot: script = new InventoryDocumentScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.ItemSnapshot: script = new ItemSnapshotScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.ItemRelation: script = new ItemRelationScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.ItemUnitRelation: script = new ItemUnitRelationScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.ItemGroupMembership: script = new ItemGroupMembershipScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.CommercialDocumentSnapshot: script = new CommercialDocumentScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.CommercialDocumentSnapshotEx: script = new CommercialDocumentExScript(this.UnitOfWork, this.ExecutionController, this.IsHeadquarter); break; case CommunicationPackageType.Series: script = new SeriesScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.CommercialWarehouseValuation: script = new CommercialWarehouseValuation(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.CommercialWarehouseRelation: script = new CommercialWarehouseRelation(UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.DocumentRelation: script = new DocumentRelationScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.IncomeOutcomeRelation: script = new IncomeOutcomeRelation(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.Payment: script = new PaymentScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.WarehouseDocumentValuation: script = new WarehouseDocumentValuation(this.UnitOfWork, this.ExecutionController, this.IsHeadquarter); break; //TODO !! aktualnie WZk dotykajaca mmki bedzie traktowana jak by nie miala nic wspolnego z mmka // czyli nie zostanie przeslana do oddzialu docelowego case CommunicationPackageType.WarehouseDocumentSnapshot: if (xmlPackage.Root.Element("warehouseDocumentLine").Elements("entry").All(row => row.Element("isDistributed").Value.Equals("1"))) { DocumentType docType = DictionaryMapper.Instance.GetDocumentType(new Guid(xmlPackage.Root.Element("warehouseDocumentHeader") .Element("entry").Element("documentTypeId").Value)); if (docType.DocumentCategory != Makolab.Fractus.Kernel.Enums.DocumentCategory.IncomeWarehouseCorrection && docType.DocumentCategory != Makolab.Fractus.Kernel.Enums.DocumentCategory.OutcomeWarehouseCorrection) { script = new ShiftDocumentSnapshot(this.UnitOfWork, this.ExecutionController, this.IsHeadquarter); } else { script = new WarehouseDocumentSnapshot(this.UnitOfWork, this.ExecutionController, this.IsHeadquarter); } } else { script = new WarehouseDocumentSnapshot(this.UnitOfWork, this.ExecutionController, this.IsHeadquarter); } break; case CommunicationPackageType.WarehouseStock: script = new WarehouseStockScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.UnrelateCommercialDocument: script = new UnrelateCommercialDocumentScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.UnrelateWarehouseDocumentForOutcome: script = new UnrelateWarehouseDocumentForOutcomeScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.UnrelateWarehouseDocumentForIncome: script = new UnrelateWarehouseDocumentForIncomeScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.ShiftDocumentStatus: script = new ShiftDocumentStatusScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.PriceRule: script = new PriceRuleScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.PriceRuleList: script = new PriceRuleListScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.Custom: script = new CustomScript(this.UnitOfWork, this.ExecutionController); break; case CommunicationPackageType.Unknown: case CommunicationPackageType.Other: default: script = new NullScript(); break; } script.LocalTransactionId = this.LocalTransactionId; return(script); }