/// <summary> /// Reperimento delle regole censite in un canale di pubblicazione /// </summary> /// <param name="idChannel">Id del canale di pubblicazione</param> /// <returns></returns> public static RuleInfo[] GetRules(int idChannel) { _logger.Info("BEGIN"); List <RuleInfo> list = new List <RuleInfo>(); try { Database db = DbHelper.CreateDatabase(); using (DBCommandWrapper cw = db.GetStoredProcCommandWrapper(DbHelper.GetSpNameForPackage("GetRules"))) { cw.AddInParameter("pIdInstance", DbType.Int32, idChannel); using (IDataReader reader = db.ExecuteReader(cw)) { while (reader.Read()) { BaseRuleInfo baseRule = CreateRuleInfo(reader); if (baseRule.GetType() == typeof(RuleInfo)) { list.Add((RuleInfo)baseRule); } else if (baseRule.GetType() == typeof(SubRuleInfo)) { SubRuleInfo subRule = (SubRuleInfo)baseRule; RuleInfo parentRule = list.Where(e => e.Id == subRule.IdParentRule).First(); parentRule.SubRulesList.Add(subRule); } } } } } 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(list.ToArray()); }
/// <summary> /// Reperimento di una regola di pubblicazione /// </summary> /// <param name="id">Identificativo univoco della regola</param> /// <returns></returns> public static RuleInfo GetRule(int id) { _logger.Info("BEGIN"); RuleInfo rule = null; try { Database db = DbHelper.CreateDatabase(); using (DBCommandWrapper cw = db.GetStoredProcCommandWrapper(DbHelper.GetSpNameForPackage("GetRule"))) { cw.AddInParameter("pId", DbType.Int32, id); using (IDataReader reader = db.ExecuteReader(cw)) { while (reader.Read()) { BaseRuleInfo baseRule = CreateRuleInfo(reader); if (baseRule.GetType() == typeof(RuleInfo)) { rule = (RuleInfo)baseRule; } else if (baseRule.GetType() == typeof(SubRuleInfo) && rule != null) { rule.SubRulesList.Add((SubRuleInfo)baseRule); } } } } } 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(rule); }
/// <summary> /// /// </summary> /// <param name="data"></param> /// <returns></returns> private static SubRuleInfo InsertSubRule(SubRuleInfo data) { _logger.Info("BEGIN"); try { Database db = DbHelper.CreateDatabase(); using (DBCommandWrapper cw = db.GetStoredProcCommandWrapper(DbHelper.GetSpNameForPackage("InsertSubRule"))) { cw.AddInParameter("pInstanceId", DbType.Int32, data.IdInstance); cw.AddInParameter("pDescription", DbType.String, data.RuleDescription); cw.AddInParameter("pEnabled", DbType.StringFixedLength, (data.Enabled ? "1" : "0")); cw.AddInParameter("pOptions", DbType.String, data.GetOptions()); cw.AddInParameter("pParentRuleId", DbType.Int32, data.IdParentRule); cw.AddInParameter("pSubName", DbType.String, data.SubRuleName); cw.AddOutParameter("pOrdinal", DbType.Int32, 4); cw.AddOutParameter("pId", DbType.Int32, 4); db.ExecuteNonQuery(cw); if (cw.RowsAffected == 1) { data.Id = Convert.ToInt32(cw.GetParameterValue("pId")); data.Ordinal = Convert.ToInt32(cw.GetParameterValue("pOrdinal")); return(data); } else { throw new SubscriberException(ErrorCodes.SP_EXECUTION_ERROR, string.Format(ErrorDescriptions.SP_EXECUTION_ERROR, "InsertSubRule", 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)); } finally { _logger.Info("END"); } }
/// <summary> /// Reperimento dei dati dello storico relativo all'ultima pubblicazione effettuata per una regola e per un oggetto /// </summary> /// <param name="idRule">Id della regola</param> /// <param name="idObject">Id dell'oggetto</param> /// <returns></returns> public static RuleHistoryInfo GetLastRuleHistory(int idRule, string idObject) { _logger.Info("BEGIN"); try { RuleHistoryInfo history = null; Database db = DbHelper.CreateDatabase(); using (DBCommandWrapper cw = db.GetStoredProcCommandWrapper(DbHelper.GetSpNameForPackage("GetLastHistory"))) { cw.AddInParameter("pIdRule", DbType.Int32, idRule); cw.AddInParameter("pIdObject", DbType.String, idObject); using (IDataReader reader = db.ExecuteReader(cw)) { if (reader.Read()) { history = CreteRuleHistoryInfo(reader); } } } return(history); } 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"); } }
/// <summary> /// Reperimento delle sottoregole di pubblicazione /// </summary> /// <param name="idRule"> /// Id della regola padre /// </param> /// <returns></returns> public static SubRuleInfo[] GetSubRules(int idRule) { _logger.Info("BEGIN"); try { List <SubRuleInfo> list = new List <SubRuleInfo>(); Database db = DbHelper.CreateDatabase(); using (DBCommandWrapper cw = db.GetStoredProcCommandWrapper(DbHelper.GetSpNameForPackage("GetSubRules"))) { cw.AddInParameter("pIdRule", DbType.Int32, idRule); using (IDataReader reader = db.ExecuteReader(cw)) { while (reader.Read()) { list.Add((SubRuleInfo)CreateRuleInfo(reader)); } } } return(list.ToArray()); } 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"); } }
/// <summary> /// Reperimento di un canale di pubblicazione /// </summary> /// <param name="id">Identificativo univoco</param> /// <returns></returns> public static ChannelInfo Get(int id) { _logger.Info("BEGIN"); ChannelInfo instance = null; try { Database db = DbHelper.CreateDatabase(); using (DBCommandWrapper cw = db.GetStoredProcCommandWrapper(DbHelper.GetSpNameForPackage("GetInstance"))) { cw.AddInParameter("pId", DbType.Int32, id); using (IDataReader reader = db.ExecuteReader(cw)) { if (reader.Read()) { instance = CreateChannelInfo(reader); } } } } 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(instance); }
/// <summary> /// Reperimento della lista dei canali di pubblicazione /// </summary> /// <returns></returns> public static ChannelInfo[] GetList() { _logger.Info("BEGIN"); List <ChannelInfo> list = new List <ChannelInfo>(); try { Database db = DbHelper.CreateDatabase(); using (DBCommandWrapper cw = db.GetStoredProcCommandWrapper(DbHelper.GetSpNameForPackage("GetInstances"))) { using (IDataReader reader = db.ExecuteReader(cw)) { while (reader.Read()) { list.Add(CreateChannelInfo(reader)); } } } } 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(list.ToArray()); }
/// <summary> /// Cancellazione di una regola /// </summary> /// <param name="id"> /// Identificativo della regola /// </param> public static void DeleteRule(int id) { _logger.Info("BEGIN"); try { Database db = DbHelper.CreateDatabase(); using (DBCommandWrapper cw = db.GetStoredProcCommandWrapper(DbHelper.GetSpNameForPackage("DeleteRule"))) { cw.AddInParameter("pId", DbType.Int32, id); db.ExecuteNonQuery(cw); if (cw.RowsAffected == 0) { throw new SubscriberException(ErrorCodes.SP_EXECUTION_ERROR, string.Format(ErrorDescriptions.SP_EXECUTION_ERROR, "DeleteRule", 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"); } }
/// <summary> /// /// </summary> /// <param name="data"></param> /// <returns></returns> private static BaseRuleInfo UpdateRule(BaseRuleInfo data) { _logger.Info("BEGIN"); try { Database db = DbHelper.CreateDatabase(); using (DBCommandWrapper cw = db.GetStoredProcCommandWrapper(DbHelper.GetSpNameForPackage("UpdateRule"))) { cw.AddInParameter("pId", DbType.Int32, data.Id); cw.AddInParameter("pDescription", DbType.String, data.RuleDescription); cw.AddInParameter("pEnabled", DbType.StringFixedLength, (data.Enabled ? "1" : "0")); cw.AddInParameter("pOptions", DbType.String, data.GetOptions()); if (data.GetType() == typeof(RuleInfo)) { cw.AddInParameter("pClassId", DbType.String, ((RuleInfo)data).RuleClassFullName); } else { cw.AddInParameter("pClassId", DbType.String, DBNull.Value); } db.ExecuteNonQuery(cw); if (cw.RowsAffected == 0) { throw new SubscriberException(ErrorCodes.SP_EXECUTION_ERROR, string.Format(ErrorDescriptions.SP_EXECUTION_ERROR, "UpdateRule", ErrorDescriptions.SP_EXECUTE_NO_ROWS)); } else { if (data.GetType() == typeof(RuleInfo)) { RuleInfo ruleInfo = (RuleInfo)data; List <SubRuleInfo> newSubRules = new List <SubRuleInfo>(); foreach (SubRuleInfo subRule in ruleInfo.SubRules) { newSubRules.Add((SubRuleInfo)UpdateRule(subRule)); } ruleInfo.SubRulesList = newSubRules; } } } 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)); } finally { _logger.Info("END"); } }
/// <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"); } }
/// <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"); } }
/// <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); }