Example #1
0
        public ActionResult Status()
        {
            try {
                if (_cacheClient.Get <string>("__PING__") != null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable, "Cache Not Working"));
                }
            } catch (Exception ex) {
                return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable, "Cache Not Working: " + ex.Message));
            }

            try {
                if (!GlobalApplication.IsDbUpToDate())
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable, "Mongo DB Schema Outdated"));
                }

                var numberOfUsers = _userRepository.Count();
            } catch (Exception ex) {
                return(new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable, "Mongo Not Working: " + ex.Message));
            }

            //if (!_notificationSender.IsListening())
            //    return new HttpStatusCodeResult(HttpStatusCode.ServiceUnavailable, "Ping Not Received");

            return(new ContentResult {
                Content = "All Systems Check"
            });
        }
        public void OnEnd_Should_Log_Warning()
        {
            log.Expect(l => l.Warning(It.IsAny <string>())).Verifiable();

            GlobalApplication.OnEnd();

            log.Verify();
        }
Example #3
0
 public GlobalApplication()
 {
     instance = this;
     container = new WindsorContainer(
         new XmlInterpreter(new ConfigResource())
     );
     logger = CreateLogger(GetType());
 }
Example #4
0
File: Startup.cs Project: ntzw/cms
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            var moduleInitializers = app.ApplicationServices.GetServices <IModuleInitializer>();

            foreach (var moduleInitializer in moduleInitializers)
            {
                moduleInitializer.Configure(app, env);
            }

            GlobalApplication.Inject(app);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseStatusCodePagesWithReExecute("/Error", "?code={0}");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }


            //app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();
            app.UseSession();
            app.UseAuthorization();

            app.Use(async(content, next) =>
            {
                var host = content.Request.Host.Value;

                var currentSite = SessionHelper.Get <Site>("CurrentSite");
                if (currentSite == null)
                {
                    var siteService = app.ApplicationServices.GetService <ISiteService>();
                    var site        = await siteService.GetByHost(host) ?? await siteService.GetByDefault();

                    site.IsMobileSite = site.IsEnableMobileSite && site.MobileHost.IsNotEmpty() && site.MobileHost
                                        .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList()
                                        .Exists(temp => string.Equals(temp, host));

                    SessionHelper.Set("CurrentSite", site);
                }

                await next();
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Content}/{action=Index}/{id?}");
            });
        }
        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterInstance(Container);
            modulesManager = new ModulesManager();
            var mainThread = new MainThread();

            GlobalApplication.InitializeApplication(mainThread, GlobalApplication.AppBackend.Avalonia);
            containerRegistry.RegisterInstance <IMainThread>(mainThread);
            containerRegistry.RegisterInstance(modulesManager);
        }
 /**
  * 프로필 이미지에 대해 view를 update한다.
  *
  * @param profileImageURL 화면에 반영할 프로필 이미지
  */
 public void SetProfileURL(string profileImageURL)
 {
     if (profile != null && profileImageURL != null)
     {
         Application app = GlobalApplication.GetGlobalApplicationContext();
         if (app == null)
         {
             throw new UnsupportedOperationException("needs com.kakao.GlobalApplication in order to use ImageLoader");
         }
         profile.SetImageUrl(profileImageURL, ((GlobalApplication)app).GetImageLoader());
     }
 }
 public void SetBgImageURL(string bgImageURL)
 {
     if (bgImageURL != null)
     {
         Application app = GlobalApplication.GetGlobalApplicationContext();
         if (app == null)
         {
             throw new UnsupportedOperationException("needs com.kakao.GlobalApplication in order to use ImageLoader");
         }
         background.SetImageUrl(bgImageURL, ((GlobalApplication)app).GetImageLoader());
     }
 }
Example #8
0
        public void CanMatchUsingRouteEvaluator()
        {
            var routes = new RouteCollection();

            GlobalApplication.RegisterRoutes(routes);

            var evaluator         = new RouteEvaluator(routes);
            var matchingRouteData = evaluator.GetMatches("~/foo/bar");

            Assert.True(matchingRouteData.Count > 0);
            matchingRouteData = evaluator.GetMatches("~/foo/bar/baz/quux/yadda/billy");
            Assert.Equal(0, matchingRouteData.Count);
        }
        private void LogAuthError(Exception e)
        {
            if (e == null)
            {
                return;
            }
            if (e.Message.Contains("Unable to fetch from"))
            {
                //return;
            }

            GlobalApplication.LogException(e);
        }
