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}"); } } } } }
public Todo Add(SandboxContext db, Todo todo) { db.Todos.Add(todo); db.SaveChanges(); return(todo); }
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(); }
public void Delete(int id) { using (SandboxContext db = new SandboxContext()) { bool result = Repo.Delete(db, id); } }
public Links UpdateLink(SandboxContext db, Links link) { db.Links.Attach(link); db.Entry(link).State = EntityState.Modified; db.SaveChanges(); return(link); }
public Todo Update(SandboxContext db, Todo todo) { db.Todos.Attach(todo); db.Entry(todo).State = EntityState.Modified; db.SaveChanges(); return(todo); }
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); } }
public static void EnsureSeedData(this SandboxContext context, IHostingEnvironment env) { if (!env.IsDevelopment()) { return; } context.SeedTopics(); }
public Links Update([FromBody] Links link) { using (SandboxContext db = new SandboxContext()) { Links result = Repo.UpdateLink(db, link); return(result); } }
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); }
public Links Get(int id) { using (SandboxContext db = new SandboxContext()) { Links link = Repo.GetLinkById(db, id); return(link); } }
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); }
public IEnumerable <Links> Get() { using (SandboxContext db = new SandboxContext()) { List <Links> result = Repo.GetAll(db); return(result); } }
public Links AddLink(SandboxContext db, Links link) { link.CreateTimestamp = DateTime.Now; link.Visible = true; db.Links.Add(link); db.SaveChanges(); return(link); }
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); }
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); } }
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); } } } }
public List <Links> GetAll(SandboxContext db) { return(db.Links.Where(l => l.Visible == true).OrderBy(l => l.Sort).ToList()); }
public GameService(SandboxContext context) { _context = context; }
public EFCorePitcherRepository(SandboxContext context) { this.context = context; }
public Links GetLinkById(SandboxContext db, int linkId) { return(db.Links.Where(l => l.Id == linkId).FirstOrDefault()); }
public QueryProvider(SandboxContext context) { this.context = context; context.Database.EnsureCreated(); // Ignore this. It is needed for the In-Memory DbContext. }
public void runApexClass(SandboxContext param1) { throw new global::System.NotImplementedException("SandboxPostCopy.RunApexClass"); }
public SandboxBot(string token) { var connection = ConnectionFactory.GetSandboxConnection(token); _context = connection.Context; }
public async Task Collect(SandboxContext context) { var currencyFigis = new Dictionary <CurrencyCode, string> {
public List <Todo> GetAll(SandboxContext db) { List <Todo> result = db.Todos.OrderBy(x => x.Sort).ToList(); return(result); }