public override void Show(MvxViewModelRequest request)
        {
			if (TryShowPage(request))
                return;

            Mvx.Error("Skipping request for {0}", request.ViewModelType.Name);
        }
        public static IMvxItemUniqueIdProvider BuildUniqueItemIdProvider(Context context, IAttributeSet attrs)
        {
            var templateSelectorAttributes = ReadRecyclerViewItemTemplateSelectorAttributes(context, attrs);
            var type = Type.GetType(templateSelectorAttributes.UniqueItemIdProviderClassName);

            if (type == null)
            {
                var message = $"Can't build unique item id provider." +
                              $"Sorry but type with class name: {templateSelectorAttributes.UniqueItemIdProviderClassName} does not exist." +
                              $"Make sure you have provided full Type name: namespace + class name, AssemblyName." +
                              $"Example (check Example.Droid sample!): Example.Droid.Common.TemplateSelectors.MultiItemTemplateModelTemplateSelector, Example.Droid";
                Mvx.Error(message);
                throw new InvalidOperationException(message);
            }

            if (!typeof(IMvxItemUniqueIdProvider).IsAssignableFrom(type))
            {
                string message = $"Sorry but type: {type} does not implement {nameof(IMvxItemUniqueIdProvider)} interface.";
                Mvx.Error(message);
                throw new InvalidOperationException(message);
            }

            if (type.IsAbstract)
            {
                string message = $"Sorry can not instatiate {nameof(IMvxItemUniqueIdProvider)} as provided type: {type} is abstract/interface.";
                Mvx.Error(message);
                throw new InvalidOperationException(message);
            }

            var uniqueItemIdProvider = Activator.CreateInstance(type) as IMvxItemUniqueIdProvider;

            return(uniqueItemIdProvider);
        }
Пример #3
0
        private async Task <bool> TryShowPage(MvxViewModelRequest request)
        {
            var page = MvxPresenterHelpers.CreatePage(request);

            if (page == null)
            {
                return(false);
            }

            var viewModel = MvxPresenterHelpers.LoadViewModel(request);

            var mainPage = _mvxFormsApp.MainPage as NavigationPage;

            if (mainPage == null)
            {
                _mvxFormsApp.MainPage = new NavigationPage(page);
                mainPage = _mvxFormsApp.MainPage as NavigationPage;
                CustomPlatformInitialization(mainPage);
            }
            else
            {
                try
                {
                    await mainPage.PushAsync(page);
                }
                catch (Exception e)
                {
                    Mvx.Error("Exception pushing {0}: {1}\n{2}", page.GetType(), e.Message, e.StackTrace);
                }
            }

            page.BindingContext = viewModel;
            return(true);
        }
Пример #4
0
        private async void DoScan()
        {
            try
            {
                ClearDisplay();
                IsScanning  = true;
                HasTimedOut = false;

                _cancellationTokenSource = new CancellationTokenSource();

                var record = await _nfcReadTask.ReadTag(_cancellationTokenSource.Token, TimeSpan.FromSeconds(30));

                if (record != null)
                {
                    UpdateDisplay(record.Message);
                }
                _cancellationTokenSource = null;
            }
            catch (TimeoutException)
            {
                HasTimedOut = true;
            }
            catch (Exception err)
            {
                Mvx.Error(err.ToString());
            }
            IsScanning = false;
        }
        private bool TryShowPage(MvxViewModelRequest request)
        {
            var page = MvxPresenterHelpers.CreatePage(request);
            if (page == null)
                return false;

            var viewModel = MvxPresenterHelpers.LoadViewModel(request);

            SetupForBinding(page, request);

            var mainPage = _mvxFormsApp.MainPage as NavigationPage;

            if (mainPage == null)
            {
                _mvxFormsApp.MainPage = new NavigationPage(page);
                mainPage = MvxFormsApp.MainPage as NavigationPage;
                CustomPlatformInitialization(mainPage);
            }
            else
            {
                try
                {
					// calling this sync blocks UI and never navigates hence code continues regardless here
					mainPage.PushAsync(page);
                }
                catch (Exception e)
                {
                    Mvx.Error("Exception pushing {0}: {1}\n{2}", page.GetType(), e.Message, e.StackTrace);
                    return false;
                }
            }

            return true;
        }
