Example #1
0
        private static void SetLoggingContext()
        {
            var manifest = GlobalDataStore.Manifest;

            if (manifest != null)
            {
                TraceFactory.SetThreadContextProperty("Dispatcher", manifest.Dispatcher, false);
                TraceFactory.SetSessionContext(manifest.SessionId);
            }
        }
Example #2
0
        private static void Main(string[] args)
        {
            UnhandledExceptionHandler.Attach();
            AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;

            Thread.CurrentThread.SetName("Main");

            VirtualClientController clientController = null;

            try
            {
                TraceFactory.Logger.Debug("Args: {0}".FormatWith(string.Join(" ", args)));
                int    startIndex = 0;
                string sessionId  = string.Empty;
                switch (args.Length)
                {
                case 2:
                    sessionId = args[1];
                    break;

                case 3:
                    sessionId  = args[1];
                    startIndex = int.Parse(args[2], CultureInfo.InvariantCulture);
                    break;

                default:
                    TraceFactory.Logger.Fatal("Invalid number of arguments.  Arguments passed in: {0}".FormatWith(args.Length));
                    TraceFactory.Logger.Fatal("Usage: {0} <Dispatcher Fully Qualified Domain Name> <Session Id> <Start Index for Software Installer>".FormatWith(AppDomain.CurrentDomain.FriendlyName));
                    Environment.Exit(1);
                    break;
                }

                // Set the logging context
                var dispatcher = args[0].Split('.')[0];
                TraceFactory.SetSessionContext(sessionId);
                TraceFactory.SetThreadContextProperty("Dispatcher", dispatcher, false);
                using (var officeWorkerStream =
                           File.Create(Path.Combine(Environment.CurrentDirectory, "OfficeWorkerBootStrapper.exe")))
                {
                    officeWorkerStream.Write(Properties.Resources.OfficeWorkerBootStrapper, 0,
                                             Properties.Resources.OfficeWorkerBootStrapper.Length);
                    officeWorkerStream.Flush(true);
                }


                clientController = new VirtualClientController(dispatcher, startIndex);
                clientController.Start(sessionId);
                TraceFactory.Logger.Debug("Client controller started.  Press Enter to terminate.");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                TraceFactory.Logger.Error(ex);
            }
        }
Example #3
0
        /// <summary>
        /// args[0] = VirtualResourceId
        /// args[1] = Host Name
        /// </summary>
        /// <param name="args"></param>
        private static void Main(string[] args)
        {
            Thread.CurrentThread.SetName("PerfMoncollectorMain");
            TraceFactory.SetThreadContextProperty("ResourceName", "PerfMonCounter_" + DateTime.Now.ToString("ddMMyyy", CultureInfo.InvariantCulture));

            UnhandledExceptionHandler.Attach();

            using (Program program = new Program(args[0]))
            {
                Console.ReadLine();
            }
        }
Example #4
0
        private void SetSessionContext(SessionMapElement element)
        {
            string sessionId = null;
            string elementId = null;

            if (element != null)
            {
                sessionId = element.SessionId;
                elementId = element.Id.ToString();
            }
            TraceFactory.SetSessionContext(sessionId);
            TraceFactory.SetThreadContextProperty("SessionMapElementId", elementId, false);
        }
Example #5
0
        static void Main(string[] args)
        {
            var database = args[0];
            _sessionId = args[1];
            var proxyServiceUri = new Uri(args[2]);

            TraceFactory.SetThreadContextProperty("PID", Process.GetCurrentProcess().Id.ToString());
            TraceFactory.SetSessionContext(_sessionId);
            TraceFactory.Logger.Debug(string.Join(", ", args));

            UnhandledExceptionHandler.Attach();

            GlobalSettings.Load(database);
            FrameworkServicesInitializer.InitializeExecution();

            try
            {
                using (var sessionProxy = new SessionProxy(_sessionId))
                {
                    sessionProxy.OnExit += _sessionProxy_OnExit;
                    sessionProxy.StartFrontendService(proxyServiceUri);
                    sessionProxy.StartBackendService();

                    TraceFactory.Logger.Debug("Notify Dispatcher process is up...");
                    Retry.WhileThrowing
                        (
                            () =>
                            {
                                using (var connection = SessionDispatcherConnection.Create("localhost"))
                                {
                                    connection.Channel.NotifyProxyStarted(_sessionId);
                                }
                            },
                            10,
                            TimeSpan.FromSeconds(2),
                            new List<Type>() { typeof(EndpointNotFoundException) }
                        );
                    TraceFactory.Logger.Debug("Notify Dispatcher process is up...Done");

                    _mainThreadBlock.WaitOne();
                }
            }
            catch (Exception ex)
            {
                TraceFactory.Logger.Error(ex);
            }
        }
