public override void ChangePresentation(MvxPresentationHint hint) { if (this.HandlePresentationChange(hint)) { return; } MvxTrace.Warning("Hint ignored {0}", hint.GetType().Name); }
public static async Task <Response <TOutput> > ExecuteGetAsync <TOutput>(string relativeUrl, Dictionary <string, string> parameters) where TOutput : class, new() { var url = relativeUrl; if (string.IsNullOrWhiteSpace(url)) { return(ResponseFactory.CreateResponse <TOutput>(false, 27)); } using (var client = new HttpClient()) { SetupHttpClient(client); try { if (parameters != null && parameters.Count > 0) { var queryString = GenerateQueryString(parameters); if (!string.IsNullOrWhiteSpace(queryString)) { url = $"{url}{queryString}"; } } url = $"{Constants.WEB_API_BASE_ROOT_URL}/api/{url}"; Debug.WriteLine("____________________________________________________"); Debug.WriteLine("Calling endpoint: {0}", url); Debug.WriteLine("____________________________________________________"); var response = await client.GetAsync(url).ConfigureAwait(false); if (response != null && response.IsSuccessStatusCode) { var stringfiedContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); Debug.WriteLine("____________________________________________________"); Debug.WriteLine("Got answer from endpoint {0}: {1}", url, stringfiedContent); Debug.WriteLine("____________________________________________________"); var deserializedData = string.IsNullOrWhiteSpace(stringfiedContent) ? ResponseFactory.CreateResponse <TOutput>(false, 19) : DeserializeResponse <TOutput>(stringfiedContent); return(deserializedData); } } catch (Exception ex) { MvxTrace.Warning(ex.ToString()); } } return(ResponseFactory.CreateResponse <TOutput>(false, 19)); }
public override void HandleDisposeCalled(object sender, EventArgs e) { if (IosView == null) { MvxTrace.Warning($"{nameof(IosView)} is null for clearup of bindings"); return; } IosView.ClearAllBindings(); base.HandleDisposeCalled(sender, e); }
public static IMvxIosView GetIMvxIosView(this UIViewController viewController) { var mvxView = viewController as IMvxIosView; if (mvxView == null) { MvxTrace.Warning($"Could not get IMvxIosView from ViewController {viewController.GetType().Name}"); } return(mvxView); }
public virtual void ChangePresentation(MvxPresentationHint hint) { if (hint is MvxClosePresentationHint) { Close((hint as MvxClosePresentationHint).ViewModelToClose); return; } MvxTrace.Warning("Hint ignored {0}", hint.GetType().Name); }
protected override void HandleCreateCalled(object sender, MvxValueEventArgs <Bundle> bundleArgs) { FragmentView.EnsureSetupInitialized(); if (!FragmentView.GetType().IsOwnedViewModelFragment()) { return; } Bundle bundle = null; MvxViewModelRequest request = null; if (bundleArgs != null && bundleArgs.Value != null) { // saved state bundle = bundleArgs.Value; } else { var fragment = FragmentView as Fragment; if (fragment != null && fragment.Arguments != null) { bundle = fragment.Arguments; var json = bundle.GetString("__mvxViewModelRequest"); if (!string.IsNullOrEmpty(json)) { IMvxNavigationSerializer serializer; if (!Mvx.TryResolve(out serializer)) { MvxTrace.Warning( "Navigation Serializer not available, deserializing ViewModel Request will be hard"); } else { request = serializer.Serializer.DeserializeObject <MvxViewModelRequest>(json); } } } } IMvxSavedStateConverter converter; if (!Mvx.TryResolve(out converter)) { MvxTrace.Warning("Saved state converter not available - saving state will be hard"); } else { if (bundle != null) { var mvxBundle = converter.Read(bundle); FragmentView.OnCreate(mvxBundle, request); } } }
public void Run(Action action) { var dispatcher = MvxMainThreadDispatcher.Instance; if (dispatcher == null) { MvxTrace.Warning("Not able to deliver message - no ui thread dispatcher available"); return; } dispatcher.RequestMainThreadAction(action); }
protected virtual void InitializeNavigationSerializer() { var serializer = CreateNavigationSerializer(); if (serializer == null) { MvxTrace.Warning("No navigation serializer supplied - this application will not be able to navigate between ViewModels using Intents"); return; } Mvx.RegisterSingleton(serializer); }
protected virtual void Show(Intent intent) { var activity = this.Activity; if (activity == null) { MvxTrace.Warning("Cannot Resolve current top activity"); return; } activity.StartActivity(intent); }
public override void HandleDisposeCalled(object sender, EventArgs e) { if (TouchView == null) { MvxTrace.Warning("TouchView is null for clearup of bindings in type {0}", TouchView.GetType().Name); return; } TouchView.ClearAllBindings(); base.HandleDisposeCalled(sender, e); }
public void Publish <TMessage>(TMessage message) where TMessage : MvxMessage { if (typeof(TMessage) == typeof(MvxMessage)) { MvxTrace.Warning( "MvxMessage publishing not allowed - this normally suggests non-specific generic used in calling code - switching to message.GetType()"); Publish(message, message.GetType()); return; } Publish(message, typeof(TMessage)); }
public async Task EnterCodeAsync() { if (string.IsNullOrWhiteSpace(this.CustomerCode)) { //TODO: probably should additionally implement presentation layer required field validation so we don't even get this far. await _userInteraction.AlertAsync("To register this device, submit a customer code"); return; } if (!_reachability.IsConnected()) { await _userInteraction.AlertAsync("To set-up this device, a connection to the internet is required"); } else { bool success = false; ProgressTitle = _progressTitleForCustomerCode; ProgressMessage = _progressMessageForCustomerCode; this.IsBusy = true; try { success = await this.SetupDeviceAsync(); } catch (Exception ex) { MvxTrace.Warning("Exception while setting up device: {0} at {1}", ex.Message, ex.StackTrace); success = false; _errorMessage = _unexpectedErrorMessage; } finally { this.IsBusy = false; } if (success) { ProgressTitle = _progressTitleForCheckIn; ProgressMessage = _progressMessageForCheckIn; IsBusy = true; await _navigationService.MoveToNextAsync(); IsBusy = false; } else { await _userInteraction.AlertAsync(_errorMessage); } } }
private void TryChangeViewPresentation(ChangePresentationHint hint) { var homeView = Activity as IChangePresentation; if (homeView != null) { homeView.ChangePresentation(hint); } else { MvxTrace.Warning("Can't change home view state, keeping last presentation hint"); } }
protected override void EventSourceOnStartActivityForResultCalled(object sender, MvxValueEventArgs <MvxStartActivityForResultParameters> MvxValueEventArgs) { var requestCode = MvxValueEventArgs.Value.RequestCode; switch (requestCode) { case (int)MvxIntentRequestCode.PickFromFile: MvxTrace.Warning("Warning - activity request code may clash with Mvx code for {0}", (MvxIntentRequestCode)requestCode); break; } }
private static void AddToLookup(IDictionary <string, IMvxCommand> lookup, IMvxCommand command, string name) { if (string.IsNullOrEmpty(name)) { return; } if (lookup.ContainsKey(name)) { MvxTrace.Warning("Ignoring Commmand - it would overwrite the existing Command, name {0}", name); return; } lookup[name] = command; }
protected virtual void CollectionChangedOnCollectionChanged( object sender, NotifyCollectionChangedEventArgs args) { switch (args.Action) { case NotifyCollectionChangedAction.Add: foreach (var newItem in args.NewItems) { this.AddTag(this.sourceItemToStringFunc.Invoke((TSourceItem)newItem), newItem); } break; case NotifyCollectionChangedAction.Remove: for (int i = 0; i < args.OldItems.Count; i++) { this.RemoveTag((TSourceItem)args.OldItems[i]); } break; case NotifyCollectionChangedAction.Move: if (args.NewItems.Count != 1 && args.OldItems.Count != 1) { MvxTrace.Warning("MvxTagListView: Move action called with more than one movement!"); break; } this.RemoveTag((TSourceItem)args.OldItems[0]); this.InsertTag(this.sourceItemToStringFunc.Invoke((TSourceItem)args.NewItems[0]), args.NewStartingIndex, (TSourceItem)args.NewItems[0]); break; case NotifyCollectionChangedAction.Replace: if (args.NewItems.Count != args.OldItems.Count) { break; } for (int i = 0; i < args.OldItems.Count; i++) { this.RemoveTag((TSourceItem)args.OldItems[i]); this.InsertTag(this.sourceItemToStringFunc.Invoke((TSourceItem)args.NewItems[i]), args.NewStartingIndex, (TSourceItem)args.NewItems[i]); } break; case NotifyCollectionChangedAction.Reset: this.RearrangeViews(); break; } }
protected override void OnElementChanged(ElementChangedEventArgs <Image> args) { if (args.OldElement != null) { if (_nativeControl != null) { _nativeControl.ImageChanged -= OnSourceImageChanged; _nativeControl.Dispose(); _nativeControl = null; } } if (Control == null && args.NewElement != null) { _nativeControl = new MvxIosImageView() { ContentMode = UIViewContentMode.ScaleAspectFit, ClipsToBounds = true }; _nativeControl.ImageChanged += OnSourceImageChanged; SetNativeControl(_nativeControl); } 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; } } }
public string GetDefinition(Type viewModelType, string key) { var service = Mvx.Resolve <IMvxResourceLoader>(); var path = PathForView(viewModelType.Name, key); try { return(service.GetTextResource(path)); } catch (MvxException) { MvxTrace.Warning("Definition file not loaded {0}", path); return(null); } }
public override void ChangePresentation(MvxPresentationHint hint) { if (HandlePresentationChange(hint)) { return; } if (hint is MvxClosePresentationHint) { this.Close((hint as MvxClosePresentationHint).ViewModelToClose); return; } MvxTrace.Warning("Hint ignored {0}", hint.GetType().Name); }
public override void Close(IMvxViewModel toClose) { // toClose is window if (_frameworkElementsDictionary.Any(i => (i.Key as IMvxWpfView)?.ViewModel == toClose) && CloseWindow(toClose)) { return; } // toClose is content if (_frameworkElementsDictionary.Any(i => i.Value.Any() && (i.Value.Peek() as IMvxWpfView)?.ViewModel == toClose) && CloseContentView(toClose)) { return; } MvxTrace.Warning($"Could not close ViewModel type {toClose.GetType().Name}"); }
private void ShowLocalFile(string filePath) { if (string.IsNullOrEmpty(filePath)) { FireImageChanged(null); } else { var localImage = ImageFromLocalFile(filePath); if (localImage == null) { MvxTrace.Warning("Failed to load local image for filePath {0}", filePath); } FireImageChanged(ImageFromLocalFile(filePath)); } }
public void LoadResources(string whichLocalizationFolder) { foreach (var kvp in ResourceFiles) { try { _textLoader.LoadJsonFromResource(_generalNamespaceKey, kvp.Key, GetResourceFilePath(whichLocalizationFolder, kvp.Value)); } catch (Exception exception) { MvxTrace.Warning("Language file could not be loaded for {0}.{1} - {2}", whichLocalizationFolder, kvp.Key, exception.ToLongString()); } } }
protected static void ExceptionMaskedAction(Action action) { try { action(); } catch (TargetInvocationException exception) { MvxTrace.Trace("TargetInvocateException masked " + exception.InnerException.ToLongString()); } catch (Exception exception) { // note - all exceptions masked! MvxTrace.Warning("Exception masked " + exception.ToLongString()); } }
public void RegisterBindings() { IMvxTargetBindingFactoryRegistry registry; if (!Mvx.TryResolve(out registry)) { MvxTrace.Warning( "No binding registry available - so color bindings will not be used"); return; } registry.RegisterFactory(new MvxCustomBindingFactory <View>("BackgroundColor", view => new MvxViewBackgroundColorBinding(view))); registry.RegisterFactory(new MvxCustomBindingFactory <TextView>("TextColor", textView => new MvxTextViewTextColorBinding(textView))); }
public override void ChangePresentation(MvxPresentationHint hint) { if (HandlePresentationChange(hint)) { return; } var presentationHint = hint as MvxClosePresentationHint; if (presentationHint != null) { Close(presentationHint.ViewModelToClose); return; } MvxTrace.Warning("Hint ignored {0}", hint.GetType().Name); }
protected virtual void RemoveMarkerFor(object item) { try { IMapMarker marker; if (_markers.TryGetValue(item, out marker)) { _markers.Remove(item); _mapView.RemoveMarker(marker); } (marker as ICleanable)?.CleanUp(); } catch (Exception ex) { MvxTrace.Warning("An error occurred while removing marker: {0}", ex); } }
protected override void OnRestoreInstanceState(Bundle savedInstanceState) { IMvxSavedStateConverter converter; if (!Mvx.TryResolve(out converter)) { MvxTrace.Warning("Saved state converter not available - saving state will be hard"); } else { if (savedInstanceState != null) { var mvxBundle = converter.Read(savedInstanceState); this.ViewModel.ReloadState(mvxBundle); } } base.OnRestoreInstanceState(savedInstanceState); }
private static void DoAction(Action action) { try { action(); } catch (ThreadAbortException) { throw; } catch (TargetInvocationException exception) { MvxTrace.Trace("TargetInvocateException masked " + exception.InnerException.ToLongString()); } catch (Exception exception) { // note - all exceptions masked MvxTrace.Warning("Exception masked " + exception.ToLongString()); } }
protected override void EventSourceOnSaveInstanceStateCalled(object sender, MvxValueEventArgs <Bundle> bundleArgs) { var mvxBundle = AndroidView.CreateSaveStateBundle(); if (mvxBundle != null) { IMvxSavedStateConverter converter; if (!Mvx.TryResolve <IMvxSavedStateConverter>(out converter)) { MvxTrace.Warning("Saved state converter not available - saving state will be hard"); } else { converter.Write(bundleArgs.Value, mvxBundle); } } var cache = Mvx.Resolve <IMvxSingleViewModelCache>(); cache.Cache(AndroidView.ViewModel, bundleArgs.Value); }
public override void Close(IMvxViewModel toClose) { if (_currentModalViewController != null) { IMvxIosView mvxTouchView = _currentModalViewController as IMvxIosView; if (mvxTouchView == null) { MvxTrace.Error("Unable to close view - modal is showing but not an IMvxTouchView"); } else if (mvxTouchView.ReflectionGetViewModel() != toClose) { MvxTrace.Error("Unable to close view - modal is showing but is not the requested viewmodel"); } else { // ISSUE: reference to a compiler-generated method _currentModalViewController.DismissViewController(true, () => { }); _currentModalViewController = null; } return; } // We will look across all active navigation stacks to see if we can // pop our MvxView associated with this MvxViewModel (saves explicitly having to specify) bool modelClosed = CloseTopView(toClose, CentrePanelUiNavigationController()); if (!modelClosed) { modelClosed = CloseTopView(toClose, LeftPanelUiNavigationController()); } if (!modelClosed) { modelClosed = CloseTopView(toClose, RightPanelUiNavigationController()); } if (!modelClosed) { MvxTrace.Warning("Don't know how to close this viewmodel - none of topmost views represent this viewmodel"); } }