/// <summary> /// Returns true if the contact purchased specified number of products in last X days. /// </summary> /// <param name="contact">Contact the activities of which should be checked</param> /// <param name="lowerBound">Inclusive lower bound of the number of products bought</param> /// <param name="lastXDays">Constraint for last X days (if zero or negative value is given, no constraint is applied)</param> public static bool PurchasedNumberOfProducts(object contact, int lowerBound, int lastXDays) { ContactInfo ci = contact as ContactInfo; if (ci == null) { return(false); } string where = String.Format("ActivityType = '{0}' AND ActivityActiveContactID = {1}", PredefinedActivityType.PURCHASEDPRODUCT, ci.ContactID); if (lastXDays > 0) { where = SqlHelperClass.AddWhereCondition(where, "DATEADD(day, " + lastXDays + ", ActivityCreated) >= GETDATE()"); } DataSet ds = ActivityInfoProvider.GetActivities(where, null, 1, "COUNT(ActivityID)"); if (!DataHelper.DataSourceIsEmpty(ds)) { int amount = ValidationHelper.GetInteger(ds.Tables[0].Rows[0][0], -1); if ((amount > -1) && (amount >= lowerBound)) { return(true); } } return(false); }
/// <summary> /// Returns true if the contact spent specified amount of money (counted by order total price in main currency) in last X days. /// </summary> /// <param name="contact">Contact the activities of which should be checked</param> /// <param name="lowerBound">Inclusive lower bound of the amount of money (in main currency) spent by contact</param> /// <param name="upperBound">Inclusive upper bound of the amount of money (in main currency) spent by contact</param> /// <param name="lastXDays">Constraint for last X days (if zero or negative value is given, no constraint is applied)</param> public static bool SpentMoney(object contact, double lowerBound, double upperBound, int lastXDays) { ContactInfo ci = contact as ContactInfo; if (ci == null) { return(false); } string where = String.Format("ActivityType = '{0}' AND ActivityActiveContactID = {1}", PredefinedActivityType.PURCHASE, ci.ContactID); if (lastXDays > 0) { where = SqlHelperClass.AddWhereCondition(where, "DATEADD(day, " + lastXDays + ", ActivityCreated) >= GETDATE()"); } DataSet ds = ActivityInfoProvider.GetActivities(where, null, 1, "SUM(CAST(ActivityValue AS FLOAT))"); if (!DataHelper.DataSourceIsEmpty(ds)) { double amount = ValidationHelper.GetDouble(ds.Tables[0].Rows[0][0], -1); if ((amount > -1) && (amount >= lowerBound) && (amount <= upperBound)) { return(true); } } return(false); }
/// <summary> /// Returns deleted items /// </summary> private DataSet GetData(string whereCondition, string orderBy, string columns) { if (ContactID > 0) { return(ActivityInfoProvider.GetActivities().Where(whereCondition).OrderBy(orderBy).Columns(columns)); } return(new ActivityListInfo().Generalized.GetData(null, whereCondition, orderBy, -1, columns, false)); }
public int GenerateActivitiesForContacts(IEnumerable <ContactInfo> contacts, int mediumActivitiesCount, List <TreeNode> treeNodes) { var activities = new List <ActivityInfo>(); DateTime created = DateTime.Now; foreach (var contact in contacts) { int activitiesCount = (int)(mediumActivitiesCount * StaticRandom.NextDouble() * 2); for (int i = 0; i < activitiesCount; i++) { var treeNode = treeNodes[StaticRandom.Next(treeNodes.Count)]; var activityInfo = new ActivityInfo { ActivityCreated = created, ActivityType = "pagevisit", ActivityActiveContactID = contact.ContactID, ActivityOriginalContactID = contact.ContactID, ActivitySiteID = contact.ContactSiteID, ActivityTitle = "Page visit on '" + treeNode.DocumentName + "' page", ActivityItemID = 0, ActivityItemDetailID = 0, ActivityURL = treeNode.DocumentUrlPath, ActivityNodeID = treeNode.NodeID, ActivityValue = "", ActivityIPAddress = "123.123.456.789", ActivityCampaign = "", ActivityURLReferrer = treeNode.DocumentUrlPath + "-totojereferrer", ActivityCulture = treeNode.DocumentCulture, }; activities.Add(activityInfo); } } BulkInsertion.Insert(activities); var activityIds = ActivityInfoProvider.GetActivities().WhereEquals("ActivityCreated", created).Select(a => a.ActivityID); var pageVisits = new List <PageVisitInfo>(); foreach (var activityId in activityIds) { var pageVisitInfo = new PageVisitInfo { PageVisitActivityID = activityId, PageVisitMVTCombinationName = "", PageVisitABVariantName = "", PageVisitDetail = "?totojequerystring=prase", }; pageVisits.Add(pageVisitInfo); } BulkInsertion.Insert(pageVisits); return(activities.Count); }
/// <summary> /// Removes pre-generated activities. /// </summary> /// <param name="campaignUTMCode">UTM code of the campaign.</param> public static void DeleteOldActivities(string campaignUTMCode) { var oldActivities = ActivityInfoProvider.GetActivities() .WhereStartsWith("ActivityTitle", "GeneratedActivity_") .WhereEquals("ActivityCampaign", campaignUTMCode) .ToList(); oldActivities.ForEach(ActivityInfoProvider.DeleteActivityInfo); }
/// <summary> /// Delete items. /// </summary> private void DeleteActivities(IWhereCondition whereCondition) { var activitiesToDelete = ActivityInfoProvider.GetActivities() .Columns("ActivityID", "ActivityType", "ActivityTitle") .Where(whereCondition); foreach (var activity in activitiesToDelete) { LogContext.AppendLine(string.Format("{0} - {1}", activity.ActivityTitle, activity.ActivityType)); ActivityInfoProvider.DeleteActivityInfo(activity); } }
/// <summary> /// Delete items. /// </summary> private void DeleteActivities(IWhereCondition whereCondition) { var activitiesToDelete = ActivityInfoProvider.GetActivities() .Columns("ActivityID", "ActivityType", "ActivityTitle") .Where(whereCondition); foreach (var activity in activitiesToDelete) { var safeLog = HTMLHelper.HTMLEncode(string.Format("{0} - {1}", activity.ActivityTitle, activity.ActivityType)); AddLog(safeLog); ActivityInfoProvider.DeleteActivityInfo(activity); } }
/// <summary> /// Checks activity permissions. /// Returns restricted sites condition. /// </summary> private WhereCondition CheckSitePermissions(IWhereCondition whereCondition) { var restrictedSitesCondition = new WhereCondition(); var activitiesSites = ActivityInfoProvider.GetActivities() .Distinct() .Column("ActivitySiteID") .Where(whereCondition); foreach (var activity in activitiesSites) { if (!CurrentUser.IsAuthorizedPerObject(PermissionsEnum.Modify, "om.activity", SiteInfoProvider.GetSiteName(activity.ActivitySiteID))) { SiteInfo notAllowedSite = SiteInfoProvider.GetSiteInfo(activity.ActivitySiteID); AddError(String.Format(GetString("accessdeniedtopage.info"), ResHelper.LocalizeString(notAllowedSite.DisplayName))); restrictedSitesCondition.WhereNotEquals("ActivitySiteID", activity.ActivitySiteID); } } return restrictedSitesCondition; }
/// <summary> /// Returns true if the contact did a specified activity. /// </summary> /// <param name="contact">Contact the activities of which should be checked</param> /// <param name="activityType">Name of the activity to check (can specify more than one separated with semicolon, all of the types match than)</param> /// <param name="cancelActivityType">Name of the activity which cancels the original activity (for example UnsubscribeNewsletter is a cancelling event for SubscribeNewsletter etc.)</param> /// <param name="lastXDays">Constraint for last X days (if zero or negative value is given, no constraint is applied)</param> /// <param name="whereCondition">Additional WHERE condition</param> public static bool DidActivity(object contact, string activityType, string cancelActivityType, int lastXDays, string whereCondition) { ContactInfo ci = contact as ContactInfo; if (ci == null) { return(false); } string where = GetActivityWhere(activityType, cancelActivityType, lastXDays, whereCondition, ci.ContactID); DataSet ds = ActivityInfoProvider.GetActivities(where, null, 1, "ActivityID"); if (!DataHelper.DataSourceIsEmpty(ds)) { return(true); } return(false); }
/// <summary> /// Returns true if the contact voted in the poll. /// </summary> /// <param name="contact">Contact which should be checked</param> /// <param name="pollName">Poll name</param> /// <param name="answer">Poll answer text</param> /// <param name="lastXDays">Constraint for last X days (if zero or negative value is given, no constraint is applied)</param> public static bool VotedInPoll(object contact, string pollName, string answer, int lastXDays) { int pollId = ValidationHelper.GetInteger(CMSMacroMethods.GetObjectID(PredefinedObjectType.POLL, pollName, CMSContext.CurrentSiteName, true), 0); if (!string.IsNullOrEmpty(answer)) { ContactInfo ci = contact as ContactInfo; if (ci == null) { return(false); } string where = GetActivityWhere(PredefinedActivityType.POLL_VOTING, null, lastXDays, "ActivityItemID = " + pollId, ci.ContactID); DataSet ds = ActivityInfoProvider.GetActivities(where, null, 0, "ActivityValue"); if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { string[] answers = ValidationHelper.GetString(dr[0], "").Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (string a in answers) { BaseInfo pollAnswer = CMSObjectHelper.GetObjectById("polls.pollanswer", ValidationHelper.GetInteger(a, 0)); if (pollAnswer != null) { if (pollAnswer.GetStringValue("AnswerText", "").EqualsCSafe(answer, true)) { return(true); } } } } } return(false); } else { return(DidActivity(contact, PredefinedActivityType.POLL_VOTING, null, lastXDays, "ActivityItemID = " + pollId)); } }
/// <summary> /// Returns true if the contact did any/all of the specified activities. /// </summary> /// <param name="contact">Contact the activities of which should be checked</param> /// <param name="activityType">Name of the activity(ies) to check separated with semicolon</param> /// <param name="lastXDays">Constraint for last X days (if zero or negative value is given, no constraint is applied)</param> /// <param name="allActivities">If true, all specified types has to be found for the method to return true. If false, at least one of any specified types is sufficient to return true for the method.</param> public static bool DidActivities(object contact, string activityTypes, int lastXDays, bool allActivities) { ContactInfo ci = contact as ContactInfo; if (ci == null) { return(false); } string where = null; string[] activities = activityTypes.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string activityType in activities) { where = SqlHelperClass.AddWhereCondition(where, "ActivityType = N'" + SqlHelperClass.GetSafeQueryString(activityType, false) + "'", "OR"); } if (lastXDays > 0) { where = SqlHelperClass.AddWhereCondition(where, "DATEADD(day, " + lastXDays + ", ActivityCreated) >= GETDATE()"); } where = SqlHelperClass.AddWhereCondition(where, "ActivityActiveContactID = " + ci.ContactID); DataSet ds = ActivityInfoProvider.GetActivities(where, null, 0, "DISTINCT ActivityType"); if (!DataHelper.DataSourceIsEmpty(ds)) { if (allActivities) { return(ds.Tables[0].Rows.Count == activities.Length); } else { return(true); } } return(false); }
private static bool DoActivitiesExistForContact(ContactInfo contact) { return(ActivityInfoProvider.GetActivities().WhereEquals("ActivityContactID", contact.ContactID).Count > 0); }
private IEnumerable <KeyValuePair <string, string> > GetMetricData() { string stringData = null; IEnumerable <KeyValuePair <string, string> > tupleData = null; // Gather data for each row, return special message if data is null switch (MetricCodeName) { // Categories case MetricDataEnum.support_metrics: case MetricDataEnum.support_metrics_system: case MetricDataEnum.support_metrics_environment: case MetricDataEnum.support_metrics_counters: case MetricDataEnum.support_metrics_ecommerce: case MetricDataEnum.support_metrics_tasks: case MetricDataEnum.support_metrics_eventlog: return(null); #region System case MetricDataEnum.support_metrics_system_version: stringData = CMSVersion.GetVersion(true, true, true, true); break; case MetricDataEnum.support_metrics_system_appname: stringData = SettingsHelper.AppSettings["CMSApplicationName"]; break; case MetricDataEnum.support_metrics_system_instancename: stringData = SystemContext.InstanceName; break; case MetricDataEnum.support_metrics_system_physicalpath: stringData = SystemContext.WebApplicationPhysicalPath; break; case MetricDataEnum.support_metrics_system_apppath: stringData = SystemContext.ApplicationPath; break; case MetricDataEnum.support_metrics_system_uiculture: stringData = LocalizationContext.CurrentUICulture.CultureName; break; case MetricDataEnum.support_metrics_system_installtype: stringData = SystemContext.IsWebApplicationProject ? "Web App" : "Web site"; break; case MetricDataEnum.support_metrics_system_portaltemplatepage: stringData = URLHelper.PortalTemplatePage; break; case MetricDataEnum.support_metrics_system_timesinceapprestart: stringData = (DateTime.Now - CMSApplication.ApplicationStart).ToString(@"dd\:hh\:mm\:ss"); break; case MetricDataEnum.support_metrics_system_discoveredassemblies: tupleData = AssemblyDiscoveryHelper.GetAssemblies(true).Select((a, i) => GetKeyValuePair(i, a.FullName)); break; case MetricDataEnum.support_metrics_system_targetframework: HttpRuntimeSection httpRuntime = ConfigurationManager.GetSection("system.web/httpRuntime") as HttpRuntimeSection; stringData = httpRuntime.TargetFramework; break; case MetricDataEnum.support_metrics_system_authmode: AuthenticationSection Authentication = ConfigurationManager.GetSection("system.web/authentication") as AuthenticationSection; stringData = Authentication?.Mode.ToString(); break; case MetricDataEnum.support_metrics_system_sessionmode: SessionStateSection SessionState = ConfigurationManager.GetSection("system.web/sessionState") as SessionStateSection; stringData = SessionState?.Mode.ToString(); break; case MetricDataEnum.support_metrics_system_debugmode: CompilationSection Compilation = ConfigurationManager.GetSection("system.web/compilation") as CompilationSection; stringData = Compilation?.Debug.ToString(); break; case MetricDataEnum.support_metrics_system_runallmanagedmodules: var xmlDoc = new System.Xml.XmlDocument(); xmlDoc.Load(URLHelper.GetPhysicalPath("~/Web.config")); stringData = xmlDoc.SelectSingleNode("/configuration/system.webServer/modules").Attributes["runAllManagedModulesForAllRequests"]?.Value; break; #endregion System #region Environment case MetricDataEnum.support_metrics_environment_trustlevel: AspNetHostingPermissionLevel trustLevel = AspNetHostingPermissionLevel.None; if (!SystemContext.IsWebSite) { trustLevel = AspNetHostingPermissionLevel.Unrestricted; } // Check the trust level by evaluation of levels foreach (AspNetHostingPermissionLevel permissionLevel in new[] { AspNetHostingPermissionLevel.Unrestricted, AspNetHostingPermissionLevel.High, AspNetHostingPermissionLevel.Medium, AspNetHostingPermissionLevel.Low, AspNetHostingPermissionLevel.Minimal }) { try { new AspNetHostingPermission(permissionLevel).Demand(); } catch (SecurityException) { continue; } trustLevel = permissionLevel; break; } stringData = trustLevel.ToString(); break; case MetricDataEnum.support_metrics_environment_iisversion: stringData = MetricServerVariables["SERVER_SOFTWARE"]; break; case MetricDataEnum.support_metrics_environment_https: stringData = MetricServerVariables["HTTPS"]; break; case MetricDataEnum.support_metrics_environment_windowsversion: using (RegistryKey versionKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion")) { var productName = versionKey?.GetValue("ProductName"); var currentBuild = versionKey?.GetValue("CurrentBuild"); var releaseId = versionKey?.GetValue("ReleaseId"); stringData = String.Format("{0}, build {1}, release {2}", productName.ToString(), currentBuild.ToString(), releaseId.ToString()); } break; case MetricDataEnum.support_metrics_environment_netversion: using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\")) { var keyValue = ndpKey?.GetValue("Release"); if (keyValue != null) { var releaseKey = (int)keyValue; if (releaseKey >= 461808) { stringData = "4.7.2 or later"; } else if (releaseKey >= 461308) { stringData = "4.7.1"; } else if (releaseKey >= 460798) { stringData = "4.7"; } else if (releaseKey >= 394802) { stringData = "4.6.2"; } else if (releaseKey >= 394254) { stringData = "4.6.1"; } else if (releaseKey >= 393295) { stringData = "4.6"; } else if (releaseKey >= 379893) { stringData = "4.5.2"; } else if (releaseKey >= 378675) { stringData = "4.5.1"; } else if (releaseKey >= 378389) { stringData = "4.5"; } } } break; case MetricDataEnum.support_metrics_environment_sqlserverversion: var dtm = new TableManager(null); stringData = dtm.DatabaseServerVersion; break; case MetricDataEnum.support_metrics_environment_azure: var azureStats = new Dictionary <string, string>(4) { { "Is a Cloud Service", (SettingsHelper.AppSettings["CMSAzureProject"] == "true").ToString("false") }, { "Is file system on Azure", (SettingsHelper.AppSettings["CMSExternalStorageName"] == "azure").ToString("false") }, { "Azure storage account", SettingsHelper.AppSettings["CMSAzureAccountName"] ?? String.Empty }, { "Azure CDN endpoint", SettingsHelper.AppSettings["CMSAzureCDNEndpoint"] ?? String.Empty } }; tupleData = azureStats.Select(s => GetKeyValuePair(s.Key, s.Value)); break; case MetricDataEnum.support_metrics_environment_amazon: var amazonStats = new Dictionary <string, string>(3) { { "Is file system on Amazon", (SettingsHelper.AppSettings["CMSExternalStorageName"] == "amazon").ToString() }, { "Amazon bucket name", SettingsHelper.AppSettings["CMSAmazonBucketName"] ?? String.Empty }, { "Amazon public access", SettingsHelper.AppSettings["CMSAmazonPublicAccess"] ?? String.Empty }, }; tupleData = amazonStats.Select(s => GetKeyValuePair(s.Key, s.Value)); break; case MetricDataEnum.support_metrics_environment_services: tupleData = ServiceManager.GetServices().Select(s => GetKeyValuePair(s.ServiceName, s.Status)); break; #endregion Environment #region Counters case MetricDataEnum.support_metrics_counters_webfarmservers: stringData = CoreServices.WebFarm.GetEnabledServerNames().Count().ToString(); break; case MetricDataEnum.support_metrics_counters_stagingservers: stringData = ServerInfoProvider.GetServers().GetCount().ToString(); break; case MetricDataEnum.support_metrics_counters_pagemostchildren: CMS.DocumentEngine.TreeProvider tree = new CMS.DocumentEngine.TreeProvider(); var pageWithMostChildren = tree.SelectNodes().OnCurrentSite().Published() .ToDictionary(n => n, n => n.Children.Count) .Aggregate((l, r) => l.Value > r.Value ? l : r); tupleData = new[] { GetKeyValuePair(URLHelper.GetAbsoluteUrl("~" + pageWithMostChildren.Key.NodeAliasPath), pageWithMostChildren.Value) }; break; case MetricDataEnum.support_metrics_counters_modules: stringData = ResourceInfoProvider.GetResources().GetCount().ToString(); break; case MetricDataEnum.support_metrics_counters_medialibraries: stringData = MediaLibraryInfoProvider.GetMediaLibraries().WhereNull("LibraryGroupID").GetCount().ToString(); break; case MetricDataEnum.support_metrics_counters_activities: stringData = ActivityInfoProvider.GetActivities().GetCount().ToString(); break; case MetricDataEnum.support_metrics_counters_contacts: stringData = ContactInfoProvider.GetContacts().GetCount().ToString(); break; case MetricDataEnum.support_metrics_counters_contactgroups: stringData = ContactGroupInfoProvider.GetContactGroups().GetCount().ToString(); break; case MetricDataEnum.support_metrics_counters_omrules: stringData = RuleInfoProvider.GetRules().GetCount().ToString(); break; case MetricDataEnum.support_metrics_counters_products: stringData = SKUInfoProvider.GetSKUs(SiteContext.CurrentSiteID).WhereNull("SKUOptionCategoryID").GetCount().ToString(); break; #endregion Counters #region Tasks case MetricDataEnum.support_metrics_tasks_webfarm: stringData = WebFarmTaskInfoProvider.GetWebFarmTasks() .WhereLessThan("TaskCreated", DateTime.Now.AddDays(-1)) .GetCount().ToString(); break; case MetricDataEnum.support_metrics_tasks_staging: stringData = StagingTaskInfoProvider.GetTasks() .WhereLessThan("TaskTime", DateTime.Now.AddDays(-1)) .GetCount().ToString(); break; case MetricDataEnum.support_metrics_tasks_integration: stringData = IntegrationTaskInfoProvider.GetIntegrationTasks() .WhereLessThan("TaskTime", DateTime.Now.AddDays(-1)) .GetCount().ToString(); break; case MetricDataEnum.support_metrics_tasks_scheduled: stringData = TaskInfoProvider.GetTasks() .WhereTrue("TaskDeleteAfterLastRun") .WhereLessThan("TaskNextRunTime", DateTime.Now.AddDays(-1)) .GetCount().ToString(); break; case MetricDataEnum.support_metrics_tasks_search: stringData = SearchTaskInfoProvider.GetSearchTasks() .WhereLessThan("SearchTaskCreated", DateTime.Now.AddDays(-1)) .GetCount().ToString(); break; case MetricDataEnum.support_metrics_tasks_email: stringData = EmailInfoProvider.GetEmailCount("EmailStatus = 1 AND EmailLastSendResult IS NOT NULL").ToString(); break; #endregion Tasks #region Event log case MetricDataEnum.support_metrics_eventlog_macroerrors: var macroErrors = EventLogProvider.GetEvents() .WhereEquals("Source", "MacroResolver") .WhereGreaterThan("EventTime", DateTime.Now.Subtract(TimeSpan.FromDays(7))) .OrderByDescending("EventTime") .TopN(10); tupleData = macroErrors.Select(e => GetKeyValuePair(String.Format("{0} from {1} at {2} in {3}", e.EventCode, e.Source, e.EventTime, e.EventMachineName), e.EventDescription.Length > CUTOFF ? e.EventDescription.Substring(0, CUTOFF) : e.EventDescription) ); break; case MetricDataEnum.support_metrics_eventlog_stagingerrors: var stagingErrors = EventLogProvider.GetEvents() .WhereEquals("Source", "staging") .WhereIn("EventType", new[] { "E", "W" }) .WhereGreaterThan("EventTime", DateTime.Now.Subtract(TimeSpan.FromDays(7))) .OrderByDescending("EventTime") .TopN(10); tupleData = stagingErrors.Select(e => GetKeyValuePair(String.Format("{0} from {1} at {2} in {3}", e.EventCode, e.Source, e.EventTime, e.EventMachineName), e.EventDescription.Length > CUTOFF ? e.EventDescription.Substring(0, CUTOFF) : e.EventDescription) ); break; case MetricDataEnum.support_metrics_eventlog_searcherrors: var searchErrors = EventLogProvider.GetEvents() .WhereEquals("Source", "search") .WhereIn("EventType", new[] { "E", "W" }) .WhereGreaterThan("EventTime", DateTime.Now.Subtract(TimeSpan.FromDays(7))) .OrderByDescending("EventTime") .TopN(10); tupleData = searchErrors.Select(e => GetKeyValuePair(String.Format("{0} from {1} at {2} in {3}", e.EventCode, e.Source, e.EventTime, e.EventMachineName), e.EventDescription.Length > CUTOFF ? e.EventDescription.Substring(0, CUTOFF) : e.EventDescription) ); break; case MetricDataEnum.support_metrics_eventlog_contenterrors: var contentErrors = EventLogProvider.GetEvents() .WhereEquals("Source", "content") .WhereIn("EventType", new[] { "E", "W" }) .WhereGreaterThan("EventTime", DateTime.Now.Subtract(TimeSpan.FromDays(7))) .OrderByDescending("EventTime") .TopN(10); tupleData = contentErrors.Select(e => GetKeyValuePair(String.Format("{0} from {1} at {2} in {3}", e.EventCode, e.Source, e.EventTime, e.EventMachineName), e.EventDescription.Length > CUTOFF ? e.EventDescription.Substring(0, CUTOFF) : e.EventDescription) ); break; case MetricDataEnum.support_metrics_eventlog_exceptions: var exceptions = EventLogProvider.GetEvents() .WhereEquals("EventCode", "exception") .WhereGreaterThan("EventTime", DateTime.Now.Subtract(TimeSpan.FromDays(7))) .OrderByDescending("EventTime") .TopN(10); tupleData = exceptions.Select(e => GetKeyValuePair(String.Format("{0} from {1} at {2} in {3}", e.EventCode, e.Source, e.EventTime, e.EventMachineName), e.EventDescription.Length > CUTOFF ? e.EventDescription.Substring(0, CUTOFF) : e.EventDescription) ); break; case MetricDataEnum.support_metrics_eventlog_upgrade: EventLogInfo upgrade = EventLogProvider.GetEvents().WhereLike("Source", "upgrade%").FirstOrDefault(); var version = upgrade?.Source.Split(' ')[2]; if (!String.IsNullOrEmpty(version)) { var parameters = new QueryDataParameters { { "@versionnumber", version } }; var events = ConnectionHelper.ExecuteQuery("SupportHelper.CustomMetric.checkupgrade", parameters); tupleData = (from DataRow row in events.Tables[0]?.Rows select row) .Select(r => new EventLogInfo(r)).Select(e => GetKeyValuePair(String.Format("{0} from {1} at {2} in {3}", e.EventCode, e.Source, e.EventTime, e.EventMachineName), e.EventDescription.Length > CUTOFF ? e.EventDescription.Substring(0, CUTOFF) : e.EventDescription) ); } break; #endregion Event log } if (tupleData?.Count() > 0) { return(tupleData); } if (stringData != null) { return(new[] { GetKeyValuePair(0, stringData) }); } return(new[] { GetKeyValuePair(0, ResHelper.GetStringFormat("support.metrics.invalid", MetricDisplayName, MetricCodeName)) }); }