Пример #6
0
        private async Task LoadData()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                var lst = await HttpService.GetArduinoStationList();

                if (lst != null)
                {
                    _arduinoStations = new ObservableCollection <ArduinoStation>(lst);
                }
                else
                {
                    _arduinoStations = new ObservableCollection <ArduinoStation>();
                }
            }
            catch (Exception ex)
            {
                Mvx.Error(ex.Message);
                return;
            }
            finally
            {
                IsBusy = false;
            }
            RaiseAllPropertiesChanged();
        }
Пример #7
0
        private async Task SaveDataAsync()
        {
            Device.BeginInvokeOnMainThread(() => IsBusy = true);
            Exception myEx = null;

            try
            {
                await Task.Delay(300);
            }
            catch (Exception ex)
            {
                myEx = ex;
                Mvx.Error(ex.Message);
            }
            finally
            {
                Device.BeginInvokeOnMainThread(() => IsBusy = false);
            }

            if (myEx != null)
            {
                var p = new ContentPage();
                await p.DisplayAlert("Σφάλμα κατά την αποθήκευση", myEx.Message, "ΟΚ");
            }
        }
Пример #8
0
        // Workaround from Support.v4 v22.1.1 library:
        //
        // For APIs >= 11 && < 21, there was a framework bug that prevented a LayoutInflater's
        // Factory2 from being merged properly if set after a cloneInContext from a LayoutInflater
        // that already had a Factory2 registered. We work around that bug here. If we can't we
        // log an error.
        private static void ForceSetFactory2(LayoutInflater inflater, LayoutInflater.IFactory2 factory)
        {
            if (!_checkedField)
            {
                try
                {
                    Class layoutInflaterClass = Class.FromType(typeof(LayoutInflater));
                    _layoutInflaterFactory2Field            = layoutInflaterClass.GetDeclaredField("mFactory2");
                    _layoutInflaterFactory2Field.Accessible = true;
                }
                catch (NoSuchFieldException e)
                {
                    Mvx.Error(
                        "ForceSetFactory2 Could not find field 'mFactory2' on class {0}; inflation may have unexpected results.",
                        Class.FromType(typeof(LayoutInflater)).Name);
                }
                _checkedField = true;
            }

            if (_layoutInflaterFactory2Field != null)
            {
                try
                {
                    _layoutInflaterFactory2Field.Set(inflater, (Java.Lang.Object)factory);
                }
                catch (IllegalAccessException e)
                {
                    Mvx.Error("ForceSetFactory2 could not set the Factory2 on LayoutInflater {0} ; inflation may have unexpected results.", inflater);
                }
            }
        }
