private void UpdateObjectList(string typename, HashSet <string> walked, ObjectDirectory dir, HashSet <string> names)
        {
            if (walked.Contains(dir.FullPath.ToLower()))
            {
                return;
            }

            walked.Add(dir.FullPath.ToLower());

            try
            {
                foreach (ObjectDirectoryEntry entry in dir.Entries)
                {
                    try
                    {
                        if (entry.TypeName.Equals(typename, StringComparison.OrdinalIgnoreCase))
                        {
                            names.Add(entry.FullPath);
                        }
                        else if (entry.IsDirectory)
                        {
                            UpdateObjectList(typename, walked, ObjectNamespace.OpenDirectory(null, entry.FullPath), names);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }
        }
        /// <summary>
        /// Initializes communications with the outside world by means of remoting
        /// </summary>
        private void InitializeRemotingCommunications()
        {
            // Read the configuration file.
            RemotingConfiguration.Configure("..\\..\\App.config", false);
            WellKnownServiceTypeEntry[] wkst = RemotingConfiguration.GetRegisteredWellKnownServiceTypes();

            // "Activate" the NameService singleton.
            objectDirectory = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), wkst[0].ObjectUri);

            // Bind the operational test faceade
            objectDirectory.Rebind(this, "OperationalTestFacade");

            // Retreive the directory of messaging channels
            IChannelFactory channelFactory = (IChannelFactory)objectDirectory.Resolve("ChannelFactory");

            // Retreive the Messaging Service channels we want to listen to
            rndfChannel       = channelFactory.GetChannel("RndfNetworkChannel", ChannelMode.Bytestream);
            mdfChannel        = channelFactory.GetChannel("MdfChannel", ChannelMode.Bytestream);
            positionChannel   = channelFactory.GetChannel("PositionChannel", ChannelMode.Bytestream);
            testStringChannel = channelFactory.GetChannel("TestStringChannel", ChannelMode.Vanilla);

            // Create a channel listeners and listen on wanted channels
            channelListener = new MessagingListener();
            rndfToken       = rndfChannel.Subscribe(channelListener);
            mdfToken        = mdfChannel.Subscribe(channelListener);
            //positionToken = positionChannel.Subscribe(channelListener);
            testStringToken = testStringChannel.Subscribe(new StringListener());

            // Show that the navigation system is ready and waiting for input
            Console.WriteLine("   > Remoting Communication Initialized");
        }
        private IEnumerable <string> GetObjectList(string typename)
        {
            HashSet <string> walked = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            HashSet <string> names  = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            try
            {
                ObjectDirectory basedir = ObjectNamespace.OpenDirectory(null, "\\");
                UpdateObjectList(typename, walked, basedir, names);
            }
            catch (NtException)
            {
            }

            try
            {
                ObjectDirectory sessiondir = ObjectNamespace.OpenSessionDirectory();
                UpdateObjectList(typename, walked, sessiondir, names);
            }
            catch (NtException)
            {
            }

            List <string> ret = new List <string>(names);

            ret.Sort();

            return(ret);
        }
        /// <summary>
        /// Registers with the correct services
        /// </summary>
        public void Register()
        {
            try
            {
                // "Activate" the NameService singleton.
                objectDirectory = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), wkst[0].ObjectUri);

                // Retreive the directory of messaging channels
                IChannelFactory channelFactory = (IChannelFactory)objectDirectory.Resolve("ChannelFactory");

                // Retreive the Messaging Service channels we want to push to
                simulationMessageChannel = channelFactory.GetChannel("SimulationMessageChannel", ChannelMode.UdpMulticast);

                // Rebind the Simulator as the simulator remote facade server
                objectDirectory.Rebind(this, "SimulationServer");

                // Notify user of success
                SimulatorOutput.WriteLine("Connection to Name Service and Registration of Simulation Server as Simulator Facade Successful");

                // let clients know the sim is alive
                simulationMessageChannel.PublishUnreliably(SimulationMessage.Alive);
            }
            catch (Exception e)
            {
                SimulatorOutput.WriteLine("Error Registering With Remoting Services: " + e.ToString());
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Attempts to register with the simulation
        /// </summary>
        public void AttemptSimulationConnection()
        {
            // notify
            Console.WriteLine(DateTime.Now.ToString() + ": Attempting Connection To Simulation Server");

            try
            {
                // "Activate" the NameService singleton.
                objectDirectory = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), wkst[0].ObjectUri);

                // Resolve the SimulationServer as the simulator remote facade server
                this.client.SimulationServer = (SimulatorFacade)objectDirectory.Resolve("SimulationServer");

                // create the dynamics sim facade
                this.client.DynamicsVehicle = new DynamicsSimVehicle(new SimVehicleState(), this.objectDirectory);

                // register ourselves
                bool success = this.client.SimulationServer.Register(this.client.Name());

                // notify
                if (success)
                {
                    Console.WriteLine(DateTime.Now.ToString() + ": Attempt Succeeded");
                }
                else
                {
                    Console.WriteLine(DateTime.Now.ToString() + ": Registration Failed in Simulation");
                }
            }
            catch (Exception e)
            {
                // notify
                Console.WriteLine(DateTime.Now.ToString() + ": Attempt Failed" + "\n" + e.ToString());
            }
        }
        public DynamicsSimVehicle(SimVehicleState vehicleState, ObjectDirectory od)
        {
            this.simVehicleState = vehicleState;

            InitializeState();

            Connect(od);
        }
        public virtual void TestSuccess()
        {
            // Manually force a delta of an object so we reuse it later.
            //
            TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
            PackHeader(pack, 2);
            pack.Write((Constants.OBJ_BLOB) << 4 | 1);
            Deflate(pack, new byte[] { (byte)('a') });
            pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4);
            a.CopyRawTo(pack);
            Deflate(pack, new byte[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked (
                                           (int)(0x1)), (byte)('b') });
            Digest(pack);
            OpenPack(pack);
            // Verify the only storage of b is our packed delta above.
            //
            ObjectDirectory od = (ObjectDirectory)src.ObjectDatabase;

            NUnit.Framework.Assert.IsTrue(src.HasObject(b), "has b");
            NUnit.Framework.Assert.IsFalse(od.FileFor(b).Exists(), "b not loose");
            // Now use b but in a different commit than what is hidden.
            //
            TestRepository s = new TestRepository <Repository>(src);
            RevCommit      N = s.Commit().Parent(B).Add("q", b).Create();

            s.Update(R_MASTER, N);
            // Push this new content to the remote, doing strict validation.
            //
            TransportLocal  t = new _TransportLocal_210(this, src, UriOf(dst), dst.Directory);
            RemoteRefUpdate u = new RemoteRefUpdate(src, R_MASTER, R_MASTER, false, null, null
                                                    );
            //
            //
            // src name
            // dst name
            // do not force update
            // local tracking branch
            // expected id
            PushResult r;

            try
            {
                t.SetPushThin(true);
                r = t.Push(PM, Sharpen.Collections.Singleton(u));
            }
            finally
            {
                t.Close();
            }
            NUnit.Framework.Assert.IsNotNull(r, "have result");
            NUnit.Framework.Assert.IsNull(r.GetAdvertisedRef(R_PRIVATE), "private not advertised"
                                          );
            NUnit.Framework.Assert.AreEqual(RemoteRefUpdate.Status.OK, u.GetStatus(), "master updated"
                                            );
            NUnit.Framework.Assert.AreEqual(N, dst.Resolve(R_MASTER));
        }
        /// <summary>
        /// Registers with the correct services
        /// </summary>
        public void Register()
        {
            // "Activate" the NameService singleton.
            objectDirectory = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), wkst[0].ObjectUri);

            // Retreive the directory of messaging channels
            channelFactory = (IChannelFactory)objectDirectory.Resolve("ChannelFactory");

            // register the core as implementing the arbiter advanced remote facade
            objectDirectory.Rebind(this.arbiterCore, "ArbiterAdvancedRemote" + this.RemotingSuffix);

            // shutdown old channels
            this.Shutdown();

            // get vehicle state channel
            vehicleStateChannel      = channelFactory.GetChannel("ArbiterSceneEstimatorPositionChannel" + this.RemotingSuffix, ChannelMode.UdpMulticast);
            vehicleStateChannelToken = vehicleStateChannel.Subscribe(messagingListener);

            // get observed obstacle channel
            observedObstacleChannel      = channelFactory.GetChannel("ObservedObstacleChannel" + this.RemotingSuffix, ChannelMode.UdpMulticast);
            observedObstacleChannelToken = observedObstacleChannel.Subscribe(messagingListener);

            // get observed vehicle channel
            observedVehicleChannel      = channelFactory.GetChannel("ObservedVehicleChannel" + this.RemotingSuffix, ChannelMode.UdpMulticast);
            observedVehicleChannelToken = observedVehicleChannel.Subscribe(messagingListener);

            // get vehicle speed channel
            vehicleSpeedChannel      = channelFactory.GetChannel("VehicleSpeedChannel" + this.RemotingSuffix, ChannelMode.UdpMulticast);
            vehicleSpeedChannelToken = vehicleSpeedChannel.Subscribe(messagingListener);

            // get side obstacle channel
            sideObstacleChannel      = channelFactory.GetChannel("SideObstacleChannel" + this.RemotingSuffix, ChannelMode.UdpMulticast);
            sideObstacleChannelToken = sideObstacleChannel.Subscribe(messagingListener);

            // get output channel
            if (arbiterOutputChannel != null)
            {
                arbiterOutputChannel.Dispose();
            }
            arbiterOutputChannel = channelFactory.GetChannel("ArbiterOutputChannel" + this.RemotingSuffix, ChannelMode.UdpMulticast);

            // get information channel
            if (arbiterInformationChannel != null)
            {
                arbiterInformationChannel.Dispose();
            }
            arbiterInformationChannel = channelFactory.GetChannel("ArbiterInformationChannel" + this.RemotingSuffix, ChannelMode.UdpMulticast);

            // get the operational layer
            this.operationalFacade = (OperationalFacade)objectDirectory.Resolve("OperationalService" + this.RemotingSuffix);
            this.operationalFacade.RegisterListener(this);
            this.SendProjection();

            // try connecting to the test facade
            this.TryOperationalTestFacadeConnect();
        }
        private void Connect(ObjectDirectory od)
        {
            // get the channel for the sim state
            IChannelFactory channelFactory = (IChannelFactory)od.Resolve("ChannelFactory");

            operationalStateChannel = channelFactory.GetChannel("OperationalSimState_" + SimulatorClient.MachineName, ChannelMode.Bytestream);

            // publish ourself to the object directory
            od.Rebind(this, "DynamicsSim_" + SimulatorClient.MachineName);
        }
