Ejemplo n.º 1
0
        private bool SaveConfig(out string errorMsg)
        {
            bool result;

            try
            {
                Configuration configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(base.Request.ApplicationPath);
                configuration.AppSettings.Settings.Remove("Installer");
                using (System.Security.Cryptography.RijndaelManaged cryptographer = this.GetCryptographer())
                {
                    configuration.AppSettings.Settings["IV"].Value  = System.Convert.ToBase64String(cryptographer.IV);
                    configuration.AppSettings.Settings["Key"].Value = System.Convert.ToBase64String(cryptographer.Key);
                }
                System.Web.Configuration.MachineKeySection machineKeySection = (System.Web.Configuration.MachineKeySection)configuration.GetSection("system.web/machineKey");
                machineKeySection.ValidationKey = Install.CreateKey(20);
                machineKeySection.DecryptionKey = Install.CreateKey(24);
                machineKeySection.Validation    = System.Web.Configuration.MachineKeyValidation.SHA1;
                machineKeySection.Decryption    = "3DES";
                configuration.ConnectionStrings.ConnectionStrings["EcShopSqlServer"].ConnectionString = this.GetConnectionString();
                configuration.ConnectionStrings.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
                configuration.Save();
                errorMsg = null;
                result   = true;
            }
            catch (System.Exception ex)
            {
                errorMsg = ex.Message;
                result   = false;
            }
            return(result);
        }
Ejemplo n.º 2
0
        private bool SaveSiteSettings(out string errorMsg)
        {
            errorMsg = null;
            if (this.siteName.Length > 30 || this.siteDescription.Length > 30)
            {
                errorMsg = "网店名称和简单介绍的长度不能超过30个字符";
                return(false);
            }
            bool result;

            try
            {
                string filename = base.Request.MapPath(Globals.ApplicationPath + "/config/SiteSettings.config");
                System.Xml.XmlDocument xmlDocument  = new System.Xml.XmlDocument();
                SiteSettings           siteSettings = new SiteSettings(base.Request.Url.Host);
                xmlDocument.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + System.Environment.NewLine + "<Settings></Settings>");
                siteSettings.AliOHServerUrl  = "https://openapi.alipay.com/gateway.do";
                siteSettings.SiteName        = this.siteName;
                siteSettings.SiteDescription = this.siteDescription;
                siteSettings.CheckCode       = Install.CreateKey(20);
                siteSettings.WriteToXml(xmlDocument);
                siteSettings.VipCardBG = "/Storage/master/Vipcard/vipbg.png";
                xmlDocument.Save(filename);
                result = true;
            }
            catch (System.Exception ex)
            {
                errorMsg = ex.Message;
                result   = false;
            }
            return(result);
        }
Ejemplo n.º 3
0
        private bool ExecuteScriptFile(string pathToScriptFile, out string errorMsg)
        {
            System.IO.StreamReader streamReader = null;
            System.Data.SqlClient.SqlConnection sqlConnection = null;
            string applicationPath = Globals.ApplicationPath;

            System.IO.StreamReader streamReader2;
            streamReader = (streamReader2 = new System.IO.StreamReader(pathToScriptFile));
            try
            {
                System.Data.SqlClient.SqlConnection sqlConnection2;
                sqlConnection = (sqlConnection2 = new System.Data.SqlClient.SqlConnection(this.GetConnectionString()));
                try
                {
                    System.Data.Common.DbCommand dbCommand = new System.Data.SqlClient.SqlCommand
                    {
                        Connection     = sqlConnection,
                        CommandType    = System.Data.CommandType.Text,
                        CommandTimeout = 60
                    };
                    sqlConnection.Open();
                    while (!streamReader.EndOfStream)
                    {
                        try
                        {
                            string text = Install.NextSqlFromStream(streamReader);
                            if (!string.IsNullOrEmpty(text))
                            {
                                dbCommand.CommandText = text.Replace("$VirsualPath$", applicationPath);
                                dbCommand.ExecuteNonQuery();
                            }
                        }
                        catch (System.Exception ex)
                        {
                            errorMsg = ex.Message;
                        }
                    }
                    sqlConnection.Close();
                }
                finally
                {
                    if (sqlConnection2 != null)
                    {
                        ((System.IDisposable)sqlConnection2).Dispose();
                    }
                }
                streamReader.Close();
            }
            finally
            {
                if (streamReader2 != null)
                {
                    ((System.IDisposable)streamReader2).Dispose();
                }
            }
            errorMsg = null;
            return(true);
        }
Ejemplo n.º 4
0
        private bool ExecuteTest()
        {
            this.errorMsgs = new System.Collections.Generic.List <string>();
            System.Data.Common.DbTransaction dbTransaction = null;
            System.Data.Common.DbConnection  dbConnection  = null;
            string item;

            try
            {
                if (this.ValidateConnectionStrings(out item))
                {
                    System.Data.Common.DbConnection dbConnection2;
                    dbConnection = (dbConnection2 = new System.Data.SqlClient.SqlConnection(this.GetConnectionString()));
                    try
                    {
                        dbConnection.Open();
                        System.Data.Common.DbCommand dbCommand = dbConnection.CreateCommand();
                        dbTransaction         = dbConnection.BeginTransaction();
                        dbCommand.Connection  = dbConnection;
                        dbCommand.Transaction = dbTransaction;
                        dbCommand.CommandText = "CREATE TABLE installTest(Test bit NULL)";
                        dbCommand.ExecuteNonQuery();
                        dbCommand.CommandText = "DROP TABLE installTest";
                        dbCommand.ExecuteNonQuery();
                        dbTransaction.Commit();
                        dbConnection.Close();
                        goto IL_94;
                    }
                    finally
                    {
                        if (dbConnection2 != null)
                        {
                            ((System.IDisposable)dbConnection2).Dispose();
                        }
                    }
                }
                this.errorMsgs.Add(item);
                IL_94 :;
            }
            catch (System.Exception ex)
            {
                this.errorMsgs.Add(ex.Message);
                if (dbTransaction != null)
                {
                    try
                    {
                        dbTransaction.Rollback();
                    }
                    catch (System.Exception ex2)
                    {
                        this.errorMsgs.Add(ex2.Message);
                    }
                }
                if (dbConnection != null && dbConnection.State != System.Data.ConnectionState.Closed)
                {
                    dbConnection.Close();
                    dbConnection.Dispose();
                }
            }
            string folderPath = base.Request.MapPath(Globals.ApplicationPath + "/config/test.txt");

            if (!Install.TestFolder(folderPath, out item))
            {
                this.errorMsgs.Add(item);
            }
            try
            {
                Configuration configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(base.Request.ApplicationPath);
                if (configuration.ConnectionStrings.ConnectionStrings["EcShopSqlServer"].ConnectionString == "none")
                {
                    configuration.ConnectionStrings.ConnectionStrings["EcShopSqlServer"].ConnectionString = "required";
                }
                else
                {
                    configuration.ConnectionStrings.ConnectionStrings["EcShopSqlServer"].ConnectionString = "none";
                }
                configuration.Save();
            }
            catch (System.Exception ex3)
            {
                this.errorMsgs.Add(ex3.Message);
            }
            folderPath = base.Request.MapPath(Globals.ApplicationPath + "/storage/test.txt");
            if (!Install.TestFolder(folderPath, out item))
            {
                this.errorMsgs.Add(item);
            }
            return(this.errorMsgs.Count == 0);
        }