コード例 #1
0
        private void OnStoriesChange(object sender, TestManager.StoriesStateEventArgs args)
        {
            this.UIThread(() =>
            {
                string runningText;
                string executedText;

                if (args.IsRunning)
                {
                    runningText  = args.Running.ToString();
                    executedText = args.Executed.ToString();

                    ConfigDoc config = ServerManager.Instance.Collections.Config.Values.FirstOrDefault();
                    if (config != null)
                    {
                        int threadsPerClient = config.threadsPerClient.GetValueOrDefault();
                        if (threadsPerClient > 0)
                        {
                            runningText += "/" + threadsPerClient;
                        }
                    }
                }
                else
                {
                    runningText  = "-";
                    executedText = "-";
                }

                this.lRunningCount.Text  = runningText;
                this.lExecutedCount.Text = executedText;
            });
        }
コード例 #2
0
        private void GenerateBusRouteDetailsXmlNode()
        {
            XmlElement xmlELement = ConfigDoc.CreateElement("BusRouteDetailsXmlFileLocation");
            XmlText    textField  = ConfigDoc.CreateTextNode(string.Empty);

            xmlELement.AppendChild(textField);
            ConfigDoc.DocumentElement.AppendChild(xmlELement);
        }
コード例 #3
0
        private void GenerateRouteStopXmlNode()
        {
            XmlElement routeStopXmlFileElement = ConfigDoc.CreateElement("RouteStopXmlFileLocation");
            XmlText    textField = ConfigDoc.CreateTextNode(string.Empty);

            routeStopXmlFileElement.AppendChild(textField);
            ConfigDoc.DocumentElement.AppendChild(routeStopXmlFileElement);
        }
コード例 #4
0
 /// <summary>
 /// 保存XML配置
 /// </summary>
 public void SaveConfiguration()
 {
     try
     {
         ConfigDoc?.Save(ConfigFileName);
     }
     catch (Exception)
     {
     }
 }
コード例 #5
0
        private string ReadAndGenerateConfigTextNode(string nodeName)
        {
            if (ConfigDoc.DocumentElement[nodeName] == null)
            {
                XmlElement xmlELement = ConfigDoc.CreateElement(nodeName);
                XmlText    textField  = ConfigDoc.CreateTextNode(string.Empty);
                xmlELement.AppendChild(textField);
                ConfigDoc.DocumentElement.AppendChild(xmlELement);
            }

            return(ConfigDoc.DocumentElement[nodeName].InnerText);
        }
コード例 #6
0
        private void InitializeConfigFile()
        {
            // First add in the root node
            XmlElement rootNode = ConfigDoc.CreateElement("Configuration");

            ConfigDoc.AppendChild(rootNode);

            // Then prepare the XML declaration
            XmlDeclaration xmlDeclaration = ConfigDoc.CreateXmlDeclaration("1.0", "UTF-8", null);

            ConfigDoc.InsertBefore(xmlDeclaration, rootNode);

            // Now, the Polygon KML polygon file location
            XmlElement kmlFileElement = ConfigDoc.CreateElement("PolygonKmlFileLocation");
            XmlText    kmlFileField   = ConfigDoc.CreateTextNode(string.Empty);

            kmlFileElement.AppendChild(kmlFileField);
            rootNode.AppendChild(kmlFileElement);

            // The Bus Stop XML raw file
            XmlElement busXmlFileElement = ConfigDoc.CreateElement("BusStopXmlFileLocation");
            XmlText    busXmlFileField   = ConfigDoc.CreateTextNode(string.Empty);

            busXmlFileElement.AppendChild(busXmlFileField);
            rootNode.AppendChild(busXmlFileElement);

            // The Route-Stop XML raw file
            GenerateRouteStopXmlNode();

            // The bus route details XML raw file
            GenerateBusRouteDetailsXmlNode();

            // Everything should be ready.
            // Save the config first.
            ConfigDoc.Save("config.xml");
        }
コード例 #7
0
        private void Run()
        {
            DdpSubHandler testUsersSub = null;

            try
            {
                this.State.Set("Waiting for subscriptions...");

                while (this.Thread.IsAlive && !ServerManager.Instance.AllSubscriptionsReady)
                {
                    Thread.Sleep(100);
                }

                ConfigDoc config = ServerManager.Instance.Collections.Config.Values.FirstOrDefault();
                if (config == null)
                {
                    Logs.Error("[Test] Unable to get configuration");
                    this.Stop();
                }

                int  threadsPerClient = config.threadsPerClient.GetValueOrDefault();
                bool sendTestUsers    = config.sendTestUsers.GetValueOrDefault();

                if (sendTestUsers)
                {
                    testUsersSub = ServerManager.Instance.SubscribeTestUsers(threadsPerClient);
                    this.Users   = new Queue <TestUserDoc>(ServerManager.Instance.Collections.TestUsers.Values.Take(threadsPerClient));
                }

                this.StateUpdate.Start();

                this.State.Set("Running", State.EType.SUCCESS);

                while (this.Thread.IsAlive)
                {
                    for (int i = this.Stories.Count; this.Thread.IsAlive && i < threadsPerClient; i++)
                    {
                        StoryBase story = ServerManager.Instance.CreateStory();
                        if (story == null)
                        {
                            Logs.Error("[Test] Script not exists");
                            this.Stop();
                        }

                        TestUserDoc user = null;
                        if (sendTestUsers)
                        {
                            if (this.Users.Count == 0)
                            {
                                Logs.Error("[Test] User account is missing");
                                this.Stop();
                            }

                            user = this.Users.Dequeue();
                        }

                        story.End += OnEnd;
                        this.Stories.Add(story);
                        story.Start(config.server.host, config.server.ssl, user);

                        this.OnStoriesChangeInvoke();

                        if (config.delay.to.HasValue)
                        {
                            Thread.Sleep(this.RND.Next(config.delay.from, config.delay.to.Value));
                        }
                        else
                        {
                            Thread.Sleep(config.delay.from);
                        }
                    }

                    Thread.Sleep(1000);
                }
            }
            catch (ThreadAbortException) { }
            finally
            {
                this.StateUpdate.Stop();

                StoryBase[] temp = this.Stories.ToArray();
                foreach (StoryBase story in temp)
                {
                    if (story != null)
                    {
                        story.Stop();
                    }
                }

                this.Stories.Clear();
                this.ExecutedStoriesCount = 0;

                if (this.Users != null)
                {
                    this.Users.Clear();
                    this.Users = null;
                }

                if (ServerManager.Instance.IsConnected && testUsersSub != null)
                {
                    testUsersSub.Unsub();
                }

                this.OnStoriesChangeInvoke(false);

                this.StateUpdate.UpdateStories();
                this.State.Set("Idle", State.EType.FAILED);
            }
        }