示例#1
0
        public RawGame UpdateOrCreate(RawGame entity)
        {
            SetupUpdateOrCreate(entity);

            RawGame existing;

            using (var db = new Db())
            {
                existing = FindByAPIKey(entity.APIID);
            }

            if (existing == null)
            {
                //-- Insert --
                entity           = Create(entity);
                entity.dateAdded = DateTime.UtcNow;
            }
            else
            {
                existing.TheBlob         = entity.TheBlob;
                existing.isAlsoExpansion = entity.isAlsoExpansion;
                existing.lastUpdatedBy   = "console-Update";
                existing.dateLastUpdated = DateTime.UtcNow;
                using (var db = new Db())
                {
                    db.Entry(existing).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }

            return(entity);
        }
示例#2
0
        public int pullXMLbyIDSaveToDBAndTweetAboutIt(string apiKey)
        {
            try
            {
                var API  = new APIAccessor_boardgamegeek_BoardGame();
                var BC   = new RawGamesAccessor();
                var twit = new TwitterApiAccessor("iNbJLSc1T9fvufuWbFV3V6Xni", "JFjvyyhz56ZvZR1IkGjNSXNBThUT31OUrn43LXMQkCdNyy2CpK", "749359779592613888-wWPrZIls1xVFprjqRunSpKEr5GgaXDp", "rRHz1DhGR9kJ8DwwMjGuMj3uWn9z0t1IIp3YAYDlL4FKm");

                var xml = API.getBoardGame(apiKey.ToString());

                var newGame = new RawGame();

                newGame.APIID   = apiKey;
                newGame.TheBlob = xml;

                BC.UpdateOrCreate(newGame);

                twit.SendTweet("Someone posted information about Game ID: " + newGame.APIID + " from BGG - " + DateTime.Now.ToString("yyyyMMdd-hhmmss"));

                return(100);
            }
            catch (Exception e)
            {
                return(499);
            }
        }
示例#3
0
        public string searchAndSaveAllReferences(string searchCriteria)
        {
            try
            {
                var API = new APIAccessor_boardgamegeek_BoardGame();
                var BC  = new RawGamesAccessor();

                var xml = API.search(searchCriteria);

                if (xml.Contains("<body>"))
                {
                    return("TimeOut");
                }
                //todo - log the search

                var obj = xml.ParseXML <BoardChitless.Shared.DataContracts.BoardGameGeekSearch.items>();

                foreach (BoardChitless.Shared.DataContracts.BoardGameGeekSearch.itemsItem i in obj.item)
                {
                    var g = new RawGame();

                    g.APIID = i.id.ToString();
                    g.Name  = i.name.value.ToString();
                    try
                    {
                        g.YearPublished = i.yearpublished.value;

                        if (i.typeField == "boardgameexpansion")
                        {
                            g.isAlsoExpansion = 1;
                        }
                    }
                    catch {
                        //let it be null
                    }

                    g.RecordType = i.typeField;
                    g.addedBy    = "console-search-" + searchCriteria;
                    g.dateAdded  = DateTime.UtcNow;

                    //newGame.TheBlob = xml;

                    if (i.name.type == "primary")
                    {
                        BC.UpdateOrCreate(g);
                    }
                }

                return("Done");
            }
            catch
            {
                return("Error");
            }
        }
示例#4
0
        public void TestInitialize()
        {
            _testTransactionScope = new TransactionScope();

            Target = new RawGamesAccessor();
            CreatedDataContractInstance = new RawGame();

            _record = new RawGame()
            {
                APIID = "822", Name = "Test", YearPublished = 2016, TheBlob = "<xml>test</xml>"
            };
        }
示例#5
0
        public RawGame Create(RawGame entity)
        {
            entity.dateAdded       = DateTime.UtcNow;
            entity.dateLastUpdated = DateTime.UtcNow;

            using (var db = new Db())
            {
                db.Set <RawGame>().Add(entity);
                db.SaveChanges();
            }

            return(entity);
        }
示例#6
0
        public string pullXMLbyIDAndSaveToDatabase(string apiKey)
        {
            try {
                var API = new APIAccessor_boardgamegeek_BoardGame();
                var BC  = new RawGamesAccessor();

                var xml = API.getBoardGame(apiKey.ToString());

                var newGame = new RawGame();

                newGame.APIID   = apiKey;
                newGame.TheBlob = xml;

                BC.UpdateOrCreate(newGame);

                return("Done!");
            }
            catch {
                return("Error");
            }
        }
示例#7
0
 public void SetupUpdateOrCreate(RawGame entity)
 {
     //Logger.Log(string.Format(Properties.Resources.Accessors_Updating, typeof(ReportRecord).Name, entity.Id), TraceEventType.Verbose);
 }