/// <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; } } } }
/// <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(); } }