Пример #9
0
        public static IMvxGroupedDataConverter BuildMvxGroupedDataConverter(Context context, IAttributeSet attrs)
        {
            var groupedDataConverterClassName = ReadRecyclerViewItemTemplateSelectorAttributes(context, attrs).GroupedDataConverterClassName;
            var type = Type.GetType(groupedDataConverterClassName);

            if (type == null)
            {
                var message = $"Sorry but type with class name: {groupedDataConverterClassName} does not exist." +
                              $"Make sure you have provided full Type name: namespace + class name, AssemblyName.";
                Mvx.Error(message);
                throw new InvalidOperationException(message);
            }

            if (!typeof(IMvxGroupedDataConverter).IsAssignableFrom(type))
            {
                string message = $"Sorry but type: {type} does not implement {nameof(IMvxGroupedDataConverter)} interface.";
                Mvx.Error(message);
                throw new InvalidOperationException(message);
            }

            if (type.IsAbstract)
            {
                string message = $"Sorry can not instatiate {nameof(IMvxGroupedDataConverter)} as provided type: {type} is abstract/interface.";
                Mvx.Error(message);
                throw new InvalidOperationException(message);
            }

            return(Activator.CreateInstance(type) as IMvxGroupedDataConverter);
        }
        public async Task LeaveRoom(string name)
        {
            try { await Client.LeaveRoom(name); }
            catch (Exception ex) { Mvx.Error(ex.ToString()); }

            RoomsIn.RemoveAll(r => r.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
        }
Пример #11
0
        public override void LoadFromStore(VMStore modelStore)
        {
            try
            {
                Profile               = JsonConvert.DeserializeObject <ClientProfileDTO>(modelStore.Store);
                Downloaded            = Profile.Downloaded;
                ClientId              = Profile.ClientId;
                SelectedMaritalStatus = MaritalStatus.FirstOrDefault(x => x.Id == Profile.MaritalStatus);
                SelectedKeyPop        = KeyPops.FirstOrDefault(x => x.Id == Profile.KeyPop);
                OtherKeyPop           = Profile.OtherKeyPop;
                SelectedEducation     = Educations.FirstOrDefault(x => x.ItemId == Profile.Education);
                SelectedCompletion    = Completions.FirstOrDefault(x => x.ItemId == Profile.Completion);
                SelectedOccupation    = Occupations.FirstOrDefault(x => x.ItemId == Profile.Occupation);

                if (null != Profile.RelTypeId && !string.IsNullOrWhiteSpace(Profile.RelTypeId))
                {
                    SelectedRelationshipType =
                        RelationshipTypes.FirstOrDefault(x => x.Description.ToLower() == Profile.RelTypeId.ToLower());
                }
            }
            catch (Exception e)
            {
                Mvx.Error(e.Message);
            }
        }
Пример #12
0
        protected virtual IEnumerable <PropertyInfo> FindInjectableProperties(Type type, IMvxPropertyInjectorOptions options)
        {
            var injectableProperties = type
                                       .GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy)
                                       .Where(p => p.PropertyType.GetTypeInfo().IsInterface)
                                       .Where(p => p.IsConventional())
                                       .Where(p => p.CanWrite);

            switch (options.InjectIntoProperties)
            {
            case MvxPropertyInjection.MvxInjectInterfaceProperties:
                injectableProperties = injectableProperties
                                       .Where(p => p.GetCustomAttributes(typeof(MvxInjectAttribute), false).Any());
                break;

            case MvxPropertyInjection.AllInterfaceProperties:
                break;

            case MvxPropertyInjection.None:
                Mvx.Error("Internal error - should not call FindInjectableProperties with MvxPropertyInjection.None");
                injectableProperties = new PropertyInfo[0];
                break;

            default:
                throw new MvxException("unknown option for InjectIntoProperties {0}", options.InjectIntoProperties);
            }
            return(injectableProperties);
        }
Пример #13
0
        public static MvxBaseTemplateSelector BuildItemTemplateSelector(Context context, IAttributeSet attrs)
        {
            var templateSelectorAttributes = ReadRecyclerViewItemTemplateSelectorAttributes(context, attrs);
            var type = Type.GetType(templateSelectorAttributes.TemplateSelectorClassName);

            if (type == null)
            {
                var message = $"Sorry but type with class name: {templateSelectorAttributes} does not exist." +
                              $"Make sure you have provided full Type name: namespace + class name, AssemblyName." +
                              $"Example (check Example.Droid sample!): Example.Droid.Common.TemplateSelectors.MultiItemTemplateModelTemplateSelector, Example.Droid";
                Mvx.Error(message);
                throw new InvalidOperationException(message);
            }

            if (!typeof(MvxBaseTemplateSelector).IsAssignableFrom(type))
            {
                string message = $"Sorry but type: {type} does not implement {nameof(MvxBaseTemplateSelector)} interface.";
                Mvx.Error(message);
                throw new InvalidOperationException(message);
            }

            if (type.IsAbstract)
            {
                string message = $"Sorry can not instatiate {nameof(MvxBaseTemplateSelector)} as provided type: {type} is abstract/interface.";
                Mvx.Error(message);
                throw new InvalidOperationException(message);
            }

            var templateSelector = Activator.CreateInstance(type) as MvxBaseTemplateSelector;

            templateSelector.FooterLayoutId       = templateSelectorAttributes.FooterLayoutId;
            templateSelector.HeaderLayoutId       = templateSelectorAttributes.HeaderLayoutId;
            templateSelector.GroupSectionLayoutId = templateSelectorAttributes.GroupSectionLayoutId;
            return(templateSelector);
        }
        private async Task ShowLocalFileAsync(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                FireImageChanged(null);
            }
            else
            {
                FireImageChanged(null);

                try
                {
                    var localImage = await ImageFromLocalFileAsync(filePath).ConfigureAwait(false);

                    if (localImage == null)
                    {
                        MvxTrace.Warning("Failed to load local image for filePath {0}", filePath);
                    }

                    FireImageChanged(localImage);
                }
                catch (Exception ex)
                {
                    Mvx.Error(ex.Message);
                }
            }
        }