Esempio n. 10
0
 static void OutputNameOnly(ObjectDirectory base_dir, IEnumerable <ObjectDirectoryEntry> entries)
 {
     foreach (ObjectDirectoryEntry entry in entries)
     {
         if (entry.IsSymlink && print_link)
         {
             Console.WriteLine("{0} -> {1}", entry.FullPath, GetSymlinkTarget(entry));
         }
         else
         {
             Console.WriteLine(entry.FullPath);
         }
     }
 }
        static List <string> FindDeviceObjects(IEnumerable <string> names)
        {
            Queue <string>   dumpList     = new Queue <string>(names);
            HashSet <string> dumpedDirs   = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            List <string>    totalEntries = new List <string>();

            while (dumpList.Count > 0)
            {
                string name = dumpList.Dequeue();
                try
                {
                    ObjectDirectory directory = ObjectNamespace.OpenDirectory(null, name);

                    if (!dumpedDirs.Contains(directory.FullPath))
                    {
                        dumpedDirs.Add(directory.FullPath);
                        List <ObjectDirectoryEntry> sortedEntries = new List <ObjectDirectoryEntry>(directory.Entries);
                        sortedEntries.Sort();

                        string base_name = name.TrimEnd('\\');

                        IEnumerable <ObjectDirectoryEntry> objs = sortedEntries;

                        if (_recursive)
                        {
                            foreach (ObjectDirectoryEntry entry in sortedEntries.Where(d => d.IsDirectory))
                            {
                                dumpList.Enqueue(entry.FullPath);
                            }
                        }

                        totalEntries.AddRange(objs.Where(e => e.TypeName.Equals("device", StringComparison.OrdinalIgnoreCase)).Select(e => e.FullPath));
                    }
                }
                catch (NtException ex)
                {
                    int error = NtRtl.RtlNtStatusToDosError(ex.Status);
                    if (NtRtl.RtlNtStatusToDosError(ex.Status) == 6)
                    {
                        // Add name in case it's an absolute name, not in a directory
                        totalEntries.Add(name);
                    }
                    else
                    {
                    }
                }
            }

            return(totalEntries);
        }
        public static void InitComm()
        {
            // set the machine name from the config
            machineName = Properties.Settings.Default.MachineName.Trim().ToUpper();

            // configure remoting
            RemotingConfiguration.Configure("net.xml", false);

            // get the name service
            WellKnownServiceTypeEntry[] wkst = RemotingConfiguration.GetRegisteredWellKnownServiceTypes();
            objectDirectory = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), wkst[0].ObjectUri);

            // get the channel factory
            channelFactory = (IChannelFactory)objectDirectory.Resolve("ChannelFactory");
        }
        public static void ConfigureRemoting(string server)
        {
            RemotingConfiguration.Configure("net.xml", false);

            if (!string.IsNullOrEmpty(server))
            {
                string uri = "tcp://" + server + ":12345/ObjectDirectory";
                od = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), uri);
            }
            else
            {
                WellKnownServiceTypeEntry[] wkst = RemotingConfiguration.GetRegisteredWellKnownServiceTypes();
                // "Activate" the NameService singleton.
                od = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), wkst[0].ObjectUri);
            }
        }
