Esempio n. 1
0
        /// <summary>
        /// Aggiornamento dati
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static RuleHistoryInfo SaveHistoryItem(RuleHistoryInfo data)
        {
            _logger.Info("BEGIN");

            try
            {
                Database db = DbHelper.CreateDatabase();

                using (DBCommandWrapper cw = db.GetStoredProcCommandWrapper(DbHelper.GetSpNameForPackage("InsertHistory")))
                {
                    cw.AddInParameter("pRuleId", DbType.Int32, data.IdRule);
                    cw.AddInParameter("pIdObject", DbType.String, data.ObjectSnapshot.IdObject);
                    cw.AddInParameter("pObjectType", DbType.String, data.ObjectSnapshot.ObjectType);
                    cw.AddInParameter("pObjectTemplateName", DbType.String, data.ObjectSnapshot.TemplateName);
                    cw.AddInParameter("pObjectDescription", DbType.String, data.ObjectSnapshot.Description);
                    cw.AddInParameter("pAuthorName", DbType.String, data.Author.Name);
                    cw.AddInParameter("pAuthorId", DbType.String, data.Author.Id);
                    cw.AddInParameter("pRoleName", DbType.String, data.Author.RoleName);
                    cw.AddInParameter("pRoleId", DbType.String, data.Author.IdRole);

                    if (data.ObjectSnapshot != null)
                    {
                        cw.AddClobParameter("pObjectSnapshot", ObjectSerializerHelper.Serialize(data.ObjectSnapshot));
                    }
                    else
                    {
                        cw.AddClobParameter("pObjectSnapshot", DBNull.Value);
                    }

                    if (data.MailMessageSnapshot != null)
                    {
                        cw.AddClobParameter("pMailMessageSnapshot", ObjectSerializerHelper.Serialize(data.MailMessageSnapshot));
                    }
                    else
                    {
                        cw.AddClobParameter("pMailMessageSnapshot", DBNull.Value);
                    }

                    cw.AddInParameter("pComputed", DbType.StringFixedLength, (data.Published ? "1" : "0"));
                    cw.AddInParameter("pComputeDate", DbType.DateTime, data.PublishDate);

                    if (data.ErrorInfo != null)
                    {
                        cw.AddInParameter("pErrorId", DbType.String, data.ErrorInfo.Id);
                        cw.AddInParameter("pErrorDescription", DbType.String, data.ErrorInfo.Message);
                        cw.AddInParameter("pErrorStack", DbType.String, data.ErrorInfo.Stack);
                    }
                    else
                    {
                        cw.AddInParameter("pErrorId", DbType.String, DBNull.Value);
                        cw.AddInParameter("pErrorDescription", DbType.String, DBNull.Value);
                        cw.AddInParameter("pErrorStack", DbType.String, DBNull.Value);
                    }

                    cw.AddOutParameter("pId", DbType.Int32, 4);

                    db.ExecuteNonQuery(cw);

                    if (cw.RowsAffected == 1)
                    {
                        data.Id = Convert.ToInt32(cw.GetParameterValue("pId"));
                    }
                    else
                    {
                        throw new SubscriberException(ErrorCodes.SP_EXECUTION_ERROR,
                                                      string.Format(ErrorDescriptions.SP_EXECUTION_ERROR, "InsertHistory", ErrorDescriptions.SP_EXECUTE_NO_ROWS));
                    }
                }

                return(data);
            }
            catch (SubscriberException pubEx)
            {
                _logger.Error(pubEx.Message);

                throw pubEx;
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);

                throw new SubscriberException(ErrorCodes.UNHANDLED_ERROR,
                                              string.Format(ErrorDescriptions.UNHANDLED_ERROR, ex.Message),
                                              ex);
            }
            finally
            {
                _logger.Info("END");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Storico delle regole eseguite
        /// </summary>
        /// <param name="requestInfo">
        /// Dati di filtro per la ricerca delle regole
        /// </param>
        /// <returns></returns>
        public static GetRuleHistoryListResponse GetRuleHistoryList(GetRuleHistoryListRequest requestInfo)
        {
            _logger.Info("BEGIN");

            try
            {
                GetRuleHistoryListResponse response = new GetRuleHistoryListResponse();

                List <RuleHistoryInfo> list = new List <RuleHistoryInfo>();

                Database db = DbHelper.CreateDatabase();

                //using (DBCommandWrapper cw = db.GetStoredProcCommandWrapper(DbHelper.GetSpNameForPackage("GetRuleHistory")))
                using (DBCommandWrapper cw = db.GetStoredProcCommandWrapper(DbHelper.GetSpNameForPackage("GetRuleHistoryPaging")))
                {
                    cw.AddInParameter("pIdRule", DbType.Int32, requestInfo.IdRule);

                    // Filtri personalizzati
                    if (requestInfo.CustomFilters != null)
                    {
                        cw.AddInParameter("pObjectDescription", DbType.String, GetStringParamValue(requestInfo.CustomFilters.ObjectDescription));
                        cw.AddInParameter("pAuthorName", DbType.String, GetStringParamValue(requestInfo.CustomFilters.AuthorName));
                        cw.AddInParameter("pRoleName", DbType.String, GetStringParamValue(requestInfo.CustomFilters.RoleName));
                    }
                    else
                    {
                        cw.AddInParameter("pObjectDescription", DbType.String, DBNull.Value);
                        cw.AddInParameter("pAuthorName", DbType.String, DBNull.Value);
                        cw.AddInParameter("pRoleName", DbType.String, DBNull.Value);
                    }

                    // Criteri di paginazione
                    if (requestInfo.PagingContext != null)
                    {
                        cw.AddInParameter("pPage", DbType.Int32, requestInfo.PagingContext.PageNumber);
                        cw.AddInParameter("pObjectsPerPage", DbType.Int32, requestInfo.PagingContext.ObjectsPerPage);
                        cw.AddOutParameter("pObjectsCount", DbType.Int32, 4);
                    }
                    else
                    {
                        cw.AddInParameter("pPage", DbType.Int32, 1);
                        cw.AddInParameter("pObjectsPerPage", DbType.Int32, Int32.MaxValue);
                        cw.AddOutParameter("pObjectsCount", DbType.Int32, 4);
                    }

                    using (IDataReader reader = db.ExecuteReader(cw))
                    {
                        while (reader.Read())
                        {
                            list.Add(CreteRuleHistoryInfo(reader));
                        }

                        object objectsCountParam = cw.GetParameterValue("pObjectsCount");

                        if (objectsCountParam != null)
                        {
                            // Reperimento numero di oggetti totali
                            requestInfo.PagingContext.TotalObjects = Convert.ToInt32(objectsCountParam.ToString());
                        }
                    }
                }

                response.Rules         = list.ToArray();
                response.PagingContext = requestInfo.PagingContext;

                return(response);
            }
            catch (SubscriberException pubEx)
            {
                _logger.Error(pubEx.Message);

                throw pubEx;
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);

                throw new SubscriberException(ErrorCodes.UNHANDLED_ERROR, string.Format(ErrorDescriptions.UNHANDLED_ERROR, ex.Message));
            }
            finally
            {
                _logger.Info("END");
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Aggiornamento dati di un canale di pubblicazione
        /// </summary>
        /// <param name="data">
        /// Metadati del canale
        /// </param>
        /// <returns></returns>
        public static ChannelInfo Save(ChannelInfo data)
        {
            _logger.Info("BEGIN");

            try
            {
                bool insertMode = (data.Id == 0);

                Database db = DbHelper.CreateDatabase();

                if (insertMode)
                {
                    using (DBCommandWrapper cw = db.GetStoredProcCommandWrapper(DbHelper.GetSpNameForPackage("InsertInstance")))
                    {
                        cw.AddInParameter("pName", DbType.String, data.Name);
                        cw.AddInParameter("pDescription", DbType.String, data.Description);
                        cw.AddInParameter("pSmtpHost", DbType.String, data.SmtpHost);
                        cw.AddInParameter("pSmtpPort", DbType.Int32, data.SmtpPort);
                        cw.AddInParameter("pSmtpSsl", DbType.StringFixedLength, (data.SmtpSsl ? "1" : "0"));
                        cw.AddInParameter("pSmtpUserName", DbType.String, data.SmtpUserName);
                        cw.AddInParameter("pSmtpPassword", DbType.String, data.SmtpPassword);
                        cw.AddInParameter("pSmtpMail", DbType.String, data.SmtpMail);
                        cw.AddOutParameter("pId", DbType.Int32, 0);

                        db.ExecuteNonQuery(cw);

                        if (cw.RowsAffected == 1)
                        {
                            data.Id = Convert.ToInt32(cw.GetParameterValue("pId"));
                        }
                        else
                        {
                            throw new SubscriberException(ErrorCodes.SP_EXECUTION_ERROR,
                                                          string.Format(ErrorDescriptions.SP_EXECUTION_ERROR, "InsertInstance", ErrorDescriptions.SP_EXECUTE_NO_ROWS));
                        }
                    }
                }
                else
                {
                    using (DBCommandWrapper cw = db.GetStoredProcCommandWrapper(DbHelper.GetSpNameForPackage("UpdateInstance")))
                    {
                        cw.AddInParameter("pId", DbType.Int32, data.Id);
                        cw.AddInParameter("pName", DbType.String, data.Name);
                        cw.AddInParameter("pDescription", DbType.String, data.Description);
                        cw.AddInParameter("pSmtpHost", DbType.String, data.SmtpHost);
                        cw.AddInParameter("pSmtpPort", DbType.Int32, data.SmtpPort);
                        cw.AddInParameter("pSmtpSsl", DbType.StringFixedLength, (data.SmtpSsl ? "1" : "0"));
                        cw.AddInParameter("pSmtpUserName", DbType.String, data.SmtpUserName);
                        cw.AddInParameter("pSmtpPassword", DbType.String, data.SmtpPassword);
                        cw.AddInParameter("pSmtpMail", DbType.String, data.SmtpMail);

                        db.ExecuteNonQuery(cw);

                        if (cw.RowsAffected == 0)
                        {
                            throw new SubscriberException(ErrorCodes.SP_EXECUTION_ERROR,
                                                          string.Format(ErrorDescriptions.SP_EXECUTION_ERROR, "UpdateInstance", ErrorDescriptions.SP_EXECUTE_NO_ROWS));
                        }
                    }
                }
            }
            catch (SubscriberException pubEx)
            {
                _logger.Error(pubEx.Message);

                throw pubEx;
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);

                throw new SubscriberException(ErrorCodes.UNHANDLED_ERROR,
                                              string.Format(ErrorDescriptions.UNHANDLED_ERROR, ex.Message),
                                              ex);
            }
            finally
            {
                _logger.Info("END");
            }

            return(data);
        }