public virtual void InitializeSecondary() { if (State != MvxSetupState.InitializedPrimary) { throw new MvxException("Cannot start seconday - as state is currently {0}", State); } State = MvxSetupState.InitializingSecondary; MvxTrace.Trace("Setup: FirstChance start"); InitializeFirstChance(); MvxTrace.Trace("Setup: AdditionalPlatformServices start"); InitializeAdditionalPlatformServices(); MvxTrace.Trace("Setup: DebugServices start"); InitializeDebugServices(); MvxTrace.Trace("Setup: Conventions start"); InitializeConventions(); MvxTrace.Trace("Setup: App start"); InitializeApp(); MvxTrace.Trace("Setup: ViewsContainer start"); InitializeViewsContainer(); MvxTrace.Trace("Setup: ViewDispatcherProvider start"); InitiaiseViewDispatcherProvider(); MvxTrace.Trace("Setup: Views start"); InitializeViews(); MvxTrace.Trace("Setup: LastChance start"); InitializeLastChance(); MvxTrace.Trace("Setup: Secondary end"); State = MvxSetupState.Initialized; }
protected override void ProcessMvxIntentResult(MvxIntentResultEventArgs result) { MvxTrace.Trace("ProcessMvxIntentResult started..."); Uri uri; switch ((MvxIntentRequestCode)result.RequestCode) { case MvxIntentRequestCode.PickFromFile: uri = result.Data?.Data; break; case MvxIntentRequestCode.PickFromCamera: uri = _cachedUriLocation; break; default: // ignore this result - it's not for us MvxTrace.Trace("Unexpected request received from MvxIntentResult - request was {0}", result.RequestCode); return; } ProcessPictureUri(result, uri); }
public void TestSimpleCombinerBinding() { var text = "Target CombineThis(Foo, Foo2)"; var expected = new MvxSerializableBindingSpecification() { { "Target", new MvxSerializableBindingDescription() { Function = "CombineThis", Sources = new MvxSerializableBindingDescription[] { new MvxSerializableBindingDescription() { Path = "Foo", }, new MvxSerializableBindingDescription() { Path = "Foo2", }, } } } }; MvxTrace.Trace(MvxTraceLevel.Diagnostic, "Testing: {0}", text); PerformTest(text, expected); }
private void PurgeMessagesOfType(Type type) { lock (this) { Dictionary <Guid, BaseSubscription> messageSubscriptions; if (!_subscriptions.TryGetValue(type, out messageSubscriptions)) { return; } var deadSubscriptionIds = new List <Guid>(); foreach (var subscription in messageSubscriptions) { if (!subscription.Value.IsAlive) { deadSubscriptionIds.Add(subscription.Key); } } MvxTrace.Trace("Purging {0} subscriptions", deadSubscriptionIds.Count); foreach (var id in deadSubscriptionIds) { messageSubscriptions.Remove(id); } PublishSubscriberChangeMessage(type, messageSubscriptions); } }
private static IMvxViewModel LoadViewModel(this IMvxIosView iosView) { if (iosView.Request == null) { MvxTrace.Trace( "Request is null - assuming this is a TabBar type situation where ViewDidLoad is called during construction... patching the request now - but watch out for problems with virtual calls during construction"); iosView.Request = Mvx.Resolve <IMvxCurrentRequest>().CurrentRequest; } var instanceRequest = iosView.Request as MvxViewModelInstanceRequest; if (instanceRequest != null) { return(instanceRequest.ViewModelInstance); } var loader = Mvx.Resolve <IMvxViewModelLoader>(); var viewModel = loader.LoadViewModel(iosView.Request, null /* no saved state on iOS currently */); if (viewModel == null) { throw new MvxException("ViewModel not loaded for " + iosView.Request.ViewModelType); } return(viewModel); }
public void EnsureLoaded() { if (_loaded) { return; } _loaded = true; MvxTrace.Trace("Loading all plugins"); var loaded = new List <Type>(); var failed = new List <Type>(); var manager = Mvx.Resolve <IMvxPluginManager>(); foreach (var type in AllPluginTypes) { if (OptionalLoadPlatformAdaption(manager, type)) { loaded.Add(type); } else { failed.Add(type); } } MvxTrace.Trace("Plugins loaded: {0}", string.Join("\n", loaded.Select(x => x.FullName))); MvxTrace.Trace("Plugins failed: {0}", string.Join("\n", failed.Select(x => x.FullName))); }
private static IMvxViewModel LoadViewModel(this IMvxTouchView touchView) { #warning NullViewModel needed? // how to do N //if (typeof (TViewModel) == typeof (MvxNullViewModel)) // return new MvxNullViewModel() as TViewModel; if (touchView.Request == null) { MvxTrace.Trace( "Request is null - assuming this is a TabBar type situation where ViewDidLoad is called during construction... patching the request now - but watch out for problems with virtual calls during construction"); touchView.Request = Mvx.Resolve <IMvxCurrentRequest>().CurrentRequest; } var instanceRequest = touchView.Request as MvxViewModelInstaceRequest; if (instanceRequest != null) { return(instanceRequest.ViewModelInstance); } var loader = Mvx.Resolve <IMvxViewModelLoader>(); var viewModel = loader.LoadViewModel(touchView.Request, null /* no saved state on iOS currently */); if (viewModel == null) { throw new MvxException("ViewModel not loaded for " + touchView.Request.ViewModelType); } return(viewModel); }
public static Task <bool> RequestPermissionAsync() { var tcs = new TaskCompletionSource <bool>(); EventHandler <CLAuthorizationChangedEventArgs> handler = null; handler = (object sender, CLAuthorizationChangedEventArgs e) => { MvxTrace.Trace("CLAuthorizarion status changed: " + e.Status); if (e.Status == CLAuthorizationStatus.AuthorizedAlways) { _locationManager.AuthorizationChanged -= handler; tcs.TrySetResult(true); } else if (e.Status != CLAuthorizationStatus.NotDetermined) { _locationManager.AuthorizationChanged -= handler; tcs.TrySetResult(false); } }; _locationManager.AuthorizationChanged += handler; _locationManager.RequestAlwaysAuthorization(); return(tcs.Task); }
public virtual async Task <bool> Run() { try { MvxTrace.Trace("Executing {0}", MigrationName); var result = 0; var commands = GetCommands(); foreach (var command in commands) { MvxTrace.Trace("Executing command: '{0}'", command); try { var commandResult = await Connection.ExecuteAsync(command); MvxTrace.Trace("Executed command {0}. Rows affected {1}", command, commandResult); result = result + commandResult; } catch (Exception ex) { await Connection.ExecuteAsync("ROLLBACK;"); MvxTrace.Error("Command execution error: {0}", ex.Message); throw ex; } } MvxTrace.Trace("{0} completed. Rows affected {1}", MigrationName, result); return(result > 0); } catch (Exception ex) { MvxTrace.Error("{0} error: {1}", MigrationName, ex.Message); return(false); } }
internal void OnLocationUpdated(Android.Locations.Location androidLocation) { if (androidLocation == null) { MvxTrace.Trace("Android: Null location seen"); return; } if (androidLocation.Latitude == double.MaxValue || androidLocation.Longitude == double.MaxValue) { MvxTrace.Trace("Android: Invalid location seen"); return; } MvxGeoLocation location; try { location = CreateLocation(androidLocation); } catch (ThreadAbortException) { throw; } catch (Exception exception) { MvxTrace.Trace("Android: Exception seen in converting location " + exception.ToLongString()); return; } SendLocation(location); }
private static IMvxViewModel LoadViewModel(this IMvxElement element) { var viewModelType = element.FindAssociatedViewModelTypeOrNull(); if (viewModelType == typeof(MvxNullViewModel)) { return(new MvxNullViewModel()); } if (viewModelType == null || viewModelType == typeof(IMvxViewModel)) { MvxTrace.Trace("No ViewModel class specified for {0} in LoadViewModel", element.GetType().Name); return(null); } var loader = Mvx.Resolve <IMvxViewModelLoader>(); var viewModel = loader.LoadViewModel(new MvxViewModelRequest(viewModelType), null); if (viewModel == null) { throw new MvxException("ViewModel not loaded for " + viewModelType); } return(viewModel); }
private void OnMvxIntentResultReceived(object sender, MvxIntentResultEventArgs e) { MvxTrace.Trace("OnMvxIntentResultReceived in MvxAndroidTask"); // TODO - is this correct - should we always remove the result registration even if this isn't necessarily our result? Mvx.Resolve <IMvxIntentResultSource>().Result -= this.OnMvxIntentResultReceived; this.ProcessMvxIntentResult(e); }
protected override async Task <bool> TryReadFileCommonAsync(string path, Func <Stream, Task <bool> > streamAction) { try { using (var isf = IsolatedStorageFile.GetUserStoreForApplication()) { if (!isf.FileExists(path)) { return(false); } using (var fileStream = isf.OpenFile(path, FileMode.Open)) { return(await streamAction(fileStream).ConfigureAwait(false)); } } } catch (ThreadAbortException) { throw; } catch (Exception exception) { MvxTrace.Trace("Error during file load {0} : {1}", path, exception.ToLongString()); return(false); } }
public SavedState SaveState() { MvxTrace.Trace("SaveState called"); return(new SavedState { PlayerId = _playerId }); }
public void TestCommandParameterSpecialBinding() { var text = "Target CommandParameter(One, Two)"; var expected = new MvxSerializableBindingSpecification() { { "Target", new MvxSerializableBindingDescription() { Function = "CommandParameter", Sources = new MvxSerializableBindingDescription[] { new MvxSerializableBindingDescription() { Path = "One" }, new MvxSerializableBindingDescription() { Path = "Two" }, }, } } }; MvxTrace.Trace(MvxTraceLevel.Diagnostic, "Testing: {0}", text); PerformTest(text, expected); }
public override bool Exists(string path) { try { // this implementation is based on code from https://github.com/MvvmCross/MvvmCross/issues/521 path = ToFullPath(path); var fileName = Path.GetFileName(path); var directoryPath = Path.GetDirectoryName(path); if (!FolderExists(directoryPath)) { return(false); } var directory = StorageFolder.GetFolderFromPathAsync(directoryPath).Await(); directory.GetFileAsync(fileName).Await(); return(true); } catch (FileNotFoundException) { return(false); } catch (Exception ex) { MvxTrace.Trace("Exception seen in Exists - seen for path: {0} - {1}", path, ex.ToLongString()); throw; } }
public void TestFunctionalValueConverterWithNullInTheName() { var text = "Target NullThis(Foo, 'Hello World')"; var expected = new MvxSerializableBindingSpecification() { { "Target", new MvxSerializableBindingDescription() { Converter = "NullThis", Function = "Single", Sources = new MvxSerializableBindingDescription[] { new MvxSerializableBindingDescription() { Path = "Foo", }, }, ConverterParameter = "Hello World" } } }; MvxTrace.Trace(MvxTraceLevel.Diagnostic, "Testing: {0}", text); PerformTest(text, expected); }
public override bool FolderExists(string folderPath) { // contributed by @AlexMortola via Stackoverflow creative commons // http://stackoverflow.com/questions/19890756/mvvmcross-notimplementedexception-calling-ensurefolderexists-method-of-imvxfile try { folderPath = ToFullPath(folderPath); folderPath = folderPath.TrimEnd('\\'); var thisFolder = StorageFolder.GetFolderFromPathAsync(folderPath).Await(); return(true); } catch (System.UnauthorizedAccessException) { return(false); } catch (FileNotFoundException) { return(false); } catch (Exception ex) { MvxTrace.Trace("Exception in FolderExists - folderPath: {0} - {1}", folderPath, ex.ToLongString()); throw; } }
public virtual void EnsurePluginLoaded(Type type) { var field = type.GetField("Instance", BindingFlags.Static | BindingFlags.Public); if (field == null) { MvxTrace.Trace("Plugin Instance not found - will not autoload {0}", type.FullName); return; } var instance = field.GetValue(null); if (instance == null) { MvxTrace.Trace("Plugin Instance was empty - will not autoload {0}", type.FullName); return; } var pluginLoader = instance as IMvxPluginLoader; if (pluginLoader == null) { MvxTrace.Trace("Plugin Instance was not a loader - will not autoload {0}", type.FullName); return; } this.EnsurePluginLoaded(pluginLoader); }
protected override async Task WriteFileCommonAsync(string path, Func <Stream, Task> streamAction) { // from https://github.com/MvvmCross/MvvmCross/issues/500 we delete any existing file // before writing the new one await SafeDeleteFileAsync(path); try { var storageFile = await CreateStorageFileFromRelativePathAsync(path).ConfigureAwait(false); using (var streamWithContentType = await storageFile.OpenAsync(FileAccessMode.ReadWrite).AsTask().ConfigureAwait(false)) { using (var stream = streamWithContentType.AsStreamForWrite()) { await streamAction(stream).ConfigureAwait(false); } } } catch (Exception exception) { MvxTrace.Trace("Error during file save {0} : {1}", path, exception.ToLongString()); throw; } }
public virtual void InitializePrimary() { if (this.State != MvxSetupState.Uninitialized) { throw new MvxException("Cannot start primary - as state already {0}", this.State); } this.State = MvxSetupState.InitializingPrimary; MvxTrace.Trace("Setup: Primary start"); this.InitializeIoC(); this.State = MvxSetupState.InitializedPrimary; if (this.State != MvxSetupState.InitializedPrimary) { throw new MvxException("Cannot start seconday - as state is currently {0}", this.State); } this.State = MvxSetupState.InitializingSecondary; MvxTrace.Trace("Setup: FirstChance start"); this.InitializeFirstChance(); MvxTrace.Trace("Setup: DebugServices start"); this.InitializeDebugServices(); MvxTrace.Trace("Setup: PlatformServices start"); this.InitializePlatformServices(); MvxTrace.Trace("Setup: MvvmCross settings start"); this.InitializeSettings(); MvxTrace.Trace("Setup: Singleton Cache start"); this.InitializeSingletonCache(); }
public override bool TryMove(string from, string to, bool overwrite) { try { var fromFile = StorageFileFromRelativePath(from); if (overwrite) { 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); } }
public SavedState SaveState() { MvxTrace.Trace("SaveState called"); return(new SavedState { JourneyId = _journeyId }); }
public override bool TryCopy(string @from, string to, bool overwrite) { try { var fromFile = StorageFileFromRelativePath(from); var fullToPath = ToFullPath(to); var toDirectory = Path.GetDirectoryName(fullToPath); var toFileName = Path.GetFileName(fullToPath); if (overwrite) { var toFile = StorageFileFromRelativePath(to); fromFile.CopyAndReplaceAsync(toFile).Await(); } else { var toStorageFolder = StorageFolder.GetFolderFromPathAsync(toDirectory).Await(); fromFile.CopyAsync(toStorageFolder, toFileName).Await(); } return(true); } catch (Exception exception) { MvxTrace.Trace("Exception during file copy from {0} to {1} - {2}", from, to, exception.ToLongString()); return(false); } }
private static IMvxViewModel LoadViewModel(this IMvxFragmentView fragmentView, IMvxBundle savedState, MvxViewModelRequest request = null) { var viewModelType = fragmentView.FindAssociatedViewModelType(); 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 loaderService = Mvx.Resolve <IMvxViewModelLoader>(); var viewModel = loaderService.LoadViewModel(request, savedState); return(viewModel); }
public virtual MvxBasePresentationAttribute CreatePresentationAttribute(Type viewModelType, Type viewType) { if (viewType.IsSubclassOf(typeof(DialogFragment))) { MvxTrace.Trace("PresentationAttribute not found for {0}. Assuming DialogFragment presentation", viewType.Name); return(new MvxDialogFragmentPresentationAttribute() { ViewType = viewType, ViewModelType = viewModelType }); } else if (viewType.IsSubclassOf(typeof(Fragment))) { MvxTrace.Trace("PresentationAttribute not found for {0}. Assuming Fragment presentation", viewType.Name); return(new MvxFragmentPresentationAttribute(GetCurrentActivityViewModelType(), Android.Resource.Id.Content) { ViewType = viewType, ViewModelType = viewModelType }); } else if (viewType.IsSubclassOf(typeof(Activity))) { MvxTrace.Trace("PresentationAttribute not found for {0}. Assuming Activity presentation", viewType.Name); return(new MvxActivityPresentationAttribute() { ViewType = viewType, ViewModelType = viewModelType }); } return(null); }
private Bitmap LoadScaledBitmap(Uri uri) { ContentResolver contentResolver = Mvx.Resolve <IMvxAndroidGlobals>().ApplicationContext.ContentResolver; var maxDimensionSize = GetMaximumDimension(contentResolver, uri); var sampleSize = (int)Math.Ceiling(maxDimensionSize / (double)_currentRequestParameters.MaxPixelDimension); if (sampleSize < 1) { // this shouldn't happen, but if it does... then trace the error and set sampleSize to 1 MvxTrace.Trace( "Warning - sampleSize of {0} was requested - how did this happen - based on requested {1} and returned image size {2}", sampleSize, _currentRequestParameters.MaxPixelDimension, maxDimensionSize); // following from https://github.com/MvvmCross/MvvmCross/issues/565 we return null in this case // - it suggests that Android has returned a corrupt image uri return(null); } var sampled = LoadResampledBitmap(contentResolver, uri, sampleSize); try { var rotated = ExifRotateBitmap(contentResolver, uri, sampled); return(rotated); } catch (Exception pokemon) { Mvx.Trace("Problem seem in Exit Rotate {0}", pokemon.ToLongString()); return(sampled); } }
public void TestFunctionalValueConverterWithKEYWORDInTheName(string keyword) { var text = "Target " + keyword + "This(Foo, 'Hello World')"; var expected = new MvxSerializableBindingSpecification() { { "Target", new MvxSerializableBindingDescription() { Function = keyword + "This", Sources = new MvxSerializableBindingDescription[] { new MvxSerializableBindingDescription() { Path = "Foo", }, new MvxSerializableBindingDescription() { Literal = "Hello World", }, }, } } }; MvxTrace.Trace(MvxTraceLevel.Diagnostic, "Testing: {0}", text); PerformTest(text, expected); }
public void TestFunctionalValueConverterWithParameterBinding() { var text = "Target ConvertThis(Foo, 12)"; var expected = new MvxSerializableBindingSpecification() { { "Target", new MvxSerializableBindingDescription() { Function = "ConvertThis", Sources = new MvxSerializableBindingDescription[] { new MvxSerializableBindingDescription() { Path = "Foo", }, new MvxSerializableBindingDescription() { Literal = 12, }, }, } } }; MvxTrace.Trace(MvxTraceLevel.Diagnostic, "Testing: {0}", text); PerformTest(text, expected); }
private static bool TryReadFileCommon(string path, Func <Stream, bool> streamAction) { try { using (var isf = IsolatedStorageFile.GetUserStoreForApplication()) { if (!isf.FileExists(path)) { return(false); } using (var fileStream = isf.OpenFile(path, FileMode.Open)) { return(streamAction(fileStream)); } } } catch (ThreadAbortException) { throw; } catch (Exception exception) { MvxTrace.Trace("Error during file load {0} : {1}", path, exception.ToLongString()); return(false); } }