Пример #15
0
        public override void Show(MvxViewModelRequest request)
        {
            var viewModelType     = request.ViewModelType;
            var isMasterViewModel = viewModelType.GetCustomAttribute <MasterPageViewModelAttribute>() != null;
            var isPageViewModel   = viewModelType.GetCustomAttribute <PageViewModelAttribute>() != null;

            if (isPageViewModel)
            {
                if (TryShowPage(request))
                {
                    return;
                }

                Mvx.Error("Skipping request for {0}", request.ViewModelType.Name);
            }
            else if (isMasterViewModel)
            {
                if (TryShowMasterDetailPage(request))
                {
                    return;
                }

                Mvx.Error("Skipping request for {0}", request.ViewModelType.Name);
            }
            else
            {
                throw new Exception("VM not page or master detail ");
            }
        }
Пример #16
0
 private void InitCancellationTokenSource()
 {
     if (this._cts != null)
     {
         Mvx.Error("MvxAsyncCommand : Unexpected InitCancellationTokenSource, a token is already available!");
     }
     this._cts = new CancellationTokenSource();
 }
Пример #17
0
        /// <summary>
        /// Handle a lost connectivity against the API.
        /// </summary>
        /// <typeparam name="TResp">The type of the response.</typeparam>
        /// <param name="httpType">Type of the HTTP.</param>
        /// <param name="endpoint">Name of the host.</param>
        /// <param name="action">The action of the request.</param>
        /// <param name="exception">The exception.</param>
        /// <param name="statusCode"></param>
        /// <returns>BaseResp with a null result.</returns>
        internal BaseResponse <TResp> HandleLostConnnectivity <TResp>(string httpType, Endpoint endpoint, Exception exception, HttpStatusCode statusCode)
            where TResp : class
        {
            Mvx.Error("No Connectivity on device [" + httpType + " : URL: " + endpoint.Url + "] Message: {0} >>>>> StackTrace: {1}", exception?.Message, exception.StackTrace);

            //_eventLogger.TrackEvent(Constants.NONETWORK_EVENT_NAME, endpoint.UrlAction, $"{(statusCode == HttpStatusCode.BadRequest ? "n/a" : statusCode.ToString())} || {exception?.Message}");

            return(HandleApiCalls <TResp>(API_ERROR_NONETWORK, null, ServiceReponseType.NoNetwork, statusCode, exception.Message));
        }
Пример #18
0
        public async Task <List <Post> > GetPosts()
        {
            var json = await _httpclient.GetStringAsync("Api");

            Mvx.Error(_httpclient.BaseAddress.ToString());
            var posts = JsonConvert.DeserializeObject <List <Post> >(json);

            return(posts);
        }
Пример #19
0
        /// <summary>
        /// Handle a crash against the API.
        /// </summary>
        /// <typeparam name="TResp">The type of the response.</typeparam>
        /// <param name="httpType">Type of the HTTP.</param>
        /// <param name="endpoint">Name of the host.</param>
        /// <param name="action">The action of the request.</param>
        /// <param name="exception">The exception.</param>
        /// <param name="statusCode"></param>
        /// <returns>BaseResp with a null result.</returns>
        internal BaseResponse <TResp> HandleCrash <TResp>(string httpType, Endpoint endpoint, Exception exception, HttpStatusCode statusCode)
            where TResp : class
        {
            Mvx.Error("CRASH on Service [" + httpType + " : URL: " + endpoint.Url + "] Message: {0} >>>>> StackTrace: {1}", exception.Message, exception.StackTrace);

            //_eventLogger.TrackEvent(Constants.CRASH_EVENT_NAME, endpoint.UrlAction, $"{(statusCode == HttpStatusCode.BadRequest ? "n/a" : statusCode.ToString())} || {exception?.Message}");

            return(HandleApiCalls <TResp>(API_ERROR_CRASH, null, ServiceReponseType.Error, statusCode, exception.Message));
        }
