Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DBTable"/> class.
 /// </summary>
 /// <param name="tableElement">The xml element containing table.</param>
 /// <param name="document">The xml that this table belongs to.</param>
 public DBTable(XElement tableElement, DBXml document)
 {
     this.Document = document;
     this.Xml      = tableElement;
     this.rows     = new List <DBRow>();
     AddRows(tableElement.Elements("entry"));
 }
Esempio n. 2
0
        /// <summary>
        /// Executes the changeset. Operation is persisting changes to database.
        /// </summary>
        /// <param name="changeset">The changeset that is persisted.</param>
        public override void ExecuteChangeset(Makolab.Fractus.Communication.DBLayer.DBXml changeset)
        {
            //remove valuations that link to lines marked as deleted
            if (changeset.Table("warehouseDocumentValuation") != null && changeset.Table("warehouseDocumentLine") != null)
            {
                List <DBRow> deletedValuations = new List <DBRow>();
                foreach (var line in changeset.Table("warehouseDocumentLine").Rows.Where(l => l.Action == DBRowState.Delete))
                {
                    foreach (var valuation in changeset.Table("warehouseDocumentValuation").Rows)
                    {
                        if (valuation.Element("incomeWarehouseDocumentLineId").Value.Equals(line.Element("id").Value, StringComparison.OrdinalIgnoreCase) ||
                            valuation.Element("outcomeWarehouseDocumentLineId").Value.Equals(line.Element("id").Value, StringComparison.OrdinalIgnoreCase))
                        {
                            deletedValuations.Add(valuation);
                        }
                    }
                }
                deletedValuations.ForEach(v => v.Remove());
            }


            //TODO kod dodany by wykorzystywac mechanizm savepointow, ale dziwia warunki na korekte pz/wz
            //TODO nalezy sprawdzi czy zmiana wycen rusza wersje obiektu glownego bo wyglda na to ze nie
            var docType = Makolab.Fractus.Kernel.Mappers.DictionaryMapper.Instance.GetDocumentType(
                new Guid(this.CurrentPackage.Table(this.MainObjectTag).FirstRow().Element("documentTypeId").Value));

            if ((docType.DocumentCategory == Makolab.Fractus.Kernel.Enums.DocumentCategory.IncomeWarehouseCorrection ||
                 docType.DocumentCategory == Makolab.Fractus.Kernel.Enums.DocumentCategory.OutcomeWarehouseCorrection) &&
                changeset.Table("warehouseDocumentValuation") != null)
            {
                var warehouseValuationTable = changeset.Table("warehouseDocumentValuation");
                warehouseValuationTable.Remove();
                DBXml valuationXml = new DBXml();
                valuationXml.AddTable(warehouseValuationTable);

                this.Repository.ExecuteOperations(changeset);

                WarehouseDocumentValuation valuationProcessor = new WarehouseDocumentValuation(this.UnitOfWork, this.ExecutionController, this.IsHeadquarter);
                valuationProcessor.Log = this.Log;
                valuationProcessor.LocalTransactionId = this.LocalTransactionId;
                CommunicationPackage valuationPackage = new CommunicationPackage(new XmlTransferObject()
                {
                    Content = valuationXml.Xml.ToString(SaveOptions.DisableFormatting)
                });
                valuationPackage.DatabaseId = this.package.DatabaseId;
                valuationPackage.XmlData.LocalTransactionId    = this.package.XmlData.LocalTransactionId;
                valuationPackage.XmlData.DeferredTransactionId = this.package.XmlData.DeferredTransactionId;
                valuationProcessor.ExecutePackage(valuationPackage, 0);
            }
            else
            {
                this.Repository.ExecuteOperations(changeset);
            }
        }