Esempio n. 14
0
        static void Main(string[] args)
        {
            bool show_help = false;

            int pid = Process.GetCurrentProcess().Id;

            OptionSet opts = new OptionSet()
            {
                { "r", "Recursive tree directory listing",
                  v => _recursive = v != null },
                { "sddl", "Print full SDDL security descriptors", v => _print_sddl = v != null },
                { "p|pid=", "Specify a PID of a process to impersonate when checking", v => pid = int.Parse(v.Trim()) },
                { "w", "Show only write permissions granted", v => _show_write_only = v != null },
                { "k=", String.Format("Filter on a specific directory right [{0}]",
                                      String.Join(",", Enum.GetNames(typeof(DirectoryAccessRights)))), v => _dir_rights |= ParseRight(v, typeof(DirectoryAccessRights)) },
                { "s=", String.Format("Filter on a standard right [{0}]",
                                      String.Join(",", Enum.GetNames(typeof(StandardAccessRights)))), v => _dir_rights |= ParseRight(v, typeof(StandardAccessRights)) },
                { "x=", "Specify a base path to exclude from recursive search", v => _walked.Add(v.ToLower()) },
                { "t=", "Specify a type of object to include", v => _type_filter.Add(v.ToLower()) },
                { "h|help", "show this message and exit", v => show_help = v != null },
            };

            List <string> paths = opts.Parse(args);

            if (show_help || (paths.Count == 0))
            {
                ShowHelp(opts);
            }
            else
            {
                try
                {
                    _token = NativeBridge.OpenProcessToken(pid);

                    foreach (string path in paths)
                    {
                        ObjectDirectory dir = ObjectNamespace.OpenDirectory(path);

                        DumpDirectory(dir);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Esempio n. 15
0
        static void Main(string[] args)
        {
            // Read the configuration file.
            RemotingConfiguration.Configure("..\\..\\ProxyService.exe.config", false);
            WellKnownServiceTypeEntry[] wkst = RemotingConfiguration.GetRegisteredWellKnownServiceTypes();

            // "Activate" the NameService singleton.
            ObjectDirectory od = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), wkst[0].ObjectUri);

            // Bind the facades of components we implement.
            od.Rebind(Arbiter.FacadeImpl.Instance, "Arbiter");

            Console.WriteLine("Waiting");

            // Enter the main event loop...
            Console.ReadLine();
        }
Esempio n. 16
0
        /// <summary>
        /// Configures remoting
        /// </summary>
        public void Configure()
        {
            // configure
            RemotingConfiguration.Configure("VehicleSeparationDisplay.exe.config", false);
            wkst = RemotingConfiguration.GetRegisteredWellKnownServiceTypes();

            // "Activate" the NameService singleton.
            objectDirectory = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), wkst[0].ObjectUri);

            // Retreive the directory of messaging channels
            channelFactory = (IChannelFactory)objectDirectory.Resolve("ChannelFactory");

            // Notify user of success
            Console.WriteLine("Connection to Name Service Successful");

            // get information channel
            arbiterInformationChannel      = channelFactory.GetChannel("ArbiterInformationChannel" + this.RemotingSuffix, ChannelMode.UdpMulticast);
            arbiterInformationChannelToken = arbiterInformationChannel.Subscribe(messagingListener);
        }