Пример #20
0
        /// <summary>
        /// Handle the timeout on the API.
        /// </summary>
        /// <typeparam name="TResp">The type of the response.</typeparam>
        /// <param name="httpType">Type of the HTTP.</param>
        /// <param name="endpoint">Name of the host.</param>
        /// <param name="action">The action of the request..</param>
        /// <param name="exception">The exception.</param>
        /// <param name="statusCode"></param>
        /// <param name="suffix">[Optional] add a suffix to the logger.</param>
        /// <returns>BaseResp with a null result.</returns>
        internal BaseResponse <TResp> HandleTimeout <TResp>(string httpType, Endpoint endpoint, Exception exception, HttpStatusCode statusCode, string suffix = "")
            where TResp : class
        {
            Mvx.Error("TIMEOUT on Service [" + httpType + " : URL: " + endpoint.Url + "] {0}{1}", exception.Message, suffix);

            //_eventLogger.TrackEvent(Constants.TIMEOUT_EVENT_NAME, endpoint.UrlAction, $"{statusCode.ToString()} || {exception?.Message}{ suffix }");

            return(HandleApiCalls <TResp>(API_ERROR_TIMEOUT, null, ServiceReponseType.Timeout, statusCode, exception.Message));
        }
Пример #21
0
        /// <summary>
        /// Handle the error flow.
        /// </summary>
        /// <typeparam name="TResp">The type of the response.</typeparam>
        /// <param name="httpType">Type of the HTTP.</param>
        /// <param name="endpoint">The URL.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <param name="errorMessageException">The error message exception.</param>
        /// <param name="statusCode"></param>
        /// <returns>BaseResp with a null result.</returns>
        internal BaseResponse <TResp> HandleError <TResp>(string httpType, Endpoint endpoint, string errorMessage, string errorMessageException, HttpStatusCode statusCode)
            where TResp : class
        {
            Mvx.Error("ERROR on Service [" + httpType + " : " + endpoint.Url + "] Message : {0} >>>>> Exception: {1}", errorMessage, errorMessageException);

            //_eventLogger.TrackEvent(Constants.ERROR_EVENT_NAME, endpoint.UrlAction, $"{statusCode.ToString()} || {errorMessage}");

            return(HandleApiCalls <TResp>(errorMessage, null, ServiceReponseType.Error, statusCode, errorMessageException));
        }
Пример #22
0
        public virtual async void Show(MvxViewModelRequest request)
        {
            if (await TryShowPage(request))
            {
                return;
            }

            Mvx.Error("Skipping request for {0}", request.ViewModelType.Name);
        }
