Пример #1
0
        protected void Setup()
        {
            var dbOptions = new DbContextOptionsBuilder <GatewayContext>()
                            .UseInMemoryDatabase(databaseName: "Testing")
                            .ConfigureWarnings(w => w.Ignore(InMemoryEventId.TransactionIgnoredWarning))
                            .Options;

            this.context = new GatewayContext(dbOptions);
        }
        public UnitOfWork(GatewayContext gatewaycontext)
        {
            if (gatewaycontext == null)
            {
                throw new ArgumentNullException("dbContext");
            }

            _gatewaycontext = gatewaycontext;
        }
Пример #3
0
        protected override void Seed(GatewayContext context)
        {
            context.Merchants.AddOrUpdate(x => x.MerchantID,
                                          new Merchant()
            {
                MerchantID = 1, MerchantName = "NetFlix"
            });
            context.Merchants.AddOrUpdate(x => x.MerchantID,
                                          new Merchant()
            {
                MerchantID = 2, MerchantName = "AmazonPrime"
            });

            context.Requests.AddOrUpdate(x => x.RequestID, new Request()
            {
                RequestID      = Guid.NewGuid(),
                MerchantID     = 1,
                CardNumber     = 2541245875489853,
                ExpiryDate     = DateTime.Today,
                Amount         = 123,
                Currency       = "Yen",
                CVV            = 123,
                BankResponseID = Guid.NewGuid(),
                BankStatus     = Status.Successfull,
                RequestDate    = DateTime.Today
            });

            context.Requests.AddOrUpdate(x => x.RequestID, new Request()
            {
                RequestID      = Guid.NewGuid(),
                MerchantID     = 2,
                CardNumber     = 2541245875489854,
                ExpiryDate     = DateTime.Today,
                Amount         = 123,
                Currency       = "Yen",
                CVV            = 123,
                BankResponseID = Guid.NewGuid(),
                BankStatus     = Status.Successfull,
                RequestDate    = DateTime.Today
            });

            context.Requests.AddOrUpdate(x => x.RequestID, new Request()
            {
                RequestID      = Guid.NewGuid(),
                MerchantID     = 1,
                CardNumber     = 2451745865487541,
                ExpiryDate     = DateTime.Today,
                Amount         = 123,
                Currency       = "Yen",
                CVV            = 123,
                BankResponseID = Guid.NewGuid(),
                BankStatus     = Status.Successfull,
                RequestDate    = DateTime.Today
            });
        }
        protected GatewayContext GetGatewayContext(HttpContext context)
        {
            if (context.Items.ContainsKey(ConstGatewayContext))
            {
                return((GatewayContext)context.Items[ConstGatewayContext]);
            }

            var gatewayContext = new GatewayContext();

            context.Items[ConstGatewayContext] = gatewayContext;

            return(gatewayContext);
        }
Пример #5
0
        public void UpdateFromApi(GatewayContext context)
        {
            var searchPages = 1000;

            for (int i = 0; i < searchPages; i++)
            {
                Console.WriteLine("Loading Page " + i);
                var usergates = new List <UserGate>();
                var users     = new List <User>();
                searchPages = ProcessApiUsers(context, i, users, usergates);
                Console.WriteLine("All Data for Page " + i + " Loaded Successfully. Updating");
                users.ForEach(s => context.Users.AddOrUpdate(s));
                usergates.ForEach(s => context.UserGates.AddOrUpdate(s));
                context.SaveChanges();
                Console.WriteLine("Loaded page " + i + " successfully");
            }
            Console.WriteLine("Leaderboard update has successfully completed! There was about " + searchPages * 100 + " users processed");
        }
Пример #6
0
 public ClientConfig()
 {
     Identify = new Identify
     {
         IsCompress = true,
         Properties = new IdentifyProperties
         {
             OS      = Environment.OSVersion.Platform.ToString(),
             Browser = "DiscordCs",
             Device  = "DiscordCs"
         },
         LargeThreshold = 50,
         Presence       = new PresenceStatusUpdate
         {
             Status = PresenceStatus.Online
         },
         Intents = IdentifyIntent.Default,
         IsGuildSubscriptions = false
     };
     GatewayConfig = new GatewayConfig
     {
         BaseUrl  = "wss://gateway.discord.gg",
         Version  = 8,
         Encoding = "json"
     };
     Gateway = new GatewayContext();
     Logger  = new Logger
     {
         Level = LoggingLevel.Warning
     };
     CacheContext = new CacheContext(new CacheConfig
     {
     });
     RestConfig = new RestConfig
     {
         BaseUrl = "https://discord.com",
         Version = 8
     };
     Rest = new RestContext();
 }
