internal FilterEngineConfig() { try { string configFile = string.Format(FilterEngine.GetApplicationPath() + @"Configurations\FilterEngine.config"); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(configFile); XmlNode objectViewNode = xmlDocument.SelectSingleNode("//filterEngine/View"); Business.ViewConfig viewConfig = new Business.ViewConfig(objectViewNode); userViewTimeSpan = viewConfig.UserTimeSpanSecond; ipViewTimeSpan = viewConfig.IPTimeSpanSecond; XmlNodeList adminEmailNodes = xmlDocument.SelectNodes("//filterEngine/badWordFilterReporting/adminEmail"); foreach (XmlNode adminEmailNode in adminEmailNodes) { adminEmailList.Add(adminEmailNode.Attributes["email"].Value, adminEmailNode.Attributes["name"].Value); } XmlNode objectLinkUrlPrefixNode = xmlDocument.SelectSingleNode("//filterEngine/badWordFilterReporting/urlPrefix"); XmlNodeList objectLinkNodes = xmlDocument.SelectNodes("//filterEngine/badWordFilterReporting/objectLink"); foreach (XmlNode objectLinkNode in objectLinkNodes) { Type constants = typeof(_4screen.CSB.Common.Constants); FieldInfo fieldInfo = constants.GetField(objectLinkNode.Attributes["const"].Value); string value = (string)fieldInfo.GetValue(null); objectLinks.Add(objectLinkNode.Attributes["type"].Value, objectLinkUrlPrefixNode.InnerText + value); } } catch { } }
public static int AddView(Guid userId, string ip, Guid campaignId, string type) { int viewAdded = 0; SqlConnectionHelper sqlConnection = new SqlConnectionHelper(); try { sqlConnection.Command.CommandType = CommandType.StoredProcedure; sqlConnection.Command.CommandText = "hisp_Filter_AdCampaigns_AddView"; sqlConnection.Command.Parameters.Add(new SqlParameter("@USR_ID", SqlDbType.UniqueIdentifier)); sqlConnection.Command.Parameters["@USR_ID"].Value = userId; sqlConnection.Command.Parameters.Add(new SqlParameter("@FAC_ID", SqlDbType.UniqueIdentifier)); sqlConnection.Command.Parameters["@FAC_ID"].Value = campaignId; sqlConnection.Command.Parameters.Add(new SqlParameter("@Type", SqlDbType.NVarChar)); sqlConnection.Command.Parameters["@Type"].Value = type; sqlConnection.Command.Parameters.Add(new SqlParameter("@UserTimeSpanSecond", SqlDbType.Int)); sqlConnection.Command.Parameters["@UserTimeSpanSecond"].Value = FilterEngine.GetFilterEngineConfig().UserViewTimeSpan == 0 ? 990000000 : FilterEngine.GetFilterEngineConfig().UserViewTimeSpan; sqlConnection.Command.Parameters.Add(new SqlParameter("@IPTimeSpanSecond", SqlDbType.Int)); sqlConnection.Command.Parameters["@IPTimeSpanSecond"].Value = FilterEngine.GetFilterEngineConfig().IPViewTimeSpan == 0 ? 990000000 : FilterEngine.GetFilterEngineConfig().IPViewTimeSpan; sqlConnection.Command.Parameters.Add(new SqlParameter("@IP", SqlDbType.Char)); sqlConnection.Command.Parameters["@IP"].Value = ip; sqlConnection.Command.Parameters.Add(new SqlParameter("@ViewAdded", SqlDbType.Bit)); sqlConnection.Command.Parameters["@ViewAdded"].Direction = ParameterDirection.ReturnValue; sqlConnection.Command.ExecuteNonQuery(); viewAdded = (int)sqlConnection.Command.Parameters["@ViewAdded"].Value; } finally { sqlConnection.Close(); } return(viewAdded); }
internal void ProcessDataObjectsAll(UserDataContext udc) { FilterEngine.InitFilterAdWords(); blnCancel = false; Dictionary <string, FilterObject> adWordFilterObjects = FilterEngine.GetAdWordFilterObjects(); foreach (KeyValuePair <string, FilterObject> adWordFilterObject in adWordFilterObjects) { if (blnCancel) { break; } int counter = 0; Console.WriteLine("Loading " + adWordFilterObject.Value.TypeName); SqlConnectionHelper sqlConnection = new SqlConnectionHelper(); System.Data.SqlClient.SqlDataReader sqlDataReader = null; try { sqlConnection.Command.CommandType = CommandType.StoredProcedure; sqlConnection.Command.CommandText = "hisp_DataObject_LoadIdsByType"; sqlConnection.Command.Parameters.Add(new SqlParameter("@ObjectTypeId", SqlDbType.Int)); sqlConnection.Command.Parameters["@ObjectTypeId"].Value = adWordFilterObject.Value.ObjectTypeId; sqlDataReader = sqlConnection.Command.ExecuteReader(CommandBehavior.CloseConnection); DateTime startTime = DateTime.Now; while (sqlDataReader.Read()) { if (blnCancel) { break; } FilterObjectAdWords(udc, adWordFilterObject.Value.TypeName, adWordFilterObject.Value.ObjectTypeId, sqlDataReader["OBJ_ID"].ToString().ToGuid()); counter++; } sqlDataReader.Close(); DateTime endTime = DateTime.Now; TimeSpan duration = endTime - startTime; Console.WriteLine(counter + " items took " + duration + " secs"); } catch (Exception e) { Console.WriteLine("*** Error: " + e); } finally { sqlConnection.Close(); } } }
internal void ProcessDataObjectsForUser(UserDataContext udc, Guid userId) { FilterEngine.InitFilterAdWords(); Dictionary <string, FilterObject> adWordFilterObjects = FilterEngine.GetAdWordFilterObjects(); Dictionary <int, string> typeNameMapping = new Dictionary <int, string>(); foreach (KeyValuePair <string, FilterObject> adWordFilterObject in adWordFilterObjects) { typeNameMapping.Add(adWordFilterObject.Value.ObjectTypeId, adWordFilterObject.Value.TypeName); } int counter = 0; Console.WriteLine("Loading " + userId); SqlConnectionHelper sqlConnection = new SqlConnectionHelper(); System.Data.SqlClient.SqlDataReader sqlDataReader = null; try { sqlConnection.Command.CommandType = CommandType.StoredProcedure; sqlConnection.Command.CommandText = "hisp_DataObject_LoadIdsByUserId"; sqlConnection.Command.Parameters.Add(new SqlParameter("@UserId", SqlDbType.UniqueIdentifier)); sqlConnection.Command.Parameters["@UserId"].Value = userId; sqlDataReader = sqlConnection.Command.ExecuteReader(CommandBehavior.CloseConnection); DateTime startTime = DateTime.Now; while (sqlDataReader.Read()) { if (typeNameMapping.ContainsKey((int)sqlDataReader["OBJ_Type"])) { FilterObjectAdWords(udc, typeNameMapping[(int)sqlDataReader["OBJ_Type"]], (int)sqlDataReader["OBJ_Type"], sqlDataReader["OBJ_ID"].ToString().ToGuid()); counter++; } } sqlDataReader.Close(); DateTime endTime = DateTime.Now; TimeSpan duration = endTime - startTime; Console.WriteLine(counter + " items took " + duration + " secs"); } catch (Exception e) { Console.WriteLine("*** Error: " + e); } finally { sqlConnection.Close(); } }
private void FilterObjectAdWords(UserDataContext udc, string typeName, int objectType, Guid objectId) { MethodInfo loadMethod = typeof(Business.DataObject).GetMethod("Load", new Type[] { typeof(Guid), typeof(ObjectShowState), typeof(bool) }); Type type; if (!string.IsNullOrEmpty(Helper.GetObjectType(objectType).Assembly)) { Assembly assembly = Assembly.Load(Helper.GetObjectType(objectType).Assembly); type = assembly.GetType(typeName); } else { type = Type.GetType(typeName); } MethodInfo genericLoadMethod = loadMethod.MakeGenericMethod(type); Business.DataObject dataObject = (Business.DataObject)genericLoadMethod.Invoke(null, new object[] { objectId, null, true }); if (FilterEngine.FilterObjectAdWordsWithoutInit(dataObject)) { dataObject.UpdateBackground(); } }
internal static void ReadFilterObjectsConfig(string nodeName, Dictionary <string, FilterObject> filterObjects) { try { string configFile = string.Format(FilterEngine.GetApplicationPath() + @"Configurations\FilterEngine.config"); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(configFile); XmlNodeList filterObjectNodes = xmlDocument.SelectNodes("//filterEngine/" + nodeName + "/object"); foreach (XmlNode filterObjectNode in filterObjectNodes) { if (filterObjectNode.Attributes["type"] != null) { FilterObject filterObject = new FilterObject(filterObjectNode.Attributes["type"].Value); if (filterObjectNode.Attributes["objectTypeId"] != null) { filterObject.ObjectTypeId = int.Parse(filterObjectNode.Attributes["objectTypeId"].Value); } XmlNodeList filterObjectProperties = filterObjectNode.SelectNodes("property"); foreach (XmlNode filterObjectProperty in filterObjectProperties) { if (filterObjectProperty.Attributes["name"] != null) { string propertyCopyToName = ""; if (filterObjectProperty.Attributes["linkedName"] != null) { propertyCopyToName = filterObjectProperty.Attributes["linkedName"].Value; } filterObject.Properties.Add(new FilterObjectProperty(filterObjectProperty.Attributes["name"].Value, propertyCopyToName)); } } filterObjects.Add(filterObjectNode.Attributes["type"].Value, filterObject); } } } catch { } }
internal static void InformAdmin(BadWordFilterActions action, string value, string word, bool isExactMatch, Type type, FilterObjectTypes filterObjectType, Guid objectId, Guid userId) { try { string markedValue = Regex.Replace(value, @"(\w*" + word + @"\w*)(?=[^>]*?<)", "<u><font color=\"#AA0000\">$1</font></u>", RegexOptions.IgnoreCase); string exactValue = isExactMatch ? "Ja" : "Nein"; string userLink = FilterEngine.GetFilterEngineConfig().ObjectLinks["User"] + userId.ToString(); string objectLink = ""; switch (filterObjectType) { case FilterObjectTypes.DataObject: if (FilterEngine.GetFilterEngineConfig().ObjectLinks.ContainsKey(type.ToString())) { objectLink = FilterEngine.GetFilterEngineConfig().ObjectLinks[type.ToString()] + objectId.ToString(); } break; case FilterObjectTypes.Comment: if (FilterEngine.GetFilterEngineConfig().ObjectLinks.ContainsKey(type.ToString())) { objectLink = FilterEngine.GetFilterEngineConfig().ObjectLinks[type.ToString()] + objectId.ToString(); } break; case FilterObjectTypes.Profile: objectLink = FilterEngine.GetFilterEngineConfig().ObjectLinks["Profile"] + objectId.ToString(); break; } SmtpSection smtpSection = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp"); MailMessage mailMessage = new MailMessage(); mailMessage.From = new MailAddress(smtpSection.From); foreach (KeyValuePair <string, string> adminEmail in FilterEngine.GetFilterEngineConfig().AdminEmailList) { mailMessage.To.Add(new MailAddress(adminEmail.Key, adminEmail.Value)); } mailMessage.Subject = "Bad Word Filter"; StringBuilder bodyString = new StringBuilder(1000); bodyString.Append("<table border=0>"); bodyString.Append(" <tr>"); bodyString.Append(" <td>Aktion(en):</td><td>" + GetActionsString(action) + "</td>"); bodyString.Append(" </tr><tr>"); bodyString.Append(" <td>Wort:</td><td>" + word + "<br/>"); bodyString.Append(" </tr><tr>"); bodyString.Append(" <td>Genau:</td><td>" + exactValue + "<br/>"); bodyString.Append(" </tr><tr>"); bodyString.Append(" <td valign=\"top\">Text:</td><td>" + markedValue + "<br/>"); bodyString.Append(" </tr><tr>"); bodyString.Append(" <td>Typ:</td><td>" + filterObjectType + "<br/>"); bodyString.Append(" </tr><tr>"); bodyString.Append(" <td>Object:</td><td><a href=\"" + objectLink + "\">" + objectId + "</a><br/>"); bodyString.Append(" </tr><tr>"); bodyString.Append(" <td>User:</td><td><a href=\"" + userLink + "\">" + userId + "</a><br/>"); bodyString.Append(" </tr>"); bodyString.Append("</table>"); mailMessage.Body = bodyString.ToString(); mailMessage.IsBodyHtml = true; SmtpClient smtpClient = new SmtpClient(); smtpClient.Send(mailMessage); } catch (Exception e) { new Exception("Error while sending bad word info mail", e); } }