protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Frame> e) { _uas = SLWIOC.Get <IConnectedUasManager>().Active.Uas; _uas.Attitude.PropertyChanged += Attitude_PropertyChanged; DataContext = _uas; var gpsBindingHelper = new BindingHelper <GPSStatus>(_gpsStatus); gpsBindingHelper.Add(_uas.GPSs.First()).For(mod => mod.FixType, ctl => ctl.FixType); gpsBindingHelper.Add(_uas.GPSs.First()).For(mod => mod.HDOP, ctl => ctl.HDOP); gpsBindingHelper.Add(_uas.GPSs.First()).For(mod => mod.VDOP, ctl => ctl.VDOP); gpsBindingHelper.Add(_uas.GPSs.First()).For(mod => mod.SateliteCount, ctl => ctl.SatCount); var sysStatusbindingHelper = new BindingHelper <Controls.SystemStatus>(_systemStatus); sysStatusbindingHelper.Add(_uas.SystemStatus).For(mod => mod.Armed, ctl => ctl.Armed); sysStatusbindingHelper.Add(_uas.Batteries.First()).For(mod => mod.Voltage, ctl => ctl.BatteryVoltage); sysStatusbindingHelper.Add(_uas.Batteries.First()).For(mod => mod.RemainingPercent, ctl => ctl.PercentRemaining); sysStatusbindingHelper.Add(_uas.Batteries.First()).For(mod => mod.TimeRemaining, ctl => ctl.TimeRemaining); var altStatusbindingHelper = new BindingHelper <Controls.AltitudeIndicator>(_altitudeIndicator); altStatusbindingHelper.Add(_uas).For(mod => mod.CurrentLocation, ctl => ctl.Location); // _bindignHelper.Add(_uas.GPSs.First(), () => _gpsStatus.FixType, nameof(GPS.FixType)); base.OnElementChanged(e); Background = new SolidColorBrush(Colors.LightBlue); _video.GetDevices(); }
public async Task <InvokeResult <AuthResponse> > LoginAsync(AuthRequest loginInfo, CancellationTokenSource cancellationTokenSource = null) { var client = SLWIOC.Get <HttpClient>(); var json = JsonConvert.SerializeObject(loginInfo); var content = new StringContent(json, Encoding.UTF8, "application/json"); try { var response = await client.PostAsync("/api/v1/auth", content); if (response.IsSuccessStatusCode) { var resultContent = await response.Content.ReadAsStringAsync(); var serializerSettings = new JsonSerializerSettings(); serializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); var authResponse = JsonConvert.DeserializeObject <InvokeResult <AuthResponse> >(resultContent, serializerSettings); return(authResponse); } else { return(InvokeResult <AuthResponse> .FromErrors(new ErrorMessage() { Message = response.ReasonPhrase })); } } catch (Exception ex) { return(InvokeResult <AuthResponse> .FromException("AuthClient_LoginAsync", ex)); } }
public static ISSDPClient CreateSSDPClient(ILogger logger = null) { var ssdpClient = SLWIOC.Create <ISSDPClient>(); ssdpClient.Logger = logger == null?SLWIOC.Get <ILogger>() : logger; return(ssdpClient); }
public static IWebServer CreateWebServer(ILogger logger = null) { var webServer = SLWIOC.Create <IWebServer>(); webServer.Logger = logger == null?SLWIOC.Get <ILogger>() : logger; return(webServer); }
public void StartSSDPServer() { _server = SLWIOC.Get <ISSDPServer>(); //_server = Core.Networking.Services.NetworkServices.GetSSDPServer(); _server.MakeDiscoverable(9050, _configuration); _server.ShowDiagnostics = true; }
public MainPage() { this.InitializeComponent(); LoadApplication(new LagoVista.Uas.BaseStation.App()); var mgr = SLWIOC.Get <IConnectedUasManager>(); var _djiDrone = new DJIDrone(mgr); }
public async Task SaveAsAsync() { var popupService = SLWIOC.Get <IPopupServices>(); _fileName = await popupService.ShowSaveFileAsync(Constants.FileFilterHeightMap); if (!String.IsNullOrEmpty(_fileName)) { await Core.PlatformSupport.Services.Storage.StoreAsync(this, _fileName); } }
public static ISSDPServer GetSSDPServer(ILogger logger = null) { ISSDPServer ssdpServer; if (SLWIOC.TryResolve <ISSDPServer>(out ssdpServer)) { ssdpServer.Logger = logger == null?SLWIOC.Get <ILogger>() : logger; return(ssdpServer); } throw new Exception("Nothing registered for type ISSDPServer."); }
public static ISSDPClient GetSSDPClient(ILogger logger = null) { ISSDPClient ssdpClient; if (SLWIOC.TryResolve(out ssdpClient)) { ssdpClient.Logger = logger == null?SLWIOC.Get <ILogger>() : logger; return(ssdpClient); } throw new Exception("Nothing registered for type ISSDPClient."); }
public static IWebServer GetWebServer(ILogger logger = null) { IWebServer webServer; if (SLWIOC.TryResolve(out webServer)) { webServer.Logger = logger == null?SLWIOC.Get <ILogger>() : logger; return(webServer); } throw new Exception("Nothing registered for type IWebServer."); }
private void _mapControl_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { var locationProvier = SLWIOC.Get <ILocationProvider>(); if (locationProvier.HasLocation) { _mapControl.Center = new Geopoint(new BasicGeoposition() { Latitude = locationProvier.CurrentLocation.Latitude, Longitude = locationProvier.CurrentLocation.Longitude, Altitude = locationProvier.CurrentLocation.Altitude, }); _mapControl.ZoomLevel = 16; } }
public MainPage() { _flightStick = new Controller.NiVekFlightStick(Dispatcher); this.InitializeComponent(); _flightRecorder = SLWIOC.Get <IFlightRecorder>(); var uasMgr = SLWIOC.Get <IConnectedUasManager>(); var missionPlanner = new MissionPlanner(uasMgr); _navigation = new LagoVista.Uas.Core.Services.Navigation(uasMgr, missionPlanner, _flightRecorder); _hudViewModel = new HudViewModel(uasMgr, _navigation, _flightRecorder, _flightStick.State); _timer = new Timer(Timer_callBack, null, 100, 100); }
public static async Task <HeightMap> OpenAsync(MachineSettings settings) { var popupService = SLWIOC.Get <IPopupServices>(); var fileName = await popupService.ShowSaveFileAsync(Constants.FileFilterHeightMap); if (fileName != null) { var heightMap = await Core.PlatformSupport.Services.Storage.GetAsync <HeightMap>(fileName); heightMap.Refresh(); return(heightMap); } else { return(null); } }
private void CreateMenu() { _menu = new SideMenu(SLWIOC.Get <IAuthManager>()); _menu.MenuItemTapped += _menu_MenuItemTapped; _menu.IsVisible = false; _menu.TranslationX = -MENU_WIDTH; _menu.BackgroundColor = AppStyle.MenuBarBackground.ToXamFormsColor(); _menu.WidthRequest = MENU_WIDTH; _menu.HorizontalOptions = LayoutOptions.Start; _menu.SetValue(Grid.RowProperty, 1); _pageMenuMask = new Grid() { BackgroundColor = Xamarin.Forms.Color.Black, Opacity = 0.50 }; _pageMenuMask.SetValue(Grid.RowProperty, 1); _pageMenuMask.IsVisible = false; }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Frame> e) { if (e.NewElement != null) { SLWIOC.Get <ILocationProvider>().LocationUpdated += _locationProvier_LocationUpdated; _uas = SLWIOC.Get <IConnectedUasManager>().Active.Uas; _navigation = (e.NewElement.BindingContext as INavigationProvider).Navigation; if (_navigation == null) { throw new ArgumentException("Argument Not Set"); } _navigation.PropertyChanged += _navigation_PropertyChanged; } base.OnElementChanged(e); }
public void HandleURIActivation(Uri uri) { var logger = SLWIOC.Get <ILogger>(); if (this.MainPage == null) { logger.AddCustomEvent(LogLevel.Error, "App_HandleURIActivation", "Main Page Null"); } else { if (this.MainPage is LagoVistaNavigationPage page) { page.HandleURIActivation(uri); } else { logger.AddCustomEvent(LogLevel.Error, "App_HandleURIActivation", "InvalidPageType - Not LagoVistaNavigationPage", new System.Collections.Generic.KeyValuePair <string, string>("type", this.MainPage.GetType().Name)); } } }
protected override void OnActivated(IActivatedEventArgs args) { if (args.Kind == ActivationKind.Protocol) { var logger = SLWIOC.Get <ILogger>(); var protocolActivatedEventArgs = (args as ProtocolActivatedEventArgs); if (protocolActivatedEventArgs == null) { logger.AddCustomEvent(LogLevel.Error, "App_OnActivated", "EventArgs Not ProtocolActivatedEventArgs", new System.Collections.Generic.KeyValuePair <string, string>("type", args.GetType().Name)); } else { logger.AddCustomEvent(LogLevel.Message, "App_OnActivated", "URI App Activation", new System.Collections.Generic.KeyValuePair <string, string>("uri", protocolActivatedEventArgs.Uri.ToString())); LagoVista.Simulator.App.Instance.HandleURIActivation(protocolActivatedEventArgs.Uri); } } base.OnActivated(args); }
public void HandleURIActivation(Uri uri) { var logger = SLWIOC.Get <ILogger>(); if (this.CurrentPage == null) { logger.AddCustomEvent(LogLevel.Error, "LagoVistaNavigationPage_HandleURIActivation", "Main Page Null"); } else { var contentPage = this.CurrentPage as LagoVistaContentPage; if (contentPage != null) { contentPage.HandleURIActivation(uri); } else { logger.AddCustomEvent(LogLevel.Error, "App_OnActivated", "EventArgs Not ProtocolActivatedEventArgs", new System.Collections.Generic.KeyValuePair <string, string>("type", this.CurrentPage.GetType().Name)); } } }
public void HandleURIActivation(Uri uri) { var logger = SLWIOC.Get <ILogger>(); if (ViewModel != null) { var query = uri.Query.TrimStart('?'); var segments = query.Split('&'); var kvps = new Dictionary <string, string>(); foreach (var segment in segments) { var parts = segment.Split('='); if (parts.Length != 2) { logger.AddCustomEvent(LagoVista.Core.PlatformSupport.LogLevel.Error, "VerifyUserViewModel_HandleURIActivation", "Invalid Query String", new KeyValuePair <string, string>("queryString", query)); return; } if (String.IsNullOrEmpty(parts[0])) { logger.AddCustomEvent(LagoVista.Core.PlatformSupport.LogLevel.Error, "VerifyUserViewModel_HandleURIActivation", "Invalid Key on Query String", new KeyValuePair <string, string>("queryString", query)); return; } if (String.IsNullOrEmpty(parts[1])) { logger.AddCustomEvent(LagoVista.Core.PlatformSupport.LogLevel.Error, "VerifyUserViewModel_HandleURIActivation", "Invalid Value on Query String", new KeyValuePair <string, string>("queryString", query)); return; } kvps.Add(parts[0].ToLower(), parts[1]); } ViewModel.HandleURIActivation(uri, kvps); } else { logger.AddCustomEvent(LogLevel.Error, "LagoVistaNavigationPage_HandleURIActivation", "Main Page Null"); } }
private async void DeleteButton_Clicked(object sender, EventArgs e) { var btn = sender as IconButton; var deleteItemArgs = new DeleteItemEventArgs() { Id = btn.Tag as String, Type = Field.Name.ToPropertyName() }; var obj = ChildItems as Object; if (obj is System.Collections.IList) { if (await SLWIOC.Get <LagoVista.Core.PlatformSupport.IPopupServices>().ConfirmAsync(XPlatResources.Msg_ConfirmDeleteItemTitle, XPlatResources.Msg_ConfirmDeleteItem)) { var childList = ChildItems as System.Collections.IList; var itemToBeDeleted = ChildItems.Where(itm => itm.ToEntityHeader().Id == btn.Tag as string).FirstOrDefault(); childList.Remove(itemToBeDeleted); Deleted?.Invoke(sender, deleteItemArgs); Refresh(); } } }
public void SimpleSingletonInjectionTest() { SLWIOC.RegisterSingleton <IClassA, ClassA>(); SLWIOC.RegisterSingleton <IClassB, ClassB>(); SLWIOC.RegisterSingleton <IClassC, ClassC>(); var classA = SLWIOC.Get <IClassA>(); classA.PropertyA = "1234"; Assert.Equal("1234", SLWIOC.Get <IClassA>().PropertyA); var classB = SLWIOC.Get <IClassB>(); classB.PropertyA = "4567"; Assert.Equal("4567", SLWIOC.Get <IClassB>().PropertyA); var classC = SLWIOC.Get <IClassC>(); Assert.Equal(classC.ClassA.PropertyA, classA.PropertyA); Assert.Equal(classC.ClassB.PropertyA, classB.PropertyA); }
public async void GetSerialPorts() { var deviceManager = SLWIOC.Get <IDeviceManager>(); SerialPorts = await deviceManager.GetSerialPortsAsync(); }
private void InitServices() { _appConfig = new AppConfig(); #if ENV_MASTER var serverInfo = new ServerInfo() { SSL = true, RootUrl = "api.nuviot.com", }; _appConfig.Environment = Environments.Production; #elif ENV_DEV var serverInfo = new ServerInfo() { SSL = true, RootUrl = "dev-api.nuviot.com", }; _appConfig.Environment = Environments.Development; #elif ENV_LOCAL var serverInfo = new ServerInfo() { SSL = false, RootUrl = "localhost:5001", }; _appConfig.Environment = Environments.Local; #elif ENV_STAGE var serverInfo = new ServerInfo() { SSL = true, RootUrl = "stage-api.nuviot.com", }; _appConfig.Environment = Environments.Staging; #endif var clientAppInfo = new ClientAppInfo() { MainViewModel = typeof(MainViewModel) }; DeviceInfo.Register(); var deviceInfo = SLWIOC.Get <IDeviceInfo>(); SLWIOC.RegisterSingleton <IClientAppInfo>(clientAppInfo); SLWIOC.RegisterSingleton <IAppConfig>(_appConfig); var navigation = new ViewModelNavigation(this); LagoVista.XPlat.Core.Startup.Init(this, navigation); LagoVista.Client.Core.Startup.Init(serverInfo); navigation.Add <MainViewModel, Views.MainView>(); navigation.Add <SimulatorViewModel, Views.Simulator.SimulatorView>(); navigation.Add <SimulatorEditorViewModel, Views.Simulator.SimulatorEditorView>(); navigation.Add <MessageEditorViewModel, Views.Messages.MessageEditorView>(); navigation.Add <SendMessageViewModel, Views.Messages.SendMessageView>(); navigation.Add <MessageHeaderViewModel, Views.Messages.MessageHeaderView>(); navigation.Add <PasswordEntryViewModel, Views.Simulator.PasswordEntryView>(); navigation.Add <UnlockStorageViewModel, Views.Simulator.UnlockStorageView>(); navigation.Add <SetStoragePasswordViewModel, Views.Simulator.SetStoragePasswordView>(); navigation.Add <DynamicAttributeViewModel, Views.Messages.DynamicAttributeView>(); navigation.Add <SplashViewModel, Views.SplashView>(); navigation.Start <SplashViewModel>(); SLWIOC.Register <IMQTTAppClient, MQTTAppClient>(); SLWIOC.Register <IMQTTDeviceClient, MQTTDeviceClient>(); SLWIOC.RegisterSingleton <IViewModelNavigation>(navigation); }
protected override void OnLaunched(LaunchActivatedEventArgs e) { #if ENV_STAGE var mobileCenterKey = "d3f162da-76c5-4880-b19c-7a038d6af46f"; var serverInfo = new ServerInfo() { SSL = true, RootUrl = "api.nuviot.com", }; #elif ENV_DEV var mobileCenterKey = "d3f162da-76c5-4880-b19c-7a038d6af46f"; var serverInfo = new ServerInfo() { SSL = true, RootUrl = "dev-api.nuviot.com", }; #elif ENV_LOCALDEV var mobileCenterKey = "d3f162da-76c5-4880-b19c-7a038d6af46f"; var serverInfo = new ServerInfo() { SSL = false, RootUrl = "localhost:5001", }; #elif ENV_MASTER var mobileCenterKey = "d3f162da-76c5-4880-b19c-7a038d6af46f"; var serverInfo = new ServerInfo() { SSL = true, RootUrl = "api.nuviot.com", }; #endif var rootFrame = Window.Current.Content as Frame; if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } Window.Current.Content = rootFrame; } var dispatcherService = new DispatcherService(Window.Current.Dispatcher); this.DebugSettings.EnableFrameRateCounter = false; var uasMgr = new ConnectedUasManager(); var flightStick = new Controller.NiVekFlightStick(rootFrame.Dispatcher); SLWIOC.Register <INiVekFlightStick>(flightStick); SLWIOC.Register <IHeartBeatManager, HeartBeatManager>(); SLWIOC.RegisterSingleton <IConnectedUasManager>(uasMgr); SLWIOC.Register <IMissionPlanner, MissionPlanner>(); SLWIOC.RegisterSingleton <IConfigurationManager>(new ConfigurationManager()); SLWIOC.RegisterSingleton <ITelemetryService, TelemetryService>(); SLWIOC.RegisterSingleton <IFlightRecorder>(new FlightRecorder(dispatcherService)); SLWIOC.RegisterSingleton <IClientAppInfo>(new ClientAppInfo()); SLWIOC.RegisterSingleton <IAppConfig>(new UwpAppConfig()); SLWIOC.RegisterSingleton <IDeviceInfo>(new UWPDeviceInfo()); SLWIOC.RegisterSingleton <INavigation, LagoVista.Uas.Core.Services.Navigation>(); LagoVista.Core.UWP.Startup.Init(this, rootFrame.Dispatcher, mobileCenterKey); Startup.Init(serverInfo); var navigation = new LagoVista.UWP.UI.Navigation(); navigation.Initialize(rootFrame); navigation.Add <SplashViewModel, SplashView>(); navigation.Add <LoginViewModel, LoginView>(); navigation.Add <FlightViewModel, FlightView>(); navigation.Add <DroneConnectViewModel, DroneConnectView>(); _flightStickService = new FlightStickService(flightStick, rootFrame.Dispatcher, SLWIOC.Get <INavigation>()); SLWIOC.Register <IViewModelNavigation>(navigation); //new DJIDrone(uasMgr, Window.Current.Dispatcher); new TelloDrone(uasMgr, Window.Current.Dispatcher); if (e.PrelaunchActivated == false) { if (rootFrame.Content == null) { navigation.Navigate <SplashViewModel>(); } Window.Current.Activate(); } }
/// <summary> /// Validate an IValidateable object. /// </summary> /// <param name="entity">Object to validate</param> /// <param name="action">Action to execute: if not specified, use Any, this is normally used for custom validation routines</param> /// <param name="requirePopulatedEHValues">If this is set to true it will require that the entire object graphs, including traversing through EntityHeader<T>.Value will be required if the parameter is required.</param> /// <returns></returns> public static ValidationResult Validate(IValidateable entity, Actions action = Actions.Any, bool requirePopulatedEHValues = false) { var result = new ValidationResult(); if (entity == null) { if (SLWIOC.Contains(typeof(ILogger))) { var logger = SLWIOC.Get <ILogger>(); logger.AddException("Validator_Validate", new Exception("NULL Value Passed to Validate Method")); } result.AddSystemError("Null Value Provided for model on upload."); return(result); } ValidateAuditInfo(result, entity); ValidateId(result, entity); var properties = entity.GetType().GetTypeInfo().GetAllProperties(); foreach (var prop in properties) { var attr = prop.GetCustomAttributes(typeof(FormFieldAttribute), true).OfType <FormFieldAttribute>().FirstOrDefault(); if (attr != null) { ValidateProperty(attr, result, entity, prop, action); } } var methods = entity.GetType().GetTypeInfo().DeclaredMethods; foreach (var method in methods) { var attr = method.GetCustomAttributes(typeof(CustomValidatorAttribute), true).OfType <CustomValidatorAttribute>().FirstOrDefault(); if (attr != null) { CallCustomValidationRoutine(attr, result, entity, method, action); } } foreach (var prop in properties) { var attr = prop.GetCustomAttributes(typeof(FormFieldAttribute), true).OfType <FormFieldAttribute>().FirstOrDefault(); var propValue = prop.GetValue(entity); if (propValue != null) { if (propValue is IValidateable validateablePropValue) { var childResult = Validator.Validate(validateablePropValue, action); result.Concat(childResult); } if (propValue.GetType().GetTypeInfo().IsGenericType&& propValue.GetType().GetGenericTypeDefinition() == typeof(EntityHeader <>)) { var valueProperty = propValue.GetType().GetTypeInfo().GetDeclaredProperty("Value"); if (valueProperty.GetValue(propValue) is IValidateable validatableChild) { var childResult = Validator.Validate(validatableChild, action); result.Concat(childResult); } else { if (attr != null && attr.IsRequired && requirePopulatedEHValues) { AddRequiredFieldMissingMessage(result, attr, prop.Name); } } } if (prop.GetValue(entity) is System.Collections.IEnumerable listValues) { foreach (var listValue in listValues) { if (listValue is IValidateable validatableListValue) { var childResult = Validator.Validate(validatableListValue, action); result.Concat(childResult); } } } } } return(result); }
public async Task ShowMessage(string message) { await SLWIOC.Get <IPopupServices>().ShowAsync(message); }
public async void OpenPort() { var deviceManager = SLWIOC.Get <IDeviceManager>(); var port = deviceManager.CreateSerialPort(SelectedSerialPort); await port.OpenAsync(); }
public async Task InitAsync() { if (Settings.CurrentSerialPort == null) { Settings.CurrentSerialPort = new SerialPortInfo() { Id = "empty", Name = "-select-" }; } var ports = await SLWIOC.Get <IDeviceManager>().GetSerialPortsAsync(); #if DEBUG ports.Insert(0, new SerialPortInfo() { Id = "Simulated", Name = "Simulated" }); #endif ports.Insert(0, new SerialPortInfo() { Id = "empty", Name = "-select-" }); SerialPorts = ports; RaisePropertyChanged(nameof(SerialPorts)); var machineTypes = new ObservableCollection <string>(); var enums = Enum.GetValues(typeof(FirmwareTypes)); foreach (var enumType in enums) { machineTypes.Add(enumType.ToString().Replace("_", ".")); } MachineTypes = machineTypes; RaisePropertyChanged(nameof(MachineTypes)); var gcodeCommands = Enum.GetValues(typeof(JogGCodeCommand)); var gcodeJogCommands = new ObservableCollection <string>(); foreach (var gcodeCmd in gcodeCommands) { gcodeJogCommands.Add(gcodeCmd.ToString().Replace("_", ".")); } GCodeJogCommands = gcodeJogCommands; RaisePropertyChanged(nameof(GCodeJogCommands)); var origins = Enum.GetValues(typeof(MachineOrigin)); var originOptions = new ObservableCollection <string>(); foreach (var origin in origins) { originOptions.Add(origin.ToString().Replace("_", " ")); } MachineOrigins = originOptions; RaisePropertyChanged(nameof(MachineOrigins)); var outputLevels = Enum.GetValues(typeof(MessageVerbosityLevels)); var outputLevelOptions = new ObservableCollection <string>(); foreach (var outputLevel in outputLevels) { outputLevelOptions.Add(outputLevel.ToString().Replace("_", " ")); } MessageOutputLevels = outputLevelOptions; RaisePropertyChanged(nameof(MessageOutputLevels)); var connectionTypes = Enum.GetValues(typeof(ConnectionTypes)); var connectionTypeOptions = new ObservableCollection <string>(); foreach (var connectionType in connectionTypes) { connectionTypeOptions.Add(connectionType.ToString().Replace("_", " ")); } ConnectionTypes = connectionTypeOptions; RaisePropertyChanged(nameof(ConnectionTypes)); }
protected override void Dispose(bool disposing) { base.Dispose(disposing); SLWIOC.Get <ILocationProvider>().LocationUpdated -= _locationProvier_LocationUpdated; }