Example #10
0
            /// <summary>
            /// 将主程序的TimeSpan属性与指定的TimeSpan值进行比较,并将主程序的TimeSpan扩展为二者的并集的大区间
            /// </summary>
            /// <param name="ComparedDateSpan">要与主程序的TimeSpan进行比较的TimeSpan值</param>
            /// <remarks></remarks>
            public void refreshGlobalDateSpan(DateSpan ComparedDateSpan)
            {
                GlobalApplication with_1 = this;

                if (!blnTimeSpanInitialized)
                {
                    with_1.F_DateSpan      = ComparedDateSpan;
                    blnTimeSpanInitialized = true;
                }
                else
                {
                    with_1.F_DateSpan = GeneralMethods.ExpandDateSpan(with_1.DateSpan, ComparedDateSpan);
                }
            }
Example #11
0
        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterInstance(Container);
            var vfs                 = new VirtualFileSystem();
            var fs                  = new FileSystem(vfs);
            var userSettings        = new UserSettings(fs, new DummyStatusBar());
            var currentCoreSettings = new CurrentCoreSettings(userSettings);

            modulesManager = new ModulesManager(currentCoreSettings);
            var mainThread = new MainThread();

            GlobalApplication.InitializeApplication(mainThread, GlobalApplication.AppBackend.Avalonia);
            containerRegistry.RegisterInstance <IMainThread>(mainThread);
            containerRegistry.RegisterInstance(modulesManager);
        }
Example #12
0
        public void CanMatchRouteTheShortWay()
        {
            // Arrange
            var routes = new RouteCollection();

            GlobalApplication.RegisterRoutes(routes);
            var context = RoutingMockHelpers.FakeHttpContext("~/foo/bar");

            // Act
            var routeData = routes.GetRouteData(context);

            // Assert
            Assert.Equal("bar", routeData.Values["id"]);
            Assert.Equal("Test", routeData.Values["controller"]);
            Assert.Equal("Index", routeData.Values["action"]);
            Assert.Equal("foo-route", routeData.DataTokens["routeName"]);
        }
Example #13
0
        public void CanMatchRouteTheLongWay()
        {
            // Arrange
            var routes = new RouteCollection();

            GlobalApplication.RegisterRoutes(routes);

            var contextMock = new Mock <HttpContextBase>();
            var requestMock = new Mock <HttpRequestBase>();

            contextMock.Setup(ctx => ctx.Request).Returns(requestMock.Object);
            requestMock.Setup(req => req.PathInfo).Returns(string.Empty);
            requestMock.Setup(req => req.AppRelativeCurrentExecutionFilePath).Returns("~/foo/bar");

            // Act
            var routeData = routes.GetRouteData(contextMock.Object);

            // Assert
            Assert.Equal("bar", routeData.Values["id"]);
            Assert.Equal("Test", routeData.Values["controller"]);
            Assert.Equal("Index", routeData.Values["action"]);
            Assert.Equal("foo-route", routeData.DataTokens["routeName"]);
        }
