Esempio n. 1
0
        /// <summary>Reads the steam store and returns a Subscription object</summary>
        static Sub SteamSub(string fileContent)
        {
            if (fileContent == null)
            {
                throw new ArgumentNullException("fileContent");
            }
            var rgxBundleName = new Regex("<div class=\"game_name\">\\s+<div class=\"blockbg\">\\s+(.+)\\s+</div>");
            var rgxBundle =
                new Regex("<div class=\"tab_overlay\">\\s+<a href=\"http://store.steampowered.com/app/(\\d{2,7})");

            var sub = new Sub { Name = rgxBundleName.Match(fileContent).Groups[1].Value.Trim().Clean().Trim() };
            if (sub.Name.Contains(BadNames))
            {
                return null;
            }
            string sid = rgxSteamId.Match(fileContent).Groups[2].Value;
            sub.SteamId = Convert.ToInt32(sid);
            sub.ReleaseDate = GetReleaseDate(fileContent);

            MatchCollection matches = rgxBundle.Matches(fileContent);

            // Sometimes Steam has remanents of old bundles or bundles with only 1 app.
            if (matches.Count == 1)
            {
                return null;
            }
            for (int x = 0; x < matches.Count; x++)
            {
                int id = Convert.ToInt32(matches[x].Groups[1].Value);

                // Store bugs
                switch (id)
                {
                    case 2277:
                        continue;
                    case 34270:
                        return null;
                }
                var svc = new GamesService();
                        var subApp = (App)svc.Get(new GetApp(id));

                        if (subApp == null)
                        {
                            SteamApp(id);
                            subApp = (App)svc.Get(new GetApp(id));
                            if (subApp == null)
                            {
                                continue;
                            }
                        }

                        if (sub.Apps.All(y => subApp != null && y != subApp.SteamId))
                        {
                            sub.Apps.Add(subApp.SteamId);
                        }
            }
            int subCount = sub.Apps.Count;
            if (subCount < 2)
            {
                // Bad Subscription
                return null;
            }
            return sub;
        }
Esempio n. 2
0
        public Response Put(Sub request)
        {
            if (string.IsNullOrWhiteSpace(request.Name))
            {
                throw new ArgumentNullException("request", "Subscription name is required");
            }

            if (request.Apps.Count < 2)
            {
                throw new ArgumentException("Subscription must have at least 2 apps.", "request");
            }

            Db.Save(request.ConvertTo<Sub>());
            if (request.Id != Guid.Empty)
            {
                return new Response(true);
            }

            string id = request.SteamId + request.Name + request.Id;
            Request.RemoveFromCache(base.Cache, id);

            return new Response(true);
        }
 public BadSubscriptionException(Sub sub)
     : base(sub.ToString())
 {
 }