Esempio n. 1
0
 public ModuleHttpContext(HttpContext httpContext, HttpRequestBase httpRequest, HttpResponseBase httpResponse, ModuleContext moduleContext)
     : base(httpContext)
 {
     this._httpRequest = httpRequest;
     this._httpResponse = httpResponse;
     this.ModuleContext = moduleContext;
 }
Esempio n. 2
0
        public void OnIncluded(ModuleContext moduleContext)
        {
            // Add code here that will be executed when the module was included to the site.

            // API access to the local or public file path
            // var privatedatafolder = new ModulePathHelper(ModuleAreaRegistration.ModuleName, site).GetModuleLocalFilePath();
        }
Esempio n. 3
0
        public ModuleHttpRequest(HttpRequest httpRequest, string moduleUrl, ModuleContext moduleContext, ControllerContext pageControllerContext)
            : base(httpRequest)
        {
            this.appRelativeCurrentExecutionFilePath = moduleUrl;
            int queryStringIndex = moduleUrl.IndexOf('?');
            if (queryStringIndex != -1)
            {
                this.appRelativeCurrentExecutionFilePath = moduleUrl.Substring(0, queryStringIndex);
                if (queryStringIndex < moduleUrl.Length - 1)
                {
                    this.queryString = new HttpValueCollection(moduleUrl.Substring(queryStringIndex + 1), true, false, Encoding.UTF8);
                }
            }
            this.absolutePath = this.appRelativeCurrentExecutionFilePath.Replace("~", "");
            url = new Uri(new Uri(httpRequest.Url.Scheme + "://" + httpRequest.Url.Authority), this.absolutePath);

            _httpMethod = httpRequest.HttpMethod;
            //To ignore the POST action by other module
            if (moduleContext != null && pageControllerContext != null)
            {
                if (httpRequest.HttpMethod.ToUpper() == "POST")
                {
                    var postModule = pageControllerContext.RequestContext.GetRequestValue(Kooboo.CMS.Sites.View.ModuleUrlContext.PostModuleParameter);
                    if (!string.IsNullOrEmpty(postModule))
                    {
                        if (postModule.ToUpper() != moduleContext.ModulePosition.PagePositionId.ToUpper())
                        {
                            _httpMethod = "GET";
                        }
                    }
                }
            }
        }
Esempio n. 4
0
 private void WriteText(ModuleContext moduleContext, string eventName)
 {
     var logFile = moduleContext.ModulePath.GetModuleSharedFilePath(@"logs.txt");
     var dir = Path.GetDirectoryName(logFile.PhysicalPath);
     if (!Directory.Exists(dir))
     {
         Directory.CreateDirectory(dir);
     }
     System.IO.File.AppendAllLines(logFile.PhysicalPath, new[] { string.Format("Run '{0}' at {1}", eventName, DateTime.Now) });
 }
Esempio n. 5
0
        public static ModuleContext Create(Site site, string moduleName, ModuleSettings moduleSettings, ModulePosition position)
        {
            var context = new ModuleContext(site, moduleName, moduleSettings, position);

            if (!System.IO.Directory.Exists(context.ModulePath.PhysicalPath))
            {
                throw new Exception(string.Format("The module does not exist.Module name:{0}".Localize(), moduleName));
            }

            return context;
        }
        public void OnInstalling(ModuleContext moduleContext, ControllerContext controllerContext)
        {
            var moduleInfo = ModuleInfo.Get(SampleAreaRegistration.ModuleName);
            var installModel = new InstallModel();
            Kooboo.CMS.Sites.Extension.ModelBindHelper.BindModel<InstallModel>(installModel, controllerContext);

            moduleInfo.DefaultSettings.CustomSettings["DatabaseServer"] = installModel.DatabaseServer;
            moduleInfo.DefaultSettings.CustomSettings["UserName"] = installModel.UserName;
            moduleInfo.DefaultSettings.CustomSettings["Password"] = installModel.Password;
            ModuleInfo.Save(moduleInfo);

            // Add code here that will be executed when the module installing.
        }
Esempio n. 7
0
 public void OnUninstalling(ModuleContext moduleContext, ControllerContext controllerContext)
 {
     var installationModel = new InstallationModel();
     if (Kooboo.CMS.Sites.Extension.ModelBindHelper.BindModel(installationModel, controllerContext))
     {
         try
         {
             _dbInitializer.DeleteDb(installationModel.ConnectionString);
         }
         catch (Exception e)
         {
             controllerContext.Controller.ViewData.ModelState.AddModelError("ConnectionString", e);
         }
     }
 }
