コード例 #1
0
        private async Task TryConnect(ShowContext context)
        {
            var connectionString = context.Database.GetDbConnection().ConnectionString;
            var builder          = new NpgsqlConnectionStringBuilder(connectionString)
            {
                Database = null
            };

            connectionString = builder.ConnectionString;

            try
            {
                await Policy
                .Handle <NpgsqlException>((ex) =>
                {
                    _logger.LogWarning(EventIds.MigrationTestConnectFailed, ex, "TryMigrate test connect failed, retrying.");
                    return(true);
                })
                .WaitAndRetryAsync(5, attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt)))
                .ExecuteAsync(async() =>
                {
                    using (var connection = new NpgsqlConnection(connectionString))
                    {
                        await connection.OpenAsync();
                        Console.WriteLine($"Connected: {connectionString}");
                    }
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(EventIds.MigrationTestConnectFailed, ex, "TryMigrate could not connect to database.");
                throw;
            }
        }
コード例 #2
0
 public ShowRepository(
     ILogger <ShowRepository> logger,
     ShowContext showContext)
 {
     _logger      = logger;
     _showContext = showContext;
 }
コード例 #3
0
ファイル: TabContentImpl.cs プロジェクト: ctguxp/dnSpy
        void ShowInternal(IFileTabContent tabContent, object serializedUI, Action <ShowTabContentEventArgs> onShownHandler, bool isRefresh)
        {
            Debug.Assert(asyncWorkerContext == null);
            var oldUIContext = UIContext;

            UIContext = tabContent.CreateUIContext(fileTabUIContextLocator);
            var cachedUIContext = UIContext;

            Debug.Assert(cachedUIContext.FileTab == null || cachedUIContext.FileTab == this);
            cachedUIContext.FileTab = this;
            Debug.Assert(cachedUIContext.FileTab == this);
            Debug.Assert(tabContent.FileTab == null || tabContent.FileTab == this);
            tabContent.FileTab = this;
            Debug.Assert(tabContent.FileTab == this);

            UpdateTitleAndToolTip();
            var showCtx = new ShowContext(cachedUIContext, isRefresh);

            tabContent.OnShow(showCtx);
            bool asyncShow       = false;
            var  asyncTabContent = tabContent as IAsyncFileTabContent;

            if (asyncTabContent != null)
            {
                if (asyncTabContent.CanStartAsyncWorker(showCtx))
                {
                    asyncShow = true;
                    var ctx = new AsyncWorkerContext();
                    asyncWorkerContext = ctx;
                    Task.Factory.StartNew(() => {
                        AppCulture.InitializeCulture();
                        asyncTabContent.AsyncWorker(showCtx, ctx.CancellationTokenSource);
                    }, ctx.CancellationTokenSource.Token)
                    .ContinueWith(t => {
                        bool canShowAsyncOutput = ctx == asyncWorkerContext &&
                                                  cachedUIContext.FileTab == this &&
                                                  UIContext == cachedUIContext;
                        if (asyncWorkerContext == ctx)
                        {
                            asyncWorkerContext = null;
                        }
                        ctx.Dispose();
                        asyncTabContent.EndAsyncShow(showCtx, new AsyncShowResult(t, canShowAsyncOutput));
                        bool success = !t.IsFaulted && !t.IsCanceled;
                        OnShown(serializedUI, onShownHandler, showCtx, success);
                    }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
                }
                else
                {
                    asyncTabContent.EndAsyncShow(showCtx, new AsyncShowResult());
                }
            }
            if (!asyncShow)
            {
                OnShown(serializedUI, onShownHandler, showCtx, true);
            }
            fileTabManager.OnNewTabContentShown(this);
        }
コード例 #4
0
        public async Task TryMigrate(ShowContext context)
        {
            using (context)
            {
                await TryConnect(context);

                await TryRunMigration(context);
            }
        }
コード例 #5
0
 public void Configure(IApplicationBuilder app, IHostingEnvironment env, ShowContext context)
 {
     if (env.IsDevelopment())
     {
         app.UseDeveloperExceptionPage();
     }
     context.Database.EnsureCreated();
     app.UseMvc();
 }
コード例 #6
0
 //admin related tasks
 public void add(string name, double price)
 {
     using (var db = new ShowContext()) {
         Show s = new Show {
             Name = name, Price = price
         };
         db.Shows.Add(s);
         showsList.Add(s);
         db.SaveChanges();
     }
 }
コード例 #7
0
        void ShowInternal(DocumentTabContent tabContent, object uiState, Action <ShowTabContentEventArgs> onShownHandler, bool isRefresh)
        {
            Debug.Assert(asyncWorkerContext == null);
            UIContext = tabContent.CreateUIContext(documentTabUIContextLocator);
            var cachedUIContext = UIContext;

            Debug.Assert(cachedUIContext.DocumentTab == null || cachedUIContext.DocumentTab == this);
            cachedUIContext.DocumentTab = this;
            Debug.Assert(cachedUIContext.DocumentTab == this);
            Debug.Assert(tabContent.DocumentTab == null || tabContent.DocumentTab == this);
            tabContent.DocumentTab = this;
            Debug.Assert(tabContent.DocumentTab == this);

            UpdateTitleAndToolTip();
            DnSpyEventSource.Log.ShowDocumentTabContentStart();
            var showCtx = new ShowContext(cachedUIContext, isRefresh);

            tabContent.OnShow(showCtx);
            bool asyncShow = false;

            if (tabContent is AsyncDocumentTabContent asyncTabContent)
            {
                if (asyncTabContent.NeedAsyncWork(showCtx))
                {
                    asyncShow = true;
                    var ctx = new AsyncWorkerContext();
                    asyncWorkerContext = ctx;
                    var asyncShowCtx = new AsyncShowContext(showCtx, ctx);
                    Task.Run(() => asyncTabContent.CreateContentAsync(asyncShowCtx), ctx.CancellationToken)
                    .ContinueWith(t => {
                        bool canShowAsyncOutput = ctx == asyncWorkerContext &&
                                                  cachedUIContext.DocumentTab == this &&
                                                  UIContext == cachedUIContext;
                        if (asyncWorkerContext == ctx)
                        {
                            asyncWorkerContext = null;
                        }
                        ctx.Dispose();
                        asyncTabContent.OnShowAsync(showCtx, new AsyncShowResult(t, canShowAsyncOutput));
                        bool success = !t.IsFaulted && !t.IsCanceled;
                        OnShown(uiState, onShownHandler, showCtx, success ? ShowTabContentResult.ShowedContent : ShowTabContentResult.Failed);
                    }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
                }
                else
                {
                    asyncTabContent.OnShowAsync(showCtx, new AsyncShowResult());
                }
            }
            if (!asyncShow)
            {
                OnShown(uiState, onShownHandler, showCtx, ShowTabContentResult.ShowedContent);
            }
            documentTabService.OnNewTabContentShown(this);
        }
コード例 #8
0
        public Controller()
        {
            var db = new ShowContext();

            showsList = db.Shows.ToList();
            obs       = new List <IObserver <AvailableShow> >();
            obsSeats  = new List <IObserver <Seat> >();
            clients   = new List <Client>();
            avShow    = new Show();
            customers = new Dictionary <Tuple <string, string>, List <Seat> >();
            reserved  = new List <Seat>();
        }
コード例 #9
0
 private async Task TryRunMigration(ShowContext context)
 {
     try
     {
         await context.Database.MigrateAsync();
     }
     catch (Exception ex)
     {
         // Ignored
         _logger.LogError(EventIds.MigrationFailed, ex, "Migration failed to run: {message}", ex.Message);
     }
 }
コード例 #10
0
        public ActionResult Index()
        {
            using (var context = new ShowContext("GameShow"))
            {
                var result = context;
                //context.SaveChanges();
            }
            IndexVM vm = new IndexVM();

            vm.GameState  = gameState;
            vm.Briefcases = repo.All().ToList();
            return(View(vm));
        }
コード例 #11
0
        public void Initialize()
        {
            var options = new DbContextOptionsBuilder <ShowContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            this.context        = new ShowContext(options);
            this.showRepoLogger = new DebugLogger <ShowRepository>();
            var showRepo = new ShowRepository(this.showRepoLogger, this.context);

            var svclogger = new DebugLogger <ShowService>();

            this.showService = new ShowService(showRepo, svclogger, new MockMessageHub());
        }
コード例 #12
0
        public void Initialize()
        {
            // var connstr = ConfigurationManager.ConnectionStrings["ShowConnection"].ConnectionString;
            var connstr = @"Server=.\sqlexpress;Database=tvmaze;Trusted_Connection=True;Connection Timeout=30;Application Name=TvMazeScraperTest";
            var options = new DbContextOptionsBuilder <ShowContext>()
                          .UseSqlServer(connstr)
                          .Options;
            var context = new ShowContext(options);

            var repologger = new DebugLogger <ShowRepository>();
            var showRepo   = new ShowRepository(repologger, context);

            this.showServiceLogger = new DebugLogger <ShowService>();
            this.showService       = new ShowService(showRepo, this.showServiceLogger, new MockMessageHub());
        }
コード例 #13
0
        private List <ShowWithCast> ShowsWithCasts(PagingParameterModel pagingparametermodel)
        {
            List <ShowWithCast> results = new List <ShowWithCast>();

            try
            {
                _ShowCastcontext = new ShowCastContext();
                _Showcontext     = new ShowContext();
                _Castcontext     = new CastContext();
                var shows = from sh in _Showcontext.Show
                            select sh;
                int ii        = shows.Count();
                var showsList = shows.Skip((pagingparametermodel.pageNumber - 1) * pagingparametermodel.pageSize).Take(pagingparametermodel.pageSize).ToList();

                foreach (Show s in showsList)
                {
                    ShowWithCast sc = new ShowWithCast();
                    sc.ShowID = s.ShowID;
                    sc.Name   = s.ShowName;

                    var showPairs = from sp in _ShowCastcontext.ShowCast
                                    where sp.ShowID == s.ShowID
                                    select sp;

                    sc.Cast = new List <Cast>();

                    foreach (ShowCast item in showPairs)
                    {
                        var casts = from cst in _Castcontext.Cast
                                    where cst.CastID == item.CastID
                                    select cst;

                        foreach (Cast aCast in casts)
                        {
                            sc.Cast.Add(aCast);
                        }
                    }
                    sc.Cast = sc.Cast.OrderByDescending(x => x.BirthDay).ToList();
                    results.Add(sc);
                }
            }
            catch (Exception ex)
            {
                string er = ex.ToString();
            }
            return(results);
        }
コード例 #14
0
        public async Task <JsonResult> ScrapeShowsAndPersistData()
        {
            _ShowCastcontext = new ShowCastContext();
            _Showcontext     = new ShowContext();
            _Castcontext     = new CastContext();
            //Clears existing data in the database first:
            _Showcontext.Database.ExecuteSqlCommand("TRUNCATE TABLE [Show]");

            string url = "http://api.tvmaze.com/shows";
            List <ShowWithCast> jSonResult = new List <ShowWithCast>();

            try
            {
                _Showcontext = new ShowContext();
                var showName = from sn in _Showcontext.Show
                               select sn;


                using (var client = new HttpClient())
                {
                    using (var r = await client.GetAsync(new Uri(url)))
                    {
                        string JsonStr = await r.Content.ReadAsStringAsync();

                        var result = JsonConvert.DeserializeObject <List <ShowFull> >(JsonStr);

                        foreach (ShowFull fliek in result)
                        {
                            Show aShow = new Show();
                            aShow.ShowID   = fliek.id;
                            aShow.ShowName = fliek.name;
                            _Showcontext.Add(aShow);
                            await _Showcontext.SaveChangesAsync();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string error = ex.ToString();
            }
            var shows = from sctx in _Showcontext.Show
                        select sctx;

            return(await Task.FromResult(Json(shows)));
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: shtik/Shows
        static void Main(string[] args)
        {
            var connectionString = args.Length == 1
                ? args[0]
                : DesignTimeShowContextFactory.LocalPostgres;

            var options = new DbContextOptionsBuilder <ShowContext>()
                          .UseNpgsql(connectionString, b => b.MigrationsAssembly(DesignTimeShowContextFactory.MigrationAssemblyName))
                          .Options;

            var context = new ShowContext(options);

            var loggerFactory = new LoggerFactory().AddConsole();

            var migrationHelper = new MigrationHelper(loggerFactory);

            Console.WriteLine("Trying migration...");
            migrationHelper.TryMigrate(context).GetAwaiter().GetResult();
            Console.WriteLine("Done.");
        }
コード例 #16
0
 public void delete(string name, double price)
 {
     using (var db = new ShowContext()) {
         Show s = new Show {
             Name = name, Price = price
         };
         var oldShow = from b in db.Shows
                       where b.Name == name
                       select b;
         if (avShow.ShowID != oldShow.First().ShowID)
         {
             db.Shows.Remove((Show)oldShow.First());
             db.SaveChanges();
             showsList = db.Shows.ToList();
         }
         else
         {
             MessageBox.Show("Cannot delete the current available show.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
コード例 #17
0
 public MoviesController(ShowContext context)
 {
     _context = context;
 }
コード例 #18
0
ファイル: ViewService.cs プロジェクト: zaharvsb52/MyWmsPro
 void IViewService.Show(string command, ShowContext context)
 {
     throw new NotImplementedException();
 }
コード例 #19
0
ファイル: ViewService.cs プロジェクト: zaharvsb52/MyWmsPro
 void IViewService.Show(IViewModel viewModel, ShowContext context, ref IViewModel currentViewModel)
 {
     throw new NotImplementedException();
 }
コード例 #20
0
        static void Main(string[] args)
        {
            using (var context = new ShowContext())
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                var Show1 = new Show
                {
                    Name      = "Lions Show",
                    StartDate = DateTime.Now,
                    EndDate   = DateTime.Now.AddDays(30)
                };
                var Show2 = new Show
                {
                    Name      = "Elephants Show",
                    StartDate = DateTime.Now,
                    EndDate   = DateTime.Now.AddDays(30)
                };
                var Show3 = new Show
                {
                    Name      = "Monkeys Show",
                    StartDate = DateTime.Now.AddDays(15),
                    EndDate   = DateTime.Now.AddDays(45)
                };
                var Show4 = new Show
                {
                    Name      = "Parrots Show",
                    StartDate = DateTime.Now.AddDays(15),
                    EndDate   = DateTime.Now.AddDays(45)
                };
                var Show5 = new Show
                {
                    Name      = "Acrobats Show",
                    StartDate = DateTime.Now.AddDays(30),
                    EndDate   = DateTime.Now.AddDays(60)
                };
                var Show6 = new Show
                {
                    Name      = "Jugglers Show",
                    StartDate = DateTime.Now.AddDays(30),
                    EndDate   = DateTime.Now.AddDays(60)
                };

                List <Show> showList = new List <Show>();
                showList.Add(Show1);
                showList.Add(Show2);
                showList.Add(Show3);
                showList.Add(Show4);
                showList.Add(Show5);
                showList.Add(Show6);

                List <Room> roomList = GenerateRoom(2);
                context.AddRange(roomList);

                List <Person> personList  = new List <Person>();
                var           manyPersons = (from i in Enumerable.Range(0, 3)
                                             select new Person {
                    Name = "Bob" + i, Password = "******"
                }).ToList();
                personList.AddRange(manyPersons);

                var manyPersons2 = (from i in Enumerable.Range(0, 3)
                                    select new Person {
                    Name = "Emy" + i, Password = "******"
                }).ToList();
                personList.AddRange(manyPersons2);
                context.AddRange(personList);

                List <Presentation> presList = new List <Presentation>();
                for (int i = 0; i < showList.Count(); i++)
                {
                    if (i % 2 == 0)
                    {
                        showList[i].Presentations = GeneratePresentation(showList[i], 6, roomList[0]);
                        presList.AddRange(showList[i].Presentations);
                    }
                    else
                    {
                        showList[i].Presentations = GeneratePresentation(showList[i], 6, roomList[1]);
                        presList.AddRange(showList[i].Presentations);
                    }
                }

                Random random = new Random();

                List <Order> orderList = new List <Order>();
                foreach (Person person in personList)
                {
                    int          numberRdm  = random.Next(0, 35);
                    int          numberRdm2 = random.Next(1, 5);
                    List <Order> orderList1 = GenerateOrder(person, 6, numberRdm2);
                    orderList.AddRange(orderList1);
                }

                for (int i = 0; i < orderList.Count; i++)
                {
                    orderList[i].Presentation = presList[i];
                }
                context.AddRange(orderList);

                for (int i = 0; i < presList.Count; i++)
                {
                    presList[i].Orders.Add(orderList[i]);
                }
                context.AddRange(presList);

                context.AddRange(showList);
                context.SaveChanges();
            }
        }
コード例 #21
0
ファイル: TabContentImpl.cs プロジェクト: yueding/dnSpy
        void ShowInternal(IFileTabContent tabContent, object serializedUI, Action<ShowTabContentEventArgs> onShownHandler, bool isRefresh)
        {
            Debug.Assert(asyncWorkerContext == null);
            var oldUIContext = UIContext;
            UIContext = tabContent.CreateUIContext(fileTabUIContextLocator);
            var cachedUIContext = UIContext;
            Debug.Assert(cachedUIContext.FileTab == null || cachedUIContext.FileTab == this);
            cachedUIContext.FileTab = this;
            Debug.Assert(cachedUIContext.FileTab == this);
            Debug.Assert(tabContent.FileTab == null || tabContent.FileTab == this);
            tabContent.FileTab = this;
            Debug.Assert(tabContent.FileTab == this);

            UpdateTitleAndToolTip();
            var showCtx = new ShowContext(cachedUIContext, isRefresh);
            tabContent.OnShow(showCtx);
            bool asyncShow = false;
            var asyncTabContent = tabContent as IAsyncFileTabContent;
            if (asyncTabContent != null) {
                if (asyncTabContent.CanStartAsyncWorker(showCtx)) {
                    asyncShow = true;
                    var ctx = new AsyncWorkerContext();
                    asyncWorkerContext = ctx;
                    Task.Factory.StartNew(() => asyncTabContent.AsyncWorker(showCtx, ctx.CancellationTokenSource), ctx.CancellationTokenSource.Token)
                    .ContinueWith(t => {
                        bool canShowAsyncOutput = ctx == asyncWorkerContext &&
                                                cachedUIContext.FileTab == this &&
                                                UIContext == cachedUIContext;
                        if (asyncWorkerContext == ctx)
                            asyncWorkerContext = null;
                        ctx.Dispose();
                        asyncTabContent.EndAsyncShow(showCtx, new AsyncShowResult(t, canShowAsyncOutput));
                        bool success = !t.IsFaulted && !t.IsCanceled;
                        OnShown(serializedUI, onShownHandler, showCtx, success);
                    }, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
                }
                else
                    asyncTabContent.EndAsyncShow(showCtx, new AsyncShowResult());
            }
            if (!asyncShow)
                OnShown(serializedUI, onShownHandler, showCtx, true);
            fileTabManager.OnNewTabContentShown(this);
        }
コード例 #22
0
ファイル: ShowsController.cs プロジェクト: shtik/Shows
 public ShowsController(ShowContext context, ILogger <ShowsController> logger)
 {
     _context = context;
     _logger  = logger;
 }
コード例 #23
0
 public void Show(FrameworkElement content, ShowContext context)
 {
     throw new NotImplementedException();
 }
コード例 #24
0
 public void Show(IViewModel viewModel, ShowContext context)
 {
     throw new NotImplementedException();
 }
コード例 #25
0
 public void Show(string command, ShowContext context)
 {
     throw new NotImplementedException();
 }
コード例 #26
0
ファイル: FindController.cs プロジェクト: DeckHubApp/Shows
 public FindController(ShowContext context, ILogger <FindController> logger)
 {
     _context = context;
     _logger  = logger;
 }
コード例 #27
0
 public void Show(IView view, ShowContext context)
 {
 }
コード例 #28
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     this.context?.Dispose();
     this.context = null;
 }
コード例 #29
0
ファイル: SlidesController.cs プロジェクト: shtik/Shows
 public SlidesController(ShowContext context, ConnectionMultiplexer redis)
 {
     _context = context;
     _redis   = redis;
 }
コード例 #30
0
 public ShowRepository(ShowContext db)
 {
     this.db = db;
 }
コード例 #31
0
ファイル: TabContentImpl.cs プロジェクト: manojdjoshi/dnSpy
		void ShowInternal(DocumentTabContent tabContent, object uiState, Action<ShowTabContentEventArgs> onShownHandler, bool isRefresh) {
			Debug.Assert(asyncWorkerContext == null);
			UIContext = tabContent.CreateUIContext(documentTabUIContextLocator);
			var cachedUIContext = UIContext;
			Debug.Assert(cachedUIContext.DocumentTab == null || cachedUIContext.DocumentTab == this);
			cachedUIContext.DocumentTab = this;
			Debug.Assert(cachedUIContext.DocumentTab == this);
			Debug.Assert(tabContent.DocumentTab == null || tabContent.DocumentTab == this);
			tabContent.DocumentTab = this;
			Debug.Assert(tabContent.DocumentTab == this);

			UpdateTitleAndToolTip();
			var showCtx = new ShowContext(cachedUIContext, isRefresh);
			tabContent.OnShow(showCtx);
			bool asyncShow = false;
			var asyncTabContent = tabContent as AsyncDocumentTabContent;
			if (asyncTabContent != null) {
				if (asyncTabContent.NeedAsyncWork(showCtx)) {
					asyncShow = true;
					var ctx = new AsyncWorkerContext();
					asyncWorkerContext = ctx;
					var asyncShowCtx = new AsyncShowContext(showCtx, ctx);
					Task.Run(() => asyncTabContent.CreateContentAsync(asyncShowCtx), ctx.CancellationToken)
					.ContinueWith(t => {
						bool canShowAsyncOutput = ctx == asyncWorkerContext &&
												cachedUIContext.DocumentTab == this &&
												UIContext == cachedUIContext;
						if (asyncWorkerContext == ctx)
							asyncWorkerContext = null;
						ctx.Dispose();
						asyncTabContent.OnShowAsync(showCtx, new AsyncShowResult(t, canShowAsyncOutput));
						bool success = !t.IsFaulted && !t.IsCanceled;
						OnShown(uiState, onShownHandler, showCtx, success ? ShowTabContentResult.ShowedContent : ShowTabContentResult.Failed);
					}, CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
				}
				else
					asyncTabContent.OnShowAsync(showCtx, new AsyncShowResult());
			}
			if (!asyncShow)
				OnShown(uiState, onShownHandler, showCtx, ShowTabContentResult.ShowedContent);
			documentTabService.OnNewTabContentShown(this);
		}
コード例 #32
0
 public TorrentAPIRepository(ShowContext context)
 {
     _context = context;
 }