示例#1
0
        public async Task <Status> Get()
        {
            var sites = _settingsHelper.GetSites().ToList();

            Trace.WriteLine("Sites: " + string.Join(", ", sites));
            var siteSet = new HashSet <string>(sites.Concat(sites.Select(s => s + "(staging)")), StringComparer.OrdinalIgnoreCase);

            WebSpacesListResponse spaces;

            try
            {
                var client = _clientHelper.GetWebSiteClient();
                spaces = await client.WebSpaces.ListAsync(CancellationToken.None);
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                throw;
            }
            try
            {
                var siteLists = await Task.WhenAll(spaces.Select(space => ListWebSites(space.Name, siteSet)));

                Output = DtoCollection.Create(siteLists.SelectMany(l => l).Select(WebSiteDto.FromSdk).OrderBy(dto => dto.Name));
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                throw;
            }
            return(200);
        }
示例#2
0
        public IUser GetLoggedInUser(IContext context)
        {
            string[] header;
            if (!context.Request.Headers.TryGetValue("Authorization", out header))
            {
                return(null);
            }
            if (header == null || header.Length != 1)
            {
                return(null);
            }
            var user = HttpRuntime.Cache.Get(header[0]) as IgorUser;

            if (user != null)
            {
                return(user);
            }
            var dict = ConnectionStringParser.ParseConnectionString(header[0]);

            if (!(dict.ContainsKey("User") && dict.ContainsKey("Password")))
            {
                return(null);
            }
            user = new IgorUser(dict["User"], Uri.UnescapeDataString(dict["Password"]));
            var site   = _settingsHelper.GetSites().First();
            var client = _clientHelper.GetWebSiteExtensionsClient(site, user.Name, user.Password);

            try
            {
                var task = client.Settings.ListAsync(CancellationToken.None);
                task.Wait();
                if (task.IsFaulted || task.IsCanceled)
                {
                    return(null);
                }
                HttpRuntime.Cache[header[0]] = user;
                return(user);
            }
            catch (Exception)
            {
                return(null);
            }
        }