Пример #23
0
        public override async void Show(MvxViewModelRequest request)
        {
            if (await AdaptiveTryShowPage(request))
            {
                return;
            }

            Mvx.Error("Skipping request for {0}", request.ViewModelType.Name);
        }
        public async Task JoinRoom(Room room)
        {
            try { await Client.JoinRoom(room.Name); }
            catch (Exception ex) { Mvx.Error(ex.ToString()); }

            if (!RoomsIn.Exists(r => r.Name.Equals(room.Name, StringComparison.OrdinalIgnoreCase)))
            {
                RoomsIn.Add(room);
            }
        }
        public static IMvxTemplateSelector BuildItemTemplateSelector(Context context, IAttributeSet attrs)
        {
            var templateSelectorAttributes = ReadRecyclerViewItemTemplateSelectorAttributes(context, attrs);
            var type = Type.GetType(templateSelectorAttributes.TemplateSelectorClassName);

            if (type == null && templateSelectorAttributes.ItemTemplateLayoutId == 0)
            {
                var message = $"Cant create template selector." +
                              $"Sorry but type with class name: {templateSelectorAttributes.TemplateSelectorClassName} does not exist." +
                              $"Make sure you have provided full Type name: namespace + class name, AssemblyName." +
                              $"Example (check Example.Droid sample!): Example.Droid.Common.TemplateSelectors.MultiItemTemplateModelTemplateSelector, Example.Droid";
                Mvx.Error(message);
                throw new InvalidOperationException(message);
            }

            if (type != null && !typeof(IMvxTemplateSelector).IsAssignableFrom(type))
            {
                string message = $"Sorry but type: {type} does not implement {nameof(IMvxTemplateSelector)} interface.";
                Mvx.Error(message);
                throw new InvalidOperationException(message);
            }

            if (type?.IsAbstract ?? false)
            {
                string message = $"Sorry can not instatiate {nameof(IMvxTemplateSelector)} as provided type: {type} is abstract/interface.";
                Mvx.Error(message);
                throw new InvalidOperationException(message);
            }

            IMvxTemplateSelector templateSelector = null;

            if (type != null)
            {
                templateSelector = Activator.CreateInstance(type) as IMvxTemplateSelector;
            }
            else
            {
                templateSelector = new MvxDefaultHeaderFooterTemplateSelector(templateSelectorAttributes.ItemTemplateLayoutId);
            }

            var headerTemplate = templateSelector as IMvxHeaderTemplate;
            var footerTemplate = templateSelector as IMvxFooterTemplate;

            if (headerTemplate != null)
            {
                headerTemplate.HeaderLayoutId = templateSelectorAttributes.HeaderLayoutId;
            }

            if (footerTemplate != null)
            {
                footerTemplate.FooterLayoutId = templateSelectorAttributes.FooterLayoutId;
            }

            return(templateSelector);
        }
Пример #26
0
 public WriteTask()
 {
     try
     {
         _proximityDevice = ProximityDevice.GetDefault();
     }
     catch (System.UnauthorizedAccessException)
     {
         //You don't have permission to read NFC
         Mvx.Error("You don't have permission to read NFC. Please update your manifest file");
     }
 }
Пример #27
0
 public object GetResponse()
 {
     try
     {
         return(ReadResponse());
     }
     catch (Exception e)
     {
         Mvx.Error(e.Message);
         return(null);
     }
 }
Пример #28
0
 private void DoScan()
 {
     try
     {
         IsScanning = true;
         _watcher.Start();
     }
     catch (Exception err)
     {
         Mvx.Error(err.ToString());
     }
 }
Пример #29
0
 private void ClearCancellationTokenSource()
 {
     if (this._cts == null)
     {
         Mvx.Error("MvxAsyncCommand : Unexpected ClearCancellationTokenSource, no token available!");
     }
     else
     {
         this._cts.Dispose();
         this._cts = null;
     }
 }
Пример #30
0
        public override bool TryGetValue(IEnumerable <IMvxSourceStep> steps, out object value)
        {
            var resultPairs = steps.Select(step => step.GetValue()).ToList();

            while (resultPairs.Count > 1)
            {
                var first  = resultPairs[0];
                var second = resultPairs[1];

                if (first == MvxBindingConstant.DoNothing ||
                    second == MvxBindingConstant.DoNothing)
                {
                    value = MvxBindingConstant.DoNothing;
                    return(true);
                }

                if (first == MvxBindingConstant.UnsetValue ||
                    second == MvxBindingConstant.UnsetValue)
                {
                    value = MvxBindingConstant.UnsetValue;
                    return(true);
                }

                first  = this.ForceToSimpleValueTypes(first);
                second = this.ForceToSimpleValueTypes(second);

                var firstType  = this.GetLookupTypeFor(first);
                var secondType = this.GetLookupTypeFor(second);

                CombinerFunc <object, object> combinerFunc;
                if (!this._combinerActions.TryGetValue(new TypeTuple(firstType, secondType), out combinerFunc))
                {
                    Mvx.Error("Unknown type pair in Pairwise combiner {0}, {1}", firstType, secondType);
                    value = MvxBindingConstant.UnsetValue;
                    return(true);
                }

                object newValue;
                var    newIsAvailable = combinerFunc(first, second, out newValue);
                if (!newIsAvailable)
                {
                    value = MvxBindingConstant.UnsetValue;
                    return(true);
                }

                resultPairs.RemoveAt(0);
                resultPairs[0] = newValue;
            }

            value = resultPairs[0];
            return(true);
        }