Esempio n. 3
0
        public virtual bool ExecuteCustomPackage(DBXml package)
        {
            SqlCommand cmd = this.helper.CreateCommand(StoredProcedure.custom_p_executeCustomPackage.ToProcedureName(),
                                                       new SqlParameter("@xmlVar", SqlDbType.Xml), package.Xml.ToString());

            using (this.Database.SynchronizeConnection())
            {
                cmd.ExecuteNonQuery();
            }

            return(true);
        }
        /// <summary>
        /// Updates the communication statistics by pesristing them.
        /// </summary>
        /// <param name="statistics">The statistics data.</param>
        /// <param name="departmentId">The statistics target department id.</param>
        public virtual void UpdateStatistics(CommunicationStatistics statistics, Guid departmentId)
        {
            if (statistics == null)
            {
                throw new ArgumentNullException("statistics");
            }

            if (departmentId == null)
            {
                throw new ArgumentNullException("departmentId");
            }

            SynchronizeStatisticTime(statistics);

            DBRow row = new DBXml().AddTable("statistics").AddRow();

            row.AddElement("databaseId", departmentId.ToUpperString());
            row.AddElement("lastUpdate", DateTime.Now.ToIsoString());
            row.AddElement("undeliveredPackagesQuantity", statistics.PackagesToSend);
            row.AddElement("unprocessedPackagesQuantity", statistics.PackagesToExecute);
            if (statistics.LastExecutionTime != null)
            {
                row.AddElement("lastExecutionTime", statistics.LastExecutionTime.Value.ToIsoString());
            }

            if (statistics.LastSendMessage != null)
            {
                row.AddElement("lastSentMessage", statistics.LastSendMessage.Message);
                row.AddElement("sentMessageTime", statistics.LastSendMessage.Time.Value.ToIsoString());
            }

            if (statistics.LastExecutionMessage != null)
            {
                row.AddElement("lastExecutionMessage", statistics.LastExecutionMessage.Message);
                row.AddElement("executionMessageTime", statistics.LastExecutionMessage.Time.Value.ToIsoString());
            }

            if (statistics.LastReceiveMessage != null)
            {
                row.AddElement("lastReceiveMessage", statistics.LastReceiveMessage.Message);
                row.AddElement("receiveMessageTime", statistics.LastReceiveMessage.Time.Value.ToIsoString());
            }

            SqlCommand cmd = this.helper.CreateCommand(StoredProcedure.communication_p_updateStatistics.ToProcedureName(),
                                                       new SqlParameter("@xmlVar", SqlDbType.Xml),
                                                       this.helper.CreateSqlXml(row.Table.Document.Xml));

            using (this.Database.SynchronizeConnection())
            {
                cmd.ExecuteNonQuery();
            }
        }
        /// <summary>
        /// Puts the communication package in outgoing queue.
        /// </summary>
        /// <param name="xml">The XML package to save.</param>
        /// <param name="targetBranches">The target branches.</param>
        public void SaveOutgoingPackage(ICommunicationPackage xml, IEnumerable <Guid> targetBranches)
        {
            if (xml == null)
            {
                throw new ArgumentNullException("xml");
            }
            if (targetBranches == null || targetBranches.Count() == 0)
            {
                return;
            }

            DBTable outgoingXmlQueue = new DBXml().AddTable("outgoingXmlQueue");

            foreach (var branchId in targetBranches)
            {
                DBRow row = outgoingXmlQueue.AddRow();
                row.AddElement("id", Guid.NewGuid().ToUpperString());
                row.AddElement("localTransactionId", xml.XmlData.LocalTransactionId.ToUpperString());
                row.AddElement("deferredTransactionId", xml.XmlData.DeferredTransactionId.ToUpperString());
                row.AddElement("databaseId", branchId.ToUpperString());
                row.AddElement("type", xml.XmlData.XmlType);
                row.AddElement("xml", XElement.Parse(xml.XmlData.Content));
            }

            SqlCommand cmd = this.helper.CreateCommand(StoredProcedure.communication_p_insertOutgoingPackage.ToProcedureName(),
                                                       new SqlParameter("@xmlVar", SqlDbType.Xml),
                                                       this.helper.CreateSqlXml(outgoingXmlQueue.Document.Xml));

            using (this.Database.SynchronizeConnection())
            {
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (SqlException e)
                {
                    if (e.Number == 2627)
                    {
                        throw new CommunicationPackageExistsException("Communication package with the same id already exists in the database.",
                                                                      xml.XmlData.Id.ToString(),
                                                                      e);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
        /// <summary>
        /// Saves the package.
        /// </summary>
        /// <param name="xml">The XML package to save.</param>
        public virtual void SavePackage(ICommunicationPackage xml)
        {
            if (xml == null)
            {
                throw new ArgumentNullException("xml");
            }

            DBRow row = new DBXml().AddTable("incomingXmlQueue").AddRow();

            row.AddElement("id", xml.XmlData.Id.ToUpperString());
            row.AddElement("localTransactionId", xml.XmlData.LocalTransactionId.ToUpperString());
            row.AddElement("deferredTransactionId", xml.XmlData.DeferredTransactionId.ToUpperString());
            row.AddElement("databaseId", xml.DatabaseId);
            row.AddElement("type", xml.XmlData.XmlType);
            row.AddElement("xml", XElement.Parse(xml.XmlData.Content));

            SqlCommand cmd = this.helper.CreateCommand(StoredProcedure.communication_p_insertIncomingPackage.ToProcedureName(),
                                                       new SqlParameter("@xmlVar", SqlDbType.Xml),
                                                       this.helper.CreateSqlXml(row.Table.Document.Xml));

            using (this.Database.SynchronizeConnection())
            {
                try
                {
                    cmd.ExecuteNonQuery();
                }
                catch (SqlException e)
                {
                    if (e.Number == 2627)
                    {
                        //xml with the same id is already in database so we assume that it's the same and skip this one usually
                        //but its other method decision
                        throw new CommunicationPackageExistsException("Communication package with the same id already exists in the database.",
                                                                      xml.XmlData.Id.ToString(),
                                                                      e);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DBTable"/> class.
 /// </summary>
 /// <param name="tableTagName">Name of the table root element.</param>
 /// <param name="document">The xml that this table belongs to.</param>
 public DBTable(string tableTagName, DBXml document) : this(tableTagName)
 {
     this.Document = document;
 }
Esempio n. 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DBXml"/> class by cloning existing other database xml.
 /// </summary>
 /// <param name="dbXml">The <see cref="DBXml"/> source object.</param>
 public DBXml(DBXml dbXml) : this(new XDocument(dbXml.Xml))
 {
 }