示例#1
0
 private static void WriteResultToFile(HypervisorManager manager, string filename)
 {
     try
     {
         File.WriteAllText(filename, manager.GetJsonResultString());
     }
     catch (Exception e)
     {
         Console.WriteLine($"Error writing profiling result to file {filename}: ", e);
     }
 }
        static void Main(string[] args)
        {
            // Get default path and filenames from the .config file
            _path = ConfigurationManager.AppSettings[CONF_KEY_DEFAULTPATH] ?? "./";
            string filenameHypervisor = ConfigurationManager.AppSettings[CONF_KEY_FILENAME_HYPERVISOR] ?? "hypervisor.json";
            string filenameVms        = ConfigurationManager.AppSettings[CONF_KEY_FILENAME_VMS] ?? "vms.json";

            // Read the configuration settings for the profiling mode.
            ReadProfilerConfiguration();

            if (_isProfilingActive)
            {
                Profiler.Profile(_numProfilingRuns, _numProfilingHypervisors, _numProfilingVms, _saveProfilingResults);
                return;
            }

            // Process Command-Line arguments
            if (!ProcessArgs(args))
            {
                return;
            }

            // Import the VMs and Hypervisors from the json files
            List <Hypervisor> hypervisors = ReadHypervisors(Path.Combine(_path, filenameHypervisor));

            if (hypervisors == null)
            {
                return;
            }

            List <Vm> vms = ReadVms(Path.Combine(_path, filenameVms));

            if (vms == null)
            {
                return;
            }

            var hvManager = new HypervisorManager(hypervisors);

            // Distribute the Vms one after another to the Hypervisors.
            // If intermediate Results should be logged to the Console, move the 'Console.WriteLine' statement into the foreach-block.
            foreach (var vm in vms)
            {
                hvManager.AddVm(vm);
            }

            Console.WriteLine("\r\nResult:");
            // Log the result to the Console.
            Console.WriteLine(hvManager.GetJsonResultString());
        }