Esempio n. 17
0
        static void DumpDirectory(ObjectDirectory dir)
        {
            if (_walked.Contains(dir.FullPath.ToLower()))
            {
                return;
            }

            _walked.Add(dir.FullPath.ToLower());

            try
            {
                CheckAccess(dir.FullPath, dir.SecurityDescriptor, NtType.GetTypeByName("Directory"));

                if (_recursive)
                {
                    foreach (ObjectDirectoryEntry entry in dir.Entries)
                    {
                        try
                        {
                            if (entry.IsDirectory)
                            {
                                using (ObjectDirectory newdir = ObjectNamespace.OpenDirectory(dir, entry.ObjectName))
                                {
                                    DumpDirectory(newdir);
                                }
                            }
                            else
                            {
                                CheckAccess(entry.FullPath, entry.SecurityDescriptor, NtType.GetTypeByName(entry.TypeName));
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.Error.WriteLine("Error opening {0} {1}", entry.FullPath, ex.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error dumping directory {0} {1}", dir.FullPath, ex.Message);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Registers with the correct services
        /// </summary>
        public void Register()
        {
            // "Activate" the NameService singleton.
            objectDirectory = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), wkst[0].ObjectUri);

            // Retreive the directory of messaging channels
            channelFactory = (IChannelFactory)objectDirectory.Resolve("ChannelFactory");

            // Notify user of success
            RemoraOutput.WriteLine("Connection to Name Service Successful", OutputType.Remora);

            // get simulation if supposed to
            if (global::RemoraAdvanced.Properties.Settings.Default.SimMode)
            {
                this.simulatorFacade = (SimulatorFacade)objectDirectory.Resolve("SimulationServer");

                // Notify user of success
                RemoraOutput.WriteLine("Connection to Simulation Service Successful", OutputType.Remora);
            }
        }
        static Dictionary <string, string> FindSymlinks()
        {
            Queue <string>              dumpList   = new Queue <string>(new string[] { "\\" });
            HashSet <string>            dumpedDirs = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            Dictionary <string, string> symlinks   = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            while (dumpList.Count > 0)
            {
                string name = dumpList.Dequeue();
                try
                {
                    ObjectDirectory directory = ObjectNamespace.OpenDirectory(null, name);

                    if (!dumpedDirs.Contains(directory.FullPath))
                    {
                        dumpedDirs.Add(directory.FullPath);
                        List <ObjectDirectoryEntry> sortedEntries = new List <ObjectDirectoryEntry>(directory.Entries);
                        sortedEntries.Sort();

                        string base_name = name.TrimEnd('\\');

                        IEnumerable <ObjectDirectoryEntry> objs = sortedEntries;

                        foreach (ObjectDirectoryEntry entry in sortedEntries.Where(d => d.IsDirectory))
                        {
                            dumpList.Enqueue(entry.FullPath);
                        }

                        foreach (ObjectDirectoryEntry entry in sortedEntries.Where(d => d.IsSymlink))
                        {
                            symlinks[GetSymlinkTarget(entry)] = entry.FullPath;
                        }
                    }
                }
                catch (NtException)
                {
                }
            }

            return(symlinks);
        }
Esempio n. 20
0
        public void TryConnect()
        {
            try
            {
                // configure
                RemotingConfiguration.Configure("FakeOperational.exe.config", false);
                WellKnownServiceTypeEntry[] wkst = RemotingConfiguration.GetRegisteredWellKnownServiceTypes();

                // "Activate" the NameService singleton.
                ObjectDirectory objectDirectory = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), wkst[0].ObjectUri);

                // register the core as implementing the arbiter advanced remote facade
                objectDirectory.Rebind(this, "OperationalService_" + Environment.MachineName);

                Console.WriteLine("Connection and Registration Success");
            }
            catch (Exception e)
            {
                Console.WriteLine("Connection error: \n" + e.ToString());
            }
        }
Esempio n. 21
0
        private void ProcessDirectory(ulong tableAddress, int parent)
        {
            ObjectDirectory objectDirectory = new ObjectDirectory(_profile, _dataProvider, virtualAddress: tableAddress);

            //byte[] buffer = _dataProvider.ReadMemoryBlock(tableAddress, _objectMap.ObjectDirectorySize);
            //var dll = _profile.GetStructureAssembly("_OBJECT_DIRECTORY");
            //Type t = dll.GetType("liveforensics.OBJECT_DIRECTORY");
            //GCHandle pinnedPacket = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            //objectDirectory = Marshal.PtrToStructure(Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0), t);
            //pinnedPacket.Free();

            byte[] hashBucket = objectDirectory.Members.HashBuckets;
            int    count      = hashBucket.Length / 8;

            for (int i = 0; i < count; i++)
            {
                ulong ptr = (BitConverter.ToUInt64(hashBucket, i * 8)) & 0xffffffffffff;
                if (ptr == 0)
                {
                    continue;
                }
                BuildTree(ptr, parent);
            }
        }
Esempio n. 22
0
        static void OutputNone(ObjectDirectory base_dir, IEnumerable <ObjectDirectoryEntry> objs)
        {
            if (print_sddl)
            {
                Console.WriteLine("SDDL: {0} -> {1}", base_dir.FullPath, base_dir.StringSecurityDescriptor);
            }

            foreach (ObjectDirectoryEntry ent in objs.Where(e => e.IsDirectory))
            {
                Console.WriteLine("<DIR> {0}", ent.FullPath);
            }

            foreach (ObjectDirectoryEntry ent in objs.Where(e => !e.IsDirectory))
            {
                if (ent.IsSymlink && print_link)
                {
                    Console.WriteLine("      {0} -> {1}", ent.FullPath, GetSymlinkTarget(ent));
                }
                else
                {
                    Console.WriteLine("      {0} ({1})", ent.FullPath, ent.TypeName);
                }
            }
        }
Esempio n. 23
0
        private static ObjectDirectory PurgeEddnFromDirectory(ObjectDirectory directory)
        {
            ObjectDirectory newDirectory;

            if(directory.GetType() == typeof(StationDirectory))
                newDirectory = new StationDirectory();
            else
                newDirectory = new CommodityDirectory();

            foreach (var x in directory)
            {
                var newList = new List<CsvRow>();
                foreach (var y in x.Value)
                    if (y.SourceFileName != "<From EDDN>")
                        newList.Add(y);

                if(newList.Count > 0)
                    newDirectory.Add(x.Key, newList);
            }
            return newDirectory;
        }
Esempio n. 24
0
        /// <summary>
        /// Registers with the correct services
        /// </summary>
        public void Register()
        {
            try
            {
                // "Activate" the NameService singleton.
                objectDirectory = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), wkst[0].ObjectUri);

                // Retreive the directory of messaging channels
                IChannelFactory channelFactory = (IChannelFactory)objectDirectory.Resolve("ChannelFactory");

                // Retreive the Messaging Service channels we want to interact with
                if (simulationMessageChannel != null)
                {
                    simulationMessageChannel.Dispose();
                }
                simulationMessageChannel = channelFactory.GetChannel("SimulationMessageChannel", ChannelMode.UdpMulticast);

                // Listen to channels we wish to listen to
                simulationMessageChannelToken = simulationMessageChannel.Subscribe(this.messagingListener);

                // Rebind the Simulator as the simulator remote facade server
                objectDirectory.Rebind(this.client, this.client.Name());

                // get vehicle state channel
                if (vehicleStateChannel != null)
                {
                    vehicleStateChannel.Dispose();
                }
                vehicleStateChannel = channelFactory.GetChannel("ArbiterSceneEstimatorPositionChannel_" + SimulatorClient.MachineName, ChannelMode.Bytestream);

                // get observed obstacle channel
                if (observedObstacleChannel != null)
                {
                    observedObstacleChannel.Dispose();
                }
                observedObstacleChannel = channelFactory.GetChannel("ObservedObstacleChannel_" + SimulatorClient.MachineName, ChannelMode.Bytestream);

                // get observed vehicle channel
                if (observedVehicleChannel != null)
                {
                    observedVehicleChannel.Dispose();
                }
                observedVehicleChannel = channelFactory.GetChannel("ObservedVehicleChannel_" + SimulatorClient.MachineName, ChannelMode.Bytestream);

                // get vehicle speed channel
                if (vehicleSpeedChannel != null)
                {
                    vehicleSpeedChannel.Dispose();
                }
                vehicleSpeedChannel = channelFactory.GetChannel("VehicleSpeedChannel_" + SimulatorClient.MachineName, ChannelMode.Bytestream);

                // get the local road estimate channel
                if (localRoadChannel != null)
                {
                    localRoadChannel.Dispose();
                }
                localRoadChannel = channelFactory.GetChannel(LocalRoadEstimate.ChannelName + "_" + SimulatorClient.MachineName, ChannelMode.Bytestream);

                // Notify user of success
                Console.WriteLine(DateTime.Now.ToString() + ": Connection to Name Service and Registration of Simulation Client Successful");
            }
            catch (Exception e)
            {
                // notify
                Console.WriteLine(DateTime.Now.ToString() + ": Error Registering With Remoting Services: " + e.ToString());
            }
        }
Esempio n. 25
0
        private static ObjectDirectory PurgeOldDataFromDirectory(ObjectDirectory directory, DateTime deadline)
        {
            ObjectDirectory newDirectory;
            
            if(directory.GetType() == typeof(StationDirectory))
                newDirectory = new StationDirectory();
            else
                newDirectory = new CommodityDirectory();

            foreach (var x in directory)
            {
                var newList = new List<CsvRow>();
                foreach (var y in x.Value)
                    if (y.SampleDate >= deadline)
                        newList.Add(y);

                if(newList.Count > 0)
                    newDirectory.Add(x.Key, newList);
            }
            return newDirectory;
        }
Esempio n. 26
0
        private void RenameStation(object sender, EventArgs e)
        {
            var existingStationName = getCmbItemKey(cmbStation.SelectedItem);

            tbStationRename.Text    = _textInfo.ToTitleCase(tbStationRename.Text.ToLower());

            var newStationName = tbStationRename.Text + " [" + tbSystemRename.Text + "]";

            List<CsvRow> newRows = new List<CsvRow>();

            foreach (var row in StationDirectory[existingStationName])
            {
                CsvRow newRow = new CsvRow
                {
                    BuyPrice = row.BuyPrice,
                    Cargo = row.Cargo,
                    CommodityName = row.CommodityName,
                    Demand = row.Demand,
                    DemandLevel = row.DemandLevel,
                    SampleDate = row.SampleDate,
                    SellPrice = row.SellPrice,
                    StationName = tbStationRename.Text,
                    StationID = newStationName,
                    Supply = row.Supply,
                    SupplyLevel = row.SupplyLevel,
                    SystemName = tbSystemRename.Text,
                    SourceFileName = row.SourceFileName
                };

                newRows.Add(newRow);
            }


            StationDirectory.Remove(existingStationName);

            if (!StationDirectory.ContainsKey(newStationName))
                StationDirectory.Add(newStationName, newRows);
            else StationDirectory[newStationName].AddRange(newRows);

            var newCommodityDirectory = new CommodityDirectory();

            foreach (var collectionOfRows in CommodityDirectory)
            {
                newRows = new List<CsvRow>();

                foreach (var row in collectionOfRows.Value)
                {

                    CsvRow newRow = new CsvRow
                    {
                        BuyPrice = row.BuyPrice,
                        Cargo = row.Cargo,
                        CommodityName = row.CommodityName,
                        Demand = row.Demand,
                        DemandLevel = row.DemandLevel,
                        SampleDate = row.SampleDate,
                        SellPrice = row.SellPrice,
                        StationID = row.StationID == existingStationName ? newStationName : row.StationID,
                        Supply = row.Supply,
                        SupplyLevel = row.SupplyLevel,
                        SystemName = row.StationID == existingStationName ? tbSystemRename.Text : row.SystemName
                    };

                    newRows.Add(newRow);
                }

                newCommodityDirectory.Add(collectionOfRows.Key, newRows);
            }

            CommodityDirectory = newCommodityDirectory;

            //Remove duplicates (incl. historical)
            var newStationDirectory = new List<CsvRow>();

            var distinctCommodityNames = StationDirectory[newStationName].ToList().Select(x => x.CommodityName).Distinct();

            foreach (var c in distinctCommodityNames)
            {
                newStationDirectory.Add(StationDirectory[newStationName].ToList().Where(x => x.CommodityName == c).OrderByDescending(x => x.SampleDate).First());
            }

            StationDirectory[newStationName] = newStationDirectory;

            var newCommodityDirectory2 = new CommodityDirectory();

            for (int i = 0; i < CommodityDirectory.Keys.Count; i++)
            {
                var distinctStationNames = CommodityDirectory.ElementAt(i).Value.Select(x => x.StationID).Distinct();
                foreach (var d in distinctStationNames)
                {
                    if (!newCommodityDirectory2.Keys.Contains(CommodityDirectory.ElementAt(i).Key))
                        newCommodityDirectory2.Add(CommodityDirectory.ElementAt(i).Key, new List<CsvRow> { CommodityDirectory.ElementAt(i).Value.ToList().Where(x => x.StationID == d).OrderByDescending(x => x.SampleDate).First() });
                    else newCommodityDirectory2[CommodityDirectory.ElementAt(i).Key].Add(CommodityDirectory.ElementAt(i).Value.ToList().Where(x => x.StationID == d).OrderByDescending(x => x.SampleDate).First());
                }
            }

            CommodityDirectory = newCommodityDirectory2;

            _StationHistory.RenameStation(existingStationName, newStationName);

            SetupGui();
        }
Esempio n. 27
0
 private void cmdPurgeEDDNData(object sender, EventArgs e)
 {
     StationDirectory = PurgeEddnFromDirectory(StationDirectory);
     CommodityDirectory = PurgeEddnFromDirectory(CommodityDirectory);
     SetupGui();
 }
Esempio n. 28
0
        /// <summary>
        /// Initializes communications with the outside world by means of remoting
        /// </summary>
        public void InitializeRemotingCommunications()
        {
            // try to shut down in case we have already been active
            this.ShutDown();

            try
            {
                // Read the configuration file.
                RemotingConfiguration.Configure("Remora.exe.config", false);
                WellKnownServiceTypeEntry[] wkst = RemotingConfiguration.GetRegisteredWellKnownServiceTypes();

                // "Activate" the NameService singleton.
                objectDirectory = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), wkst[0].ObjectUri);

                // Retreive the directory of messaging channels
                IChannelFactory channelFactory = (IChannelFactory)objectDirectory.Resolve("ChannelFactory");

                // Retreive the Messaging Service channels we want to listen to
                vehicleStateChannel       = channelFactory.GetChannel("PositionChannel", ChannelMode.UdpMulticast);
                observedObstacleChannel   = channelFactory.GetChannel("ObservedObstacleChannel", ChannelMode.UdpMulticast);
                observedVehicleChannel    = channelFactory.GetChannel("ObservedVehicleChannel", ChannelMode.UdpMulticast);
                arbiterInformationChannel = channelFactory.GetChannel("ArbiterInformationChannel", ChannelMode.UdpMulticast);
                carModeChannel            = channelFactory.GetChannel("CarMode", ChannelMode.UdpMulticast);
                fakeVehicleChannel        = channelFactory.GetChannel("FakeVehicleChannel", ChannelMode.UdpMulticast);

                // Create a channel listeners and listen on wanted channels
                channelListener          = new MessagingListener();
                vehicleStateChannelToken = vehicleStateChannel.Subscribe(channelListener);
                observedObstacleChannel.Subscribe(channelListener);
                observedVehicleChannel.Subscribe(channelListener);
                arbiterInformationChannelToken = arbiterInformationChannel.Subscribe(channelListener);
                carModeChannelToken            = carModeChannel.Subscribe(channelListener);
                fakeVehicleChannelToken        = fakeVehicleChannel.Subscribe(channelListener);

                // set that remoting has been successfully initialize
                this.RemotingInitialized = true;
                RemoraOutput.WriteLine("Successfully initialized communications");
            }
            catch (Exception e)
            {
                RemoraOutput.WriteLine(e.ToString() + "\n\n" + "Could not initialize communications, attempting to reconnect");

                try
                {
                    WellKnownServiceTypeEntry[] wkst = RemotingConfiguration.GetRegisteredWellKnownServiceTypes();

                    // "Activate" the NameService singleton.
                    objectDirectory = (ObjectDirectory)Activator.GetObject(typeof(ObjectDirectory), wkst[0].ObjectUri);

                    // Retreive the directory of messaging channels
                    IChannelFactory channelFactory = (IChannelFactory)objectDirectory.Resolve("ChannelFactory");

                    // Retreive the Messaging Service channels we want to listen to
                    vehicleStateChannel       = channelFactory.GetChannel("PositionChannel", ChannelMode.UdpMulticast);
                    observedObstacleChannel   = channelFactory.GetChannel("ObservedObstacleChannel", ChannelMode.UdpMulticast);
                    observedVehicleChannel    = channelFactory.GetChannel("ObservedVehicleChannel", ChannelMode.UdpMulticast);
                    arbiterInformationChannel = channelFactory.GetChannel("ArbiterInformationChannel", ChannelMode.UdpMulticast);
                    carModeChannel            = channelFactory.GetChannel("CarMode", ChannelMode.UdpMulticast);
                    fakeVehicleChannel        = channelFactory.GetChannel("FakeVehicleChannel", ChannelMode.UdpMulticast);

                    // Create a channel listeners and listen on wanted channels
                    channelListener          = new MessagingListener();
                    vehicleStateChannelToken = vehicleStateChannel.Subscribe(channelListener);
                    observedObstacleChannel.Subscribe(channelListener);
                    observedVehicleChannel.Subscribe(channelListener);
                    arbiterInformationChannelToken = arbiterInformationChannel.Subscribe(channelListener);
                    carModeChannelToken            = carModeChannel.Subscribe(channelListener);
                    fakeVehicleChannelToken        = fakeVehicleChannel.Subscribe(channelListener);

                    // set that remoting has been successfully initialize
                    this.RemotingInitialized = true;
                    RemoraOutput.WriteLine("Successfully initialized communications");
                }
                catch (Exception e1)
                {
                    RemoraOutput.WriteLine(e1.ToString() + "\n\n" + "Could not reinitialize nameservice communications");

                    try
                    {
                        // Retreive the directory of messaging channels
                        IChannelFactory channelFactory = (IChannelFactory)objectDirectory.Resolve("ChannelFactory");

                        // Retreive the Messaging Service channels we want to listen to
                        vehicleStateChannel       = channelFactory.GetChannel("PositionChannel", ChannelMode.UdpMulticast);
                        observedObstacleChannel   = channelFactory.GetChannel("ObservedObstacleChannel", ChannelMode.UdpMulticast);
                        observedVehicleChannel    = channelFactory.GetChannel("ObservedVehicleChannel", ChannelMode.UdpMulticast);
                        arbiterInformationChannel = channelFactory.GetChannel("ArbiterInformationChannel", ChannelMode.UdpMulticast);
                        carModeChannel            = channelFactory.GetChannel("CarMode", ChannelMode.UdpMulticast);
                        fakeVehicleChannel        = channelFactory.GetChannel("FakeVehicleChannel", ChannelMode.UdpMulticast);

                        // Create a channel listeners and listen on wanted channels
                        channelListener          = new MessagingListener();
                        vehicleStateChannelToken = vehicleStateChannel.Subscribe(channelListener);
                        observedObstacleChannel.Subscribe(channelListener);
                        observedVehicleChannel.Subscribe(channelListener);
                        arbiterInformationChannelToken = arbiterInformationChannel.Subscribe(channelListener);
                        carModeChannelToken            = carModeChannel.Subscribe(channelListener);
                        fakeVehicleChannelToken        = fakeVehicleChannel.Subscribe(channelListener);

                        // set that remoting has been successfully initialize
                        this.RemotingInitialized = true;
                        RemoraOutput.WriteLine("Successfully initialized communications");
                    }
                    catch (Exception e2)
                    {
                        RemoraOutput.WriteLine(e2.ToString() + "\n\n" + "Could not reinitialize messaging communications");
                    }
                }
            }
        }
