Exemplo n.º 1
0
        public static List <RemoteMachine> GetAll()
        {
            string[]             entries  = Global.Configuration.RemoteMachines.Split(',');
            List <RemoteMachine> machines = new List <RemoteMachine>();

            foreach (string entry in entries)
            {
                string[] tokens = entry.Split('|');

                RemoteMachine machine = new RemoteMachine {
                    Name             = tokens[0],
                    CurrentDirectory = Path.GetDirectoryName(tokens[1]),
                    Filename         = tokens[1],
                    CommandLine      = tokens[1]
                };

                for (int i = 2; i < tokens.Length; i++)
                {
                    machine.Arguments   += ((i == 2 ? null : " ") + tokens[i]);
                    machine.CommandLine += (" " + tokens[i]);

                    if (tokens[i].StartsWith("/c="))
                    {
                        machine.ConfigurationPath = tokens[i].Substring(3);
                    }

                    if (tokens[i].StartsWith("/p="))
                    {
                        machine.PrintFilePath = tokens[i].Substring(3);
                    }
                }

                if (string.IsNullOrEmpty(machine.ConfigurationPath))
                {
                    machine.ConfigurationPath = machine.CurrentDirectory + @"\" + ConfigurationManagerRSG.DEFAULT_CONFIGURATION_NAME;
                }

                if (string.IsNullOrEmpty(machine.PrintFilePath))
                {
                    machine.PrintFilePath = machine.CurrentDirectory + @"\" + DaySim.Framework.Core.PrintFile.DEFAULT_PRINT_FILENAME;
                }

                machines.Add(machine);
            }

            return(machines);
        }
