private async System.Threading.Tasks.Task InitializeDb(TextView textView) { var dbFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); var fileName = "Cats.db"; var dbFullPath = Path.Combine(dbFolder, fileName); CreateDb(dbFullPath); try { _db = new CatContext(dbFullPath); var lol = await _db.Cats.ToListAsync(); if (!lol.Any()) { await generateFakeData(_db); } await PrintUsers(textView, _db); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } }
public static void Initialize(CatContext context) { context.Database.EnsureCreated(); if (context.cats.Any()) { return; } var cats = new Cat[] { new Cat { Name = "MeowMeow1", Color = "Caucasian", Price = 400, FavoriteDish = "Tuna", Birthdate = DateTime.Today }, new Cat { Name = "MeowMeow2", Color = "AfricanAmerican", Price = 500, FavoriteDish = "Tuna", Birthdate = DateTime.Today }, new Cat { Name = "MeowMeow3", Color = "Asian", Price = 450, FavoriteDish = "Tuna", Birthdate = DateTime.Today } }; foreach (Cat p in cats) { context.Add(p); } context.SaveChanges(); }
/// <summary> /// 客户端创建请求上下文 /// </summary> /// <param name="contextName">上下文名称</param> public static CatContext LogRemoteCallClient(string contextName) { var ctx = new CatContext(contextName); var tree = GetManager().ThreadLocalMessageTree; if (tree.MessageId == null) { tree.MessageId = CreateMessageId(); } var messageId = tree.MessageId; var childId = CreateMessageId(); LogEvent(PureCatConstants.TYPE_REMOTE_CALL, ctx.ContextName, PureCatConstants.SUCCESS, childId); var rootId = tree.RootMessageId; if (rootId == null) { rootId = tree.MessageId; } ctx.CatRootId = rootId; ctx.CatParentId = messageId; ctx.CatChildId = childId; return(ctx); }
private static async System.Threading.Tasks.Task generateFakeData(CatContext db) { await db.Database.MigrateAsync(); //We need to ensure the latest Migration was added. This is different than EnsureDatabaseCreated. Cat catGary = new Cat() { CatId = 1, Name = "Gary", MeowsPerSecond = 5 }; Cat catJack = new Cat() { CatId = 2, Name = "Jack", MeowsPerSecond = 11 }; Cat catLuna = new Cat() { CatId = 3, Name = "Luna", MeowsPerSecond = 3 }; List <Cat> catsInTheHat = new List <Cat>() { catGary, catJack, catLuna }; if (await db.Cats.CountAsync() < 3) { await db.Cats.AddRangeAsync(catsInTheHat); await db.SaveChangesAsync(); } }
/// <summary> /// 服务端串联上下文 /// </summary> /// <param name="context">上下文</param> public static void LogRemoteCallServer(CatContext context) { if (context == null) { return; } var tree = GetManager().ThreadLocalMessageTree; var messageId = context.CatChildId; var rootId = context.CatRootId; var parentId = context.CatParentId; if (messageId != null) { tree.MessageId = messageId; } if (parentId != null) { tree.ParentMessageId = parentId; } if (rootId != null) { tree.RootMessageId = rootId; } }
public override async void ViewDidLoad() { System.Diagnostics.Debug.WriteLine("ViewController.ViewDidLoad()"); base.ViewDidLoad(); // NOTE: See LinkDescription.xml, which describes how to get the Xamarin linker to preserve key types and // methods that Entity Framework Core uses only via reflection. Without such instructions to the linker, // EF Core code such as below would generate runtime errors when the linker is used; e.g. in builds that // are deployed to device or for publishing to the App Store. Unfortunately, such issues aren't immediately // evident when running a sample like this in the simulator, as the default Xamarin iOS project config has // linking disabled for the iPhoneSimulator target. var dbFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); var fileName = "Cats.db"; var dbFullPath = Path.Combine(dbFolder, fileName); try { using (var db = new CatContext(dbFullPath)) { await db.Database.MigrateAsync(); //We need to ensure the latest Migration was added. This is different than EnsureDatabaseCreated. Cat catGary = new Cat() { CatId = 1, Name = "Gary", MeowsPerSecond = 5 }; Cat catJack = new Cat() { CatId = 2, Name = "Jack", MeowsPerSecond = 11 }; Cat catLuna = new Cat() { CatId = 3, Name = "Luna", MeowsPerSecond = 3 }; List <Cat> catsInTheHat = new List <Cat>() { catGary, catJack, catLuna }; if (await db.Cats.CountAsync() < 3) { await db.Cats.AddRangeAsync(catsInTheHat); await db.SaveChangesAsync(); } var catsInTheBag = await db.Cats.ToListAsync(); foreach (var cat in catsInTheBag) { textView.Text += $"{cat.CatId} - {cat.Name} - {cat.MeowsPerSecond}" + System.Environment.NewLine; } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } }
public UnitOfWork(CatContext context, IServerRepository serverRepository, IUserRepository userRepository, ILogsRepository logsRepository) { _context = context; Servers = serverRepository; Users = userRepository; Logs = logsRepository; }
protected override void Seed(CatContext context) { var breeds = new List <Breed> { new Breed { Name = "Black" }, new Breed { Name = "Tabby" }, new Breed { Name = "Calico" }, new Breed { Name = "Serval" }, new Breed { Name = "Tiger" }, new Breed { Name = "Persian" }, new Breed { Name = "Jaguar" }, new Breed { Name = "Mountain Lion" } }; context.Breeds.AddRange(breeds); context.SaveChanges(); }
static void Add(int a, int b, CatContext context = null) { Thread.Sleep(_rand.Next(1000)); PureCatClient.LogRemoteCallServer(context); PureCatClient.LogEvent("Do", nameof(Add), "0", $"{a} + {b} = {a + b}"); Task.Factory.StartNew(() => PureCatClient.DoTransaction("Do", nameof(Add2), () => PureCatClient.LogRemoteCallClient("callAdd2"))); }
/// <summary> /// 设置消息树到当前请求头 /// </summary> /// <returns></returns> public static void SetCatContextToRequestHeader(System.Web.HttpContext http, CatContext context) { if (http.Request.Headers.GetValues("catContext") != null && http.Request.Headers.GetValues("catContext").Length > 0) { http.Request.Headers.Remove("catContext"); } http.Request.Headers.Add("catContext", Lind.DDD.Utils.SerializeMemoryHelper.SerializeToJson(context)); }
/// <summary> /// 设置catContext到响应头 /// </summary> /// <param name="response"></param> /// <param name="context"></param> public static void SetCatContextToResponseHeader(HttpResponseBase response, CatContext context) { if (response.Headers.GetValues("catContext") != null && response.Headers.GetValues("catContext").Length > 0) { response.Headers.Remove("catContext"); } response.Headers.Add("catContext", Lind.DDD.Utils.SerializeMemoryHelper.SerializeToJson(context)); }
protected async override void OnAppearing() { var dbFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments); var fileName = "Cats.db"; var dbFullPath = Path.Combine(dbFolder, fileName); try { using (var db = new CatContext(dbFullPath)) { await db.Database.MigrateAsync(); //We need to ensure the latest Migration was added. This is different than EnsureDatabaseCreated. Cat catGary = new Cat() { CatId = 1, Name = "Gary", MeowsPerSecond = 5 }; Cat catJack = new Cat() { CatId = 2, Name = "Jack", MeowsPerSecond = 11 }; Cat catLuna = new Cat() { CatId = 3, Name = "Luna", MeowsPerSecond = 3 }; List <Cat> catsInTheHat = new List <Cat>() { catGary, catJack, catLuna }; if (await db.Cats.CountAsync() < 3) { await db.Cats.AddRangeAsync(catsInTheHat); await db.SaveChangesAsync(); } var catsInTheBag = await db.Cats.ToListAsync(); textView.Text = ""; foreach (var cat in catsInTheBag) { textView.Text += $"{cat.CatId} - {cat.Name} - {cat.MeowsPerSecond}" + System.Environment.NewLine; } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } }
/// <summary> /// 运行一个已有事务的代码段 /// </summary> /// <param name="type"></param> /// <param name="name"></param> /// <param name="context"></param> /// <param name="action"></param> /// <returns></returns> public static CatContext DoTransaction(string type, string name, CatContext context, Action action) { var tran = NewTransaction(type, name); try { action(); return(context); } catch (Exception ex) { LogError(ex); tran.SetStatus(ex); throw; } finally { tran.Complete(); } }
protected async override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById <Button>(Resource.Id.MyButton); button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); }; TextView textView = FindViewById <TextView>(Resource.Id.TextView1); var dbFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); var fileName = "Cats.db"; var dbFullPath = Path.Combine(dbFolder, fileName); try { using (var db = new CatContext(dbFullPath)) { await db.Database.MigrateAsync(); //We need to ensure the latest Migration was added. This is different than EnsureDatabaseCreated. Cat catGary = new Cat() { CatId = 1, Name = "Gary", MeowsPerSecond = 5 }; Cat catJack = new Cat() { CatId = 2, Name = "Jack", MeowsPerSecond = 11 }; Cat catLuna = new Cat() { CatId = 3, Name = "Luna", MeowsPerSecond = 3 }; List <Cat> catsInTheHat = new List <Cat>() { catGary, catJack, catLuna }; if (await db.Cats.CountAsync() < 3) { await db.Cats.AddRangeAsync(catsInTheHat); await db.SaveChangesAsync(); } var catsInTheBag = await db.Cats.ToListAsync(); foreach (var cat in catsInTheBag) { textView.Text += $"{cat.CatId} - {cat.Name} - {cat.MeowsPerSecond}" + System.Environment.NewLine; } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } }
public UserRepository(CatContext context) : base(context) { }
public HomeController(CatContext context) { db = context; }
private static async System.Threading.Tasks.Task PrintUsers(TextView textView, CatContext db) { var catsInTheBag = await db.Cats.ToListAsync(); textView.Text = String.Empty; foreach (var cat in catsInTheBag) { textView.Text += $"{cat.CatId} - {cat.Name} - {cat.MeowsPerSecond}" + System.Environment.NewLine; } }
public ProdutoRepository(CatContext c) { _context = c; }
public HomeController() { catContext = new CatContext(); }
public AbstractCatState(CatContext handle) { Handle = handle; }
public ContemplatingState(CatContext Handle) : base(Handle) { }
public RoomManager(CatContext context) { _context = context; }
public RoomController(CatContext context) { _context = context; roomManager = new RoomManager(_context); }
public AddCatModel(CatContext db, IHostingEnvironment environment) { _db = db; _appEnvironment = environment; }
static void Add(int a, int b, CatContext context = null) { PureCat.LogRemoteCallServer(context); PureCat.LogEvent("Do", nameof(Add), "0", $"{a} + {b} = {a + b}"); }
public LogsRepository(CatContext context) : base(context) { }
public SleepingState(CatContext Handle) : base(Handle) { }
void Awake() { catContext = new CatContext(new Good()); }
public CatsController(CatContext context) { this.Context = context; }
public DogController(CatContext context) { db = context; }