protected void Page_Load(object sender, EventArgs e)
        {
            // Get PageFlowService.
            IPageFlowService pageFlowService = BundleRuntime.Instance.GetFirstOrDefaultService <IPageFlowService>();

            if (pageFlowService == null)
            {
                throw new ServiceNotAvailableException(typeof(IPageFlowService).FullName, Properties.Resources.IOpenWorksWebShellName);
            }

            if (string.IsNullOrEmpty(pageFlowService.FirstPageNodeValue))
            {
                throw new Exception(Properties.Resources.CanNotFindAnAvailablePageNode);
            }
            // Redirect to first node.
            Response.Redirect(pageFlowService.FirstPageNodeValue);
        }
Exemple #2
0
        private static void RunApplication()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            const string PAGE_NAME_LOGIN = "******";

            FileLogUtility.SetFileLogEnabled(true);
            FileLogUtility.SetLogFileName("log.txt");
            FileLogUtility.SetLogLevel(LogLevel);
            FileLogUtility.SetMaxFileSizeByMB(MaxLogFileSize);
            FileLogUtility.SetCreateNewFileOnMaxSize(CreateNewLogFileOnMaxSize);

            using (BundleRuntime bundleRuntime = new BundleRuntime())
            {
                bundleRuntime.Start();

                // Get the page flow service.
                IPageFlowService pageFlowService = bundleRuntime.GetFirstOrDefaultService <IPageFlowService>();

                if (pageFlowService == null)
                {
                    throw new Exception(Resources.IPageFlowServiceServiceNotFound);
                }

                // Assert the first page node.
                if (string.IsNullOrEmpty(pageFlowService.FirstPageNodeValue) ||
                    string.IsNullOrEmpty(pageFlowService.FirstPageNodeName) ||
                    pageFlowService.FirstPageNodeOwner == null)
                {
                    throw new Exception(Resources.CanNotFindAnAvailablePageNode);
                }

                // Load the form type of first page node.
                Type formType = pageFlowService.FirstPageNodeOwner.LoadClass(pageFlowService.FirstPageNodeValue);
                if (formType == null)
                {
                    throw new Exception(string.Format(Resources.CanNotLoadTypeFromBundle, pageFlowService.FirstPageNodeValue, pageFlowService.FirstPageNodeOwner.SymbolicName));
                }

                // Create the form instance of first page node and show it.
                Form formInstance = System.Activator.CreateInstance(formType) as Form;

                if (formInstance == null)
                {
                    throw new Exception(string.Format(Resources.TypeIsNotWindowsFormType, pageFlowService.FirstPageNodeValue, pageFlowService.FirstPageNodeOwner.SymbolicName));
                }

                // If first page node name is 'Login' then, show the dialog and then run application.
                if (pageFlowService.FirstPageNodeName.Equals(PAGE_NAME_LOGIN))
                {
                    DialogResult result = formInstance.ShowDialog();
                    if (result == DialogResult.OK || result == DialogResult.Yes)
                    {
                        PageNode nextNode = pageFlowService.GetNextPageNode(pageFlowService.FirstPageNodeName);
                        if (nextNode != null)
                        {
                            Type mainPageFormType = nextNode.Bundle.LoadClass(nextNode.Value);
                            if (mainPageFormType == null)
                            {
                                throw new Exception(string.Format(Resources.CanNotLoadTypeFromBundle, nextNode.Value, nextNode.Bundle.SymbolicName));
                            }
                            Form mainPageForm = System.Activator.CreateInstance(mainPageFormType) as Form;
                            Application.Run(mainPageForm);
                        }
                    }
                }
                else // Run the application directly.
                {
                    Application.Run(formInstance);
                }
            }
        }