コード例 #1
0
        public async Task <HttpResponseMessage> CheckAccess(CancellationToken cancellationToken)
        {
            var response = new List <object>();

            foreach (var config in AccountConfig.GetAll())
            {
                bool   hasAccess   = false;
                bool   isConnected = false;
                string error       = string.Empty;

                try
                {
                    isConnected = await uSplitAuthorizationCodeFlow.GetInstance(config).IsConnected(cancellationToken);

                    if (isConnected)
                    {
                        hasAccess = await new CheckAccess(config).ExecuteAsync();
                    }
                }
                catch (Exception ex)
                {
                    error = ex.Message;
                }
                response.Add(new
                {
                    Name        = config.Name,
                    HasAccess   = hasAccess,
                    IsConnected = isConnected,
                    Error       = error,
                    ProfileId   = config.UniqueId,
                });
            }
            return(CreateResponse(response));
        }
コード例 #2
0
        protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
        {
            var menu = new MenuItemCollection();

            var accounts = AccountConfig.GetAll().ToList();

            if (IsRootNode(id))
            {
                if (accounts.Count == 1)
                {
                    menu.Items.Add <ActionNew>("Create a new experiment", "profileId", accounts.First().UniqueId);
                }
            }
            else if (accounts.Any(x => x.UniqueId == id))
            {
                menu.Items.Add <ActionNew>("Create a new experiment", "profileId", id);
            }
            else //experiment node
            {
                //TODO: Nice-to-haves
                //menu.Items.Add<ActionPublish>("Start this experiment");
                //menu.Items.Add<ActionDisable>("Stop this experiment");
                menu.Items.Add <ActionDelete>("Delete this experiment");
            }

            return(menu);
        }
コード例 #3
0
ファイル: ExperimentsUpdater.cs プロジェクト: fret1224/uSplit
        public async Task UpdateExperimentsCacheAsync()
        {
            //TODO: check if we are configured, otherwise this will generate errors every now and then

            var experiments = new List <GoogleExperiment>();

            foreach (var config in AccountConfig.GetAll())
            {
                logger.Info(typeof(ExperimentsUpdater), $"Updating experiments data from Google Analytics for {config.Name} (ID {config.UniqueId}).");
                try
                {
                    var result = await new GetExperiments(config).ExecuteAsync();
                    experiments.AddRange(result.Items);
                }
                catch (Exception ex)
                {
                    logger.Error(typeof(ExperimentsUpdater), $"Failed to download A/B testing data for {config.Name} (ID {config.UniqueId}).", ex);
                }
            }

            try
            {
                var cache = ApplicationContext.Current.ApplicationCache.RuntimeCache;
                cache.InsertCacheItem(Constants.Cache.RawExperimentData, () => experiments,
                                      Constants.Cache.ExperimentsRefreshInterval);
                cache.ClearCacheItem(Constants.Cache.ParsedExperiments);
            }
            catch (Exception ex)
            {
                logger.Error(typeof(ExperimentsUpdater), $"Failed to update cache after downloading experiments.", ex);
            }
        }
コード例 #4
0
        protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
        {
            if (IsRootNode(id))
            {
                var nodes = AsyncHelpers.RunSync(() => GetTreeNodesAsync(queryStrings));
                return(nodes);
            }

            var accounts = AccountConfig.GetAll().ToList();
            var account  = accounts.FirstOrDefault(x => x.UniqueId == id);

            if (account != null)
            {
                var nodes = AsyncHelpers.RunSync(() => GetTreeNodesForAccountAsync(queryStrings, account));
                return(nodes);
            }

            throw new NotSupportedException("Invalid node id");
        }
コード例 #5
0
        private async Task <TreeNodeCollection> GetTreeNodesAsync(FormDataCollection queryStrings)
        {
            var nodes    = new TreeNodeCollection();
            var accounts = AccountConfig.GetAll().ToList();

            if (accounts.Count() > 1)
            {
                foreach (var account in AccountConfig.GetAll())
                {
                    var accountNode = CreateAccountNode(account, queryStrings);
                    nodes.Add(accountNode);
                }
            }
            else if (accounts.Count() == 1)
            {
                return(await GetTreeNodesForAccountAsync(queryStrings, accounts[0]));
            }

            return(nodes);
        }
コード例 #6
0
ファイル: ManageController.cs プロジェクト: fret1224/uSplit
        public async Task DeleteExperimentAsync(string id, string profileId)
        {
            var           accountConfigs = AccountConfig.GetAll().ToList();
            AccountConfig config;

            if ((id.IsNullOrWhiteSpace() || id == "-1") && accountConfigs.Count == 1)
            {
                config = accountConfigs.First();
            }
            else
            {
                config = AccountConfig.GetByUniqueId(profileId);
            }


            //TODO: add an option to delete variations (e.g. Umbraco content linked to it)
            await ExecuteAsync(new DeleteExperiment(config)
            {
                GoogleExperimentId = id
            });
        }