Exemplo n.º 1
0
        public async Task LoadProject(string path)
        {
            try
            {
                var deserialized = _serializerService.DeserializeFromFile <IUniconProject>(path);
                _uniconProject.ConnectableItems = deserialized.ConnectableItems;
                _uniconProject.LayoutString     = deserialized.LayoutString;
                _uniconProject.ProjectPath      = Path.GetDirectoryName(path);
                _uniconProject.Name             = Path.GetFileNameWithoutExtension(path);
                _devicesContainerService.Refresh();
                foreach (IConnectable connectableItem in _uniconProject.ConnectableItems)
                {
                    if (connectableItem.DeviceConnection != null)
                    {
                        var res = await _devicesContainerService.ConnectDeviceAsync(connectableItem as IDevice,
                                                                                    connectableItem.DeviceConnection);

                        if (!res.IsSuccess)
                        {
                            await _devicesContainerService.ConnectDeviceAsync(connectableItem as IDevice,
                                                                              _container.Resolve <IDeviceConnectionFactory>(ApplicationGlobalNames
                                                                                                                            .OFFLINE_CONNECTION_FACTORY_NAME).CreateDeviceConnection());
                        }

                        if (!_devicesContainerService.ConnectableItems.Contains(connectableItem as IDevice))
                        {
                            _devicesContainerService.AddConnectableItem(connectableItem as IDevice);
                        }
                    }
                }

                string message = string.Empty;
                message += _localizerService.GetLocalizedString(ServicesKeys.PROJECT_OPENED);
                message += " " + _uniconProject.ProjectPath + "\\" + _uniconProject.Name + ".uniproj";

                _logService.LogMessage(message);
                _applicationSettingsService.AddRecentProject(path);
            }
            catch (Exception ex)
            {
                _logService.LogMessage(ex.Message);
            }
        }