Пример #7
0
        public void CreateGates(GatewayContext context)
        {
            var courses = new List <Gate>
            {
                new Gate {
                    GateID = 1, Theme = "Nintendo", Keys = 5
                },
                new Gate {
                    GateID = 2, Theme = "Indie Games", Keys = 4
                },
                new Gate {
                    GateID = 3, Theme = "Unknown", Keys = 0
                },
                new Gate {
                    GateID = 4, Theme = "Unknown", Keys = 0
                },
                new Gate {
                    GateID = 5, Theme = "Unknown", Keys = 0
                },
                new Gate {
                    GateID = 6, Theme = "Unknown", Keys = 0
                },
                new Gate {
                    GateID = 7, Theme = "Unknown", Keys = 0
                },
                new Gate {
                    GateID = 8, Theme = "BETA GATE 1", Keys = 0
                },
                new Gate {
                    GateID = 9, Theme = "BETA GATE 2", Keys = 0
                },
                new Gate {
                    GateID = 10, Theme = "BETA GATE 3", Keys = 0
                },
            };

            courses.ForEach(s => context.Gates.AddOrUpdate(s));
            context.SaveChanges();
        }
Пример #8
0
        // Please set the following connection strings in app.config for this WebJob to run:
        // AzureWebJobsDashboard and AzureWebJobsStorage
        static void Main()
        {
            var config = new JobHostConfiguration();

            if (config.IsDevelopment)
            {
                config.UseDevelopmentSettings();
            }

            var host = new JobHost(config);

            // The following code ensures that the WebJob will be running continuously
            //host.RunAndBlock();
            Console.WriteLine("importing users from api...");
            var updater = new ApiUpdater();

            using (var context = new GatewayContext())
            {
                context.Configuration.AutoDetectChangesEnabled = false;

                updater.CreateGates(context);
                updater.UpdateFromApi(context);
            }
        }
Пример #9
0
        /// <summary>
        /// Creates the MerchelloPluginContext (singleton)
        /// </summary>
        /// <param name="serviceContext">The service context</param>
        /// <param name="cache">The cache helper</param>
        /// <remarks>
        /// Since we load fire our boot manager after Umbraco fires its "started" even, Merchello gets the benefit
        /// of allowing Umbraco to manage the various caching providers via the Umbraco CoreBootManager or WebBootManager
        /// depending on the context.
        /// </remarks>
        protected void CreateMerchelloContext(ServiceContext serviceContext, CacheHelper cache)
        {
            var gateways = new GatewayContext(serviceContext, GatewayProviderResolver.Current);

            _merchelloContext = MerchelloContext.Current = new MerchelloContext(serviceContext, gateways, cache);
        }
Пример #10
0
 public void Dispose()
 {
     gatewaysController = null;
     gatewayContext.Dispose();
     gatewayContext = null;
 }
Пример #11
0
 public BaseService(GatewayContext context)
 {
     Context = context;
 }
 public SeedDataClass(GatewayContext db)
 {
     _db = db;
 }
Пример #13
0
 public Repository(GatewayContext context)
 {
     this.context = context;
     this.dbSet   = context.Set <TEntity>();
 }
Пример #14
0
 public DataService(GatewayContext context, ILogger <DataService> log)
 {
     _context = context;
     _log     = log;
 }
Пример #15
0
 /// <summary>
 /// Creates the MerchelloPluginContext (singleton)
 /// </summary>
 /// <param name="serviceContext">The service context</param>
 /// <param name="cache">The cache helper</param>
 /// <remarks>
 /// Since we load fire our boot manager after Umbraco fires its "started" even, Merchello gets the benefit
 /// of allowing Umbraco to manage the various caching providers via the Umbraco CoreBootManager or WebBootManager
 /// depending on the context.
 /// </remarks>
 protected void CreateMerchelloContext(ServiceContext serviceContext, CacheHelper cache)
 {
     var gateways = new GatewayContext(serviceContext, GatewayProviderResolver.Current);
     _merchelloContext = MerchelloContext.Current = new MerchelloContext(serviceContext, gateways, cache);
 }
Пример #16
0
 public GatewayRepository(GatewayContext context)
 {
     _context = context;
 }
Пример #17
0
 public DeviceService(GatewayContext context) : base(context)
 {
     DataHolder = context.DatDevice;
 }
