示例#1
0
        public async static Task <AppInfoEnvelope> Load(UserConfiguration uc)
        {
            HttpWebRequest webRequest = HttpWebRequest.CreateHttp(uc.ApiBase + "apps");

            webRequest.Method      = WebRequestMethods.Http.Get;
            webRequest.ContentType = "application/x-www-form-urlencoded";
            webRequest.UserAgent   = "HockeyAppLoader";
            webRequest.Headers.Add("X-HockeyAppToken", uc.UserToken);

            WebResponse response = await webRequest.GetResponseAsync();

            Stream stream = response.GetResponseStream();
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(AppInfoEnvelope));

            AppInfoEnvelope envelope = serializer.ReadObject(stream) as AppInfoEnvelope;

            List <AppInfo> localAppData = uc.AppInfos;

            foreach (AppInfo app in envelope.Apps)
            {
                var local = localAppData.FirstOrDefault(p => p.Id.Equals(app.Id));
                if (local != null)
                {
                    app.CompleteWithLocalData(local);
                }
            }

            uc.AppInfos = envelope.Apps;

            return(envelope);
        }
        public async Task<List<AppInfo>> GetMatchingApps(CommandLineArgs args)
        {
            Configuration configuration = Configuration.Instance;
            this._args=args;
            if (!String.IsNullOrWhiteSpace(args.Accountname))
            {
                ActiveUserConfiguration = configuration.UserConfigurations.FirstOrDefault(p => p.ConfigurationName.ToUpper().Equals(args.Accountname.ToUpper()));
            }
            else
            {
                ActiveUserConfiguration = configuration.DefaultUserConfiguration;
            }
            if (ActiveUserConfiguration == null)
            {
                throw new Exception("Wrong AccountName or no default account configured!");
            }

            this._envelope = await AppInfoEnvelope.Load(ActiveUserConfiguration);

            switch (args.Platform)
            {
                case AppInfoPlatforms.None:
                    throw new Exception("Platform not supported!");

                case AppInfoPlatforms.Android:
                    MatchAndroid();
                    break;
                case AppInfoPlatforms.Windows:
                    MatchWindows();
                    break;
                case AppInfoPlatforms.Custom:
                    MatchCustom();
                    break;
                case AppInfoPlatforms.WindowsPhone:
                    MatchWindowsPhone();
                    break;
            }

            if (_matchingApps.Count == 0)
            {
                this._matchingApps.AddRange(this._envelope.Apps.Where(p => p.Platform == args.Platform));
            }

            return _matchingApps;
        }