Ejemplo n.º 1
0
            public HalHtmlResponse(IHal hal, Optional <object> resource)
            {
                _resource = resource.HasValue ? resource.Value : EmptyBody;
                _hal      = hal;

                Headers.Add("content-type", "text/html");
            }
Ejemplo n.º 2
0
        /// <summary>
        /// Serializes a resource to a hal+json string using the provided <paramref name="representationGenerator"/>
        /// instance.
        /// </summary>
        /// <param name="representationGenerator">The <see cref="IHal"/> instance for generating a resource representation</param>
        /// <param name="resource">The object to serialize</param>
        /// <param name="serializerOptions"></param>
        /// <returns>A hal+json string</returns>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="InvalidJsonSerializerOptionsException">Thrown if the provided <paramref name="serializerOptions"/> does not have the required converters</exception>
        public static async Task <string> SerializeAsync(IHal representationGenerator, object resource, JsonSerializerOptions serializerOptions)
        {
            if (representationGenerator == null)
            {
                throw new ArgumentNullException(nameof(representationGenerator));
            }
            if (resource == null)
            {
                throw new ArgumentNullException(nameof(resource));
            }
            if (serializerOptions == null)
            {
                throw new ArgumentNullException(nameof(serializerOptions));
            }

            if (!HalJsonConvertersPresent(serializerOptions))
            {
                var converters = string.Join(", ", RequiredConverters.Select(x => x.Name));
                throw new InvalidJsonSerializerOptionsException($"The JSON converters [{converters}] are required to serialize to hal+json");
            }

            var representation = await representationGenerator.RepresentationOfAsync(resource);

            var json = JsonSerializer.Serialize(representation, serializerOptions);

            return(json);
        }
Ejemplo n.º 3
0
            public HalHtmlResponse(IHal hal, Optional <object> resource)
            {
                _resource = resource.HasValue ? resource.Value : EmptyBody;
                _hal      = hal;

                Headers.ContentType = ContentType;
            }
Ejemplo n.º 4
0
            public HalJsonResponse(IHal hal, Optional <object> resource)
            {
                _resource = resource.HasValue ? resource.Value : EmptyBody;
                _hal      = hal;

                Headers.Add("content-type", HalJson.ToString());
            }
Ejemplo n.º 5
0
        public App(IHal proxy)
        {
            InitializeComponent();

            MainPage = new MainPage(proxy)
            {
            };
        }
Ejemplo n.º 6
0
        private static async Task <IEnumerable <Link> > LinksFor(IHal representation, TResource resource)
        {
            if (representation is IHalLinksAsync <TResource> asyncLinks)
            {
                return(await asyncLinks.LinksForAsync(resource));
            }

            if (representation is IHalLinks <TResource> links)
            {
                return(links.LinksFor(resource));
            }

            return(Enumerable.Empty <Link>());
        }
Ejemplo n.º 7
0
        private static async Task <object> EmbeddedFor(IHal representation, TResource resource)
        {
            if (representation is IHalEmbeddedAsync <TResource> asyncEmbedded)
            {
                return(await asyncEmbedded.EmbeddedForAsync(resource));
            }

            if (representation is IHalEmbedded <TResource> embedded)
            {
                return(embedded.EmbeddedFor(resource));
            }

            return(null);
        }
Ejemplo n.º 8
0
        private static async Task <object> StateFor(IHal representation, TResource resource)
        {
            if (representation is IHalStateAsync <TResource> asyncState)
            {
                return(await asyncState.StateForAsync(resource));
            }

            if (representation is IHalState <TResource> state)
            {
                return(state.StateFor(resource));
            }

            return(resource ?? new object {});
        }
Ejemplo n.º 9
0
        public MainPage(IHal proxy)
        {
            StoreFactory.HalProxy = proxy;
            proxy.WriteLog(LogSeverity.Info, "Creating main window");
            var vm = new MainVM(this);

            proxy.WriteLog(LogSeverity.Info, "Binding context");
            this.BindingContext = vm;
            proxy.WriteLog(LogSeverity.Info, "Initialize component");
            try
            {
                InitializeComponent();
            }
            catch (Exception ex)
            {
                proxy.WriteLog(LogSeverity.Error, "Init component: " + ex.Message);
            }

            proxy.WriteLog(LogSeverity.Info, "Initializing navigation");
            StoreFactory.CurrentVM.Navi = this.Navigation;
            vm.Navi = this.Navigation;
            proxy.WriteLog(LogSeverity.Info, "Init pages");
            vm.InitPages();
        }
