示例#1
0
        public static ContainerBuilder RegisterODataClient(this ContainerBuilder containerBuilder)
        {
            if (containerBuilder == null)
            {
                throw new ArgumentNullException(nameof(containerBuilder));
            }

            Simple.OData.Client.V4Adapter.Reference();

            containerBuilder.Register(c =>
            {
                HttpMessageHandler authenticatedHttpMessageHandler = c.ResolveNamed <HttpMessageHandler>(ContractKeys.AuthenticatedHttpMessageHandler);

                IClientAppProfile clientAppProfile = c.Resolve <IClientAppProfile>();

                IODataClient odataClient = new ODataClient(new ODataClientSettings(new Uri(clientAppProfile.HostUri, clientAppProfile.ODataRoute))
                {
                    RenewHttpConnection    = false,
                    OnCreateMessageHandler = () => authenticatedHttpMessageHandler
                });

                return(odataClient);
            }).PreserveExistingDefaults();

            containerBuilder
            .Register(c => new ODataBatch(c.Resolve <IODataClient>(), reuseSession: true))
            .PreserveExistingDefaults();

            return(containerBuilder);
        }
        public static IDependencyManager RegisterODataClient(this IDependencyManager dependencyManager, Action <ODataClientSettings>?odataClientSettingsCustomizer = null)
        {
            if (dependencyManager == null)
            {
                throw new ArgumentNullException(nameof(dependencyManager));
            }

            Simple.OData.Client.V4Adapter.Reference();

            dependencyManager.RegisterUsing(resolver =>
            {
                IClientAppProfile clientAppProfile = resolver.Resolve <IClientAppProfile>();

                ODataClientSettings settings = new ODataClientSettings(httpClient: resolver.Resolve <HttpClient>(), new Uri(clientAppProfile.ODataRoute ?? throw new InvalidOperationException($"{nameof(IClientAppProfile.ODataRoute)} is null."), uriKind: UriKind.RelativeOrAbsolute))
                {
                    RenewHttpConnection = false,
                    NameMatchResolver   = ODataNameMatchResolver.AlpahumericCaseInsensitive
                };

                odataClientSettingsCustomizer?.Invoke(settings);

                IODataClient odataClient = new ODataClient(settings);

                return(odataClient);
            }, overwriteExisting: false, lifeCycle: DependencyLifeCycle.Transient);

            dependencyManager
            .RegisterUsing(resolver => new ODataBatch(resolver.Resolve <IODataClient>(), reuseSession: true), lifeCycle: DependencyLifeCycle.Transient, overwriteExisting: false);

            return(dependencyManager);
        }
        public static ContainerBuilder RegisterODataClient(this ContainerBuilder containerBuilder)
        {
            if (containerBuilder == null)
            {
                throw new ArgumentNullException(nameof(containerBuilder));
            }

            Simple.OData.Client.V4Adapter.Reference();

            containerBuilder.Register(c =>
            {
                IClientAppProfile clientAppProfile = c.Resolve <IClientAppProfile>();

                IODataClient odataClient = new ODataClient(new ODataClientSettings(httpClient: c.Resolve <HttpClient>(), new Uri(clientAppProfile.ODataRoute, uriKind: UriKind.Relative))
                {
                    RenewHttpConnection = false
                });

                return(odataClient);
            }).PreserveExistingDefaults();

            containerBuilder
            .Register(c => new ODataBatch(c.Resolve <IODataClient>(), reuseSession: true))
            .PreserveExistingDefaults();

            return(containerBuilder);
        }
        public static ContainerBuilder RegisterODataClient(this ContainerBuilder containerBuilder, Action <ODataClientSettings> odataClientSettingsCustomizer = null)
        {
            if (containerBuilder == null)
            {
                throw new ArgumentNullException(nameof(containerBuilder));
            }

            Simple.OData.Client.V4Adapter.Reference();

            containerBuilder.Register(c =>
            {
                IClientAppProfile clientAppProfile = c.Resolve <IClientAppProfile>();

                ODataClientSettings settings = new ODataClientSettings(httpClient: c.Resolve <HttpClient>(), new Uri(clientAppProfile.ODataRoute, uriKind: UriKind.RelativeOrAbsolute))
                {
                    RenewHttpConnection = false,
                    NameMatchResolver   = ODataNameMatchResolver.AlpahumericCaseInsensitive
                };

                odataClientSettingsCustomizer?.Invoke(settings);

                IODataClient odataClient = new ODataClient(settings);

                return(odataClient);
            }).PreserveExistingDefaults();

            containerBuilder
            .Register(c => new ODataBatch(c.Resolve <IODataClient>(), reuseSession: true))
            .PreserveExistingDefaults();

            return(containerBuilder);
        }