Example #14
0
 public void Init(GlobalApplication context, XmlNode node)
 {
     context.UserSearchWord += new UserSearchEventHandler(context_UserSearchWord);
 }
 public void Init(GlobalApplication context, XmlNode node)
 {
     context.PostUserUpdate += new UserEventHandler(context_PostUserUpdate);
     context.UserValidated  += new UserEventHandler(context_UserValidated);
 }
        private ActionResult FetchFromGoogle(string accessToken)
        {
            string    result        = null;
            Exception lastException = null;

            for (var retry = 0; retry < GoogleAuthRetryAttempts; retry++)
            {
                try
                {
                    var url = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + accessToken;
                    using (var wc = new WebClient())
                    {
                        result = wc.DownloadString(url);
                        if (result.HasValue())
                        {
                            break;
                        }
                    }
                }
                catch (WebException e)
                {
                    using (var reader = new StreamReader(e.Response.GetResponseStream()))
                    {
                        var text = reader.ReadToEnd();
                        LogAuthError(new Exception("Error fetching from google: " + text));
                    }
                    continue;
                }
                catch (Exception e)
                {
                    lastException = e;
                }
                if (retry == GoogleAuthRetryAttempts - 1)
                {
                    LogAuthError(lastException);
                }
            }

            if (result.IsNullOrEmpty() || result == "false")
            {
                return(LoginError("Error accessing Google account"));
            }

            try
            {
                var person = JsonConvert.DeserializeObject <GooglePerson>(result);

                if (person == null)
                {
                    return(LoginError("Error fetching user from Google"));
                }
                if (person.email == null)
                {
                    return(LoginError("Error fetching email from Google"));
                }

                return(LoginViaEmail(person.email, person.name, "/"));
            }
            catch (Exception e)
            {
                GlobalApplication.LogException(new Exception("Error in parsing google response: " + result, e));
                return(LoginError("There was an error fetching your account from Google.  Please try logging in again"));
            }
        }
Example #17
0
        public ActionResult ErrorTestPage()
        {
            GlobalApplication.LogException(new Exception("Test Exception via GlobalApplication.LogException()"));

            throw new NotImplementedException("I AM IMPLEMENTED, I WAS BORN TO THROW ERRORS!");
        }
Example #18
0
            /// <summary>
            /// 构造函数
            /// </summary>
            /// <remarks></remarks>
            public APPLICATION_MAINFORM()
            {
                // This call is required by the designer.
                InitializeComponent();

                //Added to support default instance behavour in C#
                if (m_uniqueInstance == null)
                {
                    m_uniqueInstance = this;
                }
                // Add any initialization after the InitializeComponent() call.
                //----------------------------
                GlbApp = new GlobalApplication();
                //为关键字段赋初始值()
                F_main_Form = this;
                //----------------------------
                MainUI_ProjectNotOpened();
                //获取与文件或文件夹路径有关的数据
                GetPath();
                //----------------------------
                //创建新窗口,窗口在创建时默认是不隐藏的。
                frmSectionView                      = new frmDrawElevation();
                frmSectionView.FormClosing         += frmSectionView.frmDrawSectionalView_FormClosing;
                frmSectionView.Disposed            += frmSectionView.frmDrawElevation_Disposed;
                frmMnt_Incline                      = new frmDrawing_Mnt_Incline();
                frmMnt_Incline.FormClosing         += frmMnt_Incline.frmDrawing_Mnt_Incline_FormClosing;
                frmMnt_Incline.Disposed            += frmMnt_Incline.frmDrawing_Mnt_Incline_Disposed;
                frmMnt_Incline.DataWorkbookChanged += frmMnt_Incline.frmDrawing_Mnt_Incline_DataWorkbookChanged;
                frmMnt_Incline.Activated           += frmMnt_Incline.frmDrawing_Mnt_Incline_Activated;
                frmMnt_Incline.Deactivate          += frmMnt_Incline.frmDrawing_Mnt_Incline_Deactivate;
                frmMnt_Others                      = new frmDrawing_Mnt_Others();
                frmMnt_Others.Load                += frmMnt_Others.frmDrawingMonitor_Load;
                frmMnt_Others.FormClosing         += frmMnt_Others.frmDrawing_Mnt_Others_FormClosing;
                frmMnt_Others.Disposed            += frmMnt_Others.frmDrawing_Mnt_Others_Disposed;
                frmMnt_Others.DataWorkbookChanged += frmMnt_Others.frmDrawing_Mnt_Incline_DataWorkbookChanged;
                frmMnt_Others.Activated           += frmMnt_Others.frmDrawing_Mnt_Incline_Activated;
                frmMnt_Others.Deactivate          += frmMnt_Others.frmDrawing_Mnt_Incline_Deactivate;
                frmRolling = new frmRolling();

                // ----------------------- 设置MDI窗体的背景
                foreach (Control C in Controls)
                {
                    if (string.Compare(C.GetType().ToString(), "System.Windows.Forms.MdiClient", true) == 0)
                    {
                        MdiClient MDIC = (MdiClient)C;
                        MDIC.BackgroundImage       = Resources.线条背景;
                        MDIC.BackgroundImageLayout = ImageLayout.Tile;
                        break;
                    }
                }
                // ----------------------- 设置主程序窗口启动时的状态
                APPLICATION_MAINFORM with_2     = this;
                mySettings_UI        mysettings = new mySettings_UI();
                FormWindowState      winState   = mysettings.WindowState;

                switch (winState)
                {
                case FormWindowState.Maximized:
                    with_2.WindowState = winState;
                    break;

                case FormWindowState.Minimized:
                    with_2.WindowState = FormWindowState.Normal;
                    break;

                case FormWindowState.Normal:
                    with_2.WindowState = winState;
                    with_2.Location    = mysettings.WindowLocation;
                    with_2.Size        = mysettings.WindowSize;
                    break;
                }
                //在新线程中进行程序的一些属性的初始值的设置
                Thread thd = new Thread(new ThreadStart(myDefaltSettings));

                thd.Name = "程序的一些属性的初始值的设置";
                thd.Start();
            }
