public Window1(Json_tool toolkit)
        {
            InitializeComponent();
            this.toolkit = toolkit;
            try
            {
                toolkit.Connections();
            }
            catch
            {
                Console.Write("No Credit Union Connections Found");
            }

            DataContext = this;

            _bgWorker.DoWork += (s, e) =>
            {
                make_Pings();
            };

            _bgWorker.RunWorkerAsync();
        }
        public InfoWin(Json_tool toolkit)
        {
            InitializeComponent();

            //sets heading to Credit union and name
            //if name not given screen prints user
            CU.Text = toolkit.QAmap[1];
            if (!String.IsNullOrEmpty(toolkit.QAmap[2]))
            {
                Intro.Text = toolkit.QAmap[2] + " at";
            }
            //sets up the diagnosis and the errorcode
            this.Diagnosis.Text = toolkit.ErDisplay(toolkit.Ernum);
            this.Raw.Text       = toolkit.Ernum.ToString();
            //base 3 to decimal to hexadecimal
            List <int> digits = toolkit.Ernum.Select(x => Convert.ToInt32(x.ToString())).ToList();

            this.Code.Text = FromDigits(digits, 3).ToString("X");

            //runs DisplaySteps and sets steps, description, and contact on page
            toolkit.DisplaySteps();
            this.information  = toolkit.steps.ToString();
            this.Contact.Text = toolkit.contacts;

            bool qa = toolkit.QAMap();

            if (qa == true)
            {
                this.QACode.Text         = toolkit.QAmap[0];
                this.ProblemMap.Text     = toolkit.QAProb;
                this.ProblemName.Text    = toolkit.QAName;
                this.QA.Visibility       = Visibility.Visible;
                this.QA.Margin           = new Thickness(0);
                this.QaBorder.Visibility = Visibility.Visible;
            }


            ColumnDefinition col = new ColumnDefinition();

            col.Width = GridLength.Auto;
            this.descGrid.ColumnDefinitions.Add(col);
            int b = 0;

            for (int i = 0; i < toolkit.desc.Count(); i++)
            {
                this.descGrid.Height         = Double.NaN;
                descGrid.HorizontalAlignment = HorizontalAlignment.Center;
                RowDefinition newdesc  = new RowDefinition();
                RowDefinition newsteps = new RowDefinition();
                newdesc.Height  = GridLength.Auto;
                newsteps.Height = GridLength.Auto;
                this.descGrid.RowDefinitions.Add(newdesc);
                this.descGrid.RowDefinitions.Add(newsteps);
                TextBlock descript = new TextBlock();
                descript.Text = toolkit.desc[i];
                descript.VerticalAlignment = VerticalAlignment.Center;
                descript.Margin            = new Thickness(0, 5, 0, 0);
                Grid.SetRow(descript, i * 2);
                descGrid.Children.Add(descript);
                string    steps = "";
                TextBlock step  = new TextBlock();
                while ((toolkit.steps.Count != b + 1) && (toolkit.steps[b][1] < toolkit.steps[b + 1][1]))
                {
                    steps += toolkit.steps[b];
                    b++;
                }
                steps                 += toolkit.steps[b];
                b                     += 1;
                step.Text              = steps;
                step.Margin            = new Thickness(0, 25, 25, 5);
                step.TextWrapping      = TextWrapping.Wrap;
                step.VerticalAlignment = VerticalAlignment.Center;
                Grid.SetRow(step, (i * 2) + 1);

                descGrid.Children.Add(step);
                //<Border CornerRadius="5,5,5,5" BorderThickness="3" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="3" Padding="1" BorderBrush="DimGray" Margin="20,0,20,0"/>
                Border box = new Border();
                box.CornerRadius    = new CornerRadius(5, 5, 5, 5);
                box.BorderThickness = new Thickness(3);
                Grid.SetColumn(box, (i * 2) + 1);
                Grid.SetRow(box, (i * 2) + 1);
                box.Padding     = new Thickness(1);
                box.BorderBrush = Brushes.DimGray;
                box.Margin      = new Thickness(20, 0, 20, 0);
                box.Width       = 550;
                descGrid.Children.Add(box);
            }

            HyperLinker(toolkit);
            logger log = new logger(toolkit);
        }