Esempio n. 8
0
        public void OnExcluded(ModuleContext moduleContext)
        {
            var repository = moduleContext.Site.AsActual().GetRepository();
            if (repository != null)
            {
                TextFolder productFolder = new TextFolder(repository, "Product");
                if (productFolder.AsActual() != null)
                {
                    _textFolderManager.Remove(repository, productFolder);
                }
                Schema productSchema = new Schema(repository, "Product");
                if (productSchema.AsActual() != null)
                {
                    _schemaManager.Remove(repository, productSchema);
                }

            }
        }
Esempio n. 9
0
 public void OnInstalling(ModuleContext moduleContext, ControllerContext controllerContext)
 {
     var installationModel = new InstallationModel();
     var connectString = controllerContext.HttpContext.Request.Form["ConnectionString"];
     if (Kooboo.CMS.Sites.Extension.ModelBindHelper.BindModel(installationModel, controllerContext))
     {
         try
         {
             _dbInitializer.InitializeDb(installationModel.ConnectionString);
             ModuleInfo moduleInfo = ModuleInfo.Get(ModuleAreaRegistration.ModuleName);
             moduleInfo.DefaultSettings.CustomSettings["ConnectionString"] = installationModel.ConnectionString;
             ModuleInfo.Save(moduleInfo);
         }
         catch (Exception e)
         {
             controllerContext.Controller.ViewData.ModelState.AddModelError("ConnectionString", e);
         }
     }
 }
Esempio n. 10
0
 public void OnReinstalling(ModuleContext moduleContext, ControllerContext controllerContext, InstallationContext installationContext)
 {
     // Add code here that will be executed when the module reinstalling.
     // To use custom UI during reinstalling, define the view location in the module.config
     WriteText(moduleContext, "OnReinstalling");
 }
Esempio n. 11
0
 public void OnExcluded(ModuleContext moduleContext)
 {
     // Add code here that will be executed when the module was excluded to the site.
 }
Esempio n. 12
0
 public void OnUninstalling(ModuleContext moduleContext, ControllerContext controllerContext)
 {
     
 }
 public void OnUninstalling(ModuleContext moduleContext, ControllerContext controllerContext)
 {
     // Add code here that will be executed when the module uninstalling.
     // To use custom UI during uninstalling, define the view location in the module.config
 }
Esempio n. 14
0
 public ModuleRequestContext(HttpContextBase httpContext, RouteData routeData, ModuleContext moduleContext)
     : base(httpContext, routeData)
 {
     this.ModuleContext = moduleContext;
 }
 public void OnInstalling(ModuleContext moduleContext, ControllerContext controllerContext)
 {
     //Add code here that will be executed when the module installing.
     // Installing UI template is defined in the module.config
 }
 public void OnReinstalling(ModuleContext moduleContext, ControllerContext controllerContext, InstallationContext installationContext)
 {
     // Add code here that will be executed when the module was including to the site.
 }
Esempio n. 17
0
 public void OnReinstalling(ModuleContext moduleContext, ControllerContext controllerContext, Sites.Extension.ModuleArea.Management.InstallationContext installationContext)
 {
     // Add code here that will be executed when the module reinstalling.
 }
Esempio n. 18
0
        public void OnIncluded(ModuleContext moduleContext)
        {
            var repository = moduleContext.Site.AsActual().GetRepository();
            if (repository != null)
            {
                //import the content types. the zip file contains "Category" content type.
                //var contentTypePath = new ModulePathHelper(ModuleAreaRegistration.ModuleName).GetModuleInstallationFilePath("ContentType.zip");
                //if (File.Exists(contentTypePath.PhysicalPath))
                //{
                //    using (FileStream fs = new FileStream(contentTypePath.PhysicalPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                //    {
                //        _schemaManager.Import(repository, fs, true);
                //    }
                //}
                Schema productSchema = new Schema(repository, "Product");
                productSchema.AddColumn("ProductName", "TextBox", DataType.String, "", true, true);
                productSchema.AddColumn("ProductDetail", "Tinymce", DataType.String, "", false, true);
                if (productSchema.AsActual() == null)
                {
                    _schemaManager.Add(repository, productSchema);
                }

                TextFolder productFolder = new TextFolder(repository, "Product")
                {
                    SchemaName = "Product"
                };
                if (productFolder.AsActual() == null)
                {
                    _textFolderManager.Add(repository, productFolder);
                }
            }
        }
Esempio n. 19
0
 public ModuleHttpResponse(HttpResponse httpResponse, ModuleContext moduleContext)
     : base(httpResponse)
 {
     this.moduleContext = moduleContext;
 }
