Exemplo n.º 1
0
        public void CreateConfigFile(Int32 bufferSize, Int32 totalClientsToRun, Int32 numOfMessages, Int32 theMaximumNumberOfSimultaneousClientConnections, bool isNew)
        {
            HostFinder hostFinder = new HostFinder();

            if (isNew == true)
            {              
                this.remoteEndPoint = hostFinder.GetValidHost();
                this.theWay = hostFinder.theWay;
                this.host = hostFinder.host;
                this.portOnHost = hostFinder.portOnHost;                
                this.saveDirectory = GetLogFilePath();
                this.testBufferSize = bufferSize;
                this.totalNumberOfClientConnectionsToRun = totalClientsToRun;
                this.numberOfReceivedMessagesPerConnection = numOfMessages;
                this.numberOfSentMessagesPerConnection = this.numberOfReceivedMessagesPerConnection;
                this.maximumNumberOfSimultaneousClientConnections = theMaximumNumberOfSimultaneousClientConnections;
            }
            else
            {
                this.remoteEndPoint = hostFinder.GetValidHost(this.theWay, this.host, this.portOnHost);
            }
                        
            try
            {
                // create the config file and write to it.
                TextWriter tw = new StreamWriter(configFilenameString);

                //0                
                tw.WriteLine(hostFinder.theWay);                

                //1                
                tw.WriteLine(hostFinder.host);                

                //2
                tw.WriteLine(hostFinder.portString);                

                //3
                tw.WriteLine(this.saveDirectory);

                //4                
                tw.WriteLine(this.testBufferSize.ToString(CultureInfo.InvariantCulture));                

                //5
                tw.WriteLine(this.totalNumberOfClientConnectionsToRun.ToString(CultureInfo.InvariantCulture));                

                //6
                tw.WriteLine(this.numberOfReceivedMessagesPerConnection.ToString(CultureInfo.InvariantCulture));

                //7
                tw.WriteLine(this.maximumNumberOfSimultaneousClientConnections.ToString(CultureInfo.InvariantCulture));
         
                //close the writer
                tw.Close();
            }
            catch
            {
                Console.WriteLine("Could not create config file.");
            }
        }
Exemplo n.º 2
0
        public void CreateConfigFile(Int32 bufferSize, Int32 totalClientsToRun, Int32 numOfMessages, Int32 theMaximumNumberOfSimultaneousClientConnections, bool isNew)
        {
            HostFinder hostFinder = new HostFinder();

            if (isNew == true)
            {
                this.remoteEndPoint = hostFinder.GetValidHost();
                this.theWay         = hostFinder.theWay;
                this.host           = hostFinder.host;
                this.portOnHost     = hostFinder.portOnHost;
                this.saveDirectory  = GetLogFilePath();
                this.testBufferSize = bufferSize;
                this.totalNumberOfClientConnectionsToRun          = totalClientsToRun;
                this.numberOfReceivedMessagesPerConnection        = numOfMessages;
                this.numberOfSentMessagesPerConnection            = this.numberOfReceivedMessagesPerConnection;
                this.maximumNumberOfSimultaneousClientConnections = theMaximumNumberOfSimultaneousClientConnections;
            }
            else
            {
                this.remoteEndPoint = hostFinder.GetValidHost(this.theWay, this.host, this.portOnHost);
            }

            try
            {
                // create the config file and write to it.
                TextWriter tw = new StreamWriter(configFilenameString);

                //0
                tw.WriteLine(hostFinder.theWay);

                //1
                tw.WriteLine(hostFinder.host);

                //2
                tw.WriteLine(hostFinder.portString);

                //3
                tw.WriteLine(this.saveDirectory);

                //4
                tw.WriteLine(this.testBufferSize.ToString(CultureInfo.InvariantCulture));

                //5
                tw.WriteLine(this.totalNumberOfClientConnectionsToRun.ToString(CultureInfo.InvariantCulture));

                //6
                tw.WriteLine(this.numberOfReceivedMessagesPerConnection.ToString(CultureInfo.InvariantCulture));

                //7
                tw.WriteLine(this.maximumNumberOfSimultaneousClientConnections.ToString(CultureInfo.InvariantCulture));

                //close the writer
                tw.Close();
            }
            catch
            {
                Console.WriteLine("Could not create config file.");
            }
        }