Example #6
0
 private static void SetLoggingContext(FrameworkServer dispatcher)
 {
     try
     {
         // Set the logging context
         if (dispatcher != null)
         {
             TraceFactory.SetThreadContextProperty("Dispatcher", dispatcher.HostName, false);
         }
         string environment = GlobalSettings.Items[Setting.Environment];
         TraceFactory.SetThreadContextProperty("Environment", environment, false);
         TraceFactory.Logger.Debug("Set logging context");
     }
     catch (Exception ex)
     {
         TraceFactory.Logger.Error("Unable to set logging context", ex);
     }
 }
Example #7
0
        static void Main()
        {
            TraceFactory.SetThreadContextProperty("ProcessId", Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture));
            Thread.CurrentThread.SetName("Main");

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Load settings from App.Config
            GlobalSettings.Load();

            using (Form mainForm = new MainForm())
            {
                Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
                ApplicationExceptionHandler.Attach(mainForm);
                Application.Run(mainForm);
            }
        }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ResourceHost" /> class.
        /// </summary>
        /// <param name="manifest">The manifest.</param>
        public ResourceHost(SystemManifest manifest)
        {
            Manifest = manifest;

            // Set the logging thread context
            if (manifest != null)
            {
                TraceFactory.SetThreadContextProperty("SessionId", manifest.SessionId, false);
                TraceFactory.SetThreadContextProperty("Dispatcher", manifest.Dispatcher, false);
            }

            Resources = new Collection <ResourceInstance>();

            // Define an empty machine class as simply a placeholder.  It will be replaced with an
            // actual machine class in the validate step.
            Machine = new HostMachine(manifest);

            Machine.OnStatusChanged += Machine_OnStatusChanged;

            // Create a temporary Id for the map element as it won't be set until the machines are created
            MapElement         = new SessionMapElement(Guid.NewGuid().ToString(), ElementType.Machine);
            MapElement.Enabled = false;
        }
Example #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandLineExec"/> class.
        /// Validates the App Config key-value entries.
        /// </summary>
        /// <param name="appConfig">The App Config arguments.</param>
        public CommandLineExec(NameValueCollection appConfig)
        {
            AllocConsole();
            TraceFactory.SetThreadContextProperty("PID", Process.GetCurrentProcess().Id.ToString(), false);
            _arguments = appConfig;

            _state = SessionState.Available;
            string dispatcher              = string.Empty;
            string database                = string.Empty;
            string sessionName             = string.Empty;
            int    durationHours           = 2;
            IEnumerable <string> scenarios = null;

            if (_arguments != null)
            {
                scenarios     = _arguments["scenarios"].ToString().Split(';');
                dispatcher    = string.IsNullOrEmpty(_arguments["dispatcher"]) ? Environment.MachineName : _arguments["dispatcher"].ToString();
                database      = _arguments["database"].ToString();
                sessionName   = _arguments["sessionName"].ToString();
                durationHours = string.IsNullOrEmpty(_arguments["durationHours"]) ? 2 : Convert.ToInt32(_arguments["durationHours"]);
            }

            if (string.IsNullOrEmpty(dispatcher))
            {
                _state = SessionState.Error;
                throw new ArgumentException("Dispatcher is required.", "dispatcher");
            }
            TraceFactory.SetThreadContextProperty("Dispatcher", dispatcher, false);

            if (string.IsNullOrEmpty(sessionName))
            {
                _state = SessionState.Error;
                throw new ArgumentException("Session Name is required.", "sessionName");
            }
            if (string.IsNullOrEmpty(database))
            {
                _state = SessionState.Error;
                throw new ArgumentException("Database Host is required.", "database");
            }

            if (string.IsNullOrEmpty(_arguments["owner"].ToString()))
            {
                _state = SessionState.Error;
                throw new ArgumentException("Session Owner User name is required.", "owner");
            }

            if (GlobalSettings.IsDistributedSystem)
            {
                //We only care about password and domain if it's STF
                if (string.IsNullOrEmpty(_arguments["password"]))
                {
                    _state = SessionState.Error;
                    throw new ArgumentException("Session owner Password is required.", "password");
                }

                if (string.IsNullOrEmpty(_arguments["domain"]))
                {
                    _state = SessionState.Error;
                    throw new ArgumentException("User Domain is required.", "domain");
                }
            }

            // No need to check optional args.  They will be handled later.

            //Initialize the environment and create a ticket.
            GlobalSettings.SetDispatcher(dispatcher);
            GlobalSettings.Load(database);

            _ticket = SessionTicket.Create(scenarios, sessionName, durationHours);
            _ticket.SessionOwner   = GetSessionOwner(_arguments["owner"], _arguments["password"], _arguments["domain"] ?? Environment.UserDomainName);
            _ticket.ExpirationDate = SessionLogRetention.Month.GetExpirationDate(DateTime.Now);
        }
