public void Load() { #warning One day I would like to decouple this implementation from the FileStore plugin File.PluginLoader.Instance.EnsureLoaded(); Mvx.RegisterSingleton <IMvxHttpFileDownloader>(new MvxHttpFileDownloader()); #warning Huge Magic numbers here - what cache sizes should be used? try { var fileDownloadCache = new MvxFileDownloadCache("_PicturesMvvmCross", "_Caches/Pictures.MvvmCross/", 500, TimeSpan.FromDays(3.0)); var fileCache = new MvxImageCache <Bitmap>(fileDownloadCache, 30, 4000000); Mvx.RegisterSingleton <IMvxImageCache <Bitmap> >(fileCache); Mvx.RegisterType <IMvxImageHelper <Bitmap>, MvxDynamicImageHelper <Bitmap> >(); Mvx.RegisterSingleton <IMvxLocalFileImageLoader <Bitmap> >(new MvxAndroidLocalFileImageLoader()); } catch (Exception exception) { MvxTrace.Error("Binding", "Exception {0}", exception.ToLongString()); throw; } }
public static void OnViewCreate(this IMvxView view, Func <IMvxViewModel> viewModelLoader) { // note - we check the DataContent before the ViewModel to avoid casting errors // in the case of 'simple' binding code if (view.DataContext != null) { return; } if (view.ViewModel != null) { return; } var viewModel = viewModelLoader(); if (viewModel == null) { MvxTrace.Warning("ViewModel not loaded for view {0}", view.GetType().Name); return; } view.ViewModel = viewModel; }
private Dictionary <string, Entry> LoadIndexEntries() { try { var store = Mvx.Resolve <IMvxFileStore>(); string text; if (store.TryReadTextFile(IndexFilePath, out text)) { var list = TextConvert.DeserializeObject <List <Entry> >(text); return(list.ToDictionary(x => x.HttpSource, x => x)); } } //catch (ThreadAbortException) //{ // throw; //} catch (Exception exception) { MvxTrace.Warning("Failed to read cache index {0} - reason {1}", _cacheFolder, exception.ToLongString()); } return(new Dictionary <string, Entry>()); }
public virtual bool TryLoad(Type viewModelType, IMvxBundle parameterValues, IMvxBundle savedState, out IMvxViewModel viewModel) { viewModel = null; try { viewModel = (IMvxViewModel)Mvx.IocConstruct(viewModelType); } catch (Exception exception) { MvxTrace.Warning("Problem creating viewModel of type {0} - problem {1}", viewModelType.Name, exception.ToLongString()); return(false); } try { CallCustomInitMethods(viewModel, parameterValues); if (savedState != null) { CallReloadStateMethods(viewModel, savedState); } viewModel.Start(); } catch (Exception exception) { MvxTrace.Warning("Problem initialising viewModel of type {0} - problem {1}", viewModelType.Name, exception.ToLongString()); return(false); } return(true); }
public override MvxBasePresentationAttribute GetOverridePresentationAttribute(Type viewModelType, Type viewType) { if (viewType?.GetInterface(nameof(IMvxOverridePresentationAttribute)) != null) { var viewInstance = WpfViewLoader.CreateView(viewType) as IDisposable; using (viewInstance) { MvxBasePresentationAttribute presentationAttribute = null; if (viewInstance is IMvxOverridePresentationAttribute overrideInstance) { presentationAttribute = overrideInstance.PresentationAttribute(); } if (presentationAttribute == null) { MvxTrace.Warning("Override PresentationAttribute null. Falling back to existing attribute."); } else { if (presentationAttribute.ViewType == null) { presentationAttribute.ViewType = viewType; } if (presentationAttribute.ViewModelType == null) { presentationAttribute.ViewModelType = viewModelType; } return(presentationAttribute); } } } return(null); }
public virtual Type FindTypeOrNull(Type candidateType) { if (!CheckCandidateTypeIsAView(candidateType)) { return(null); } if (!candidateType.IsConventional()) { return(null); } var typeByAttribute = LookupAttributedViewModelType(candidateType); if (typeByAttribute != null) { return(typeByAttribute); } var concrete = LookupAssociatedConcreteViewModelType(candidateType); if (concrete != null) { return(concrete); } var typeByName = LookupNamedViewModelType(candidateType); if (typeByName != null) { return(typeByName); } MvxTrace.Trace("No view model association found for candidate view {0}", candidateType.Name); return(null); }
public void TestFunctionalValueConverterBinding() { var text = "Target ConvertThis(Foo)"; var expected = new MvxSerializableBindingSpecification() { { "Target", new MvxSerializableBindingDescription() { Function = "ConvertThis", Sources = new MvxSerializableBindingDescription[] { new MvxSerializableBindingDescription() { Path = "Foo", }, } } } }; MvxTrace.Trace(MvxTraceLevel.Diagnostic, "Testing: {0}", text); this.PerformTest(text, expected); }
public override bool TryMove(string from, string to, bool deleteExistingTo) { try { StorageFile fromFile; try { fromFile = StorageFileFromRelativePath(from); } catch (FileNotFoundException) { return(false); } if (deleteExistingTo) { if (!SafeDeleteFile(to)) { return(false); } } var fullToPath = ToFullPath(to); var toDirectory = Path.GetDirectoryName(fullToPath); var toFileName = Path.GetFileName(fullToPath); var toStorageFolder = StorageFolder.GetFolderFromPathAsync(toDirectory).Await(); fromFile.MoveAsync(toStorageFolder, toFileName).Await(); return(true); } catch (Exception exception) { MvxTrace.Trace("Exception during file move from {0} to {1} - {2}", from, to, exception.ToLongString()); return(false); } }
protected override void OnElementChanged(ElementChangedEventArgs <Image> args) { if (args.OldElement != null) { if (_nativeControl != null) { _nativeControl.Dispose(); _nativeControl = null; } } if (Element.Source != null) { MvxTrace.Warning("Source property ignored on MvxImageView"); } base.OnElementChanged(args); if (_nativeControl != null) { if (_nativeControl.ErrorImagePath != SharedControl.ErrorImagePath) { _nativeControl.ErrorImagePath = SharedControl.ErrorImagePath; } if (_nativeControl.DefaultImagePath != SharedControl.DefaultImagePath) { _nativeControl.DefaultImagePath = SharedControl.DefaultImagePath; } if (_nativeControl.ImageUrl != SharedControl.ImageUri) { _nativeControl.ImageUrl = SharedControl.ImageUri; } } }
protected MvxBasePresentationAttribute GetPresentationAttributes(UIViewController viewController) { var attributes = viewController.GetType().GetCustomAttributes(typeof(MvxBasePresentationAttribute), true).FirstOrDefault() as MvxBasePresentationAttribute; if (attributes != null) { return(attributes); } if (MasterNavigationController == null && (TabBarViewController == null || !TabBarViewController.CanShowChildView(viewController)) ) { MvxTrace.Trace($"PresentationAttribute nor MasterNavigationController found for {viewController.GetType().Name}. Assuming Root presentation"); return(new MvxRootPresentationAttribute() { WrapInNavigationController = true }); } MvxTrace.Trace($"PresentationAttribute not found for {viewController.GetType().Name}. Assuming animated Child presentation"); return(new MvxChildPresentationAttribute()); }
private static void LogUncaughtException(object handle) { var exception = handle as Exception; try { var deviceService = Mvx.Resolve <IDeviceService>(); var data = Mvx.Resolve <ILogService>().Read(); Mvx.Resolve <IErrorService>().Send( exception?.Message, exception?.BuildAllMessagesAndStackTrace(), deviceService.PackageName, deviceService.AppVersion, deviceService.OSVersion, data ); } catch (Exception ex) { MvxTrace.TaggedTrace(MvxTraceLevel.Warning, nameof(BaseAndroidSetup), ex.BuildAllMessagesAndStackTrace()); } }
public static IMvxViewModel LoadViewModel(this IMvxFragmentView fragmentView, IMvxBundle savedState, Type fragmentParentActivityType, MvxViewModelRequest request = null) { var viewModelType = fragmentView.FindAssociatedViewModelType(fragmentParentActivityType); if (viewModelType == typeof(MvxNullViewModel)) { return(new MvxNullViewModel()); } if (viewModelType == null || viewModelType == typeof(IMvxViewModel)) { MvxTrace.Trace("No ViewModel class specified for {0} in LoadViewModel", fragmentView.GetType().Name); } if (request == null) { request = MvxViewModelRequest.GetDefaultRequest(viewModelType); } var viewModelCache = Mvx.Resolve <IMvxChildViewModelCache>(); if (viewModelCache.Exists(viewModelType)) { var viewModelCached = viewModelCache.Get(viewModelType); viewModelCache.Remove(viewModelType); return(viewModelCached); } var loaderService = Mvx.Resolve <IMvxViewModelLoader>(); var viewModel = loaderService.LoadViewModel(request, savedState); return(viewModel); }
private static IMvxViewModel LoadViewModel(this IMvxAndroidView androidView, IMvxBundle savedState) { var activity = androidView.ToActivity(); var viewModelType = androidView.FindAssociatedViewModelTypeOrNull(); if (viewModelType == typeof(MvxNullViewModel)) { return(new MvxNullViewModel()); } if (viewModelType == null || viewModelType == typeof(IMvxViewModel)) { MvxTrace.Warning("No ViewModel class specified for {0} - returning null from LoadViewModel", androidView.GetType().Name); return(null); } var translatorService = Mvx.Resolve <IMvxAndroidViewModelLoader>(); var viewModel = translatorService.Load(activity.Intent, savedState, viewModelType); return(viewModel); }
public static Task <CLLocation> GetCurrentLocationAsync() { var tcs = new TaskCompletionSource <CLLocation>(); EventHandler <CLLocationsUpdatedEventArgs> handler = null; EventHandler <NSErrorEventArgs> failedHandler = null; handler = (object sender, CLLocationsUpdatedEventArgs e) => { MvxTrace.Trace("UpdatedLocations: " + e.Locations.FirstOrDefault()); _locationManager.LocationsUpdated -= handler; _locationManager.Failed -= failedHandler; LastKnownLocation = e.Locations.FirstOrDefault() ?? new CLLocation(); tcs.TrySetResult(LastKnownLocation); }; failedHandler = (object sender, NSErrorEventArgs e) => { MvxTrace.Trace("Failed to get location: " + e.Error); _locationManager.LocationsUpdated -= handler; _locationManager.Failed -= failedHandler; tcs.TrySetResult(new CLLocation()); }; _locationManager.DesiredAccuracy = CLLocation.AccuracyHundredMeters; _locationManager.LocationsUpdated += handler; _locationManager.Failed += failedHandler; _locationManager.RequestLocation(); return(tcs.Task); }
public void TestValueConverterNullBinding() { var text = "Target Conv(null)"; var expected = new MvxSerializableBindingSpecification() { { "Target", new MvxSerializableBindingDescription() { Function = "Conv", Sources = new MvxSerializableBindingDescription[] { new MvxSerializableBindingDescription() { Literal = MvxTibetBindingParser.LiteralNull }, }, } } }; MvxTrace.Trace(MvxTraceLevel.Diagnostic, "Testing: {0}", text); this.PerformTest(text, expected); }
public override Stream OpenWrite(string path) { try { StorageFile storageFile; if (Exists(path)) { storageFile = StorageFileFromRelativePath(path); } else { storageFile = CreateStorageFileFromRelativePathAsync(path).GetAwaiter().GetResult(); } var streamWithContentType = storageFile.OpenAsync(FileAccessMode.ReadWrite).Await(); return(streamWithContentType.AsStream()); } catch (Exception exception) { MvxTrace.Trace("Error during file save {0} : {1}", path, exception.ToLongString()); throw; } }
public static object GetArgumentValue(this IDictionary <string, string> data, ParameterInfo requiredParameter, string debugText) { string parameterValue; if (data == null || !data.TryGetValue(requiredParameter.Name, out parameterValue)) { if (requiredParameter.IsOptional) { return(Type.Missing); } MvxTrace.Trace( "Missing parameter for call to {0} - missing parameter {1} - asssuming null - this may fail for value types!", debugText, requiredParameter.Name); parameterValue = null; } var value = MvxSingletonCache.Instance.Parser.ReadValue(parameterValue, requiredParameter.ParameterType, requiredParameter.Name); return(value); }
public async Task Start() { var result = await BeaconsUtil.RequestPermissionAsync(); if (!result) { return; } _locationMgr.DidRangeBeacons += HandleDidRangeBeacons; _locationMgr.DidDetermineState += HandleDidDetermineState; _locationMgr.PausesLocationUpdatesAutomatically = false; _locationMgr.StartUpdatingLocation(); beacon_operations_queue.DispatchAsync(StartScanningSynchronized); var location = await BeaconsUtil.GetCurrentLocationAsync(); var ibeacons = await BeaconsService.Instance.LoadBeaconsByUserLocation(location.Coordinate.Latitude, location.Coordinate.Longitude); //Начинаем мониторинг foreach (var ibeacon in ibeacons) { var clBeaconRegion = new CLBeaconRegion(new NSUuid(ibeacon.UUID), (ushort)ibeacon.Major, (ushort)ibeacon.Minor, $"{BEACONS_REGION_HEADER}.{ibeacon.ToString()}"); clBeaconRegion.NotifyEntryStateOnDisplay = true; clBeaconRegion.NotifyOnEntry = true; clBeaconRegion.NotifyOnExit = true; _listOfCLBeaconRegion.Add(clBeaconRegion); _locationMgr.StartMonitoring(clBeaconRegion); _locationMgr.StartRangingBeacons(clBeaconRegion); MvxTrace.TaggedTrace(MvxTraceLevel.Diagnostic, "Beacons", "Start monitoring " + JsonConvert.SerializeObject(ibeacon)); } }
private static void ShowPageChanged(int toPage) { MvxTrace.TaggedTrace("SimpleListViewModel", "Page changed to {0}", toPage); }
public virtual void ChangePresentation(MvxPresentationHint hint) { MvxTrace.Warning("Hint ignored {0}", hint.GetType().Name); }
private static void ShowItemPageChanged(SimpleViewModel toPage) { MvxTrace.TaggedTrace("SimpleListViewModel", "Page changed to {0}", toPage.Name); }
public static void Trace(MvxTraceLevel level, string message, params object[] args) { MvxTrace.Trace(level, message, args); }
private void OnError(SearchServiceError searchServiceError) { MvxTrace.Trace("Sorry - a problem occurred - " + searchServiceError.ToString()); }
public static void Error(string message, params object[] args) { MvxTrace.TaggedTrace(MvxTraceLevel.Error, Tag, message, args); }
public static object ReadValue(string rawValue, Type targetType, string fieldOrParameterName) { if (targetType == typeof(string)) { return(rawValue); } if (targetType == typeof(bool)) { bool boolValue; if (!bool.TryParse(rawValue, out boolValue)) { MvxTrace.Error("Failed to parse boolean parameter {0} from string {1}", fieldOrParameterName, rawValue); } return(boolValue); } if (targetType == typeof(int)) { int intValue; if (!int.TryParse(rawValue, out intValue)) { MvxTrace.Error("Failed to parse int parameter {0} from string {1}", fieldOrParameterName, rawValue); } return(intValue); } if (targetType == typeof(long)) { long longValue; if (!long.TryParse(rawValue, out longValue)) { MvxTrace.Error("Failed to parse long parameter {0} from string {1}", fieldOrParameterName, rawValue); } return(longValue); } if (targetType == typeof(double)) { double doubleValue; if (!double.TryParse(rawValue, out doubleValue)) { MvxTrace.Error("Failed to parse double parameter {0} from string {1}", fieldOrParameterName, rawValue); } return(doubleValue); } if (targetType == typeof(Guid)) { Guid guidValue; if (!Guid.TryParse(rawValue, out guidValue)) { MvxTrace.Error("Failed to parse Guid parameter {0} from string {1}", fieldOrParameterName, rawValue); } return(guidValue); } if (targetType.IsEnum) { object enumValue = null; try { enumValue = Enum.Parse(targetType, rawValue, true); } catch (Exception exception) { MvxTrace.Error("Failed to parse enum parameter {0} from string {1}", fieldOrParameterName, rawValue); } if (enumValue == null) { try { // we set enumValue to 0 here - just have to hope that's the default enumValue = Enum.ToObject(targetType, 0); } catch (Exception) { MvxTrace.Error("Failed to create default enum value for {0} - will return null", fieldOrParameterName); } } return(enumValue); } MvxTrace.Error("Parameter {0} is invalid targetType {1}", fieldOrParameterName, targetType.Name); return(null); }
public static void Warn(string message, params object[] args) { MvxTrace.TaggedTrace(MvxTraceLevel.Warning, Tag, message, args); }
public static void Info(string message, params object[] args) { MvxTrace.TaggedTrace(MvxTraceLevel.Diagnostic, Tag, message, args); }
public virtual bool ClosePlatformViews() { MvxTrace.Trace($"Closing of native Views in Forms is not supported on UWP."); return(false); }
public void ReloadState(ViewModelState searchText) { MvxTrace.Trace("ReloadState called with {0}", searchText.SearchText); SearchText = searchText.SearchText; }
protected virtual void InitializeDebugServices() { MvxTrace.Initialize(); }