public void Run()
        {
            var builder = new DbContextOptionsBuilder <SandboxContext>();

            builder.UseSqlServer(Settings.ConnectionString);
            using (var context = new SandboxContext(builder.Options))
            {
                var connection = context.Database.GetDbConnection();
                using (var command = connection.CreateCommand())
                {
                    command.CommandType = CommandType.Text; // or StoredProcedure
                    command.CommandText = "SELECT Id, Name FROM [dbo].[Lookup] WHERE IsDeleted = 0";

                    if (connection.State != ConnectionState.Open)
                    {
                        connection.Open();
                    }

                    using (var dataReader = command.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.CloseConnection))
                    {
                        while (dataReader.Read())
                        {
                            var id   = dataReader["Id"];
                            var name = dataReader["Name"];
                            // Console.WriteLine handles a lot of additional parsing, checks, etc. that would normally be done.
                            Console.WriteLine($"Id = {id} | Name = {name}");
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public Todo Add(SandboxContext db, Todo todo)
        {
            db.Todos.Add(todo);
            db.SaveChanges();

            return(todo);
        }
Ejemplo n.º 3
0
        private static void SeedTopics(this SandboxContext context)
        {
            var topics = new List <Topic>()
            {
                new Topic()
                {
                    Body = "This is the body of a topic to test the thing. Plz tho.", Title = "Test the thing", Downdoots = 0, Updoots = 0
                },
                new Topic()
                {
                    Body = "This is the body of a second topic to test the thing. Plz tho.", Title = "Test the thing 2", Downdoots = 0, Updoots = 0
                },
                new Topic()
                {
                    Body = "This is the body of a third topic to test the thing. Plz tho.", Title = "Test the thing 3", Downdoots = 0, Updoots = 0
                },
            };

            var existing = context.Topics.ToList();

            var newTopics = new List <Topic>();

            newTopics.AddRange(topics.Where(t => existing.All(e => e.Body != t.Body)));

            context.Topics.AddRange(newTopics);

            context.SaveChanges();
        }
Ejemplo n.º 4
0
 public void Delete(int id)
 {
     using (SandboxContext db = new SandboxContext())
     {
         bool result = Repo.Delete(db, id);
     }
 }
Ejemplo n.º 5
0
        public Links UpdateLink(SandboxContext db, Links link)
        {
            db.Links.Attach(link);
            db.Entry(link).State = EntityState.Modified;
            db.SaveChanges();

            return(link);
        }
Ejemplo n.º 6
0
        public Todo Update(SandboxContext db, Todo todo)
        {
            db.Todos.Attach(todo);
            db.Entry(todo).State = EntityState.Modified;
            db.SaveChanges();

            return(todo);
        }
Ejemplo n.º 7
0
        internal InstallationInfo(string path)
        {
            Path      = path;
            Installed = File.Exists(InstallationManager.GetDebuggerVisualizerFilePath(path));

            if (!Installed)
            {
                return;
            }

            // Trying to determine the version by loading it into a sandbox domain.
            try
            {
#if NETFRAMEWORK
                Evidence  evidence      = new Evidence(AppDomain.CurrentDomain.Evidence);
                AppDomain sandboxDomain = AppDomain.CreateDomain(nameof(InitializerSandbox), evidence, Files.GetExecutingPath(), null, false);
                try
                {
                    // initializing by the constructor rather than unwrapping and calling a public method because unwrap may fail if executed from a Visual Studio package
#if NET35
                    Activator.CreateInstance(sandboxDomain, Assembly.GetExecutingAssembly().FullName, typeof(InitializerSandbox).FullName, false, BindingFlags.Public | BindingFlags.Instance, null, new object[] { this, path }, null, null, evidence);
#else
                    Activator.CreateInstance(sandboxDomain, Assembly.GetExecutingAssembly().FullName, typeof(InitializerSandbox).FullName, false, BindingFlags.Public | BindingFlags.Instance, null, new object[] { this, path }, null, null);
#endif
                }
                finally
                {
                    AppDomain.Unload(sandboxDomain);
                }
#else
                var context = new SandboxContext(path);
                try
                {
                    // note: we use LoadFromStream instead of LoadFromAssemblyPath because that keeps the file locked even after unloading the context
                    using var fs = File.OpenRead(InstallationManager.GetDebuggerVisualizerFilePath(path));
                    Assembly asm = context.LoadFromStream(fs);
                    Version         = asm.GetName().Version;
                    RuntimeVersion  = asm.ImageRuntimeVersion;
                    TargetFramework = (Attribute.GetCustomAttribute(asm, typeof(TargetFrameworkAttribute)) as TargetFrameworkAttribute)?.FrameworkName;
                }
                catch (Exception e) when(!e.IsCritical())
                {
                    Version        = null;
                    RuntimeVersion = null;
                }
                finally
                {
                    context.Unload();
                }
#endif
            }
            catch (Exception e) when(!e.IsCritical())
            {
                RuntimeVersion = null;
                InitializeInfoByFileVersion(path);
            }
        }
Ejemplo n.º 8
0
        public static void EnsureSeedData(this SandboxContext context, IHostingEnvironment env)
        {
            if (!env.IsDevelopment())
            {
                return;
            }

            context.SeedTopics();
        }
Ejemplo n.º 9
0
        public Links Update([FromBody] Links link)
        {
            using (SandboxContext db = new SandboxContext())
            {
                Links result = Repo.UpdateLink(db, link);

                return(result);
            }
        }
Ejemplo n.º 10
0
        public bool Delete(SandboxContext db, int todoId)
        {
            Todo todo = db.Todos.Where(x => x.Id == todoId).FirstOrDefault();

            db.Todos.Remove(todo);
            db.SaveChanges();

            return(true);
        }
Ejemplo n.º 11
0
        public Links Get(int id)
        {
            using (SandboxContext db = new SandboxContext())
            {
                Links link = Repo.GetLinkById(db, id);

                return(link);
            }
        }
Ejemplo n.º 12
0
        public bool Delete(SandboxContext db, int linkId)
        {
            Links link = db.Links.Where(l => l.Id == linkId).FirstOrDefault();

            db.Links.Remove(link);
            db.SaveChanges();

            return(true);
        }
Ejemplo n.º 13
0
        public IEnumerable <Links> Get()
        {
            using (SandboxContext db = new SandboxContext())
            {
                List <Links> result = Repo.GetAll(db);

                return(result);
            }
        }
Ejemplo n.º 14
0
        public Links AddLink(SandboxContext db, Links link)
        {
            link.CreateTimestamp = DateTime.Now;
            link.Visible         = true;
            db.Links.Add(link);
            db.SaveChanges();

            return(link);
        }
Ejemplo n.º 15
0
        public SandboxRobot(TradingBaseStrategy tradingBaseStrategy, string token)
        {
            var connection = ConnectionFactory.GetSandboxConnection(token);

            _context                                = connection.Context;
            _tradingBaseStrategy                    = tradingBaseStrategy;
            _tradingBaseStrategy.Context            = _context;
            _tradingBaseStrategy.OnActionOperation += ProcessEventOperation;
            _tradePositions                         = new List <TradePosition>();
        }
        private static SandGrainEntity CloneGrain(SandboxContext context, SandGrainEntity original)
        {
            var clonedGrain = new SandGrainEntity();
            var cloneValues = context.Entry(original).CurrentValues.Clone();

            context.Entry(clonedGrain).CurrentValues.SetValues(cloneValues);
            clonedGrain.InternalId = 0;
            clonedGrain.Id         = Guid.NewGuid();

            return(clonedGrain);
        }
        private static BeachEntity CloneBeach(SandboxContext context, BeachEntity original)
        {
            var cloned      = new BeachEntity();
            var cloneValues = context.Entry(original).CurrentValues.Clone();

            context.Entry(cloned).CurrentValues.SetValues(cloneValues);
            cloned.InternalId = 0;
            cloned.Id         = Guid.NewGuid();

            cloned.Grains = original.Grains.Select(d => CloneGrain(context, d)).ToList();
            return(cloned);
        }
Ejemplo n.º 18
0
        public static void Initialize(SandboxContext context)
        {
            if (context.Users.Any())
            {
                return;
            }

            User user = new User {
                Name = "Ivan", Email = "*****@*****.**", Password = "******"
            };

            context.Users.Add(user);
            context.SaveChanges();
        }
        static void Main(string[] args)
        {
            var inMemoryContextOptions = new DbContextOptionsBuilder <SandboxContext>()
                                         .UseInMemoryDatabase(databaseName: "Test")
                                         .Options;

            using (var context = new SandboxContext(inMemoryContextOptions))
            {
                var beach = new BeachEntity();
                beach.Id = Guid.NewGuid();

                for (int i = 0; i < 5; i++)
                {
                    var grain = new SandGrainEntity
                    {
                        CreatedDate = DateTime.UtcNow,
                        Id          = Guid.NewGuid()
                    };
                    beach.Grains.Add(grain);
                }

                context.Database.EnsureCreated();
                context.Beaches.Add(beach);
                int savedCount = context.SaveChanges();

                System.Console.WriteLine();
                System.Console.WriteLine($"Created {savedCount} new entries.");
                System.Console.WriteLine();

                WriteBeach(beach);

                BeachEntity clonedBeach = CloneBeach(context, beach);
                context.Beaches.Add(clonedBeach);

                savedCount = context.SaveChanges();
                System.Console.WriteLine();
                System.Console.WriteLine($"Created {savedCount} new entries.");
                System.Console.WriteLine();
                WriteBeach(clonedBeach);
            }
        }
Ejemplo n.º 20
0
        public async Task Init()
        {
            _sandbox = _broker.SandboxConnection.Context;
            var account = await _sandbox.RegisterAsync(BrokerAccountType.Tinkoff);

            _accountId = account.BrokerAccountId;

            //await _sandbox.ClearAsync(_accountId);
            // set balance
            //foreach (var currency in new[] { Currency.Rub, Currency.Usd })
            //    await _sandbox.SetCurrencyBalanceAsync(currency,
            //        currency == Currency.Rub ? 100_000 : 10_000, _accountId);
            _currencies["USD"] = new CurrencyInfo {
                Balance = 2000, Currency = Currency.Usd
            };
            _currencies["RUB"] = new CurrencyInfo {
                Balance = 100000, Currency = Currency.Rub
            };

            _telegram.PostMessage($"Аккаунт песочницы создан. Id {_accountId}.", null);

            await ReportBalances();
        }
        public async Task Collect(SandboxContext context)
        {
            foreach (var metadata in _metadataManager.GetAll())
            {
                if (metadata.Figi == null)
                {
                    continue;
                }
                var isin      = metadata.Isin;
                var intervals = _intervalCalculator.TryCalculateRequiredIntervals(isin);
                foreach (var(startDate, endDate) in intervals)
                {
                    var candles = await context.MarketCandlesAsync(
                        metadata.Figi, startDate, endDate, CandleInterval.Day);

                    _logger.LogTrace($"Found asset candles: {string.Join("\n", candles.Candles.Select(c => c.ToString()))}");
                    if (candles.Candles.Count > 0)
                    {
                        await _priceManager.AddOrAppendCandles(isin, candles);
                    }
                }
            }
        }
Ejemplo n.º 22
0
 public List <Links> GetAll(SandboxContext db)
 {
     return(db.Links.Where(l => l.Visible == true).OrderBy(l => l.Sort).ToList());
 }
Ejemplo n.º 23
0
 public GameService(SandboxContext context)
 {
     _context = context;
 }
Ejemplo n.º 24
0
 public EFCorePitcherRepository(SandboxContext context)
 {
     this.context = context;
 }
Ejemplo n.º 25
0
 public Links GetLinkById(SandboxContext db, int linkId)
 {
     return(db.Links.Where(l => l.Id == linkId).FirstOrDefault());
 }
Ejemplo n.º 26
0
 public QueryProvider(SandboxContext context)
 {
     this.context = context;
     context.Database.EnsureCreated(); // Ignore this. It is needed for the In-Memory DbContext.
 }
Ejemplo n.º 27
0
 public void runApexClass(SandboxContext param1)
 {
     throw new global::System.NotImplementedException("SandboxPostCopy.RunApexClass");
 }
Ejemplo n.º 28
0
        public SandboxBot(string token)
        {
            var connection = ConnectionFactory.GetSandboxConnection(token);

            _context = connection.Context;
        }
Ejemplo n.º 29
0
 public async Task Collect(SandboxContext context)
 {
     var currencyFigis = new Dictionary <CurrencyCode, string> {
Ejemplo n.º 30
0
        public List <Todo> GetAll(SandboxContext db)
        {
            List <Todo> result = db.Todos.OrderBy(x => x.Sort).ToList();

            return(result);
        }