Example #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="workerIndent"></param>
        public PluginPackAttribute(string workerIndent)
        {
            this.WorkIndent = workerIndent;
            bool isChanged = false;
            var dirPath = String.Concat(
                AppDomain.CurrentDomain.BaseDirectory,
                PluginConfig.PLUGIN_DIRECTORY,
                workerIndent,
                "/");

            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath).Create();
            }

            settings = new SettingFile(string.Concat(dirPath, "plugin.config"));

            if (!settings.Contains("state"))
            {
                settings.Add("state", "Normal");
                isChanged = true;
            }
            if (!settings.Contains("override.url.indent"))
            {
                settings.Add("override.url.indent", "");
                isChanged = true;
            }

            if (isChanged)
            {
                settings.Flush();
            }
        }
        public InstallCode Process(HttpContext context)
        {

            NameValueCollection form = context.Request.Form;
            string physical = AtNet.Cms.Cms.PyhicPath;

            if (!Directory.Exists(AtNet.Cms.Cms.PyhicPath + "config"))
            {
                Directory.CreateDirectory(AtNet.Cms.Cms.PyhicPath + "config").Create();
            }

            if (System.IO.File.Exists(String.Concat(physical, INSTALL_LOCK)))
            {
                return InstallCode.Installed;
            }

            string t_key = form["t_key"],
                   t_name = form["t_name"],
                   site_name = form["site_name"],
                   site_domain = form["site_domain"],
                   site_language = form["site_language"],
                   user_name = form["user_name"],
                   user_pwd = form["user_pwd"],
                   db_type = form["db_type"],
                   db_server = form["db_server"],
                   db_prefix = form["db_prefix"],
                   db_prefix1 = form["db_prefix1"],
                   db_name = form["db_name"],
                   db_usr = form["db_usr"],
                   db_pwd = form["db_pwd"],
                   db_file = form["db_file"];

            string db_str = "";

            #region 检测数据

            if (String.IsNullOrEmpty(user_name) || String.IsNullOrEmpty(user_pwd))
            {
                return InstallCode.NO_USER;
            }

            #endregion

            #region 初始化数据库设置

            //数据表前缀
            if (String.IsNullOrEmpty(db_prefix)) db_prefix = db_prefix1;


            //移动Access或SQLite数据库
            if (db_type == "sqlite")
            {
                if (db_file == "")
                {
                    db_file ="rd_"+string.Empty.RandomLetters(5)+".db";
                }
                else if (db_file.IndexOf(".") == -1)
                {
                    db_file += ".db";
                }
                if (!Directory.Exists(physical + "sqlite.db"))
                {
                    Directory.CreateDirectory(physical + "sqlite.db").Create();
                }

                System.IO.File.Copy(physical + FILE_DB_SQLITE, physical + "sqlite.db/" + db_file, true);
                db_str = "Data Source=$ROOT/sqlite.db/" + db_file;
            }
            else if (db_type == "oledb")
            {
                if (db_file == "")
                {
                    db_file = "rd_" + string.Empty.RandomLetters(5) + ".mdb";
                }
                else if (db_file.IndexOf(".") == -1)
                {
                    db_file += ".mdb";
                }

                if (!Directory.Exists(physical + "ole.db"))
                {
                    Directory.CreateDirectory(physical + "ole.db").Create();
                }
                File.Copy(physical + FILE_DB_OLEDB, physical + "ole.db/" + db_file, true);
                db_str = "Data Source=$ROOT/ole.db/" + db_file;
            }
            else
            {
                //数据库资料不全
                if (String.IsNullOrEmpty(db_server) || String.IsNullOrEmpty(db_usr) || String.IsNullOrEmpty(db_name) || String.IsNullOrEmpty(db_prefix))
                {
                    return InstallCode.DB_ERROR;
                }

                if (db_type == "mysql")
                {
                    db_str = String.Format("server={0};database={1};uid={2};pwd={3};charset=utf8", db_server, db_name, db_usr, db_pwd);
                }
                else if (db_type == "mssql")
                {
                    db_str = String.Format("server={0};database={1};uid={2};pwd={3}", db_server, db_name, db_usr, db_pwd);
                }
                else
                {
                    return InstallCode.DB_UNKNOWN;
                }
            }

            #endregion

            #region 写入配置

            if (System.IO.File.Exists(physical + FILE_SETTING))
            {
                System.IO.File.Delete(physical + FILE_SETTING);
            }
            SettingFile file = new SettingFile(physical + FILE_SETTING);
            file.Add("license_key", t_key);
            file.Add("license_name", t_name);
            file.Add("server_static", "");
            file.Add("server_static_enabled", "false");

            file.Add("db_type", db_type);
            file.Add("db_conn", db_str);
            file.Add("db_prefix", db_prefix);

            file.Add("mm_avatar_path", "/file/avatar/");
            file.Flush();

            #endregion

            #region 初始化数据库

            if (!ExtraDB(db_type, db_str, db_prefix))
            {
                return InstallCode.DB_INIT_ERROR;
            }

            #endregion

            #region 初始化数据

            //默认数据为:
            // cms_sites        siteid为1的站点
            // cms_category   默认的about分类
            // cms_usergroup


            //更新默认站点
            this.db.ExecuteNonQuery(new SqlQuery(
                String.Format("UPDATE {0}site SET domain=@domain,name=@name,tpl=@tpl,seotitle=@name where siteid=1", db_prefix),
                new object[,]{
                    {"@domain",site_domain},
                    {"@name",site_name},
                    {"@tpl","default"}
                }));

            //创建管理用户
            this.db.ExecuteNonQuery(new SqlQuery(
                String.Format(@"
                        INSERT INTO {0}user (
                        siteid ,
                        username ,
                        password ,
                        name ,
                        groupid ,
                        available ,
                        createdate ,
                        lastlogindate ) VALUES (0,@username,@password,@name,1,1,@dt,@dt)
                    ", db_prefix),
                     new object[,]{
                         {"@username",user_name},
                         {"@password",  user_pwd.Encode16MD5().EncodeMD5()},
                         {"@name","系统管理员"},
                         {"@dt",DateTime.Now}
                     }));
            #endregion


            //创建安装文件
            System.IO.File.Create(String.Concat(physical, INSTALL_LOCK));

            Settings.TurnOffDebug();

            AtNet.Cms.Cms.Init();

            // 重启
            HttpRuntime.UnloadAppDomain();
            //AppDomain.Unload(AppDomain.CurrentDomain);

            return InstallCode.SUCCESS;
        }
Example #3
0
        public void Save()
        {
            SettingFile sf = new SettingFile(String.Format("{0}templates/{1}/tpl.conf",AtNet.Cms.Cms.PyhicPath,this.tplName));

            /**************** 模板设置 ****************/
             if (sf.Contains("CFG_ShowErrror"))
            {
                sf["CFG_ShowErrror"] = this.CFG_ShowError?"true":"false";
            }
            else
            {
                sf.Add("CFG_ShowErrror", this.CFG_ShowError ? "true" : "false");
            }
            
            if (sf.Contains("CFG_SitemapSplit"))
            {
                sf["CFG_SitemapSplit"] = this.cfg_sitemapSplit;
            }
            else
            {
                sf.Add("CFG_SitemapSplit", this.cfg_sitemapSplit);
            }
            if (sf.Contains("CFG_ArchiveTagsFormat"))
            {
                sf["CFG_ArchiveTagsFormat"] = this.cfg_ArchiveTagsFormat;
            }
            else
            {
                sf.Add("CFG_ArchiveTagsFormat", this.cfg_ArchiveTagsFormat);
            }
            if (sf.Contains("CFG_NavigatorLinkFormat"))
            {
                sf["CFG_NavigatorLinkFormat"] = this.cfg_navigatorLinkFormat;
            }
            else
            {
                sf.Add("CFG_NavigatorLinkFormat", this.cfg_navigatorLinkFormat);
            }
            if (sf.Contains("CFG_NavigatorChildFormat"))
            {
                sf["CFG_NavigatorChildFormat"] = this.cfg_navigatorChildFormat;
            }
            else
            {
                sf.Add("CFG_NavigatorChildFormat", this.cfg_navigatorChildFormat);
            }
            if (sf.Contains("CFG_FriendShowNum"))
            {
                sf["CFG_FriendShowNum"] = this.cfg_friendShowNum.ToString();
            }
            else
            {
                sf.Add("CFG_FriendShowNum", this.cfg_friendShowNum.ToString());
            }
            if (sf.Contains("CFG_FriendLinkFormat"))
            {
                sf["CFG_FriendLinkFormat"] = this.cfg_friendLinkFormat;
            }
            else
            {
                sf.Add("CFG_FriendLinkFormat", this.cfg_friendLinkFormat);
            }
            if (sf.Contains("CFG_TrafficFormat"))
            {
                sf["CFG_TrafficFormat"] = this.cfg_trafficFormat;
            }
            else
            {
                sf.Add("CFG_TrafficFormat", this.cfg_trafficFormat);
            }
            if (sf.Contains("CFG_CommentEditorHtml"))
            {
                sf["CFG_CommentEditorHtml"] = this.cfg_commentEditorHtml;
            }
            else
            {
                sf.Add("CFG_CommentEditorHtml", this.cfg_commentEditorHtml);
            }
            if (sf.Contains("CFG_allowAmousComment"))
            {
                sf["CFG_allowAmousComment"] = this.cfg_allowAmousComment ? "true" : "false";
            }
            else
            {
                sf.Add("CFG_allowAmousComment", this.cfg_allowAmousComment ? "true" : "false");
            }
            if (sf.Contains("CFG_OutlineLength"))
            {
                sf["CFG_OutlineLength"] = this.cfg_outlineLength.ToString();
            }
            else
            {
                sf.Add("CFG_OutlineLength", this.cfg_outlineLength.ToString());
            }
            if (sf.Contains("CFG_ArchiveFormat"))
            {
                sf["CFG_ArchiveFormat"] = this.cfg_archiveFormat;
            }
            else
            {
                sf.Add("CFG_ArchiveFormat", this.cfg_archiveFormat);
            }
            if (sf.Contains("CFG_ArchiveLinkFormat"))
            {
                sf["CFG_ArchiveLinkFormat"] =this.cfg_archiveLinkFormat;
            }
            else
            {
                sf.Add("CFG_ArchiveLinkFormat", this.cfg_archiveLinkFormat);
            }
            if (sf.Contains("CFG_PrevArchiveFormat"))
            {
                sf["CFG_PrevArchiveFormat"] = this.cfg_prevArchiveFormat;
            }
            else
            {
                sf.Add("CFG_PrevArchiveFormat", this.cfg_prevArchiveFormat);
            }
            if (sf.Contains("CFG_NextArchiveFormat"))
            {
                sf["CFG_NextArchiveFormat"] = this.cfg_nextArchiveFormat;
            }
            else
            {
                sf.Add("CFG_NextArchiveFormat", this.cfg_nextArchiveFormat);
            }

            if (sf.Contains("CFG_CategoryLinkFormat"))
            {
                sf["CFG_CategoryLinkFormat"] = this.cfg_categoryLinkFormat;
            }
            else
            {
                sf.Add("CFG_CategoryLinkFormat", this.cfg_categoryLinkFormat);
            }
            sf.Flush();
        }