示例#5
0
 public DefaultSecurityService(IClientAppProfile clientAppProfile,
                               IDateTimeProvider dateTimeProvider,
                               IContainer container)
 {
     _clientAppProfile = clientAppProfile;
     _dateTimeProvider = dateTimeProvider;
     _container        = container;
     Current           = this;
 }
示例#6
0
        public static HubConnection IHubConnectionFactory(IClientAppProfile clientAppProfile)
        {
            if (clientAppProfile == null)
            {
                throw new ArgumentNullException(nameof(clientAppProfile));
            }

            return(new HubConnection($"{clientAppProfile.HostUri ?? throw new InvalidOperationException($"{nameof(IClientAppProfile.HostUri)} is null")}{clientAppProfile.SignalrEndpint ?? throw new InvalidOperationException($"{nameof(IClientAppProfile.SignalrEndpint)} is null")}")
            {
                TransportConnectTimeout = TimeSpan.FromSeconds(3)
            });
示例#7
0
 public DefaultSecurityService(AccountStore accountStore,
                               IClientAppProfile clientAppProfile,
                               IDateTimeProvider dateTimeProvider,
                               IBrowserService browserService,
                               IContainerProvider containerProvider)
 {
     _clientAppProfile  = clientAppProfile;
     _accountStore      = accountStore;
     _dateTimeProvider  = dateTimeProvider;
     _browserService    = browserService;
     _containerProvider = containerProvider;
     _current           = this;
 }
        public EvaluationRequestFilesViewModel(IMedia media,
                                               IODataClient oDataClient,
                                               IUserDialogs userDialogs,
                                               IInitialDataService initialDataService,
                                               IPageDialogService dialogService,
                                               IClientAppProfile clientApp,
                                               IEventAggregator eventAggregator,
                                               ISecurityService securityService)
        {
            _oDataClient        = oDataClient;
            _userDialogs        = userDialogs;
            _initialDataService = initialDataService;

            TakePhoto = new BitDelegateCommand <EvlRequestFileItemSource>(async(file) =>
            {
                //500 is ID for More pictures
                if (file.TypeId == 500)
                {
                    Files.Add(new EvlRequestFileItemSource {
                        TypeId = file.TypeId, TypeName = file.TypeName, Image = file.Image
                    });
                }

                _fileIndex = Files.IndexOf(file);

                eventAggregator.GetEvent <TakePhotoEvent>().Publish(new TakePhotoEvent());
            });

            GoBack = new BitDelegateCommand(async() =>
            {
                await NavigationService.GoBackAsync();
            });

            OpenCamera = new BitDelegateCommand(async() =>
            {
                eventAggregator.GetEvent <TakePhotoEvent>().Publish(new TakePhotoEvent());

                MediaFile mediaFile = await media.TakePhotoAsync(new StoreCameraMediaOptions
                {
                    Directory          = "Sanaap",
                    SaveToAlbum        = true,
                    CompressionQuality = 25,
                    CustomPhotoSize    = 30,
                    PhotoSize          = PhotoSize.Medium,
                    MaxWidthHeight     = 2000,
                    AllowCropping      = true,
                    DefaultCamera      = CameraDevice.Rear
                });

                if (mediaFile != null)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        mediaFile.GetStream().CopyTo(ms);
                        Files[_fileIndex].Data = ms.ToArray();
                    }

                    Files[_fileIndex].Image    = ImageSource.FromStream(() => mediaFile.GetStream());
                    Files[_fileIndex].HasImage = true;
                }
                else
                {
                    await dialogService.DisplayAlertAsync(ConstantStrings.Error, ConstantStrings.PictureIsNull, ConstantStrings.Ok);
                }
            });

            Gallery = new BitDelegateCommand(async() =>
            {
                eventAggregator.GetEvent <TakePhotoEvent>().Publish(new TakePhotoEvent());

                MediaFile mediaFile = await media.PickPhotoAsync(new PickMediaOptions
                {
                    PhotoSize          = PhotoSize.Medium,
                    CompressionQuality = 25,
                });

                if (mediaFile != null)
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        mediaFile.GetStream().CopyTo(ms);
                        Files[_fileIndex].Data = ms.ToArray();
                    }

                    Files[_fileIndex].Image    = ImageSource.FromStream(() => mediaFile.GetStream());
                    Files[_fileIndex].HasImage = true;
                }
                else
                {
                    await dialogService.DisplayAlertAsync(ConstantStrings.Error, ConstantStrings.PictureIsNull, ConstantStrings.Ok);
                }
            });

            Submit = new BitDelegateCommand(async() =>
            {
                if (Files.Any(f => f.IsRequired && f.HasImage == false))
                {
                    await dialogService.DisplayAlertAsync(ConstantStrings.Error, ConstantStrings.PictureIsRequired, ConstantStrings.Ok);

                    return;
                }

                if (await dialogService.DisplayAlertAsync(string.Empty, ConstantStrings.AreYouSure, ConstantStrings.Yes, ConstantStrings.No))
                {
                    using (HttpClient http = new HttpClient())
                    {
                        http.BaseAddress = clientApp.HostUri;

                        http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", (await securityService.GetCurrentTokenAsync()).access_token);

                        using (userDialogs.Loading(ConstantStrings.SendingRequestAndPictures))
                        {
                            MultipartFormDataContent submitEvlRequestContents = new MultipartFormDataContent
                            {
                                new StringContent(JsonConvert.SerializeObject(Request), Encoding.UTF8, "application/json")
                            };

                            foreach (EvlRequestFileDto file in Files.Where(f => f.Data != null))
                            {
                                submitEvlRequestContents.Add(new ByteArrayContent(file.Data), file.TypeId.ToString(), file.TypeId.ToString());
                            }

                            HttpRequestMessage submitEvlRequest = new HttpRequestMessage(HttpMethod.Post, "api/evl-requests/submit-evl-request")
                            {
                                Content = submitEvlRequestContents
                            };

                            HttpResponseMessage submitEvlRequestExpertResponse = await http.SendAsync(submitEvlRequest);

                            submitEvlRequestExpertResponse.EnsureSuccessStatusCode();

                            Request = JsonConvert.DeserializeObject <EvlRequestItemSource>(await submitEvlRequestExpertResponse.Content.ReadAsStringAsync());

                            await NavigationService.NavigateAsync(nameof(EvaluationRequestWaitView), new NavigationParameters
                            {
                                { nameof(Request), Request }
                            });
                        }
                    }
                }
            });

            OpenPhoto = new BitDelegateCommand <EvlRequestFileItemSource>(async(image) =>
            {
                await NavigationService.NavigateAsync(nameof(OpenImagePopup), new NavigationParameters
                {
                    { nameof(image.Image), image.Image }
                });
            });

            DeletePhoto = new BitDelegateCommand <EvlRequestFileItemSource>(async(image) =>
            {
                if (image.HasImage == false)
                {
                    return;
                }

                if (await dialogService.DisplayAlertAsync(ConstantStrings.Error, ConstantStrings.AreYouSureToDelete, ConstantStrings.Yes, ConstantStrings.No))
                {
                    image.Image    = null;
                    image.HasImage = false;

                    await NavigationService.GoBackAsync();
                }
            });
        }
 public BitHttpClientHandler(IEnumerable <ITelemetryService> telemetryServices, IDateTimeProvider dateTimeProvider, IClientAppProfile clientAppProfile)
 {
     _clientAppProfile  = clientAppProfile;
     _dateTimeProvider  = dateTimeProvider;
     _telemetryServices = telemetryServices;
 }