Esempio n. 29
0
        static void DumpDirectories(IEnumerable <string> names)
        {
            Queue <Tuple <ObjectDirectory, string> > dumpList
                = new Queue <Tuple <ObjectDirectory, string> >(names.Select(s => new Tuple <ObjectDirectory, string>(null, s)));
            HashSet <string>            dumpedDirs   = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            List <ObjectDirectoryEntry> totalEntries = new List <ObjectDirectoryEntry>();

            while (dumpList.Count > 0)
            {
                Tuple <ObjectDirectory, string> name = dumpList.Dequeue();
                try
                {
                    using (ObjectDirectory directory = ObjectNamespace.OpenDirectory(name.Item1, name.Item2))
                    {
                        if (!dumpedDirs.Contains(directory.FullPath))
                        {
                            dumpedDirs.Add(directory.FullPath);
                            List <ObjectDirectoryEntry> sortedEntries = new List <ObjectDirectoryEntry>(directory.Entries);
                            sortedEntries.Sort();

                            string base_name = name.Item2.TrimEnd('\\');

                            IEnumerable <ObjectDirectoryEntry> objs = sortedEntries;

                            if (recursive)
                            {
                                foreach (ObjectDirectoryEntry entry in sortedEntries.Where(d => d.IsDirectory))
                                {
                                    dumpList.Enqueue(new Tuple <ObjectDirectory, string>(directory.Duplicate(), entry.ObjectName));
                                }
                            }

                            if (typeFilter.Count > 0)
                            {
                                objs = objs.Where(e => typeFilter.Contains(e.TypeName.ToLower()));
                            }

                            switch (format)
                            {
                            case OutputFormat.NameOnly:
                                OutputNameOnly(directory, objs);
                                break;

                            case OutputFormat.TypeGroup:
                                totalEntries.AddRange(objs);
                                break;

                            case OutputFormat.None:
                            default:
                                OutputNone(directory, objs);
                                break;
                            }
                        }
                    }
                }
                catch (Win32Exception ex)
                {
                    Console.Error.WriteLine("Error querying {0} - {1}", name.Item2, ex.Message);
                }
            }

            switch (format)
            {
            case OutputFormat.TypeGroup:
                OutputTypeGroup(totalEntries);
                break;
            }
        }
Esempio n. 30
0
        private void cmdPurgeOldData_Click(object sender, EventArgs e)
        {

            if(MsgBox.Show(String.Format("Delete all data older than {0} days", nudPurgeOldDataDays.Value), "Delete old price data", MessageBoxButtons.OKCancel, MessageBoxIcon.Question ) == System.Windows.Forms.DialogResult.OK)
            {
                DateTime deadline = DateTime.Now.AddDays(-1*(Int32)(nudPurgeOldDataDays.Value)).Date;
                StationDirectory = PurgeOldDataFromDirectory(StationDirectory, deadline);
                CommodityDirectory = PurgeOldDataFromDirectory(CommodityDirectory, deadline);
                SetupGui();
            }

        }