void gen(PlaceHolder Stats, Log.Items item) { Query q = new Query(); q.ExtraSelectElements.Add("Count", "SUM([Log].[Count])"); q.ExtraSelectElements.Add("Day", "DATENAME(DW,[Log].[Date])"); q.QueryCondition = new Q(Log.Columns.Item, item); q.GroupBy = new GroupBy("DATENAME(DW,[Log].[Date])"); q.Columns = new ColumnSet(); LogSet ls = new LogSet(q); Dictionary<DayOfWeek, double> weight = new Dictionary<DayOfWeek, double>(); int total = 0; foreach (Log l in ls) { total += (int)l.ExtraSelectElements["Count"]; } foreach (Log l in ls) { double fraction = (double)(int)l.ExtraSelectElements["Count"] / (double)total; switch ((string)l.ExtraSelectElements["Day"]) { case "Monday": weight[DayOfWeek.Monday] = fraction; break; case "Tuesday": weight[DayOfWeek.Tuesday] = fraction; break; case "Wednesday": weight[DayOfWeek.Wednesday] = fraction; break; case "Thursday": weight[DayOfWeek.Thursday] = fraction; break; case "Friday": weight[DayOfWeek.Friday] = fraction; break; case "Saturday": weight[DayOfWeek.Saturday] = fraction; break; case "Sunday": weight[DayOfWeek.Sunday] = fraction; break; default: break; } } Stats.Controls.Add(new LiteralControl("<table><tr><td>Month</td><td>Year</td><td>Weight</td><td>Actual pages</td><td>Weighted pages</td></tr>")); for (DateTime dtMonth = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(-12); dtMonth <= new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); dtMonth = dtMonth.AddMonths(1)) { try { double monthWeight = 0.0; for (DateTime dtDay = dtMonth; dtDay < dtMonth.AddMonths(1) && dtDay < DateTime.Today; dtDay = dtDay.AddDays(1)) { monthWeight += weight[dtDay.DayOfWeek]; } Query qMonth = new Query(); qMonth.ExtraSelectElements.Add("Count", "SUM([Log].[Count])"); qMonth.QueryCondition = new And( new Q(Log.Columns.Item, item), new Q(Log.Columns.Date, QueryOperator.GreaterThanOrEqualTo, dtMonth), new Q(Log.Columns.Date, QueryOperator.LessThan, dtMonth.AddMonths(1)), new Q(Log.Columns.Date, QueryOperator.LessThan, DateTime.Today)); qMonth.Columns = new ColumnSet(); LogSet lsMonth = new LogSet(qMonth); int actualPages = (int)lsMonth[0].ExtraSelectElements["Count"]; double pagesPerWeek = (double)actualPages / monthWeight; double pagesPerMonth = pagesPerWeek * 4.345238095; Stats.Controls.Add(new LiteralControl("<tr><td>" + dtMonth.ToString("MMM") + "</td><td>" + dtMonth.Year + "</td><td>" + monthWeight.ToString("0.00") + "</td><td>" + actualPages.ToString("0") + "</td><td>" + pagesPerMonth.ToString("0") + "</td></tr>")); // Stats.Controls.Add(new LiteralControl( + " " + + " is " + + " weeks. " + + " pages per week.<br>")); } catch { } } Stats.Controls.Add(new LiteralControl("</table>")); }
public Dictionary<DateTime, int> GetCountOfLogItemForDates(Log.Items logItemType, List<DateTime> dates) { return Caching.Instances.Main.GetWithLocalCaching( String.Format("GetCountOfLogItemForDates(logItemType={0}, dates={1})", logItemType, string.Join(",", dates.ConvertAll(d => d.ToShortDateString()).ToArray())), () => { var query = new Query(); query.Columns = new ColumnSet(Log.Columns.Count, Log.Columns.Date); query.QueryCondition = new And( new Q(Log.Columns.Item, logItemType), new Or( dates.ConvertAll(date => new Q(Log.Columns.Date, date.Date)).ToArray() ) ); var ls = new LogSet(query); var results = new Dictionary<DateTime, int>(); foreach (Log l in ls) { results.Add(l.Date, l.Count); } foreach (DateTime d in dates) { if (!results.ContainsKey(d.Date)) { results.Add(d.Date, 0); } } return results; }, 5.Minutes(), 1.Days() ); }
protected override void OnFormat(ConvertEventArgs e) { // this doesn't 't call the base implementation as we're overriding behavior, not extending... // log... if (this.Log.IsInfoEnabled) { this.Log.Info(string.Format(Cultures.Log, "Requested format of '{0}' to '{1}'", LogSet.ToString(e.Value), e.DesiredType)); } // convert... if (typeof(string).IsAssignableFrom(e.DesiredType)) { e.Value = ConversionHelper.ToString(e.Value, Cultures.User); } else { e.Value = ConversionHelper.ChangeType(e.Value, e.DesiredType, Cultures.User, ConversionFlags.Safe); } // log... if (this.Log.IsInfoEnabled) { this.Log.Info(string.Format(Cultures.Log, "\tResult: {0}", LogSet.ToString(e.Value))); } }
public static Task ProcessItemsInParallel <T>(this IEnumerable <T> items, Action <T> doWork, Action <T> ok = null, Action <T, Exception> failure = null, Action <T> finished = null, ITimingBucket timings = null) { var tasks = new List <Task>(); items.ProcessItemsInternal <T>((item) => { var task = Task.Run <Exception>(() => { try { doWork(item); return(null); } catch (Exception ex) { return(ex); } }); tasks.Add(task); return(task); }, ok, failure, finished, timings); // wait... var log = LogSet.GetLog(typeof(CollectionsExtender)); if (log.IsInfoEnabled) { log.InfoFormat("{0}: waiting for threads...", typeof(T).Name); } return(Task.WhenAll(tasks.ToArray())); }
/// <summary> /// Creates a LogSetTabItem /// </summary> /// <param name="logset"></param> /// <returns></returns> private void CreateLogSetTabItem(LogSet logset) { Interlocked.Increment(ref _currentTabCount); var heading = string.Format("Set [{0}]", _currentTabCount); logset.Name = heading; var tabitem = new LogSetTabItem() { Header = heading, Content = new LogSetGrid(logset), SearchOptions = new LogSetSearchOptions() { IsEmptySearch = true }, OwnerWindow = this }; tabitem.Close += (sen, arg) => { tcLogSets.RemoveLogSetTab(sen); if (tcLogSets.Items.Count == 0) { EnableLogSetControls(false); } }; tcLogSets.AddLogSetTab(tabitem); }
protected override void OnParse(ConvertEventArgs e) { // this doesn't 't call the base implementation as we're overriding behavior, not extending... // log... if (this.Log.IsInfoEnabled) { this.Log.Info(string.Format(Cultures.Log, "Requested parse of '{0}' to '{1}'", LogSet.ToString(e.Value), e.DesiredType)); } // unwrap an entity view... object value = EntityView.Unwrap(e.Value); // get the entity type... if (e.DesiredType.IsAssignableFrom(value.GetType()) == true) { e.Value = value; } else { throw new InvalidOperationException(string.Format(Cultures.Exceptions, "Cannot convert '{0}' to '{1}'.", value.GetType(), e.DesiredType)); } // log... if (this.Log.IsInfoEnabled) { this.Log.Info(string.Format(Cultures.Log, "\tResult: {0}", LogSet.ToString(e.Value))); } }
protected override void OnSaved(EventArgs e) { base.OnSaved(e); // if the file has been saved, redo the logs... (we can't redo connection strings as this would probably break the app, // but logs should be fairly innocuous.) LogSet.IncrementContextId(); }
public LogSetMetricsHTML(LogSet logset) : this() { _logset = logset; _logset.PropertyChanged += logset_PropertyChanged; this.Title = GetTitle(); LoadMetrics(); }
public Dictionary <string, LogSession> LoadSet(LogSet set, Dictionary <string, string> environments = null) { var logSessions = new Dictionary <string, LogSession>(); foreach (var app in set.Logs.Keys) { if (!Options.Applications.TryGetValue(app, out Application appObj)) { throw new ArgumentException("Application not found.", app); } foreach (var module in set.Logs[app]) { if (!appObj.Modules.TryGetValue(module.Key, out Module moduleObj)) { throw new ArgumentException("Module not found.", $"{app}:{module.Key}"); } string environment = null; if (environments != null) { if (!environments.TryGetValue(app, out environment)) { environment = set.Environments[app]; } } if (environment == null) { throw new ArgumentException("Missing environment for application.", app); } //if (!appObj.Environments.Contains(environment)) // throw new ArgumentException("Environment not declared.", $"{app}:{environment}"); // should be just a warning if (!moduleObj.Connections.TryGetValue(environment, out Connection connection)) { throw new ArgumentException("Connection not found.", $"{app}:{module.Key}:{environment}"); } if (!Options.Credentials.TryGetValue(connection.Credentials, out Credentials credentials)) { throw new ArgumentException("Credentials not found.", $"{connection.Credentials}"); } foreach (var log in module.Value) { if (!moduleObj.Logs.TryGetValue(log, out Log logObj)) { throw new ArgumentException("Log not found.", $"{app}:{module.Key}:{log}"); } logSessions.Add($"{app}.{module.Key}.{log}", new LogSession(connection, credentials, logObj)); } } } return(logSessions); }
protected void bind(DateTime d) { Query q = new Query(); q.NoLock = false; q.QueryCondition = new Q(Log.Columns.Date, d.Date); q.OrderBy = new OrderBy(Log.Columns.Item); LogSet ls = new LogSet(q); Times.DataSource = ls; Times.DataBind(); }
public SPLogMonitor(LogSet logset) : this() { var grid = new LogSetGrid(logset, true); Grid.SetColumn(grid, 0); Grid.SetRow(grid, 1); main.Children.Add(grid); this.Closing += SPLogMonitor_Closing; }
public void DumpToLog(ILog log = null) { if (log == null) { log = LogSet.GetLog <ProcessRunResults>(); } if (log.IsInfoEnabled) { log.Info(this.ToString()); } }
private void menuLogTestMessage_Click(object sender, System.EventArgs e) { ILog log = LogSet.GetLog(this.GetType()); log.Debug("I am a debug message"); log.Info("I am a info message"); log.Warn("I am a warning message"); log.Error("I am a error message"); log.Fatal("I am a fatal message"); // tell... Alert.ShowInformation(this, "Messages have been written to all categories."); }
private void OnEnable() { testList.Add(new TestUnit("name1", "success")); testList.Add(new TestUnit("qqeqame2", "success")); testList.Add(new TestUnit("name3", "success")); testList.Add(new TestUnit("qeqe", "false")); testList.Add(new TestUnit("name5", "success")); testList.Add(new TestUnit("eqwq", "success")); testList.Add(new TestUnit("name7", "success")); for (int i = 0; i < 100; i++) { testList.Add(new TestUnit("name1", "success")); LogSet.Add(new Tuple <ToolLogType, string>(ToolLogType.Info, "11")); } }
public LogSetGrid(LogSet logset, bool IsLogMonitor = false) : this() { this.LogSetDataSource = logset; //init grid CreateGridColumns(); BindGrid(); if (IsLogMonitor) { //grid.CellStyle = null; grid.RowStyle = null; grid.IsReadOnly = true; } }
protected override void OnResize(EventArgs e) { base.OnResize(e); if (this.DesignMode) { return; } try { // get... Image image = this.ResolvedImage; Size size = Size.Empty; if (image == null) { size = new Size(32, 32); } else { size = image.Size; } // get... Rectangle all = new Rectangle(this.ClientRectangle.Location, this.ClientRectangle.Size); const int padding = 5; all.Inflate(0 - padding, 0 - padding); // image... _imageRectangle = new Rectangle(all.Right - size.Width - padding, all.Top + (all.Height / 2) - (size.Height / 2), size.Width, size.Height); _textRectangle = new Rectangle(all.Left, all.Top, all.Right - _imageRectangle.Width - (2 * padding), all.Height); // invalidate... this.Invalidate(); } catch (Exception ex) { ILog log = LogSet.GetLog(this.GetType()); if (log.IsWarnEnabled) { log.Warn("Failed when resizing.", ex); } } }
protected string Number(int DateSpan, int StatType) { TimeSpan ts = DateTime.Today.Subtract(new DateTime(1970, 1, 1)); int dayIndexNow = ts.Days; //return dayIndexNow.ToString(); int dayMin = dayIndexNow; int dayMax = dayIndexNow; DateTime dateMin = DateTime.Today; DateTime dateMax = DateTime.Today.AddDays(1); bool estimateWholeDay = false; if (DateSpan == 10) estimateWholeDay = true; else if (DateSpan == 1) { dayMin = dayIndexNow - 1; dayMax = dayIndexNow - 1; dateMin = DateTime.Today.AddDays(-1); dateMax = DateTime.Today; } else if (DateSpan == 2) { dayMin = dayIndexNow - 7; dayMax = dayIndexNow - 1; dateMin = DateTime.Today.AddDays(-7); dateMax = DateTime.Today; } else if (DateSpan == 3) { dayMin = dayIndexNow - 30; dayMax = dayIndexNow - 1; dateMin = DateTime.Today.AddMonths(-1); dateMax = DateTime.Today; } else if (DateSpan == 4) { dayMin = dayIndexNow - 365; dayMax = dayIndexNow - 1; dateMin = DateTime.Today.AddDays(-365); dateMax = DateTime.Today; } else if (DateSpan == 5) { dayMin = 0; dayMax = dayIndexNow; dateMin = new DateTime(2000, 1, 1); dateMax = new DateTime(3000, 1, 1); } else if (DateSpan == 15) { dayMin = 0; dayMax = dayIndexNow; dateMin = DateTime.Now.AddMinutes(-5); dateMax = DateTime.Now; } else if (DateSpan == 130) { dayMin = 0; dayMax = dayIndexNow; dateMin = DateTime.Now.AddMinutes(-30); dateMax = DateTime.Now; } int number = 0; if (StatType == 1) // Uniques { Query q = new Query(); q.NoLock = true; q.Columns = new ColumnSet(); q.ExtraSelectElements["count"] = "count(distinct Guid)"; q.QueryCondition = new And( new Or(new Q(Visit.Columns.DateTimeStart, QueryOperator.GreaterThanOrEqualTo, dateMin), new Q(Visit.Columns.DateTimeLast, QueryOperator.GreaterThanOrEqualTo, dateMin)), new Or(new Q(Visit.Columns.DateTimeStart, QueryOperator.LessThan, dateMax), new Q(Visit.Columns.DateTimeLast, QueryOperator.LessThan, dateMax)), new Or(new Q(Visit.Columns.Pages, QueryOperator.GreaterThan, 1), new Q(Visit.Columns.IsNewGuid, false)) ); VisitSet vs = new VisitSet(q); number = (int)vs[0].ExtraSelectElements["count"]; } else if (StatType == 2) //Pages { Query q = new Query(); q.NoLock = true; q.Columns = new ColumnSet(); q.ExtraSelectElements["sum"] = "sum(Count)"; q.QueryCondition = new And( new Q(Log.Columns.Date, QueryOperator.GreaterThanOrEqualTo, dateMin), new Q(Log.Columns.Date, QueryOperator.LessThan, dateMax), new Q(Log.Columns.Item, Log.Items.DsiPages) ); LogSet ls = new LogSet(q); number = (int)ls[0].ExtraSelectElements["sum"]; } else if (StatType == 4) //Photos { if (DateSpan == 5) { Query q = new Query(); q.NoLock = true; q.OrderBy = new OrderBy(Photo.Columns.K, OrderBy.OrderDirection.Descending); q.Columns = new ColumnSet(Photo.Columns.K); q.TopRecords = 1; PhotoSet ps = new PhotoSet(q); number = ps[0].K; } else { Query q = new Query(); q.NoLock = true; q.QueryCondition = new And( Photo.EnabledQueryCondition, new Q(Photo.Columns.EnabledDateTime, QueryOperator.GreaterThanOrEqualTo, dateMin), new Q(Photo.Columns.EnabledDateTime, QueryOperator.LessThan, dateMax) ); q.ReturnCountOnly = true; PhotoSet ps = new PhotoSet(q); number = ps.Count; } } else if (StatType == 5) //Events { if (DateSpan == 5) { Query q = new Query(); q.NoLock = true; q.OrderBy = new OrderBy(Event.Columns.K, OrderBy.OrderDirection.Descending); q.Columns = new ColumnSet(Event.Columns.K); q.TopRecords = 1; EventSet es = new EventSet(q); number = es[0].K; } else { Query q = new Query(); q.NoLock = true; q.QueryCondition = new And( new Q(Event.Columns.AddedDateTime, QueryOperator.GreaterThanOrEqualTo, dateMin), new Q(Event.Columns.AddedDateTime, QueryOperator.LessThan, dateMax) ); q.ReturnCountOnly = true; EventSet es = new EventSet(q); number = es.Count; } } else if (StatType == 6) //New users { if (DateSpan == 5) { Query q = new Query(); q.NoLock = true; q.OrderBy = new OrderBy(Usr.Columns.K, OrderBy.OrderDirection.Descending); q.Columns = new ColumnSet(Usr.Columns.K); q.TopRecords = 1; UsrSet us = new UsrSet(q); number = us[0].K; } else { Query q = new Query(); q.NoLock = true; q.QueryCondition = new And( new Q(Usr.Columns.DateTimeSignUp, QueryOperator.GreaterThanOrEqualTo, dateMin), new Q(Usr.Columns.DateTimeSignUp, QueryOperator.LessThan, dateMax) ); q.ReturnCountOnly = true; UsrSet us = new UsrSet(q); number = us.Count; } } else if (StatType == 7) //Users logged on { if (DateSpan == 5) { Query q = new Query(); q.NoLock = true; q.QueryCondition = Usr.IsNotSkeletonQ; q.ReturnCountOnly = true; UsrSet us = new UsrSet(q); number = us.Count; } else { Query q = new Query(); q.NoLock = true; if (DateSpan == 1) { q.QueryCondition = new Q(Usr.Columns.DateTimeLastPageRequest, QueryOperator.GreaterThanOrEqualTo, DateTime.Now.AddDays(-1)); } else { q.QueryCondition = new And( new Q(Usr.Columns.DateTimeLastPageRequest, QueryOperator.GreaterThanOrEqualTo, dateMin), new Q(Usr.Columns.DateTimeLastPageRequest, QueryOperator.LessThan, dateMax) ); } q.QueryCondition = new And(Usr.IsNotSkeletonQ, q.QueryCondition); q.ReturnCountOnly = true; UsrSet us = new UsrSet(q); number = us.Count; } } else if (StatType == 8) //Comments { if (DateSpan == 5) { Query q = new Query(); q.NoLock = true; q.OrderBy = new OrderBy(Comment.Columns.K, OrderBy.OrderDirection.Descending); q.Columns = new ColumnSet(Comment.Columns.K); q.TopRecords = 1; CommentSet cs = new CommentSet(q); number = cs[0].K; } else { Query q = new Query(); q.NoLock = true; q.QueryCondition = new And( new Q(Comment.Columns.DateTime, QueryOperator.GreaterThanOrEqualTo, dateMin), new Q(Comment.Columns.DateTime, QueryOperator.LessThan, dateMax) ); q.ReturnCountOnly = true; CommentSet cs = new CommentSet(q); number = cs.Count; } } else if (StatType == 9) //PMs { Query q = new Query(); q.NoLock = true; q.QueryCondition = new And( new Q(Comment.Columns.DateTime, QueryOperator.GreaterThanOrEqualTo, dateMin), new Q(Comment.Columns.DateTime, QueryOperator.LessThan, dateMax), new Q(Thread.Columns.Private, true), new Q(Comment.Columns.UsrK, QueryOperator.NotEqualTo, 7646) ); q.TableElement = Comment.ThreadJoin; q.ReturnCountOnly = true; CommentSet cs = new CommentSet(q); number = cs.Count; } else if (StatType == 10) //Chat massages { if (DateSpan == 5) { Query q = new Query(); q.NoLock = true; q.OrderBy = new OrderBy(ChatMessage.Columns.K, OrderBy.OrderDirection.Descending); q.Columns = new ColumnSet(ChatMessage.Columns.K); q.TopRecords = 1; ChatMessageSet cms = new ChatMessageSet(q); number = cms[0].K; } else { Query q = new Query(); q.NoLock = true; q.QueryCondition = new And( new Q(ChatMessage.Columns.DateTime, QueryOperator.GreaterThanOrEqualTo, dateMin), new Q(ChatMessage.Columns.DateTime, QueryOperator.LessThan, dateMax) ); q.ReturnCountOnly = true; ChatMessageSet cms = new ChatMessageSet(q); number = cms.Count; } } else if (StatType == 11) //Photo views { Query q = new Query(); q.NoLock = true; q.Columns = new ColumnSet(); q.ExtraSelectElements["sum"] = "sum(Count)"; q.QueryCondition = new And( new Q(Log.Columns.Date, QueryOperator.GreaterThanOrEqualTo, dateMin), new Q(Log.Columns.Date, QueryOperator.LessThan, dateMax), new Q(Log.Columns.Item, Log.Items.PhotoImpressions) ); LogSet ls = new LogSet(q); number = (int)ls[0].ExtraSelectElements["sum"]; } else if (StatType == 12) // Unique members from visit table { Query q = new Query(); q.NoLock = true; q.Columns = new ColumnSet(); q.ExtraSelectElements["count"] = "count(distinct UsrK)"; q.QueryCondition = new And( new Or(new Q(Visit.Columns.DateTimeStart, QueryOperator.GreaterThanOrEqualTo, dateMin), new Q(Visit.Columns.DateTimeLast, QueryOperator.GreaterThanOrEqualTo, dateMin)), new Or(new Q(Visit.Columns.DateTimeStart, QueryOperator.LessThan, dateMax), new Q(Visit.Columns.DateTimeLast, QueryOperator.LessThan, dateMax)) ); VisitSet vs = new VisitSet(q); number = (int)vs[0].ExtraSelectElements["count"]; } else if (StatType == 13) //New users { Query q = new Query(); q.NoLock = true; q.QueryCondition = new And( new Q(Usr.Columns.DateTimeSignUp, QueryOperator.GreaterThanOrEqualTo, dateMin), new Q(Usr.Columns.DateTimeSignUp, QueryOperator.LessThan, dateMax), new Or(new Q(Usr.Columns.IsSkeleton, false), new Q(Usr.Columns.IsSkeleton, QueryOperator.IsNull, null)) ); q.ReturnCountOnly = true; UsrSet us = new UsrSet(q); number = us.Count; } else number = 0; //if (estimateWholeDay) //{ // number = (int)Banner.EstimateFullDay(DateTime.Now, number); //} if (number == 0) return "<small>n/a</small>"; else return number.ToString("###,##0"); }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs) { global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); LogSet ds = new LogSet(); global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny(); any1.Namespace = "http://www.w3.org/2001/XMLSchema"; any1.MinOccurs = new decimal(0); any1.MaxOccurs = decimal.MaxValue; any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any1); global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny(); any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1"; any2.MinOccurs = new decimal(1); any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax; sequence.Items.Add(any2); global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute1.Name = "namespace"; attribute1.FixedValue = ds.Namespace; type.Attributes.Add(attribute1); global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute(); attribute2.Name = "tableTypeName"; attribute2.FixedValue = "dbo_RX_logDataTable"; type.Attributes.Add(attribute2); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext(); ) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte())); ) { ; } if ((s1.Position == s1.Length)) { return type; } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return type; }
public Admin(DiscordSocketClient client, LogSet log, BotDbContext db) { Client = client; Logs = log; Database = db; }
protected void Page_Load(object sender, EventArgs e) { if (!Usr.Current.IsAdmin) throw new Exception("Admin only!"); Write("Year", Year.ToString()); Write("Month", Month.ToString("00")); Write("GenerationDateTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); try { Query q = new Query(); q.NoLock = true; q.Columns = new ColumnSet(); q.ExtraSelectElements["sum"] = "sum(Count)"; q.QueryCondition = new And( new Q(Log.Columns.Date, QueryOperator.GreaterThanOrEqualTo, Start), new Q(Log.Columns.Date, QueryOperator.LessThan, End), new Q(Log.Columns.Item, Log.Items.DsiPages) ); LogSet ls = new LogSet(q); Write("PageImpressions", ls[0].ExtraSelectElements["sum"].ToString()); } catch { Write("PageImpressions", "0"); } /* UniqueVisitors MembersOnline NewMembers LiveChatPosts Comments PhotosAdded EventsAdded TunesAdded NewPromoters Stat1 Stat2 Stat3 Stat4 Stat5 Banner1Name Banner1SlotWeekPrice Banner1MaximumSlotWeeks Banner1Impressions Banner1SlotWeeksSold Banner1Revenue Banner2Name Banner2SlotWeekPrice Banner2MaximumSlotWeeks Banner2Impressions Banner2SlotWeeksSold Banner2Revenue Banner3Name Banner3SlotWeekPrice Banner3MaximumSlotWeeks Banner3Impressions Banner3SlotWeeksSold Banner3Revenue Banner4Name Banner4SlotWeekPrice Banner4MaximumSlotWeeks Banner4Impressions Banner4SlotWeeksSold Banner4Revenue Banner5Name Banner5SlotWeekPrice Banner5MaximumSlotWeeks Banner5Impressions Banner5SlotWeeksSold Banner5Revenue Banner6Name Banner6SlotWeekPrice Banner6MaximumSlotWeeks Banner6Impressions Banner6SlotWeeksSold Banner6Revenue Banner7Name Banner7SlotWeekPrice Banner7MaximumSlotWeeks Banner7Impressions Banner7SlotWeeksSold Banner7Revenue Banner8Name Banner8SlotWeekPrice Banner8MaximumSlotWeeks Banner8Impressions Banner8SlotWeeksSold Banner8Revenue Banner9Name Banner9SlotWeekPrice Banner9MaximumSlotWeeks Banner9Impressions Banner9SlotWeeksSold Banner9Revenue Banner10Name Banner10SlotWeekPrice Banner10MaximumSlotWeeks Banner10Impressions Banner10SlotWeeksSold Banner10Revenue Banner1AgencyImpressionsSent Banner1AgencyDefaultReturned Banner2AgencyImpressionsSent Banner2AgencyDefaultReturned Banner3AgencyImpressionsSent Banner3AgencyDefaultReturned Banner4AgencyImpressionsSent Banner4AgencyDefaultReturned Banner5AgencyImpressionsSent Banner5AgencyDefaultReturned Banner6AgencyImpressionsSent Banner6AgencyDefaultReturned Banner7AgencyImpressionsSent Banner7AgencyDefaultReturned Banner8AgencyImpressionsSent Banner8AgencyDefaultReturned Banner9AgencyImpressionsSent Banner9AgencyDefaultReturned Banner10AgencyImpressionsSent Banner10AgencyDefaultReturned DonationsCount DonationsRevenue OtherRevenue1Name OtherRevenue1Value OtherRevenue2Name OtherRevenue2Value OtherRevenue3Name OtherRevenue3Value OtherRevenue4Name OtherRevenue4Value OtherRevenue5Name OtherRevenue5Value GuestlistCreditsUsed GuestlistCreditRevenue TicketsCount TicketsRevenue DownloadsCount DownloadsRevenue * */ Response.Write("<pre>"); Response.Write(sb.ToString()); Response.Write("</pre>"); Response.End(); }
internal static void ProcessItemsInternal <T>(this IEnumerable <T> items, Func <T, Task <Exception> > doWork, Action <T> ok, Action <T, Exception> failure, Action <T> finished, ITimingBucket bucket) { if (doWork == null) { throw new ArgumentNullException("doWork"); } var log = LogSet.GetLog(typeof(CollectionsExtender)); if (bucket == null) { bucket = NullTimingBucket.Instance; } var name = typeof(T).Name; var result = new ProcessItemsResult <T>(DateTime.UtcNow); if (items.Any()) { log.LogTrace(() => string.Format("{0}: processing '{1}' items(s)...", name, items.Count())); var tasks = new List <Task>(); foreach (var item in items) { try { var timer = new AccurateTimer(); timer.Start(); var error = doWork(item); timer.Stop(); if (error == null) { throw new InvalidOperationException("Work delegate returned null."); } // error? error.Wait(); if (error.Result != null) { throw new InvalidOperationException("Item processing failed.", error.Result); } // set... result.Timings[item] = timer.DurationAsDecimal; if (ok != null) { ok(item); } } catch (Exception ex) { if (log.IsErrorEnabled) { if (typeof(T).IsAssignableFrom(typeof(IEntityId))) { log.Error(string.Format("Failed to process item of type '{0}' with ID #{1}.", name, ((IEntityId)item).Id), ex); } else { log.Error(string.Format("Failed to process item of type '{0}'.", name), ex); } } if (failure != null) { failure(item, ex); } } finally { if (finished != null) { finished(item); } } } log.LogTrace(() => string.Format("{0}: finished.", name)); } else { log.LogTrace(() => string.Format("{0}: nothing to do.", name)); } }
public Search(LogSet logs, BotDbContext db, SearchService searchService) : base(db) { Logs = logs; SearchService = searchService; }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) { LogSet ds = new LogSet(); global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny(); any.Namespace = ds.Namespace; sequence.Items.Add(any); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext(); ) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte())); ) { ; } if ((s1.Position == s1.Length)) { return type; } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return type; }
public Standard(BotDbContext db, LogSet logs) : base(db) { Logs = logs; }
public All(LogSet logs, SearchService search) { Logs = logs; SearchService = search; }
/// <summary> /// Основной рабочий конструктор /// </summary> /// <param name="set">Набор логеров для записи</param> public DayLoger(LogSet set) : base(set) { }
public static int GetSum(Items item, DateTime dateTimeGreaterThanOrEqualTo, DateTime dateTimeLessThan) { Query q = new Query(); q.Columns = new ColumnSet(); q.ExtraSelectElements.Add("sum", "sum(Count)"); q.QueryCondition = new And( new Q(Log.Columns.Date, QueryOperator.GreaterThanOrEqualTo, dateTimeGreaterThanOrEqualTo), new Q(Log.Columns.Date, QueryOperator.LessThan, dateTimeLessThan), new Q(Log.Columns.Item, item)); LogSet ls = new LogSet(q); if (ls[0].ExtraSelectElements["sum"].Equals(System.DBNull.Value)) return 0; else return (int)ls[0].ExtraSelectElements["sum"]; }
static void Main(string[] args) { int cnt = 10000; int mod = 1000; if (args.Length > 0 && int.TryParse(args[0], out int usercnt)) { cnt = usercnt; } if (args.Length > 1 && int.TryParse(args[1], out int usermod)) { mod = usermod; } var rnd = new Random(); var set = new LogSet <Data>( ".", "test", 100, d => (rnd.Next() % 10), d => (d.Id), d => UTF8.GetBytes(JsonConvert.SerializeObject(d)), bArr => JsonConvert.DeserializeObject <Data>(UTF8.GetString(bArr)), maxFileSize: sizeof(byte) * 2048 * 1000); var data = new Data[cnt]; for (int i = 0; i < cnt; i++) { var d = new Data { DateTime = DateTime.Now, Id = new Guid( BitConverter.GetBytes(rnd.Next() % mod) .Concat(BitConverter.GetBytes(2)) .Concat(BitConverter.GetBytes(2)) .Concat(BitConverter.GetBytes(2)).ToArray()), //Id = Guid.NewGuid(), Num = i, Name = rnd.Next().ToString() }; data[i] = d; } var w = new Stopwatch(); w.Start(); for (int i = 0; i < cnt; i++) { set.Add(data[i]); //set.Remove(data[i]); } w.Stop(); //set = null; //GC.WaitForPendingFinalizers(); //GC.Collect(); Console.WriteLine($"WRITE: {w.ElapsedMilliseconds}ms -> {(double)w.ElapsedMilliseconds / cnt}ms/op -> {cnt / TimeSpan.FromMilliseconds(w.ElapsedMilliseconds).TotalSeconds}ops/sec"); set.Compact(false); w.Restart(); set = new LogSet <Data>( ".", "test", 100, d => (rnd.Next() % 10), d => (d.Id), d => UTF8.GetBytes(JsonConvert.SerializeObject(d)), bArr => JsonConvert.DeserializeObject <Data>(UTF8.GetString(bArr)), true); w.Stop(); //foreach (var item in set) //{ // Console.WriteLine($"{item.DateTime} ; {item.Name} ; {item.Num} ; {item.Id}"); //} Console.WriteLine($"Read {set.Count} in {w.ElapsedMilliseconds}ms -> {(double)w.ElapsedMilliseconds / set.Count}ms/op -> {set.Count / TimeSpan.FromMilliseconds(w.ElapsedMilliseconds).TotalSeconds}ops/sec"); }
/// <summary> /// Runs the supplied process. /// </summary> /// <param name="process"></param> public void Run(OperationDialogProcess process) { if (process == null) { throw new ArgumentNullException("process"); } // check... if (process.Context == null) { throw new InvalidOperationException("process.Context is null."); } // mbr - 2008-11-27 - if it doesn't have an operation, give it us... if (process.Context.InnerOperation == null || process.Context.DefaultInnerOperationUsed) { process.Context.InnerOperation = this; } // load called? if (!(this.LoadCalled)) { _runOnLoad = process; return; } // thread? if (_thread != null) { throw new InvalidOperationException("A thread is already running."); } // create... _thread = new ThreadUIHelper(this, this); // mbr - 10-05-2007 - changed this to create a log file if we haven't been given one explicitly... if (process.Context.HasInnerLog) { _thread.BoundLog = process.Context.InnerLog; } else { // log... FileLog log = LogSet.CreateFileLogger(process.GetType().Name, FileLoggerFlags.AddDateToFileName | FileLoggerFlags.EnsureNewFile | FileLoggerFlags.OwnFolder); if (log == null) { throw new InvalidOperationException("log is null."); } // set... _thread.BoundLog = log; } // events... _thread.Failed += new System.Threading.ThreadExceptionEventHandler(_thread_Failed); _thread.Succeeded += new ResultEventHandler(_thread_Succeeded); // run... _thread.RunAsync(process, "Run"); }
static async Task Main(string[] args) { var result = Parser.Default.ParseArguments <CliOptions>(args); await result.MapResult(async cliOptions => { var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddYamlFile(cliOptions.ConfigFile, false).Build(); var sshCatcher = new SshCatcher(config.GetSection("sshCatcher").Get <SshOptions>()); // Get logs and environments Dictionary <string, LogSession> logSessions = new Dictionary <string, LogSession>(); cliOptions.Presets.ToList().ForEach(p => { logSessions.AddRange(sshCatcher.LoadPreset(cliOptions.Presets.First(), LogSet.ParseEnvironments(cliOptions.Environments.ToArray()))); }); logSessions.AddRange(sshCatcher.LoadSet(new LogSet(cliOptions.Environments, cliOptions.Logs))); // Start capture await logSessions.SetupAll(); await logSessions.StartAll(); Console.WriteLine("Logs started! Press ENTER to stop..."); // Wait for user input before stopping capture Console.ReadLine(); Console.WriteLine("Stopping and downloading logs. Please wait..."); var output = await logSessions.StopAll(); // Get output directory string outputFolder = cliOptions.Output; if (string.IsNullOrWhiteSpace(outputFolder)) { var defaultFolder = config.GetValue <string>("outputFolder") ?? string.Empty; outputFolder = Path.Combine(defaultFolder, DateTime.Now.ToString("yyyyMMdd-HHmmss")); } var directory = Directory.CreateDirectory(outputFolder); output.ToList().ForEach(o => { File.WriteAllText(Path.Combine(directory.FullName, o.Key + ".log"), o.Value); }); }, errors => Task.FromResult(0)); }
private Exception HandleSaveException(Exception ex) { // log... FileLog log = LogSet.CreateFileLogger("Simple XML Dump Failure", FileLoggerFlags.Default, new GenericFormatter()); // dump... log.Error("Original error...", ex); // keys... List <object> testKeys = new List <object>(); foreach (object key in Keys) { testKeys.Add(key); } // while... object failKey = null; while (testKeys.Count > 0) { // also, go through and create a document with each value in it and see if you can suss it that way... XmlDocument testDoc = new XmlDocument(); XmlElement root = testDoc.CreateElement("Root"); testDoc.AppendChild(root); foreach (string key in testKeys) { this.SaveValueAsElement(root, key, this.InnerValues[key], SimpleXmlSaveMode.ReplaceExisting); } // out... try { string buf = testDoc.OuterXml; if (buf == null) { throw new InvalidOperationException("'buf' is null."); } if (buf.Length == 0) { throw new InvalidOperationException("'buf' is zero-length."); } // ok... if (failKey == null) { log.Info("OK - fail key was CLR null."); } else { log.InfoFormat("OK - fail key was: {0}", failKey); // value... object failValue = this.InnerValues[failKey]; log.InfoFormat("Fail value was: {0}", failValue); // builder... if (failValue is string) { StringBuilder builder = new StringBuilder(); string failString = (string)failValue; for (int index = 0; index < failString.Length; index++) { if (index > 0 && index % 16 == 0) { builder.Append("\r\n"); } builder.Append(((int)failString[index]).ToString("x")); builder.Append(" "); } // show... log.InfoFormat("Fail value hex dump:\r\n{0}", builder); } } // stop... break; } catch (Exception miniEx) { log.Info(string.Format("Double-check failed ({0}).\r\n-------------------------------------", testKeys.Count), miniEx); } // remove... failKey = testKeys[0]; log.InfoFormat("Key '{0}' removed...", failKey); testKeys.RemoveAt(0); } // dump... return(new InvalidOperationException(string.Format("An error occurred when saving the property bag to XML. A log file was written to: {0}", log.Path), ex)); }