Example #10
0
        static void Main(string[] args)
        {
            TraceFactory.SetThreadContextProperty("PID", Process.GetCurrentProcess().Id.ToString());

            CommandLineArguments arguments = new CommandLineArguments(args);

            string configFilePath = arguments["config"];

            if (string.IsNullOrEmpty(configFilePath))
            {
                Usage();
            }

            DateTime startTime = DateTime.Now;

            try
            {
                if (OpenBook(configFilePath))
                {
                    // Read Database name
                    string database = _sheet.get_Range("B1").get_Value().ToString();

                    int startRowIndex = 7;

                    // walk thru each row and execute sanity test
                    while (true)
                    {
                        object val = _sheet.get_Range("A" + startRowIndex.ToString()).get_Value();

                        string temp = string.Empty;
                        if (null != val)
                        {
                            temp = val.ToString();
                        }

                        int index;

                        if (int.TryParse(temp, out index))
                        {
                            // Get row status
                            temp = _sheet.get_Range("E" + startRowIndex.ToString()).get_Value().ToString();
                            bool isEnabled = temp.Equals("Yes", StringComparison.CurrentCultureIgnoreCase);

                            if (isEnabled)
                            {
                                string dispatcher = _sheet.get_Range("B" + startRowIndex.ToString()).get_Value().ToString();
                                string scenario   = _sheet.get_Range("C" + startRowIndex.ToString()).get_Value().ToString();

                                string result, sessionID, clientVM;

                                bool status = SanityTestExecution.Start(dispatcher, database, scenario, out clientVM, out sessionID, out result);

                                SetValue("F" + startRowIndex.ToString(), clientVM);
                                SetValue("G" + startRowIndex.ToString(), sessionID);
                                SetValue("H" + startRowIndex.ToString(), status.ToString());
                                SetValue("I" + startRowIndex.ToString(), result);
                            }
                        }
                        else
                        {
                            // assuming the table ends here and exit the loop
                            break;
                        }
                        ++startRowIndex;
                    }
                }

                DateTime endTime = DateTime.Now;


                // Update Start and End times
                // Start Time = B2; End Time = B3; Time Taken B4;
                SetValue("B2", startTime.ToString());
                SetValue("B3", endTime.ToString());
                TimeSpan timeTaken = endTime.Subtract(startTime);
                SetValue("B4", timeTaken.Hours + ":" + timeTaken.Minutes + "(hh::mm)");
            }
            catch (Exception e)
            {
                Console.WriteLine("Error occurred in executing sanity test...");
                Console.WriteLine(e.Message);
            }
            finally
            {
                // Save the work book
                _book.Save();

                // close the work book
                CloseBook();
            }

            Console.ReadLine();
        }
Example #11
0
        private static void ValidateArguments(string[] args)
        {
            int i;

            // Process optional arguments first.
            for (i = 0; i < args.Length; i++)
            {
                string current = args[i];
                if (current == @"/s")
                {
                    i++;
                    if (i >= args.Length)
                    {
                        throw new ArgumentException("Missing packet size value.");
                    }
                    _packetSize = int.Parse(args[i], CultureInfo.InvariantCulture);
                    continue;
                }

                if (current == @"/d")
                {
                    i++;
                    if (i >= args.Length)
                    {
                        throw new ArgumentException("Missing delay value.");
                    }
                    _delay = int.Parse(args[i], CultureInfo.InvariantCulture);
                    continue;
                }

                if (current == @"/p")
                {
                    i++;
                    if (i >= args.Length)
                    {
                        throw new ArgumentException("Missing port value.");
                    }
                    _port = int.Parse(args[i], CultureInfo.InvariantCulture);
                    continue;
                }

                if (current == @"/c")
                {
                    i++;
                    if (i >= args.Length)
                    {
                        throw new ArgumentException("Missing System Server value.");
                    }

                    // Don't load the settings yet - need to wait until the logger thread context
                    // has been set from the IP address
                    _settingsDatabase = args[i];
                    continue;
                }

                // If we made it this far, we are done processing optional arguments.
                break;
            }

            // One required argument left.
            int argsLeft = args.Length - i;

            if (argsLeft < 1)
            {
                throw new ArgumentException("No octet specified.");
            }

            if (argsLeft > 1)
            {
                throw new ArgumentException("Too many arguments.");
            }

            // We passed all of the checks.
            _deviceAddress = BuildDeviceAddress(byte.Parse(args[i], CultureInfo.InvariantCulture));
            TraceFactory.SetThreadContextProperty("Address", _deviceAddress.ToString().Replace('.', '_'));

            string environment = "Unassigned";

            if (_settingsDatabase != null)
            {
                SettingsLoader.LoadSystemConfiguration(_settingsDatabase);
                environment = SettingsLoader.RetrieveSetting("Environment");
                _dataLogger = new DataLogger(SettingsLoader.RetrieveSetting("DataLog"));
            }

            Console.Title = "{0}  {1}".FormatWith(_deviceAddress.ToString(), environment);
        }