private void RunUninstallScript(string _unistallScriptFile, string moduleFolderPath, Installers installerClass)
 {
     Exceptions = installerClass.ReadSQLFile(moduleFolderPath, _unistallScriptFile);
 }
Пример #2
0
        /// <summary>
        /// Adds file form the manifest.
        /// </summary>
        /// <param name="manifestName">Manifest name.</param>
        private void AddFile(string manifestName)
        {
            string sourcepath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "Modules");
            DirectoryInfo dir = new DirectoryInfo(sourcepath);
            foreach (Component component in Package.Components)
            {
                DirectoryInfo[] sourcedir = dir.GetDirectories(component.Name, SearchOption.AllDirectories);
                foreach (DirectoryInfo dirs in sourcedir)
                {
                    Installers installhelp = new Installers();
                    string ZipPath = Path.Combine(TempFolderPath, dirs.Name + ".zip");
                    ZipUtil.ZipFiles(dirs.FullName, ZipPath, string.Empty);
                    component.IsChecked = true;

                }
            }

        }
        private void ReadUninstallScriptAndDLLFiles(XmlDocument doc, string moduleFolderPath, Installers installerClass)
        {
            XmlElement root = doc.DocumentElement;
            if (!String.IsNullOrEmpty(root.ToString()))
            {
                ArrayList dllFiles = new ArrayList();
                string _unistallScriptFile = string.Empty;
                XmlNodeList xnFileList = doc.SelectNodes("sageframe/folders/folder/files/file");
                if (xnFileList.Count != 0)
                {
                    foreach (XmlNode xn in xnFileList)
                    {
                        string _fileName = xn["name"].InnerXml;
                        try
                        {
                            #region CheckAlldllFiles
                            if (!String.IsNullOrEmpty(_fileName) && _fileName.Contains(".dll"))
                            {
                                dllFiles.Add(_fileName);
                            }
                            #endregion
                            #region ReadUninstall SQL FileName
                            if (!String.IsNullOrEmpty(_fileName) && _fileName.Contains("Uninstall.SqlDataProvider"))
                            {
                                _unistallScriptFile = _fileName;
                            }
                            #endregion
                        }
                        catch (Exception ex)
                        {
                            Exceptions = ex.Message;
                        }
                    }
                    if (_unistallScriptFile != "")
                    {
                        RunUninstallScript(_unistallScriptFile, moduleFolderPath, installerClass);
                    }

                    // check IModuleExtraCodeExecute interface is implemented or not for install/unInstall of module
                    //if (installerClass.IsIModuleExtraCodeInterfaceImplemented(doc))
                    //{
                    //    installerClass.ExtraCodeOnUnInstallation(doc);
                    //}
                    DeleteAllDllsFromBin(dllFiles, moduleFolderPath);
                }
            }
        }
        private void UninstallModule()
        {
            ModuleInfo module = new ModuleInfo();
            Installers installerClass = new Installers();
            string path = HttpContext.Current.Server.MapPath("~/");

            //checked if directory exist for current module foldername
            if (!string.IsNullOrEmpty(txtFolderName.Text))
            {
                string moduleFolderPath = path + SageFrame.Common.RegisterModule.Common.ModuleFolder + '\\' + txtFolderName.Text;
                if (Directory.Exists(moduleFolderPath))
                {
                    //check for valid .sfe file exist or not
                    if (installerClass.checkFormanifestFile(moduleFolderPath, module) != "")
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.Load(moduleFolderPath + '\\' + module.ManifestFile);
                        XmlElement root = doc.DocumentElement;
                        if (installerClass.checkValidManifestFile(root, module))
                        {
                            XmlNodeList xnList = doc.SelectNodes("sageframe/folders/folder");
                            foreach (XmlNode xn in xnList)
                            {
                                module.ModuleName = xn["modulename"].InnerXml.ToString();
                                module.FolderName = xn["foldername"].InnerXml.ToString();

                                if (!String.IsNullOrEmpty(module.ModuleName) && !String.IsNullOrEmpty(module.FolderName) && hdnModuleName.Value == module.ModuleName && txtFolderName.Text == module.FolderName && installerClass.IsModuleExist(module.ModuleName.ToLower(), module))
                                {
                                    string moduleInstalledPath = path + SageFrame.Common.RegisterModule.Common.ModuleFolder + '\\' + module.FolderName;
                                    module.InstalledFolderPath = moduleInstalledPath;
                                }
                                else
                                {
                                    ShowMessage(SageMessageTitle.Exception.ToString(), GetSageMessage("Extensions", "ThisModuleSeemsToBeCorrupted"), "", SageMessageType.Error);
                                }
                            }
                            try
                            {
                                if (module.ModuleID > 0)
                                {
                                    //Run script  
                                    ReadUninstallScriptAndDLLFiles(doc, module.InstalledFolderPath, installerClass);
                                    //Rollback moduleid
                                    installerClass.ModulesRollBack(module.ModuleID, GetPortalID);
                                    //Delete Module's Folder
                                    installerClass.DeleteTempDirectory(module.InstalledFolderPath);
                                }
                            }
                            catch (Exception ex)
                            {
                                Exceptions = ex.Message;
                            }

                            if (Exceptions != string.Empty)
                            {
                                ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("Extensions", "ModuleExtensionIsUninstallError"), "", SageMessageType.Alert);
                            }
                            else
                            {
                                string ExtensionMessage = GetSageMessage("Extensions", "ModuleExtensionIsUninstalledSuccessfully");
                                ProcessCancelRequestBase(Request.RawUrl, true, ExtensionMessage);
                            }
                        }
                        else
                        {
                            ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("Extensions", "ThisPackageIsNotValid"), "", SageMessageType.Alert);
                        }
                    }
                    else
                    {
                        ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("Extensions", "ThisPackageDoesNotAppearToHaveManifestFile"), "", SageMessageType.Alert);
                    }
                }
                else
                {
                    ShowMessage(SageMessageTitle.Exception.ToString(), GetSageMessage("Extensions", "ModuleFolderDoesnotExist"), "", SageMessageType.Error);
                }
            }
        }
        private string ImportControl(string controlSrc)
        {
            string ExtensionMessage = string.Empty;
            if (!string.IsNullOrEmpty(controlSrc))
            {
                DropDownList ddlFirst = ((DropDownList)PackageDetails1.FindControl("ddlFirst"));
                DropDownList ddlSecond = ((DropDownList)PackageDetails1.FindControl("ddlSecond"));
                DropDownList ddlLast = ((DropDownList)PackageDetails1.FindControl("ddlLast"));
                DropDownList ddlIcon = ((DropDownList)ModuleControlsDetails1.FindControl("ddlIcon"));

                TextBox txtKey = ((TextBox)ModuleControlsDetails1.FindControl("txtKey"));
                TextBox txtTitle = ((TextBox)ModuleControlsDetails1.FindControl("txtTitle"));
                TextBox txtHelpURL = ((TextBox)ModuleControlsDetails1.FindControl("txtHelpURL"));
                TextBox txtDisplayOrder = ((TextBox)ModuleControlsDetails1.FindControl("txtDisplayOrder"));
                CheckBox chkSupportsPartialRendering = ((CheckBox)ModuleControlsDetails1.FindControl("chkSupportsPartialRendering"));
                DropDownList ddlType = ((DropDownList)ModuleControlsDetails1.FindControl("ddlType"));

                ModuleInfo objModule = new ModuleInfo();
                Installers install = new Installers();
                try
                {
                    string folder = RemoveTrailingSlash(GetSourceFolder());
                    string friendlyName = PackageDetails1.PackageName;
                    string name = GetClassName();
                    string moduleControl = "Modules/" + folder + "/" + controlSrc;

                    //add module and package tables
                    objModule.ModuleName = name;
                    objModule.Name = name;
                    objModule.FriendlyName = friendlyName;
                    objModule.Description = PackageDetails1.Description;
                    objModule.FolderName = folder;
                    objModule.Version = ddlFirst.SelectedValue + "." + ddlSecond.SelectedValue + "." + ddlLast.SelectedValue;//"01.00.00"; //new Version(1, 0, 0);
                    objModule.Owner = PackageDetails1.Owner;
                    objModule.Organization = PackageDetails1.Organization;
                    objModule.URL = PackageDetails1.Url;
                    objModule.Email = PackageDetails1.Email;
                    objModule.ReleaseNotes = PackageDetails1.ReleaseNotes;
                    objModule.License = PackageDetails1.License;
                    objModule.PackageType = "Module";
                    bool isPremium = true;
                    int supportedFeatures = 0;
                    objModule.BusinessControllerClass = "";
                    objModule.CompatibleVersions = "";
                    string dependencies = "";
                    string permissions = "";

                    try
                    {
                        //Insert into Module and Package tables
                        var LINQModuleInfo = db.sp_ModulesAdd(ref _newModuleID, ref _newModuleDefID, objModule.Name, objModule.PackageType, objModule.License,
                            objModule.Owner, objModule.Organization, objModule.URL, objModule.Email, objModule.ReleaseNotes, objModule.FriendlyName,
                            objModule.Description, objModule.Version, isPremium, false, objModule.BusinessControllerClass, objModule.FolderName,
                            objModule.ModuleName, supportedFeatures, objModule.CompatibleVersions, dependencies, permissions, 0, true, DateTime.Now,
                            GetPortalID, GetUsername);
                        objModule.ModuleID = (Int32)_newModuleID;
                    }
                    catch (Exception ex)
                    {
                        ProcessException(ex);
                    }

                    try
                    {
                        //insert into ProtalModule table
                        db.sp_PortalModulesAdd(ref _newPortalmoduleID, GetPortalID, _newModuleID, true, DateTime.Now, GetUsername);
                    }
                    catch (Exception ex)
                    {
                        ProcessException(ex);
                    }
                    //install permission for the installed module in ModuleDefPermission table with ModuleDefID and PermissionID
                    try
                    {
                        // get the default module VIEW permissions
                        var LINQModuleViewPermission = dbPermission.sp_GetPermissionByCodeAndKey("SYSTEM_VIEW", "VIEW").SingleOrDefault();
                        int _permissionIDView = LINQModuleViewPermission.PermissionID;
                        //insert into module permissions i.e., ModuleDefPermission and PortalModulePermission
                        dbPermission.sp_ModulesPermissionAdd(ref _newModuleDefPermissionID, _newModuleDefID, _permissionIDView, GetPortalID, ref _newPortalModulePermissionID, _newPortalmoduleID, true, null, true, DateTime.Now, GetUsername);


                        // get the default module EDIT permissions
                        var LINQModuleEditPermission = dbPermission.sp_GetPermissionByCodeAndKey("SYSTEM_EDIT", "EDIT").SingleOrDefault();
                        int _permissionIDEdit = LINQModuleEditPermission.PermissionID;
                        //insert into module permissions i.e., ModuleDefPermission and PortalModulePermission
                        dbPermission.sp_ModulesPermissionAdd(ref _newModuleDefPermissionID, _newModuleDefID, _permissionIDEdit, GetPortalID, ref _newPortalModulePermissionID, _newPortalmoduleID, true, null, true, DateTime.Now, GetUsername);
                    }
                    catch (Exception ex)
                    {
                        Exceptions += ex.Message;
                    }

                    try
                    {
                        //Logic for modulecontrol installation             

                        string _moduleControlKey = txtKey.Text;
                        string _moduleControlTitle = txtTitle.Text;
                        string _moduleControlSrc = moduleControl;
                        string _moduleControlHelpUrl = txtHelpURL.Text;
                        bool _moduleSupportsPartialRendering = chkSupportsPartialRendering.Checked;
                        int _controlType = int.Parse(ddlType.SelectedItem.Value);
                        string _iconFile = "";
                        if (ddlIcon.SelectedIndex != -1)
                        {
                            _iconFile = ddlIcon.SelectedItem.Value;
                        }
                        int _displayOrder = int.Parse(txtDisplayOrder.Text);
                        //add into module control table
                        dbMC.sp_ModuleControlsAdd(ref _moduleControlID, _newModuleDefID, _moduleControlKey, _moduleControlTitle, _moduleControlSrc,
                            _iconFile, _controlType, _displayOrder, _moduleControlHelpUrl, _moduleSupportsPartialRendering, true, DateTime.Now,
                            GetPortalID, GetUsername);
                        ExtensionMessage = GetSageMessage("Extensions_Editors", "ModuleExtensionIsAddedSuccessfully");                        
                    }
                    catch (Exception ex)
                    {
                        Exceptions = ex.Message; 
                    }

                    if (Exceptions != string.Empty)
                    {
                        if (objModule.ModuleID > 0 && _newModuleDefID != null && _newModuleDefID > 0)
                        {
                            //Delete Module info from data base
                            install.ModulesRollBack(objModule.ModuleID, GetPortalID);
                        }
                    }
                }
                catch
                {
                    if (objModule.ModuleID > 0 && _newModuleDefID != null && _newModuleDefID > 0)
                    {
                        //Delete Module info from data base
                        install.ModulesRollBack(objModule.ModuleID, GetPortalID);
                    }
                }                
            }
            return ExtensionMessage;
        }
    public void RegisterModule(string moduleName, string moduleFolderPath, string procedure)
    {
        ModuleInfo objModule = new ModuleInfo();
        int _newModuleID = 0;
        int _newModuleDefID = 0;
        int _newPortalmoduleID = 0;
        string Exceptions = string.Empty;
        string ExtensionMessage = string.Empty;
        try
        {
            //add module and package tables
            objModule.ModuleName = moduleName;
            objModule.Name = moduleName;
            objModule.FriendlyName = moduleName;
            objModule.Description = txtModuleDescription.Text;
            objModule.FolderName = moduleName;
            objModule.Version = "01.00.00";//ddlFirst.SelectedValue + "." + ddlSecond.SelectedValue + "." + ddlLast.SelectedValue;//"01.00.00"; //new Version(1, 0, 0);
            objModule.Owner = "";
            objModule.Organization = "";
            objModule.URL = "";
            objModule.Email = "";
            objModule.ReleaseNotes = "";
            objModule.License = "";
            objModule.PackageType = "Module";
            objModule.isPremium = true;
            objModule.supportedFeatures = 0;
            objModule.BusinessControllerClass = "";
            objModule.CompatibleVersions = "";
            objModule.dependencies = "";
            objModule.permissions = "";
            ModuleController objController = new ModuleController();

            int[] outputValue;
            outputValue = objController.AddModules(objModule, false, 0, true, DateTime.Now, GetPortalID, GetUsername);
            objModule.ModuleID = outputValue[0];
            objModule.ModuleDefID = outputValue[1];
            _newModuleID = objModule.ModuleID;
            _newModuleDefID = objModule.ModuleDefID;

            //insert into ProtalModule table
            _newPortalmoduleID = objController.AddPortalModules(GetPortalID, _newModuleID, true, DateTime.Now, GetUsername);

            //install permission for the installed module in ModuleDefPermission table with ModuleDefID and PermissionID

            // get the default module VIEW permissions
            int _permissionIDView = objController.GetPermissionByCodeAndKey("SYSTEM_VIEW", "VIEW");
            objController.AddModulePermission(_newModuleDefID, _permissionIDView, GetPortalID, _newPortalmoduleID, true, GetUsername, true, DateTime.Now, GetUsername);
            int _permissionIDEdit = objController.GetPermissionByCodeAndKey("SYSTEM_EDIT", "EDIT");
            objController.AddModulePermission(_newModuleDefID, _permissionIDEdit, GetPortalID, _newPortalmoduleID, true, GetUsername, true, DateTime.Now, GetUsername);

            RegisterControl(moduleName, moduleFolderPath + moduleName + "/" + moduleName + ".ascx", 1, _newModuleDefID);
            if (chkEdit.Checked)
            {
                RegisterControl(moduleName, moduleFolderPath + moduleName + "/" + moduleName + "Edit" + ".ascx", 2, _newModuleDefID);
            }
            if (chkSetting.Checked)
            {
                RegisterControl(moduleName, moduleFolderPath + moduleName + "/" + moduleName + "Setting" + ".ascx", 3, _newModuleDefID);
            }
            if (Exceptions != string.Empty)
            {
                if (objModule.ModuleID > 0 && _newModuleDefID > 0)
                {
                    Installers install = new Installers();
                    //Delete Module info from data base
                    install.ModulesRollBack(objModule.ModuleID, GetPortalID);
                }
            }
            else
            {
                SQLHandler sageSQLHandler = new SQLHandler();
                sageSQLHandler.ExecuteScript(procedure, true);
            }
        }
        catch (Exception ex)
        {
            ShowMessage("", ex.ToString(), "", SageMessageType.Error);
            ProcessException(ex);
        }
        Response.Redirect(Request.Url.AbsoluteUri);
    }
        private void UninstallModule(ModuleInfo moduleInfo, bool deleteModuleFolder)
        {
            Installers installerClass = new Installers();
            string path = HttpContext.Current.Server.MapPath("~/");

            //checked if directory exist for current module foldername
            string moduleFolderPath = path +"modules\\"+ moduleInfo.FolderName;
            if (!string.IsNullOrEmpty(moduleFolderPath))
            {
                if (Directory.Exists(moduleFolderPath))
                {
                    //check for valid .sfe file exist or not
                    string fileName = installerClass.checkFormanifestFile(moduleFolderPath, moduleInfo);
                    if (fileName != "")
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.Load(moduleFolderPath + '\\' + fileName);
                        XmlElement root = doc.DocumentElement;
                        if (installerClass.checkValidManifestFile(root, moduleInfo))
                        {
                            XmlNodeList xnList = doc.SelectNodes("sageframe/folders/folder");
                            foreach (XmlNode xn in xnList)
                            {
                                moduleInfo.ModuleName = xn["modulename"].InnerXml.ToString();
                                moduleInfo.FolderName = xn["foldername"].InnerXml.ToString();

                                
                            }
                            try
                            {
                                if (moduleInfo.ModuleID > 0)
                                {
                                    //Run script  
                                    ReadUninstallScriptAndDLLFiles(doc, moduleFolderPath, installerClass);
                                   
                                    if (deleteModuleFolder == true)
                                    {
                                        //Delete Module's Folder
                                        //installerClass.DeleteTempDirectory(moduleInfo.InstalledFolderPath);
                                        Directory.Delete(moduleFolderPath, true);
                                       
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Exceptions = ex.Message;
                            }

                            if (Exceptions != string.Empty)
                            {
                                ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("Extensions", "ModuleExtensionIsUninstallError"), "", SageMessageType.Alert);
                            }
                            else
                            {
                                string ExtensionMessage = GetSageMessage("Extensions", "ModuleExtensionIsUninstalledSuccessfully");
                                //UninstallProcessCancelRequestBase(Request.RawUrl, true, ExtensionMessage);
                            }
                        }
                        else
                        {
                            ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("Extensions", "ThisPackageIsNotValid"), "", SageMessageType.Alert);
                            if (Directory.Exists(moduleFolderPath))
                            {
                                Directory.Delete(moduleFolderPath, true);
                            }
                        }
                    }
                    else
                    {
                        ShowMessage(SageMessageTitle.Notification.ToString(), GetSageMessage("Extensions", "ThisPackageDoesNotAppearToBeValid"), "", SageMessageType.Alert);
                        if (Directory.Exists(moduleFolderPath))
                        {
                            Directory.Delete(moduleFolderPath, true);
                        }
                    }
                }
                else
                {
                    if (Directory.Exists(moduleFolderPath))
                    {
                        Directory.Delete(moduleFolderPath, true);
                    }
                    ShowMessage(SageMessageTitle.Exception.ToString(), GetSageMessage("Extensions", "ModuleFolderDoesnotExist"), "", SageMessageType.Error);
                }
            }
        }