示例#3
0
        public logger(Json_tool toolkit)
        {
            bool   ReturnIp = false, ReturnOS = false, ReturnEmail = false, ReturnCU = false, ReturnError = false, BothTime = true, Localtime = false, UTCtime = false, ReturnGateway = true, ReturnARP = false;
            string IP = "", OS = "", name = "", email = "", CU = "", Error = "", defaultgate = "", arpReturn = "";

            try
            {
                Dictionary <string, string> LogOptions = toolkit.js["Logs"].ToObject <Dictionary <string, string> >();
                foreach (KeyValuePair <string, string> option in LogOptions)
                {
                    if (option.Value == "True")
                    {
                        if (option.Key == "ReturnIP")
                        {
                            var host = Dns.GetHostEntry(Dns.GetHostName());
                            foreach (var ip in host.AddressList)
                            {
                                if (ip.AddressFamily == AddressFamily.InterNetwork)
                                {
                                    IP       = ip.ToString();
                                    ReturnIp = true;
                                    break;
                                }
                            }
                            if (IP == "")
                            {
                                throw new Exception("No network adapters with an IPv4 address in the system!");
                            }
                        }
                        if (option.Key == "ReturnOS")
                        {
                            using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem"))
                            {
                                ManagementObjectCollection information = searcher.Get();
                                if (information != null)
                                {
                                    foreach (ManagementObject obj in information)
                                    {
                                        OS = obj["Caption"].ToString() + " - " + obj["OSArchitecture"].ToString();
                                    }
                                }
                                OS       = OS.Replace("NT 5.1.2600", "XP");
                                OS       = OS.Replace("NT 5.2.3790", "Server 2003");
                                ReturnOS = true;
                            }
                        }
                        if (option.Key == "ReturnName")
                        {
                            if (toolkit.QAmap[2] == "")
                            {
                                name = "user";
                            }
                            else
                            {
                                name = toolkit.QAmap[2];
                            }
                        }
                        if (option.Key == "ReturnEmail")
                        {
                            if (toolkit.QAmap[3] == "")
                            {
                                email = "unknown";
                            }
                            else
                            {
                                email = toolkit.QAmap[2];
                            }
                            ReturnEmail = true;
                        }
                        if (option.Key == "ReturnCU")
                        {
                            CU       = toolkit.QAmap[1];
                            ReturnCU = true;
                        }
                        if (option.Key == "ReturnError")
                        {
                            Error       = toolkit.Ernum;
                            ReturnError = true;
                        }
                        DateTime Utctime   = DateTime.UtcNow;
                        DateTime localtime = DateTime.Now;
                        string[] log       = { Error, localtime.ToString(), Utctime.ToString(), IP, OS, CU, name, email };
                        this.logs = log;
                    }
                }
            }
            catch
            {
                Console.Write("Can't find return log setting");
            }

            using (StreamWriter writer = new StreamWriter(@"out.log"))
            {
                string logfor = "", timing = "", sysinfo = "", errorinfo = "", outlog = "";
                //userlogging
                if (ReturnEmail)
                {
                    logfor = "This log is for " + this.logs[6] + "(" + this.logs[7] + ") at " + this.logs[5] + "\n";
                }
                else
                {
                    try
                    {
                        logfor = "This log is for " + this.logs[6] + " at " + this.logs[5] + "\n";
                    }
                    catch
                    {
                        logfor = "unknown username & credit union \n";
                    }
                }

                //Time Logging
                if (BothTime || (UTCtime && Localtime))
                {
                    timing = "Log taken place " + this.logs[1] + " Local time and " + this.logs[2] + " UTC \n";
                }
                else if (UTCtime || Localtime)
                {
                    if (Localtime)
                    {
                        timing = "Log taken place " + this.logs[1] + " Local time \n";
                    }
                    else
                    {
                        timing = "Log taken place " + this.logs[2] + " UTC \n";
                    }
                }

                //System Info logging
                if (ReturnOS && ReturnIp)
                {
                    sysinfo = "System IP: " + this.logs[3] + "\tSystem OS: " + this.logs[4] + "\n";
                }
                else if (ReturnOS || ReturnIp)
                {
                    if (ReturnOS)
                    {
                        sysinfo = "System OS: " + this.logs[4] + "\n";
                    }
                    else
                    {
                        sysinfo = "System IP: " + this.logs[3] + "\n";
                    }
                }

                if (ReturnError)
                {
                    errorinfo = "Error code of (" + this.logs[0] + ") with error description of " + toolkit.ErDisplay(toolkit.Ernum) + "\n";
                }

                if (ReturnGateway)
                {
                    string gateway = NetworkInterface.GetAllNetworkInterfaces().Where(n => n.OperationalStatus == OperationalStatus.Up).Where(n => n.NetworkInterfaceType != NetworkInterfaceType.Loopback).SelectMany(n => n.GetIPProperties()?.GatewayAddresses).Select(g => g?.Address).Where(a => a != null).FirstOrDefault().ToString();
                    defaultgate  = "The default gateway to the computer is " + gateway + "\n";
                    this.gateway = gateway;
                }
                if (ReturnARP)
                {
                    arpReturn = "Check the arp.out file in the same directory to look at arp table \n";
                }

                outlog = logfor + timing + sysinfo + errorinfo + defaultgate + arpReturn;
                writer.WriteLine(outlog);
            }
        }
        public void HyperLinker(Json_tool toolkit)
        {
            List <string> Alltext = new List <string>()
            {
                this.Contact.Text, this.ProblemMap.Text
            };
            List <TextBlock> BlockNames = new List <TextBlock>()
            {
                this.Contact, this.ProblemMap
            };

            foreach (var txt in descGrid.Children)
            {
                if (txt.GetType() == typeof(TextBlock))
                {
                    TextBlock block = (TextBlock)txt;
                    string    text  = block.Text;
                    if (!string.IsNullOrEmpty(text))
                    {
                        Alltext.Add(text);
                        BlockNames.Add(block);
                    }
                }
            }


            int blockcounter = -1;

            foreach (string text in Alltext)
            {
                blockcounter += 1;
                if (text.Contains("*"))
                {
                    List <string> linker    = new List <string>();
                    List <string> addresses = new List <string>();
                    string        info      = text;
                    while (true)
                    {
                        if (!info.Contains("*"))
                        {
                            break;
                        }


                        Dictionary <string, string> Hyperlinks = toolkit.js["Hyperlinks"].ToObject <Dictionary <string, string> >();

                        foreach (KeyValuePair <string, string> link in Hyperlinks)
                        {
                            if (text.Contains("*" + link.Key))
                            {
                                int    HyperlinkStart = info.IndexOf("*");
                                string Beforelink     = info.Substring(0, HyperlinkStart);
                                linker.Add(Beforelink);
                                int    len       = link.Key.Length;
                                string LinkID    = info.Substring(HyperlinkStart, len + 1);
                                string Afterlink = info.Substring(HyperlinkStart + len + 1);
                                linker.Add(LinkID);
                                addresses.Add(link.Value);
                                info = Afterlink;
                            }
                        }
                    }
                    linker.Add(info);
                    switch (blockcounter)
                    {
                    case 0:
                        Addlink(Contact, linker, addresses, 0);
                        break;

                    case 1:
                        Addlink(ProblemMap, linker, addresses, 0);
                        break;

                    default:
                        Addlink(BlockNames[blockcounter], linker, addresses, 0);
                        break;
                    }
                }
            }
        }