Example #19
0
 public GlobalApplication()
 {
     //设置一个初始值blnTimeSpanInitialized,说明MainForm.TimeSpan还没有被初始化过,后期应该先对其赋值以进行初始化,然后再进行比较
     this.blnTimeSpanInitialized     = false;
     GlobalApplication.F_Application = this;
 }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            StringBuilder sbText   = new StringBuilder();
            Assembly      assembly = Assembly.GetEntryAssembly();

            if (assembly != null)
            {
                object[] attributes = assembly.GetCustomAttributes(false);
                foreach (object attribute in attributes)
                {
                    Type type = attribute.GetType();
                    if (type == typeof(AssemblyTitleAttribute))
                    {
                        AssemblyTitleAttribute title = (AssemblyTitleAttribute)attribute;
                        lblText.Content = title.Title;
                    }
                    if (type == typeof(AssemblyFileVersionAttribute))
                    {
                        AssemblyFileVersionAttribute version = (AssemblyFileVersionAttribute)attribute;
                        //labelAssemblyVersion.Content = version.Version;
                    }
                    if (type == typeof(AssemblyCopyrightAttribute))
                    {
                        AssemblyCopyrightAttribute copyright = (AssemblyCopyrightAttribute)attribute;
                        sbText.AppendFormat("{0}\r", copyright.Copyright);
                    }
                    if (type == typeof(AssemblyCompanyAttribute))
                    {
                        AssemblyCompanyAttribute company = (AssemblyCompanyAttribute)attribute;
                        sbText.AppendFormat("{0}\r", company.Company);
                    }
                    if (type == typeof(AssemblyDescriptionAttribute))
                    {
                        AssemblyDescriptionAttribute description = (AssemblyDescriptionAttribute)attribute;
                        sbText.AppendFormat("{0}\r", description.Description);
                    }
                }
                //labelAssembly.Content = sbText.ToString();
            }

            string path = GlobalApplication.getResourcePath("Web") + @"Desktop\WaitingList.xsl";

            string TEXT =
                @"<log4net>
  <appender name=""RollingFileAppender"" type=""log4net.Appender.RollingFileAppender"">
    <file type=""log4net.Util.PatternString"" value=""c:\log\log.xml"" />
    <appendToFile value=""true"" />
    <datePattern value=""yyyyMMdd"" />
    <rollingStyle value=""Date"" />
    <layout type=""log4net.Layout.XmlLayoutSchemaLog4j"">
      <locationInfo value=""true"" />
    </layout>
  </appender>
  <root>
    <level value=""DEBUG"" />
    <appender-ref ref=""RollingFileAppender"" />
  </root>
</log4net>";

            this.RichTextBox1.AppendText(TEXT);
        }
 public void OnStart_Should_Not_Throw_Exception()
 {
     GlobalApplication.OnStart();
 }