//reads through file line-by-line and stores line to signon or signoff query private void GatherSignOnOffs() { const int END_OF_DATE = 11; const int STATUSON = 1, STATUSOFF = 2, STATUSERR = 0; MainList.ItemsSource = null; Regex signonAcceptRegex = new Regex(@"\|=42000AA0\|"); Regex signoffAcceptRegex = new Regex(@"\|=423000E0\|"); Regex signerrorAcceptRegex = new Regex(@"\|=C23000E0\||\|=C2100140\|"); Regex exitstepAcceptRegex = new Regex(@"\|=430004C0\|"); bool passedExitStep = false; LineList.Clear(); //instantiate graph object UsageGraph myGraph = new UsageGraph(GRAPH_MARGIN, canGraph.Width - GRAPH_MARGIN, GRAPH_MARGIN, canGraph.Height - GRAPH_MARGIN, canGraph.Width, canGraph.Height, GRAPH_MARGIN); MoveDot(0, 0, 0); canGraph.Children.Clear(); canGraph.Children.Add(myGraph.getXaxis()); canGraph.Children.Add(myGraph.getYaxis()); canGraph.Children.Add(myGraph.getLine()); List <LogLine> totalTaskage = new List <LogLine>(); //this keeps track of tasks currently running Dictionary <string, int> taskagePerDate = new Dictionary <string, int>(); string line = infile.ReadLine(); while (line != null) { if (signonAcceptRegex.IsMatch(line)) //someone has signed on { LogLine newListItem = new LogLine(line, STATUSON); LineList.Add(newListItem); totalTaskage.Add(newListItem); taskagePerDate[line.Substring(0, END_OF_DATE)] = totalTaskage.Count; } else if (signoffAcceptRegex.IsMatch(line)) //someone has signed off { LogLine newListItem = new LogLine(line, STATUSOFF); try { newListItem.IP = GetPreviousUsedTask(newListItem.Task).IP; } catch { newListItem.IP = ""; } LineList.Add(newListItem); totalTaskage.RemoveAll(x => x.Task == newListItem.Task); taskagePerDate[line.Substring(0, END_OF_DATE)] = totalTaskage.Count; } else if (signerrorAcceptRegex.IsMatch(line)) { LogLine newListItem = new LogLine(line, STATUSERR); LogLine prevTask = GetPreviousUsedTask(newListItem.Task); if (prevTask != null && newListItem.Status != "Disconnect Error: -1") { newListItem.IP = prevTask.IP; LineList.Add(newListItem); totalTaskage.RemoveAll(x => x.Task == newListItem.Task); taskagePerDate[line.Substring(0, END_OF_DATE)] = totalTaskage.Count; } } else if (exitstepAcceptRegex.IsMatch(line)) { passedExitStep = true; } else if (line == "NEWFILEBREAK" && taskagePerDate.Count > 0) { string myTime = taskagePerDate.LastOrDefault().Key; while (totalTaskage.Count > 0) { LogLine newListItem = new LogLine(ForceSignoffString(myTime, totalTaskage[0].Task), STATUSOFF); try { newListItem.IP = GetPreviousUsedTask(newListItem.Task).IP; } catch { newListItem.IP = ""; } LineList.Add(newListItem); totalTaskage.RemoveAt(0); } taskagePerDate[myTime] = totalTaskage.Count; if (passedExitStep == false) { StartLabel.Text = ""; EndLabel.Text = "Exit steps not properly executed. Log information may not be correct"; } passedExitStep = false; } line = infile.ReadLine(); } if (LineList.Count <= 0) { MessageBox.Show("No acceptable data inputs"); Tabs.IsEnabled = false; return; } if (passedExitStep == false) { StartLabel.Text = ""; EndLabel.Text = "Exit steps not properly executed. Log information may not be correct"; } MainList.ItemsSource = LineList; canGraph.Width = myGraph.CreateGraph(taskagePerDate); //puts the line on the graph and returns its width //not sure how to add a list of UIelements to canGraph children, so iterate through each instead List <UIElement> labelList = myGraph.labelList; foreach (UIElement label in labelList) { canGraph.Children.Add(label); } canGraph.Children.Add(dot); canGraph.Children.Add(taskageText); //seperate days using a canvas object iterating with daywidth DrawGraphBackground(myGraph, taskagePerDate.Keys.First()); }
private void DrawGraphBackground(UsageGraph myGraph, string iniStr) { const double DAY_WIDTH = 1440; SolidColorBrush bgColor1 = new SolidColorBrush(Color.FromRgb(205, 237, 255)); SolidColorBrush bgColor2 = new SolidColorBrush(Color.FromRgb(241, 241, 252)); double iniWidth = myGraph.initialWidth; if (iniWidth <= 0) { iniWidth = canGraph.Width; //iniwidth never makes it past midnight, set the entire graph to one color } DateTime startingDay = new DateTime(Int32.Parse("20" + iniStr.Substring(0, 2)), Int32.Parse(iniStr.Substring(2, 2)), Int32.Parse(iniStr.Substring(4, 2)), Int32.Parse(iniStr.Substring(7, 2)), Int32.Parse(iniStr.Substring(9, 2)), 0); Canvas iniLayout = new Canvas(); iniLayout.Height = canGraph.Height; iniLayout.Width = iniWidth; iniLayout.Margin = new Thickness(0, 0, 0, 0); iniLayout.Background = bgColor1; Canvas.SetZIndex(iniLayout, -1); TextBlock firstDayLabel = new TextBlock(); firstDayLabel.Text = startingDay.ToString("MM/dd/yyyy"); firstDayLabel.Foreground = Brushes.Black; Canvas.SetLeft(firstDayLabel, iniLayout.Width / 2); Canvas.SetBottom(firstDayLabel, GRAPH_MARGIN - 0.8 * GRAPH_MARGIN); iniLayout.Children.Add(firstDayLabel); double offset = iniWidth; int i = 0; while (canGraph.Width > offset) { Canvas bgLayout = new Canvas(); bgLayout.Height = canGraph.Height; if (offset + DAY_WIDTH > canGraph.Width) //graph won't end evenly on midnight, set to latest possible time { bgLayout.Width = canGraph.Width - (offset); } else { bgLayout.Width = DAY_WIDTH; } bgLayout.Margin = new Thickness(offset, 0, 0, 0); if (i % 2 == 0) { bgLayout.Background = bgColor2; } else { bgLayout.Background = bgColor1; } Canvas.SetZIndex(bgLayout, -1); TextBlock dayLabel = new TextBlock(); dayLabel.Text = startingDay.AddDays(i + 1).ToString("MM/dd/yyyy"); dayLabel.Foreground = Brushes.Black; Canvas.SetLeft(dayLabel, bgLayout.Width / 2); Canvas.SetBottom(dayLabel, GRAPH_MARGIN - 0.8 * GRAPH_MARGIN); bgLayout.Children.Add(dayLabel); offset = offset + DAY_WIDTH; i = i + 1; canGraph.Children.Add(bgLayout); } iniLayout.Width = iniLayout.Width + 100; canGraph.Children.Add(iniLayout); }