예제 #1
0
        public static IWidget[] ResolveWidgetsForScope(IRUSDevice scopeDevice, BusyObject busy)
        {
            if (_models.ContainsKey(scopeDevice))
            {
                throw new InvalidOperationException("Only one set of widgets per scope is allowed");
            }

            using (var core = new DICore())
            {
                registerBasicServices();
                instantiateWidgets();

                var widgets = core.Container.ResolveAll <IWidget>().ToArray();
                _allWidgets.AddRange(widgets.Select(w => new WidgetInfo(w, scopeDevice)));
                _models[scopeDevice] = core.Container.TryResolveAll <IDeviceHandler>()?.ToList() ?? new List <IDeviceHandler>();

                return(widgets);

                void registerBasicServices()
                {
                    core.Container.Register(scopeDevice);
                    core.Container.Register(scopeDevice.Name); // We're registering string. Dont be confused
                    core.Container.Register(busy);
                }

                void instantiateWidgets()
                {
                    var instantiator            = core.InstantiationStrategy;
                    var instantiationCoroutines = widgetsFactory(core.Container).ToArray();

                    instantiator.ExecuteCoroutines(instantiationCoroutines);
                }
            }

            //////////////////////////////////////

            IEnumerable <IEnumerator <ResolutionStepResult> > widgetsFactory(IDIContainer container)
            {
                string dataViewScope      = nameof(dataViewScope);
                string flashDumpViewScope = nameof(flashDumpViewScope);

                yield return(injectExporters(container, dataViewScope));

                yield return(DeviceInitialization.InstantiationCoroutine(dataViewScope, container));

                yield return(DeviceFiles.InstantiationCoroutine(dataViewScope, container));

                yield return(DeviceStatus.InstantiationCoroutine(dataViewScope, container));

                yield return(DataRequest.InstantiationCoroutine(dataViewScope, container));

                yield return(DataView.InstantiationCoroutine("Данные", dataViewScope, container));

                foreach (var command in getCommands(scopeDevice, busy))
                {
                    if (command == Command.DOWNLOAD_FLASH && Command.DOWNLOAD_FLASH.GetInfo().IsSupportedForDevice(scopeDevice.Id))
                    {
                        yield return(FlashUploadCommand.InstantiationCoroutine(flashDumpViewScope, container));
                    }
                    yield return(DeviceCommand.InstantiationCoroutine(command, dataViewScope, container));
                }

                foreach (var calibrator in getCalibrators(scopeDevice, new FileSaver(scopeDevice.Id, FileExtensionFactory.Instance).SaveCalibrationFileAsync, busy).ToArray())
                {
                    yield return(DeviceCalibration.InstantiationCoroutine(calibrator, dataViewScope, container));

                    yield return(injectCalibrationWidgets(container, calibrator));
                }

                foreach (var widget in deviceSpecificWidgetsFactory())
                {
                    yield return(widget);
                }

                yield return(DataViewSettings.InstantiationCoroutine(false, dataViewScope, container));

                IEnumerable <IEnumerator <ResolutionStepResult> > deviceSpecificWidgetsFactory()
                {
                    if (scopeDevice.Id.IsOneOf(RUSDeviceId.RUS_TECHNOLOGICAL_MODULE, RUSDeviceId.RUS_MODULE, RUSDeviceId.EMC_MODULE))
                    {
                        yield return(FlashDumpLoad.InstantiationCoroutine(flashDumpViewScope, container));

                        yield return(DataView.InstantiationCoroutine("Данные дампа Flash", flashDumpViewScope, container));

                        yield return(DataViewSettings.InstantiationCoroutine(true, flashDumpViewScope, container));

                        yield return(injectExporters(container, flashDumpViewScope));
                    }
                    if (scopeDevice.Id.IsOneOf(RUSDeviceId.RUS_MODULE))
                    {
                        yield return(RUSModuleSetDirection.InstantiationCoroutine(dataViewScope, container));

                        yield return(RUSTelemetryStreamSender.InstantiationCoroutine(dataViewScope, container));
                    }
                }
            }
        }