Пример #18
0
        public int ProcessApiUsers(GatewayContext context, int page, ICollection <User> users, ICollection <UserGate> usergates)
        {
            int numPages = 0;

            using (var client = new HttpClient())
            {
                var response = client.GetAsync("https://api.thetheoristgateway.com/args/265048a8-8521-4e9c-84c7-1de081efe0a4/leaderboard?page=" + page).Result;

                if (response.IsSuccessStatusCode)
                {
                    var responseContent = response.Content;

                    // by calling .Result you are synchronously reading the result
                    string responseString = responseContent.ReadAsStringAsync().Result;

                    var sevengates = JsonConvert.DeserializeObject <apiresults>(responseString);
                    numPages = sevengates.total / 100;
                    var amount = sevengates.total;
                    foreach (var result in sevengates.results)
                    {
                        int rank = 0;
                        if (int.TryParse(result.rank, out rank) == false)
                        {
                            rank = sevengates.total;
                        }

                        int I1 = 0;
                        int I2 = 0;
                        int I3 = 0;
                        if (result.gates_solved == 2 && result.total_keys < 14 && result.total_keys > 11)
                        {
                            I1 = 4;
                        }
                        if (result.gates_solved < 3 && I1 == 0)
                        {
                            if (result.gates_solved == 2)
                            {
                                I1 = 1;
                            }
                            if (result.gates_solved == 1)
                            {
                                I1 = 2;
                            }
                            if (result.gates_solved == 0)
                            {
                                I1 = 3;
                            }
                        }
                        if (!result.username_raw.ToLower().Contains('<') && !result.username_raw.ToLower().Contains('>') && rank > 150)
                        {
                            if (I1 == 0)
                            {
                                I1 = 5;
                            }
                            else
                            {
                                I2 = 5;
                            }
                        }
                        if (!result.username_raw.ToLower().Contains('<') && !result.username_raw.ToLower().Contains('>') && rank < 151)
                        {
                            if (I1 == 0)
                            {
                                I1 = 6;
                            }
                            else
                            {
                                I2 = 6;
                            }
                        }
                        if (result.gates_solved == 3)
                        {
                            if (rank > 500)
                            {
                                if (I1 == 0)
                                {
                                    I1 = 7;
                                }
                                else
                                {
                                    I2 = 7;
                                }
                            }
                            if (rank > 100 && rank < 501)
                            {
                                if (I1 == 0)
                                {
                                    I1 = 8;
                                }
                                else
                                {
                                    I2 = 8;
                                }
                            }
                            if (rank < 101)
                            {
                                if (I1 == 0)
                                {
                                    I1 = 0;
                                }
                                else
                                {
                                    I2 = 0;
                                }
                            }
                        }

                        var   CollectiveTime  = new TimeSpan(0, 0, 0, 0, result.total_time);
                        var   TotalTime       = CollectiveTime;
                        var   TotalKeys       = result.total_keys;
                        float PercentFinished = 0;
                        bool  Participate     = true;
                        PercentFinished = (float)rank / (float)numPages;
                        PercentFinished = (float)Math.Ceiling(PercentFinished);
                        string PrizeQM = "0";
                        //if (PercentFinished <= 0.001)
                        //{
                        //    PercentFinished = 0.01;
                        //}
                        if (PercentFinished >= 101.0f)
                        {
                            PercentFinished = 100.0f;
                        }
                        if (PercentFinished <= 1.0f)
                        {
                            PrizeQM = "1";
                        }
                        if (PercentFinished > 1.0f && PercentFinished <= 5.0f)
                        {
                            PrizeQM = "2";
                        }
                        for (int i = 1; i < CurrentGate; i++)
                        {
                            var PreviousGate = context.UserGates.Where(u => u.UserID == result.uuid && u.GateID == i).FirstOrDefault();
                            var PreviousKeys = context.Gates.Where(u => u.GateID == i && u.Keys >= 0).FirstOrDefault();
                            if (PreviousGate != null)
                            {
                                if (TotalTime == PreviousGate.Time)
                                {
                                    Participate = false;
                                }
                                TotalTime = TotalTime - PreviousGate.Time;
                            }
                            if (PreviousKeys != null && Participate == true)
                            {
                                TotalKeys = TotalKeys - PreviousKeys.Keys;
                            }
                        }
                        var user = new User
                        {
                            ID              = result.uuid,
                            Username        = result.username_raw,
                            Keys            = result.total_keys,
                            Rank            = rank,
                            TimeForAllGates = new TimeSpan(0, 0, 0, 0, result.total_time),
                            Percentile      = PercentFinished,
                            PrizeStatus     = PrizeQM,
                            Insight1        = I1,
                            Insight2        = I2,
                            Insight3        = I3,
                        };
                        var userGate = new UserGate
                        {
                            GateID         = CurrentGate,
                            Rank           = rank,
                            UserID         = result.uuid,
                            Time           = TotalTime,
                            Keys           = TotalKeys,
                            CollectiveTime = CollectiveTime,
                            Percentile     = PercentFinished
                        };

                        users.Add(user);
                        usergates.Add(userGate);
                    }
                }
            }
            return(numPages);
        }
Пример #19
0
 public GatewayService(GatewayContext context) : base(context)
 {
     DataHolder = context.DatGateway;
 }
Пример #20
0
 public GatewaysController(GatewayContext context)
 {
     _context = context;
 }