コード例 #1
0
        /// <summary>
        /// Fetches the lodable MMUs from the adapters
        /// </summary>
        private void UpdateLoadableMMUs()
        {
            //Create a dictionary which holds the MMU Descriptions and the corresponding addresses
            Dictionary <MMUDescription, List <MIPAddress> > availableMMUs = new Dictionary <MMUDescription, List <MIPAddress> >();

            //Iterate over each adapter (do use for instead for-each due to possible changes of list)
            for (int i = RuntimeData.AdapterInstances.Count - 1; i >= 0; i--)
            {
                RemoteAdapter adapter = RuntimeData.AdapterInstances.Values.ElementAt(i);

                List <MMUDescription> mmuDescriptions = new List <MMUDescription>();
                try
                {
                    mmuDescriptions = adapter.GetLoadableMMUs("default");
                }
                catch (Exception e)
                {
                    Console.WriteLine("Problem receiving loadable MMUs: " + e.Message);
                }

                //Check if MMU is already available and add to dictionary
                foreach (MMUDescription description in mmuDescriptions)
                {
                    MMUDescription match = availableMMUs.Keys.ToList().Find(s => s.ID == description.ID && s.Name == description.Name);

                    if (match == null)
                    {
                        availableMMUs.Add(description, new List <MIPAddress>());
                        match = description;
                    }

                    availableMMUs[match].Add(new MIPAddress(adapter.Address, adapter.Port));
                }
            }

            //Update the MMU descriptions
            RuntimeData.MMUDescriptions.Clear();
            foreach (MMUDescription description in availableMMUs.Keys)
            {
                RuntimeData.MMUDescriptions.TryAdd(description.ID, description);
            }

            //Update the MMU collection in ui thread
            UIData.SetMMUDescriptions(availableMMUs.Keys.ToList());
        }
コード例 #2
0
        /// <summary>
        /// Main constructor
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            this.StopButton.IsEnabled = false;
            //Important assign the dispatcher at the beginning
            UIData.Initialize(this.Dispatcher);

            //Register for unhandled exceptions
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            //Initialize gui related things
            this.adapterListView.ItemsSource = UIData.AdapterCollection;
            this.serviceListView.ItemsSource = UIData.ServiceCollection;
            this.mmuView.ItemsSource         = UIData.MMUCollection;
            CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(this.mmuView.ItemsSource);

            //PropertyGroupDescription groupDescription = new PropertyGroupDescription("Language");
            //view.GroupDescriptions.Add(groupDescription);
            view.SortDescriptions.Add(new SortDescription("MotionType", ListSortDirection.Ascending));
            view.SortDescriptions.Add(new SortDescription("priority", ListSortDirection.Ascending));

            //Create an instance of the register service and register at events
            this.registerService = new MMIRegisterServiceImplementation();
            this.registerService.OnAdapterRegistered   += RegisterService_OnAdapterRegistered;
            this.registerService.OnAdapterUnregistered += RegisterService_OnAdapterUnregistered;
            this.registerService.OnServiceRegistered   += RegisterService_OnServiceRegistered;
            this.registerService.OnServiceUnregistered += RegisterService_OnServiceUnregistered;

            //Parse the settings from file
            try
            {
                //Load the settings file from json
                settings = Serialization.FromJsonString <ServerSettings>(File.ReadAllText("settings.json"));

                //Check if directory exists -> if not user must provide input
                if (!Directory.Exists(settings.DataPath))
                {
                    ShowFolderSelectionDialog("Invalid path: ");
                }
            }
            catch (Exception)
            {
                //Create a new settings file
                settings = new ServerSettings();

                //Show the folder selection dialog
                ShowFolderSelectionDialog("No settings file found: ");
                SaveSettings(); //if settings did not exist before save the default settings
            }

            //Read settings from system registry
            encryptionService = new Encrypt();
            LoadRegistrySettings();

            //Assign the port (common for loaded settings from file or settings from default settings file.
            RuntimeData.MMIRegisterAddress.Port    = settings.RegisterPort;
            RuntimeData.MMIRegisterAddress.Address = settings.RegisterAddress;

            //Sets up the performance bar which visualizes performance stats within the main window
            SetupPerformanceBar();

            //check if last selected adapter has the same ip address and update ip if needed
            NetworkAdapters = new NetworkAdapters();
            if (NetworkAdapters.updatedCurrentIp(settings.RegisterInterface, settings.RegisterAddress))
            { //update settings and save only if the interface or IP address has changed
                settings.RegisterAddress               = NetworkAdapters.AvailableIp[NetworkAdapters.currentIp].IP;
                settings.RegisterInterface             = NetworkAdapters.AvailableIp[NetworkAdapters.currentIp].Name;
                RuntimeData.MMIRegisterAddress.Address = settings.RegisterAddress;
                SaveSettings();
            }

            UpdateTitleBar();

            //Directly start all processes if autostart is enabled
            if (this.settings.AutoStart)
            {
                this.StartButton_Click(this, new RoutedEventArgs());
            }
        }
コード例 #3
0
 /// <summary>
 /// Method is called if a remote adapter switches to inactive
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnRemoteInactive(object sender, RemoteAdapter e)
 {
     UIData.SynchronizeAdapters();
 }
コード例 #4
0
 /// <summary>
 /// Method is called if a remote service switches to inactive
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnRemoteInactive(object sender, RemoteService e)
 {
     UIData.SynchronizeServices();
 }
コード例 #5
0
 private void RegisterService_OnAdapterRegistered(object sender, RemoteAdapter e)
 {
     e.OnInactive += OnRemoteInactive;
     UIData.SynchronizeAdapters();
 }
コード例 #6
0
        private void RegisterService_OnServiceRegistered(object sender, RemoteService e)
        {
            e.OnInactive += OnRemoteInactive;

            UIData.SynchronizeServices();
        }