Esempio n. 1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            Database.SetInitializer(new MigrationInitializer());

            WebSocketBlockStream stream = new WebSocketBlockStream(new Uri(ConfigurationManager.AppSettings["endPoint"]));

            if (stream != null)
            {
                runningTasks.Add(stream.ProcessRequest(HttpContext.Current));
            }

            CancellationTokenSource tokenSource = new CancellationTokenSource();
            DateTime startTime = RoundCurrentToNextFiveMinutes();

            Task timerTask = RunPeriodically(
                startTime, TimeSpan.FromMinutes(10), tokenSource.Token);

            runningTasks.Add(builder.CompleteBlockAdding(CancellationToken.None));

            Task.WaitAll(runningTasks.ToArray(), tokenSource.Token);
        }
Esempio n. 2
0
        public async Task <JsonResult <IEnumerable <Block> > > GetGlobalChain()
        {
            var context = HttpContext.Current;
            var stream  = new WebSocketBlockStream(context.Request.Url);
            await stream.ProcessRequest(context);

            connector.ChainReplace(connector.GetLocalChain(),
                                   new Chain(stream.GlobalChain.ToList()));
            return(Json(stream.GlobalChain));
        }