Esempio n. 20
0
        public static ModuleActionInvokedContext InvokeAction(ControllerContext controllerContext, Site site, string moduleUrl, ModulePosition modulePosition)
        {
            HttpContext context        = HttpContext.Current;
            var         moduleSettings = ModuleInfo.GetSiteModuleSettings(modulePosition.ModuleName, site == null ? "" : site.FullName);

            if (modulePosition.Entry != null)
            {
                moduleSettings.Entry = modulePosition.Entry;
            }
            var settings   = moduleSettings;
            var positionId = modulePosition.PagePositionId;
            var moduleName = modulePosition.ModuleName;

            ModuleContext moduleContext = ModuleContext.Create(site, moduleName, settings, modulePosition);

            if (string.IsNullOrEmpty(moduleUrl))
            {
                if (settings != null && settings.Entry != null)
                {
                    moduleUrl = GetEntryUrl(context, moduleContext, settings.Entry);
                    if (!string.IsNullOrEmpty(moduleUrl) && !moduleUrl.StartsWith("~"))
                    {
                        moduleUrl = "~" + moduleUrl;
                    }
                }
            }
            if (string.IsNullOrEmpty(moduleUrl))
            {
                moduleUrl = "~/";
            }
            else if (moduleUrl[0] != '~')
            {
                moduleUrl = "~/" + moduleUrl.TrimStart('/');
            }

            var httpContext = new ModuleHttpContext(context
                                                    , new ModuleHttpRequest(context.Request, moduleUrl, moduleContext, controllerContext), new ModuleHttpResponse(context.Response, moduleContext), moduleContext);

            var routeData = moduleContext.RouteTable.GetRouteData(httpContext);

            var requestContext = new ModuleRequestContext(httpContext, routeData, moduleContext)
            {
                PageControllerContext = controllerContext
            };

            string controllerName = requestContext.RouteData.GetRequiredString("controller");
            string actionName     = requestContext.RouteData.GetRequiredString("action");
            var    controller     = (Controller)ControllerBuilder.Current.GetControllerFactory().CreateController(requestContext, controllerName);

            if (controller == null)
            {
                throw new Exception(string.Format("The module '{0}' controller for path '{1}' does not found or does not implement IController.", moduleName, moduleUrl));
            }
            //if (!(controller is ModuleControllerBase))
            //{
            //    throw new Exception(string.Format("The controller type '{0}' must be inherited from ModuleControllerBase.", controller.GetType().FullName));
            //}
            //ModuleControllerBase moduleController = (ModuleControllerBase)controller;

            //ControllerContext moduleControllerContext = new ControllerContext(requestContext, moduleController);

            InitializeController(controller, requestContext);

            var result = actionInvoker.InvokeActionWithoutExecuteResult(controller.ControllerContext, actionName);

            if (result == null)
            {
                HandleUnknownAction(controller, actionName);
            }
            return(result);
        }
Esempio n. 21
0
 public void OnIncluded(ModuleContext moduleContext)
 {
     
 }
Esempio n. 22
0
 public void OnReinstalling(ModuleContext moduleContext, ControllerContext controllerContext, Sites.Extension.ModuleArea.Management.InstallationContext installationContext)
 {
     
 }
Esempio n. 23
0
 public ModuleHttpResponse(HttpResponse httpResponse, ModuleContext moduleContext)
     : base(httpResponse)
 {
     this.moduleContext = moduleContext;
 }
Esempio n. 24
0
 public ModuleRequestContext(HttpContextBase httpContext, RouteData routeData, ModuleContext moduleContext)
     : base(httpContext, routeData)
 {
     this.ModuleContext = moduleContext;
 }
Esempio n. 25
0
        public static void SetModuleSettings(this ModuleContext moduleContext, ModuleSettings moduleSettings)
        {
            var settingFile = moduleContext.ModulePath.GetModuleLocalFilePath("settings.config").PhysicalPath;

            DataContractSerializationHelper.Serialize(moduleSettings, settingFile);
        }
Esempio n. 26
0
        private static string GetEntryUrl(HttpContext context, ModuleContext moduleContext, Entry entry)
        {
            var httpContext = new GetEntryUrlContextWrapper(context, "~/");

            var routeData = moduleContext.RouteTable.GetRouteData(httpContext);

            var requestContext = new ModuleRequestContext(httpContext, routeData, moduleContext);

            UrlHelper url = new UrlHelper(requestContext, moduleContext.RouteTable);

            return url.Action(entry.Action, entry.Controller, entry.Values);
        }
 public void OnUninstalling(ModuleContext moduleContext, ControllerContext controllerContext)
 {
     // Add code here that will be executed when the module uninstalling.
 }
Esempio n. 28
0
 public ModuleHttpContext(HttpContext httpContext, HttpRequestBase httpRequest, HttpResponseBase httpResponse, ModuleContext moduleContext)
     : base(httpContext)
 {
     this._httpRequest  = httpRequest;
     this._httpResponse = httpResponse;
     this.ModuleContext = moduleContext;
 }
Esempio n. 29
0
 public void OnIncluded(ModuleContext moduleContext)
 {
     // Add code here that will be executed when the module was included to the site.
     WriteText(moduleContext, "OnIncluded");
 }