Exemplo n.º 2
0
        private static void CopyFilesToRemoteMachines()
        {
            var shadowPricesFile            = new FileInfo(Global.ShadowPricesPath);
            var parkAndRideShadowPricesFile = new FileInfo(Global.ParkAndRideShadowPricesPath);
            var machines = RemoteMachine.GetAll();

            foreach (var machine in machines)
            {
                if (shadowPricesFile.Exists)
                {
                    Console.WriteLine("Copying updated shadowPricesFile");
                    shadowPricesFile.CopyTo((machine.CurrentDirectory + @"\" + Global.GetWorkingPath("shadow_prices.txt", true)).ToUncPath(machine.Name), true);
                }

                if (parkAndRideShadowPricesFile.Exists)
                {
                    Console.WriteLine("Copying updated parkAndRideShadowPricesFile");
                    parkAndRideShadowPricesFile.CopyTo((machine.CurrentDirectory + @"\" + Global.GetWorkingPath("park_and_ride_shadow_prices.txt", true)).ToUncPath(machine.Name), true);
                }
            }
        }
Exemplo n.º 3
0
        private static void RunRemoteProcesses()
        {
            using (var reader = new CountingReader(new FileInfo(Global.GetInputPath(Global.Configuration.RawHouseholdPath)).OpenRead())) {
                while (reader.ReadLine() != null)
                {
                    _householdCount++;
                }
            }

            _householdCount--;

            var machines = RemoteMachine.GetAll();
            var range    = (int)Math.Ceiling(_householdCount / machines.Count);

            for (var i = 0; i < machines.Count; i++)
            {
                var start = (range * i);
                var end   = (int)Math.Min((range * i) + range - 1, _householdCount - 1);

                var machine = machines[i];

                //run a local remote DaySim session for debugging if desired
                if (Environment.MachineName.Equals(machine.Name, StringComparison.OrdinalIgnoreCase))
                {
                    var process = new Process {
                        StartInfo =
                        {
                            UseShellExecute = false,
                            CreateNoWindow  = true,
                            FileName        = machine.Filename,
                            Arguments       = machine.Arguments + " /s=" + start + " /e=" + end + " /i=" + i
                        }
                    };

                    process.Start();

                    _processes.Add(Tuple.Create(process, machine, new Timer()));
                }
                else
                {
                    //remote a remote DaySim session using WMI and RPC
                    var connectionOptions = new ConnectionOptions {
                        Username = Global.Configuration.RemoteUsername, Password = Global.Configuration.RemotePassword
                    };
                    var managementScope = new ManagementScope(String.Format(@"\\{0}\ROOT\CIMV2", machine.Name), connectionOptions);

                    managementScope.Connect();

                    var processClass = new ManagementClass(managementScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());
                    var inParameters = processClass.GetMethodParameters("Create");

                    inParameters["CurrentDirectory"] = machine.CurrentDirectory;
                    inParameters["CommandLine"]      = machine.CommandLine + " /s=" + start + " /e=" + end + " /i=" + i;

                    var outParameters = processClass.InvokeMethod("Create", inParameters, null);

                    if ((uint)outParameters.Properties["ReturnValue"].Value == 0)
                    {
                        _instances.Add(Tuple.Create(managementScope, outParameters, machine, new Timer()));
                    }
                }
            }

            var threads = new List <Thread>();

            foreach (var process in _processes)
            {
                var start  = new ParameterizedThreadStart(BeginLocalWatch);
                var thread = new Thread(start);

                thread.Start(process);
                threads.Add(thread);
            }

            foreach (var instance in _instances)
            {
                var start  = new ParameterizedThreadStart(BeginRemoteWatch);
                var thread = new Thread(start);

                thread.Start(instance);
                threads.Add(thread);
            }

            foreach (var thread in threads)
            {
                thread.Join();
            }
        }
Exemplo n.º 4
0
        private static void Merge()
        {
            var householdHeader       = false;
            var personHeader          = false;
            var householdDayHeader    = false;
            var jointTourHeader       = false;
            var fullHalfTourHeader    = false;
            var partialHalfTourHeader = false;
            var personDayHeader       = false;
            var tourHeader            = false;
            var tripHeader            = false;
            var tdmTripListHeader     = false;

            var machines = RemoteMachine.GetAll();

            for (var i = 0; i < machines.Count; i++)
            {
                var machine = machines[i];
                var configurationManager = new ConfigurationManagerRSG(machine.ConfigurationPath.ToUncPath(machine.Name));
                var configuration        = configurationManager.Open();

                var household = new FileInfo(Global.GetOutputPath(Global.Configuration.OutputHouseholdPath));
                AppendFile(household, new FileInfo(Global.GetOutputPath(configuration.OutputHouseholdPath).ToUncPath(machine.Name).ToIndexedPath(i)), ref householdHeader);

                var person = new FileInfo(Global.GetOutputPath(Global.Configuration.OutputPersonPath));
                AppendFile(person, new FileInfo(Global.GetOutputPath(configuration.OutputPersonPath).ToUncPath(machine.Name).ToIndexedPath(i)), ref personHeader);

                var householdDay = new FileInfo(Global.GetOutputPath(Global.Configuration.OutputHouseholdDayPath));
                AppendFile(householdDay, new FileInfo(Global.GetOutputPath(configuration.OutputHouseholdDayPath).ToUncPath(machine.Name).ToIndexedPath(i)), ref householdDayHeader);

                if (!string.IsNullOrEmpty(configuration.OutputJointTourPath))
                {
                    var jointTour = new FileInfo(Global.GetOutputPath(Global.Configuration.OutputJointTourPath));
                    AppendFile(jointTour, new FileInfo(Global.GetOutputPath(configuration.OutputJointTourPath).ToUncPath(machine.Name).ToIndexedPath(i)), ref jointTourHeader);
                }

                if (!string.IsNullOrEmpty(configuration.OutputFullHalfTourPath))
                {
                    var fullHalfTour = new FileInfo(Global.GetOutputPath(Global.Configuration.OutputFullHalfTourPath));
                    AppendFile(fullHalfTour, new FileInfo(Global.GetOutputPath(configuration.OutputFullHalfTourPath).ToUncPath(machine.Name).ToIndexedPath(i)), ref fullHalfTourHeader);
                }

                if (!string.IsNullOrEmpty(configuration.OutputPartialHalfTourPath))
                {
                    var partialHalfTour = new FileInfo(Global.GetOutputPath(Global.Configuration.OutputPartialHalfTourPath));
                    AppendFile(partialHalfTour, new FileInfo(Global.GetOutputPath(configuration.OutputPartialHalfTourPath).ToUncPath(machine.Name).ToIndexedPath(i)), ref partialHalfTourHeader);
                }

                var personDay = new FileInfo(Global.GetOutputPath(Global.Configuration.OutputPersonDayPath));
                AppendFile(personDay, new FileInfo(Global.GetOutputPath(configuration.OutputPersonDayPath).ToUncPath(machine.Name).ToIndexedPath(i)), ref personDayHeader);

                var tour = new FileInfo(Global.GetOutputPath(Global.Configuration.OutputTourPath));
                AppendFile(tour, new FileInfo(Global.GetOutputPath(configuration.OutputTourPath).ToUncPath(machine.Name).ToIndexedPath(i)), ref tourHeader);

                var trip = new FileInfo(Global.GetOutputPath(Global.Configuration.OutputTripPath));
                AppendFile(trip, new FileInfo(Global.GetOutputPath(configuration.OutputTripPath).ToUncPath(machine.Name).ToIndexedPath(i)), ref tripHeader);

                var tdmTripList = new FileInfo(Global.GetOutputPath(Global.Configuration.OutputTDMTripListPath));
                AppendFile(tdmTripList, new FileInfo(Global.GetOutputPath(configuration.OutputTDMTripListPath).ToUncPath(machine.Name).ToIndexedPath(i)), ref tdmTripListHeader);
            }
        }