Ejemplo n.º 1
0
        public ErrorPromise <RegisterationErrorResultStatus> Register(string username, string password)
        {
            ErrorDeferred <RegisterationErrorResultStatus> deferred = new ErrorDeferred <RegisterationErrorResultStatus>();

            if (InfoResolver.Resolve <FortInfo>().ServerConnectionProvider == null)
            {
                throw new Exception("No Server connection provider added");
            }
            InfoResolver.Resolve <FortInfo>().ServerConnectionProvider.UserConnection.Register(username, password).Then(() =>
            {
                ServiceLocator.Resolve <IAnalyticsService>().StatUserRegisterd();
                ServiceLocator.Resolve <IStorageService>().UpdateData(new AuthenticationInfo {
                    UserName = username
                });
                deferred.Resolve();
            }, status => deferred.Reject(status));
            return(deferred.Promise());
        }
Ejemplo n.º 2
0
        public ErrorPromise <ShowVideoFailed> ShowVideo(string zone, bool skipable, bool removabale)
        {
            if (_showingVideo)
            {
                ErrorDeferred <ShowVideoFailed> result = new ErrorDeferred <ShowVideoFailed>();
                result.Reject(ShowVideoFailed.AlreadyShowingVideo);
            }
            AdvertisementSavedData advertisementSavedData =
                ServiceLocator.Resolve <IStorageService>().ResolveData <AdvertisementSavedData>() ??
                new AdvertisementSavedData();

            if (advertisementSavedData.IsAdRemoved && removabale)
            {
                ErrorDeferred <ShowVideoFailed> result = new ErrorDeferred <ShowVideoFailed>();
                result.Reject(ShowVideoFailed.AdvertisementRemoved);
                return(result.Promise());
            }
            _showingVideo = true;
            ServerSettings serverSettings = ServiceLocator.Resolve <ISettingService>().ResolveCachedServerSetting();

            string[] videoProviderPriority = new string[0];
            int      serverCount           = 0;

            if (serverSettings != null && serverSettings.AdvertisementSettings != null &&
                serverSettings.AdvertisementSettings.VideoPriority != null &&
                serverSettings.AdvertisementSettings.VideoPriority.Length > 0)
            {
                videoProviderPriority = serverSettings.AdvertisementSettings.VideoPriority;
                serverCount           = videoProviderPriority.Select(
                    s =>
                    InfoResolver.Resolve <FortInfo>().Advertisement.AdvertisementProviders.First(
                        priority =>
                        priority.AdvertisementProvider != null && priority.AdvertisementProvider.Name == s)
                    .AdvertisementProvider).Count();
            }

            if (serverCount == 0)
            {
                videoProviderPriority =
                    InfoResolver.Resolve <FortInfo>().Advertisement.AdvertisementProviders.Where(
                        priority =>
                        priority.AdvertisementProvider != null && priority.AdvertisementProvider.IsVideoSupported)
                    .Select((priority, i) => new { Priority = priority, Index = i })
                    .OrderBy(arg => arg.Priority.VideoPriority < 0 ? arg.Index * 10000 : arg.Priority.VideoPriority)
                    .Select(arg => arg.Priority.AdvertisementProvider.Name)
                    .ToArray();
            }
            IAdvertisementProvider[] providers =
                videoProviderPriority.Select(
                    s =>
                    InfoResolver.Resolve <FortInfo>().Advertisement.AdvertisementProviders.First(
                        priority =>
                        priority.AdvertisementProvider != null && priority.AdvertisementProvider.Name == s)
                    .AdvertisementProvider).ToArray();
            if (providers.Length == 0)
            {
                _showingVideo = false;
                throw new Exception("No video provider Defined");
            }
            ErrorDeferred <ShowVideoFailed> deferred = new ErrorDeferred <ShowVideoFailed>();
            int    index     = 0;
            Action showVideo = null;

            showVideo = () =>
            {
                ServiceLocator.Resolve <IAnalyticsService>().StatVideoRequest(providers[index].Name, zone, skipable);
                providers[index].ShowVideo(zone, skipable).Then(() =>
                {
                    ServiceLocator.Resolve <IAnalyticsService>().StatVideoResult(providers[index].Name, zone, skipable, ShowVideoResult.Succeeded);
                    _showingVideo = false;
                    deferred.Resolve();
                }, failed =>
                {
                    switch (failed)
                    {
                    case ShowVideoFailed.Cancel:
                    case ShowVideoFailed.AlreadyShowingVideo:
                        ServiceLocator.Resolve <IAnalyticsService>().StatVideoResult(providers[index].Name, zone, skipable, ShowVideoResult.Cancel);
                        _showingVideo = false;
                        deferred.Reject(ShowVideoFailed.Cancel);
                        break;

                    case ShowVideoFailed.NoVideoAvilable:
                    case ShowVideoFailed.ProviderError:
                        ServiceLocator.Resolve <IAnalyticsService>().StatVideoResult(providers[index].Name, zone, skipable, failed == ShowVideoFailed.NoVideoAvilable?ShowVideoResult.NoVideoAvilable : ShowVideoResult.ProviderError);
                        if (index == providers.Length - 1)
                        {
                            _showingVideo = false;
                            deferred.Reject(failed);
                        }
                        else
                        {
                            index++;
                            showVideo();
                        }
                        break;

                    default:
                        throw new ArgumentOutOfRangeException("failed", failed, null);
                    }
                });
            };
            showVideo();
            return(deferred.Promise());
        }