Esempio n. 1
0
        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());
            }
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
        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();
            }
        }
Esempio n. 5
0
        /// <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;
            }
        }
Esempio n. 6
0
        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());
            }
        }
Esempio n. 7
0
 public UnitOfWork(CatContext context, IServerRepository serverRepository, IUserRepository userRepository, ILogsRepository logsRepository)
 {
     _context = context;
     Servers  = serverRepository;
     Users    = userRepository;
     Logs     = logsRepository;
 }
Esempio n. 8
0
        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();
        }
Esempio n. 9
0
        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")));
        }
Esempio n. 10
0
 /// <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));
 }
Esempio n. 11
0
 /// <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());
            }
        }
Esempio n. 13
0
        /// <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();
            }
        }
Esempio n. 14
0
        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());
            }
        }
Esempio n. 15
0
 public UserRepository(CatContext context) : base(context)
 {
 }
Esempio n. 16
0
 public HomeController(CatContext context)
 {
     db = context;
 }
Esempio n. 17
0
        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;
            }
        }
Esempio n. 18
0
 public ProdutoRepository(CatContext c)
 {
     _context = c;
 }
Esempio n. 19
0
 public HomeController()
 {
     catContext = new CatContext();
 }
 public AbstractCatState(CatContext handle)
 {
     Handle = handle;
 }
 public ContemplatingState(CatContext Handle) : base(Handle)
 {
 }
Esempio n. 22
0
 public RoomManager(CatContext context)
 {
     _context = context;
 }
Esempio n. 23
0
 public RoomController(CatContext context)
 {
     _context    = context;
     roomManager = new RoomManager(_context);
 }
Esempio n. 24
0
 public AddCatModel(CatContext db, IHostingEnvironment environment)
 {
     _db             = db;
     _appEnvironment = environment;
 }
Esempio n. 25
0
 static void Add(int a, int b, CatContext context = null)
 {
     PureCat.LogRemoteCallServer(context);
     PureCat.LogEvent("Do", nameof(Add), "0", $"{a} + {b} = {a + b}");
 }
Esempio n. 26
0
 public LogsRepository(CatContext context) : base(context)
 {
 }
Esempio n. 27
0
 public SleepingState(CatContext Handle) : base(Handle)
 {
 }
Esempio n. 28
0
 void Awake()
 {
     catContext = new CatContext(new Good());
 }
 public CatsController(CatContext context)
 {
     this.Context = context;
 }
Esempio n. 30
0
 public DogController(CatContext context)
 {
     db = context;
 }