public static bool NameExists(string newName) { using (ApplicationDataContext context = new ApplicationDataContext()) { var currentApp = context.Applications .Where(app => app.Name.ToLower() == newName.ToLower()) .FirstOrDefault(); return(currentApp != null); } }
public static int CountRows(DateTime fromDate, DateTime?toDate, TraceEventType?type, string appName) { using (ApplicationDataContext dataContext = new ApplicationDataContext()) { var pred = CreatePredicate(dataContext, fromDate, toDate, type, appName); return(dataContext.LogEntries .Where(pred) .Select(le => le.LogDate) .Count()); } }
public static int CountRows(DateTime fromDate, DateTime?toDate, string provider, string operation) { using (ApplicationDataContext dataContext = new ApplicationDataContext()) { var pred = CreatePredicate(dataContext, fromDate, toDate, provider, operation); return(dataContext.DataProviderCalls .Where(pred) .Select(le => le.CallTime) .Count()); } }
public static decimal SumCost(DateTime fromDate, DateTime?toDate, string provider, string operation) { using (ApplicationDataContext dataContext = new ApplicationDataContext()) { var pred = CreatePredicate(dataContext, fromDate, toDate, provider, operation); var ret = dataContext.DataProviderCalls .Where(pred) .Select(le => le.Cost); var s = ret.ToArray(); return(s.Sum()); } }
public static List <DataProviderCall> LoadByPage(DateTime fromDate, DateTime?toDate, string provider, string operation, int startRow, int pageSize) { using (ApplicationDataContext dataContext = new ApplicationDataContext()) { var pred = CreatePredicate(dataContext, fromDate, toDate, provider, operation); // Read records var ret = dataContext.DataProviderCalls .Where(pred) .OrderByDescending(dpc => dpc.CallTime) .Skip(startRow) .Take(pageSize) .ToList(); return(ret); } }
/// <summary> /// Reads the LogEntry objects as requested /// Makes dummy calls to Application and LogType properties to allow accessing them without the source data context object /// </summary> /// <param name="startRow">Zero based start row number</param> /// <param name="pageSize">Page size</param> /// <returns>The found LogEntry objects</returns> public static List <LogEntry> LoadByPage(DateTime fromDate, DateTime?toDate, TraceEventType?type, string appName, int startRow, int pageSize) { using (ApplicationDataContext dataContext = new ApplicationDataContext()) { var loadOptions = new DataLoadOptions(); loadOptions.LoadWith <LogEntry>(le => le.LogType); loadOptions.LoadWith <LogEntry>(le => le.Application); dataContext.LoadOptions = loadOptions; var pred = CreatePredicate(dataContext, fromDate, toDate, type, appName); // Read records var ret = dataContext.LogEntries .Where(pred) .OrderByDescending(le => le.LogDate) .Skip(startRow) .Take(pageSize) .ToList(); return(ret); } }
public static System.Linq.Expressions.Expression <Func <DataProviderCall, bool> > CreatePredicate(ApplicationDataContext dataContext, DateTime fromDate, DateTime?toDate, string provider, string operation) { var pred = CprBroker.Utilities.PredicateBuilder.True <DataProviderCall>(); if (toDate.HasValue && toDate.Value < fromDate) { var tmp = fromDate; fromDate = toDate.Value; toDate = tmp; } // By date pred = pred.And(dpc => dpc.CallTime >= fromDate); if (toDate.HasValue) { pred = pred.And(dpc => dpc.CallTime < toDate.Value.AddDays(1)); } // Byte type if (!string.IsNullOrEmpty(provider)) { pred = pred.And(dpc => dpc.DataProviderType == provider); } // By operation if (!string.IsNullOrEmpty(operation)) { pred = pred.And(dpc => dpc.Operation == operation); } return(pred); }
public static System.Linq.Expressions.Expression <Func <LogEntry, bool> > CreatePredicate(ApplicationDataContext dataContext, DateTime fromDate, DateTime?toDate, TraceEventType?type, string appName) { var pred = CprBroker.Utilities.PredicateBuilder.True <LogEntry>(); if (toDate.HasValue && toDate.Value < fromDate) { var tmp = fromDate; fromDate = toDate.Value; toDate = tmp; } // By date pred = pred.And(le => le.LogDate >= fromDate); if (toDate.HasValue) { pred = pred.And(le => le.LogDate < toDate.Value.AddDays(1)); } // Byte type if (type.HasValue) { pred = pred.And(le => le.LogTypeId == (int)type.Value); } // By app if (!string.IsNullOrEmpty(appName)) { var appId = dataContext.Applications.Where(app => app.Name == appName).Select(app => app.ApplicationId).FirstOrDefault(); pred = pred.And(le => le.ApplicationId == appId); } return(pred); }