Exemplo n.º 3
0
        public bool ReadConfigFile()
        {
            bool configFileIsOkay = true;
            
            TextReader tr;
                try
                {
                    tr = new StreamReader(configFilenameString);

                    //0
                    this.theWay = tr.ReadLine();
                    if (this.theWay == "N")
                    {
                        Console.WriteLine("Will use machine name in config file to find host.");
                    }
                    if (this.theWay == "I")
                    {
                        Console.WriteLine("Will use IP address in config file to find host.");
                    } 
                    
                    //1
                    this.host = tr.ReadLine();
                    Console.WriteLine("host = " + this.host);
                    
                    //2
                    string portString = tr.ReadLine();
                    this.portOnHost = Convert.ToInt32(portString, CultureInfo.InvariantCulture);
                    Console.WriteLine("port = " + portString);
                    
                    //3
                    this.saveDirectory = tr.ReadLine();
                    
                    //4
                    this.testBufferSize = Convert.ToInt32(tr.ReadLine(), CultureInfo.InvariantCulture);
                    
                    //5
                    this.totalNumberOfClientConnectionsToRun = Convert.ToInt32(tr.ReadLine(), CultureInfo.InvariantCulture);
                    
                    //6
                    this.numberOfReceivedMessagesPerConnection = Convert.ToInt32(tr.ReadLine(), CultureInfo.InvariantCulture);
                    this.numberOfSentMessagesPerConnection = numberOfReceivedMessagesPerConnection;

                    //7
                    this.maximumNumberOfSimultaneousClientConnections = Convert.ToInt32(tr.ReadLine(), CultureInfo.InvariantCulture);
                    if (this.maximumNumberOfSimultaneousClientConnections == 0)
                    {
                        this.maximumNumberOfSimultaneousClientConnections = 1000;
                    }
                    
                    //close the reader
                    tr.Close();

                    HostFinder hostFinder = new HostFinder();  
                    remoteEndPoint = hostFinder.GetValidHost(this.theWay, this.host, this.portOnHost);
                    if (remoteEndPoint == null)
                    {
                        Console.WriteLine("Do you want to make a new config file? Type 'Y' for 'yes' or 'N' for 'no' and press Enter.");
                        string question = Console.ReadLine();
                        question = question.ToUpper(CultureInfo.InvariantCulture);
                        if (question == "Y")
                        {
                            DeleteConfigFile();
                            configFileIsOkay = false;
                        }
                        else
                        {
                            Console.WriteLine("\r\nMake sure the server is available. If it is, check the config file please.\r\nThen restart the app. Click 'X' to close.");
                            Console.ReadLine();
                            Console.WriteLine("\r\n****LOOK**** Click 'X' to close.");
                            Console.WriteLine("\r\n****LOOK**** Click 'X' to close.");
                            Console.WriteLine("\r\n****LOOK**** Click 'X' to close.");
                            Console.ReadLine();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

            if ((this.theWay != "N") && (this.theWay != "I"))
            {                
                DeleteConfigFile();
                configFileIsOkay = false;
            }   
            if (this.host.Length == 0)
            {
                DeleteConfigFile();
                configFileIsOkay = false;
            }
            if ((this.portOnHost > 0) == false)
            {
                DeleteConfigFile();
                configFileIsOkay = false;
            }
            return configFileIsOkay;
        }
Exemplo n.º 4
0
        public bool ReadConfigFile()
        {
            bool configFileIsOkay = true;

            TextReader tr;

            try
            {
                tr = new StreamReader(configFilenameString);

                //0
                this.theWay = tr.ReadLine();
                if (this.theWay == "N")
                {
                    Console.WriteLine("Will use machine name in config file to find host.");
                }
                if (this.theWay == "I")
                {
                    Console.WriteLine("Will use IP address in config file to find host.");
                }

                //1
                this.host = tr.ReadLine();
                Console.WriteLine("host = " + this.host);

                //2
                string portString = tr.ReadLine();
                this.portOnHost = Convert.ToInt32(portString, CultureInfo.InvariantCulture);
                Console.WriteLine("port = " + portString);

                //3
                this.saveDirectory = tr.ReadLine();

                //4
                this.testBufferSize = Convert.ToInt32(tr.ReadLine(), CultureInfo.InvariantCulture);

                //5
                this.totalNumberOfClientConnectionsToRun = Convert.ToInt32(tr.ReadLine(), CultureInfo.InvariantCulture);

                //6
                this.numberOfReceivedMessagesPerConnection = Convert.ToInt32(tr.ReadLine(), CultureInfo.InvariantCulture);
                this.numberOfSentMessagesPerConnection     = numberOfReceivedMessagesPerConnection;

                //7
                this.maximumNumberOfSimultaneousClientConnections = Convert.ToInt32(tr.ReadLine(), CultureInfo.InvariantCulture);
                if (this.maximumNumberOfSimultaneousClientConnections == 0)
                {
                    this.maximumNumberOfSimultaneousClientConnections = 1000;
                }

                //close the reader
                tr.Close();

                HostFinder hostFinder = new HostFinder();
                remoteEndPoint = hostFinder.GetValidHost(this.theWay, this.host, this.portOnHost);
                if (remoteEndPoint == null)
                {
                    Console.WriteLine("Do you want to make a new config file? Type 'Y' for 'yes' or 'N' for 'no' and press Enter.");
                    string question = Console.ReadLine();
                    question = question.ToUpper(CultureInfo.InvariantCulture);
                    if (question == "Y")
                    {
                        DeleteConfigFile();
                        configFileIsOkay = false;
                    }
                    else
                    {
                        Console.WriteLine("\r\nMake sure the server is available. If it is, check the config file please.\r\nThen restart the app. Click 'X' to close.");
                        Console.ReadLine();
                        Console.WriteLine("\r\n****LOOK**** Click 'X' to close.");
                        Console.WriteLine("\r\n****LOOK**** Click 'X' to close.");
                        Console.WriteLine("\r\n****LOOK**** Click 'X' to close.");
                        Console.ReadLine();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            if ((this.theWay != "N") && (this.theWay != "I"))
            {
                DeleteConfigFile();
                configFileIsOkay = false;
            }
            if (this.host.Length == 0)
            {
                DeleteConfigFile();
                configFileIsOkay = false;
            }
            if ((this.portOnHost > 0) == false)
            {
                DeleteConfigFile();
                configFileIsOkay = false;
            }
            return(configFileIsOkay);
        }