Ejemplo n.º 1
0
        public void RefrenshList()
        {
            testManagerBLL = new BLL.TB_TestManager();
            testItmesListBox.ItemsSource = testList = testManagerBLL.GetModelList("");

            //如果设置了测试项目,则选中设置的测试项目
            int index = -1;

            if (testItem != null)
            {
                index = testList.FindIndex(x => x.ID == testItem.ID);
            }
            else if (testList.Count>0)
            {
                index = 0;
            }

            if (selectedTestItemIndex >= 0 && testItem == null)
            {
                testItmesListBox.SelectedIndex = selectedTestItemIndex;
            }
            else
            {
                testItmesListBox.SelectedIndex = index;
            }
        }
Ejemplo n.º 2
0
 public static int getIndex(List<string> list, string name)
 {
     int index = list.FindIndex(r => r == name);
     return index;
 }
Ejemplo n.º 3
0
        static void crawler_ProcessPageCrawlCompleted(object sender, PageCrawlCompletedArgs e)
        {
            CrawledPage crawledPage = e.CrawledPage;

            if (crawledPage.WebException != null || crawledPage.HttpWebResponse.StatusCode != HttpStatusCode.OK)
                Debug.WriteLine(string.Format("页面:{0}抓取失败,原因:{1}", crawledPage.Uri.AbsoluteUri, crawledPage.WebException.Message));

            string text = crawledPage.Content.Text;

            if (string.IsNullOrEmpty(text))
                Console.WriteLine("Page had no content {0}", crawledPage.Uri.AbsoluteUri);
            else if (text.Contains("活动八"))
            {

            }
            else
            {

                var c = Regex.Matches(text, "活动(一|二|三|四|五|六|七|八|九|十)(.|\n)*?活动时间(.|\n)*?<br");
                if (c.Count == 0)
                {
                    var a = Regex.Match(text, "thread_subject(.|\n)*?活动(.|\n){1,50}?</a");
                    if (a.Value != "")
                    {
                        var b = Regex.Match(text, "活动时间(.|\n)*?<br");
                        var time = Regex.Match(b.Value, "\\d{1,2}月\\d{1,2}(-|日)").Value;
                        Debug.Write(DateTime.Parse(time) + "   ");
                        Debug.WriteLine(Regex.Match(a.Value, "活动(.|\n)*?</a").Value.Replace("】", ":").Replace("<br", "").Replace("</a", ""));
                    }
                }

                List<string> list = new List<string>() { "古城探宝", "天降神剑" };

                foreach (Match item in c)
                {
                    string date = Regex.Match(item.Value, "\\d{1,2}月\\d{1,2}(-|日)").Value;
                    if (date != "" && !date.Contains("日"))
                    {
                        date = date.Replace("-", "日");
                    }
                    Debug.Write(DateTime.Parse(date) + "   ");
                    Debug.WriteLine(Regex.Match(item.Value, "活动(一|二|三|四|五|六|七|八|九|十)(.|\n)*?<br").Value.Replace("】", ":").Replace("<br", "").Replace("</a", ""));
                    var index = list.FindIndex(x => item.Value.Contains(x));
                    if (index != -1)
                    {
                        Activity activity = new Activity();
                        activity.Name = list[index];
                        activity.Date = DateTime.Parse(date);

                    }
                }

            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Process the Wireshark packets and determine the number of datasets
        /// </summary>
        /// <returns>An <c>AnalysisStatus</c> enumeration indicating whether the analysis process completed successfuly.</returns>
        private Enums.AnalysisStatus ProcessWiresharkOutput()
        {
            Enums.AnalysisStatus status = Enums.AnalysisStatus.Success;
            DateTime start_step = new DateTime();
            DateTime end_step = new DateTime();
            TimeSpan time_step = new TimeSpan();
            WiresharkPSMLStructure psml_structure = new WiresharkPSMLStructure();
            WiresharkPSMLPacket psml_packet = new WiresharkPSMLPacket();

            string[] delimiters = {" ",",",":"};
            int num;
            double time;
            EthernetMACAddr mac_src = new EthernetMACAddr();
            EthernetMACAddr mac_dst = new EthernetMACAddr();
            IPv4Addr ip_src = new IPv4Addr();
            IPv4Addr ip_dst = new IPv4Addr();
            int enip_cid = 0;
            int enip_seq = 0;
            string index_name;
            List<string> indices_names = new List<string>();
            int index;
            NetworkPair pair = new NetworkPair();
            JitterDatum datum = new JitterDatum();

            _process_log.Add(DateTime.Now.ToString() + ": Process Wireshark Output: Started.");
            start_step = DateTime.Now;

            _progress.Current = _progress.Minimum;
            _background_worker.ReportProgress(_progress.Current);
            _tshark.Progress = _progress;

            XmlReader reader = XmlReader.Create(_tshark.TemporaryFile.FullName);
            XmlDocument doc = new XmlDocument();
            doc.Load(reader);

            XmlNodeList structure;
            XmlNode root = doc.DocumentElement;
            structure = root.SelectNodes("//structure");
            if (structure.Count == 1)
            {
                XmlNode structure_node = structure.Item(0);
                List<string> sections = new List<string>();
                for (int i = 0; i < structure_node.ChildNodes.Count; i++)
                {
                    sections.Add(structure_node.ChildNodes[i].InnerText);
                }
                int temp = sections.FindIndex(delegate(string title) { return title == psml_structure.NumberTitle; });
                if (temp == -1)
                    status = Enums.AnalysisStatus.Error;
                else
                    psml_structure.NumberIndex = temp;
                temp = sections.FindIndex(delegate(string title) { return title == psml_structure.TimeTitle; });
                if (temp == -1)
                    status = Enums.AnalysisStatus.Error;
                else
                    psml_structure.TimeIndex = temp;
                temp = sections.FindIndex(delegate(string title) { return title == psml_structure.SourceTitle; });
                if (temp == -1)
                    status = Enums.AnalysisStatus.Error;
                else
                    psml_structure.SourceIndex = temp;
                temp = sections.FindIndex(delegate(string title) { return title == psml_structure.DestinationTitle; });
                if (temp == -1)
                    status = Enums.AnalysisStatus.Error;
                else
                    psml_structure.DestinationIndex = temp;
                temp = sections.FindIndex(delegate(string title) { return title == psml_structure.ProtocolTitle; });
                if (temp == -1)
                    status = Enums.AnalysisStatus.Error;
                else
                    psml_structure.ProtocolIndex = temp;
                temp = sections.FindIndex(delegate(string title) { return title == psml_structure.EnipCidTitle; });
                if (temp == -1)
                    status = Enums.AnalysisStatus.Error;
                else
                    psml_structure.EnipCidIndex = temp;
                temp = sections.FindIndex(delegate(string title) { return title == psml_structure.EnipSeqTitle; });
                if (temp == -1)
                    status = Enums.AnalysisStatus.Error;
                else
                    psml_structure.EnipSeqIndex = temp;
                temp = sections.FindIndex(delegate(string title) { return title == psml_structure.InfoTitle; });
                if (temp == -1)
                    status = Enums.AnalysisStatus.Error;
                else
                    psml_structure.InfoIndex = temp;
            }
            else
            {
                status = Enums.AnalysisStatus.Error;
            }

            if (status == Enums.AnalysisStatus.Error)
            {
                _process_log.Add(DateTime.Now.ToString() + ": Process Wireshark Output: Error reading structure of Wireshark PSML output.");
            }
            else
            {
                XmlNodeList packets = root.SelectNodes("//packet");
                XmlNode packet;
                if (packets.Count > 0)
                {
                    _process_log.Add(DateTime.Now.ToString() + ": Process Wireshark Output: " + packets.Count + " filtered packets");
                    for (int i = 0; i < packets.Count; i++)
                    {
                        packet = packets[i];
                        psml_packet = new WiresharkPSMLPacket();
                        psml_packet.Number = packet.ChildNodes[psml_structure.NumberIndex].InnerText;
                        psml_packet.Time = packet.ChildNodes[psml_structure.TimeIndex].InnerText;
                        psml_packet.Source = packet.ChildNodes[psml_structure.SourceIndex].InnerText;
                        psml_packet.Destination = packet.ChildNodes[psml_structure.DestinationIndex].InnerText;
                        psml_packet.Protocol = packet.ChildNodes[psml_structure.ProtocolIndex].InnerText;
                        psml_packet.EnipCid = packet.ChildNodes[psml_structure.EnipCidIndex].InnerText;
                        psml_packet.EnipSeq = packet.ChildNodes[psml_structure.EnipSeqIndex].InnerText;
                        psml_packet.Info = packet.ChildNodes[psml_structure.InfoIndex].InnerText;

                        pair = new NetworkPair();
                        int.TryParse(psml_packet.Number, out num);
                        double.TryParse(psml_packet.Time, out time);
                        mac_src = new EthernetMACAddr(psml_packet.Source);
                        pair.MacSource = mac_src;
                        ip_src = new IPv4Addr(psml_packet.Source);
                        pair.IpSource = ip_src;
                        mac_dst = new EthernetMACAddr(psml_packet.Destination);
                        pair.MacDestination = mac_dst;
                        ip_dst = new IPv4Addr(psml_packet.Destination);
                        pair.IpDestination = ip_dst;
                        if (psml_packet.Protocol == "ENIP")
                        {
                            if (!string.IsNullOrEmpty(psml_packet.EnipCid))
                            {
                                // remove the extra "0x" that appears on the EtherNet/IP Connection ID
                                int.TryParse(psml_packet.EnipCid.Remove(0, 2), NumberStyles.HexNumber, null, out enip_cid);
                                pair.UseEtherNetIP = true;
                                pair.EtherNetIPConnID = enip_cid;
                            }
                            if (!string.IsNullOrEmpty(psml_packet.EnipSeq))
                            {
                                int.TryParse(psml_packet.EnipSeq, out enip_seq);
                            }
                        }

                        // Determine index for this packet
                        index_name = pair.ToString();
                        if (indices_names.Contains(index_name))
                        {
                            index = indices_names.IndexOf(index_name);
                        }
                        else
                        {
                            index = indices_names.Count;
                            indices_names.Add(index_name);
                            string comment = "IP Source == " + ip_src.ToString() + "\nIP Destination == " + ip_dst.ToString();
                            if (pair.UseEtherNetIP)
                                comment += "\nEtherNet/IP Connection ID == 0x" + enip_cid.ToString("X");
                            Identification new_index = new Identification(indices_names.Count, index_name, "Network Address Pair", comment);
                            _indices.Add(new_index);
                        }

                        datum = new JitterDatum(index, time);
                        _full_data.Add(datum);

                        _progress.Current = (int)(i / packets.Count * 100);
                        _background_worker.ReportProgress(_progress.Current);
                    }

                    if (_indices.Count == 1)
                        _process_log.Add(DateTime.Now.ToString() + ": Process Wireshark Output: " + _indices.Count + " dataset");
                    else
                        _process_log.Add(DateTime.Now.ToString() + ": Process Wireshark Output: " + _indices.Count + " datasets");
                }
                else
                {
                    status = Enums.AnalysisStatus.NoPacketsCaptured;
                    _process_log.Add(DateTime.Now.ToString() + ": Process Wireshark Output: No packets captured that match the desired filter.");
                }
            }

            _progress.Current = _progress.Maximum;
            _background_worker.ReportProgress(_progress.Current);
            end_step = DateTime.Now;
            time_step = TimeSpan.FromTicks(end_step.Ticks - start_step.Ticks);
            _process_log.Add(DateTime.Now.ToString() + ": Process Wireshark Output: Completed in " + time_step.TotalSeconds.ToString() + " s");

            return status;
        }
Ejemplo n.º 5
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     testManagerBLL = new BLL.TB_TestManager();
     athInfoBLL = new BLL.TB_AthleteInfo();
     testList = testManagerBLL.GetModelList("");
     Binding b = new Binding() { Source = testList };
     cbTestItems.SetBinding(ComboBox.ItemsSourceProperty, b);
     if (testItem == null)
     {
         cbTestItems.SelectedIndex = 0;
     }
     else {
         cbTestItems.SelectedIndex = testList.FindIndex(x => x.ID == testItem.ID);
     }
 }
Ejemplo n.º 6
0
 public void _KeyPress(object sender, KeyEventArgs e)
 {
     List<Key> keys = new List<Key>() { Key.D1, Key.D2, Key.D3, Key.D4, Key.D5, Key.D6, Key.D7, Key.D8 };
     int number;
     try { number = keys.FindIndex(a => a == e.Key); }
     catch (System.ArgumentNullException) { number = -1; }
     if (number >= 0)
         _ButtonPress(Buttons[number], e);
 }
Ejemplo n.º 7
0
        private void queriesTimer_Tick(object sender, EventArgs e)
        {
            List<Query> queries = new List<Query>();
            using (SqlConnection connection = new SqlConnection(String.Format(Configuration.ConnectionString, Configuration.SSISDatabase)))
            {
                try
                {
                    connection.Open();
                    using (SqlCommand command = new SqlCommand(Properties.Resources.LongQueriesQuery, connection))
                    {
                        command.Parameters.AddWithValue("threshold", Configuration.QueriesThreshold);
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                queries.Add(new Query()
                                {
                                    Id = (Int32)reader["Id"],
                                    User = (String)reader["User"],
                                    Duration = TimeSpan.FromSeconds((Int32)reader["Duration"]),
                                    Command = (String)reader["Query"],
                                    Database = (String)reader["Database"]
                                });
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.NavigationService.GoBack();
                    System.Windows.MessageBox.Show("The SQL Server connection was lost", "SQL Notifier", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            if (this.lastQueries.Count != queries.Count)
            {
                foreach (Query query in queries)
                {
                    Int32 index = this.lastQueries.FindIndex(obj => obj.Id == query.Id);
                    if (index == -1 && !this.firstRun)
                        this.Window.Notify("New long query is detected");
                }
                foreach (Query query in this.lastQueries)
                {
                    Int32 index = queries.FindIndex(obj => obj.Id == query.Id);
                    if (index == -1 && !this.firstRun)
                        this.Window.Notify("A long query is done");
                }
            }
            this.lastQueries = queries;
            this.dataGridQueries.ItemsSource = queries;
        }
Ejemplo n.º 8
0
        private void packageTimer_Tick(object sender, EventArgs e)
        {
            List<Package> packages = new List<Package>();
            using (SqlConnection connection = new SqlConnection(String.Format(Configuration.ConnectionString, Configuration.SSISDatabase)))
            {
                try
                {
                    connection.Open();
                    using (SqlCommand command = new SqlCommand(Properties.Resources.RunningPackagesQuery, connection))
                    {
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                packages.Add(new Package()
                                {
                                    Id = (Int32)reader["Id"],
                                    Name = (String)reader["Name"],
                                    Duration = TimeSpan.FromSeconds((Int32)reader["Duration"])
                                });
                            }
                        }
                    }
                }
                catch(Exception ex)
                {
                    this.NavigationService.GoBack();
                    System.Windows.MessageBox.Show("The SQL Server connection was lost", "SQL Notifier", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            if (this.lastPackages.Count != packages.Count)
            {
                foreach (Package package in packages)
                {
                    Int32 index = this.lastPackages.FindIndex(obj => obj.Id == package.Id);
                    if (index == -1 && !this.firstRun)
                        this.Window.Notify(String.Format("The package {0} is running", package.Name));
                }
                foreach (Package package in this.lastPackages)
                {
                    Int32 index = packages.FindIndex(obj => obj.Id == package.Id);
                    if (index == -1 && !this.firstRun)
                        this.Window.Notify(String.Format("The package {0} is finished", package.Name));
                }
            }
            this.lastPackages = packages;
            this.dataGridPackages.ItemsSource = packages;
        }
Ejemplo n.º 9
0
        private void InitDisk()
        {
            string a=System.IO.Path.GetPathRoot(PathL.path).ToUpper();
            string b=System.IO.Path.GetPathRoot(PathR.path).ToUpper();

            DriveInfo[] allDrivers = DriveInfo.GetDrives();
            List<DiskTemplate> tmp = new List<DiskTemplate>();
            foreach (DriveInfo item in allDrivers)
            {
                if(item.IsReady) tmp.Add(new DiskTemplate(GetIcon.Icon(item.Name, true, true)," [" + WorkPath.GetNameDisk(item.Name) + "] " + item.VolumeLabel, item.Name));
                else tmp.Add(new DiskTemplate(GetIcon.Icon(item.Name, true, true), " [" + WorkPath.GetNameDisk(item.Name) + "]", item.Name));
            }

            tmp.Add(new DiskTemplate(GetIcon.Icon(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), true, true), "My Documents", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)));
            tmp.Add(new DiskTemplate(GetIcon.Icon(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), true, true), "Desktop", Environment.GetFolderPath(Environment.SpecialFolder.Desktop)));
            tmp.Add(new DiskTemplate(GetIcon.Icon(Environment.GetFolderPath(Environment.SpecialFolder.Favorites), true, true), "Favorites", Environment.GetFolderPath(Environment.SpecialFolder.Favorites)));
            tmp.Add(new DiskTemplate(GetIcon.Icon(Environment.GetFolderPath(Environment.SpecialFolder.Startup), true, true), "Startup", Environment.GetFolderPath(Environment.SpecialFolder.Startup)));

            ListDiskL.ItemsSource = tmp;
            ListDiskR.ItemsSource = tmp;
            ListDiskL.SelectedIndex = tmp.FindIndex(s => s.Path == a);
            ListDiskR.SelectedIndex = tmp.FindIndex(s => s.Path == b);
            
            ViewPathL.Content = a;
            ViewPathR.Content = b;
        }
Ejemplo n.º 10
0
 private void CreateManifest(List<FileInfo> results, string[] args)
 {
     try
     {
         int toRemove = results.FindIndex(x => x.Name.ToLowerInvariant() == "launcher.cache");
         if (toRemove >= 0)
         {
             results.RemoveAt(toRemove);
         }
         CreateManifest_(results, args);
     }
     catch (System.Exception ex)
     {
         SetStatus("Something went wrong: "+ex.ToString(), 1);
     }
 }