コード例 #1
0
        /// <summary>
        /// Process data that was received by web service method.
        /// </summary>
        /// <param name="data">The data received via web service method call.</param>
        /// <returns>Response to web service client.</returns>
        public object DataReceived(object data)
        {
            SendDataParameters methodParams = (SendDataParameters)data;

            if (methodParams == null)
            {
                return(null);
            }

            SendDataResponse response = new SendDataResponse();

            ICommunicationPackage communicationPackage = (methodParams.Xml == null) ? null : CreateCommunicationPackage(methodParams);

            DatabaseConnector.DatabaseConnectorManager dbm = GetDatabaseConnector();
            dbm.StartModule();
            try
            {
                using (IUnitOfWork uow = new UnitOfWork(dbm))
                {
                    uow.MapperFactory = IoC.Get <IMapperFactory>();
                    uow.StartTransaction(IsolationLevel.Serializable);

                    CommunicationPackageRepository repo = new CommunicationPackageRepository(uow);
                    if (communicationPackage != null)
                    {
                        repo.Add(communicationPackage);
                    }
                    if (methodParams.IsLastInTransaction)
                    {
                        repo.MarkTransactionAsCompleted(communicationPackage.XmlData.LocalTransactionId);
                    }
                    if (methodParams.Statistics != null)
                    {
                        repo.UpdateStatistics(methodParams.Statistics, methodParams.DepartmentIdentifier);
                    }

                    uow.SubmitChanges();
                }
            }
            catch (System.Data.SqlClient.SqlException e)
            {
                response.Result = false;
                Log.Error(e.ToString(), false);
                return(response);
            }
            catch (CommunicationPackageExistsException e) //Xml already in database.
            {
                Log.Info(e.ToString(), false);
            }
            finally
            {
                dbm.StopModule();
            }

            response.Result = true;
            return(response);
        }
コード例 #2
0
        /// <summary>
        /// Saves the specified xml to storage.
        /// </summary>
        /// <param name="xmlData">The xml to save.</param>
        /// <param name="databaseId">The database id.</param>
        /// <returns>
        ///     <c>true</c> if  is saving successful; otherwise, <c>false</c>.
        /// </returns>
        public bool ProcessXml(XmlTransferObject xmlData, Guid?databaseId)
        {
            bool isSaved = false;
            ICommunicationPackage xml = this.packageFactory.CreatePackage(xmlData);

            xml.DatabaseId = databaseId;
            xml.Decompress();
            if (xml.CheckSyntax())
            {
                int retryCount = 0;
                using (IUnitOfWork uow = Manager.CreateUnitOfWork())
                {
                    uow.MapperFactory = this.mapperFactory;

                    CommunicationPackageRepository repo = new CommunicationPackageRepository(uow);
                    while (isSaved == false && retryCount < 10)
                    {
                        try
                        {
                            repo.Add(xml);
                            isSaved = true;
                        }
                        catch (SqlException)
                        {
                            ++retryCount;
                            Wait();
                        }
                        catch (CommunicationPackageExistsException e) // Xml with the same id exists in db
                        {
                            this.Log.Info(e.ToString(), false);
                            isSaved = true;
                        }
                    }

                    if (!isSaved)
                    {
                        Log.Error("EXCEPTION: CRITICAL ERROR ALERT! What to do with unset (Saves the specified xml to storage) ProcessXml(XmlTransferObject xmlData,Guid? databaseId) PackageReceiver.cs");
                    }
                }
            }
            else
            {
                Log.Error("Invalid xml received, syntax error. Xml id=" + xmlData.Id + " content=" + xmlData.Content);
                ////it shouldnt be received in the first place = validation on the WebService site

                return(false);
            }

            return(isSaved);
        }