Ejemplo n.º 10
0
 protected PagedListRepresentation(string baseUrl, IHal itemRepresentation)
 {
     _baseUrl            = baseUrl;
     _itemRepresentation = itemRepresentation;
 }
Ejemplo n.º 11
0
 public HALResponse(IHal hal, object?resource = null)
 {
     _resource = resource ?? EmptyBody;
     _hal      = hal;
     Headers.Add(("content-type", Constants.MediaTypes.HalJson));
 }
Ejemplo n.º 12
0
        protected override void OnCreate(Bundle bundle)
        {
            string[] input = null;
            try
            {
                ViewConfiguration config = ViewConfiguration.Get(this);
                var menuKeyField         = config.Class.GetDeclaredField("sHasPermanentMenuKey");

                if (menuKeyField != null)
                {
                    menuKeyField.Accessible = true;
                    menuKeyField.SetBoolean(config, false);
                }
            }
            catch (Exception ex)
            {
                // Ignore
            }

            try
            {
                base.OnCreate(bundle);
                global::Xamarin.Forms.Forms.Init(this, bundle);
                global::Xamarin.Auth.Presenters.XamarinAndroid.AuthenticationConfiguration.Init(this, bundle);

                this.halProxy = new AndroidHalProxy(this.ApplicationContext, this);
                this.halProxy.WriteLog(LogSeverity.Info, "Hal created and inspecting intent");

                input = this.Intent.Extras.GetStringArray("data");
            }
            catch (Exception ex)
            {
                this.halProxy.WriteLog(LogSeverity.Warning, "Error getting intent data");
                input = new string[0];
            }
            finally
            {
                if (input == null)
                {
                    input = new string[0];
                }
            }

            try
            {
                this.halProxy.WriteLog(LogSeverity.Info, "Check input");
                if (input.Length > 0)
                {
                    this.halProxy.WriteLog(LogSeverity.Info, "Entering input mode");
                }
                else
                {
                    this.halProxy.InitialPageIndex = 0;
                }

                this.halProxy.WriteLog(LogSeverity.Info, "Loading app");

                LoadApplication(new ShopNavi.App(this.halProxy));
            }
            catch (Exception ex0)
            {
                Toast.MakeText(this.ApplicationContext, ex0.ToString(), ToastLength.Long);
                this.halProxy.WriteLog(LogSeverity.Error, ex0.Message);
                this.halProxy.WriteLog(LogSeverity.Error, ex0.StackTrace);
            }

            try
            {
                if (IsPlayServicesAvailable())
                {
                    StoreFactory.CurrentVM.Logs.Add("Starting registration service");
                    this.halProxy.WriteLog(LogSeverity.Info, "Starting registration service");
                    var intent = new Intent(this, typeof(RegistrationIntentService));
                    StartService(intent);
                }
                else
                {
                    this.halProxy.WriteLog(LogSeverity.Info, "Google play not available");
                    StoreFactory.CurrentVM.Logs.Add("Google play not available");
                }

                if (StoreFactory.Settings.FromSMS)
                {
                    this.halProxy.WriteLog(LogSeverity.Info, "Registering SMS receiver");
                    this.ApplicationContext.RegisterReceiver(new SmsReceiver(), new IntentFilter("android.provider.Telephony.SMS_RECEIVED"));
                }


                if (input.Length > 0)
                {
                    StoreFactory.CurrentVM.Logs.Add("Starting with intent ");
                    this.halProxy.WriteLog(LogSeverity.Info, "Starting with intent ");

                    StoreFactory.CurrentVM.InitInput(input);
                }
            }
            catch (Exception ex)
            {
                Toast.MakeText(this.ApplicationContext, ex.ToString(), ToastLength.Long);
                this.halProxy.WriteLog(LogSeverity.Error, ex.Message);
                this.halProxy.WriteLog(LogSeverity.Error, ex.StackTrace);
                throw;
            }

            //CarouselViewRenderer.Init();

            GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn).
                                      RequestEmail().
                                      Build();

            StoreFactory.HalProxy.GoogleClient = new GoogleApiClient.Builder(this)
                                                 .EnableAutoManage(this, this)
                                                 .AddApi(Auth.GOOGLE_SIGN_IN_API, gso)
                                                 .Build();
        }
Ejemplo n.º 13
0
 private static async Task<JsonElement> Serialize(IHal representationGenerator, object resource)
 {
     var json = await HalJsonSerializer.SerializeAsync(representationGenerator, resource, HalJsonSerializer.DefaultSerializerOptions);
     return JsonDocument.Parse(json).RootElement;
 }
Ejemplo n.º 14
0
 public AppOld(IHal proxy)
 {
     MainPage = new MainPage(proxy)
     {
     };
 }