Exemplo n.º 1
0
        public BaseResponse <bool> BackupDB()
        {
            BaseResponse <bool> response = new BaseResponse <bool>();

            try
            {
                using (SqlCommand cmdBakRst = new SqlCommand())
                {
                    SqlConnection conn = new SqlConnection(EcanSecurity.Decode(Utilitys.GetAppConfig("iCMS")));
                    //备份文件路径
                    var dir = Utilitys.GetAppConfig("BackupPath");
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }
                    //生成备份文件名
                    var fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".bak";
                    var abPath   = Path.Combine(dir, fileName);

                    var cmdText = string.Format(@"backup database  HanBinDB to disk='{0}'", abPath);

                    conn.Open();
                    cmdBakRst.Connection  = conn;
                    cmdBakRst.CommandType = CommandType.Text;
                    cmdBakRst.CommandText = cmdText;
                    cmdBakRst.ExecuteNonQuery();

                    FileInfo fileInfo = new FileInfo(abPath);
                    var      fileSize = fileInfo.Length;

                    #region 插入备份日志
                    BackupLog backupLog = new BackupLog();
                    backupLog.BackupDate = DateTime.Now;
                    backupLog.BackupPath = abPath;

                    backupLog.BackupSize = fileSize;
                    backlogRepository.AddNew <BackupLog>(backupLog);
                    #endregion
                }
            }
            catch (Exception e)
            {
                LogHelper.WriteLog(e);
                response.IsSuccessful = false;
                response.Reason       = e.Message;
            }
            return(response);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Token校验
        /// </summary>
        /// <returns></returns>
        public bool Validate(BaseRequest param)
        {
            var request = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.BaseUri.Host;

            param.RequestIP = request;

            //return true;

            if (!string.IsNullOrEmpty(param.Token))
            {
                var privateKey = Utilitys.GetAppConfig("PrivateKey");
                return(JsonWebToken.Verify(param.Token, privateKey, true));
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        static void RestoreDB(string dataBaseName, string path)
        {
            path = @"C:\Program Files (x86)\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA";

            //连接字符串
            var            connectionStr = EcanSecurity.Decode(Utilitys.GetAppConfig("iCMS"));
            DataTable      DBNameTable   = new DataTable();
            SqlDataAdapter Adapter       = new SqlDataAdapter("select name from master..sysdatabases", connectionStr);

            lock (Adapter)
            {
                Adapter.Fill(DBNameTable);
            }
            foreach (DataRow row in DBNameTable.Rows)
            {
                if (row["name"].ToString() == dataBaseName)
                {
                    throw new Exception("已存在对应的数据,请勿重复还原数据库!");
                }
            }
            //检测真正当前bak文件真正的log mdf的名字
            var            strsql   = " restore  filelistonly from disk = '" + path + "'";
            SqlDataAdapter Adapter2 = new SqlDataAdapter(strsql, connectionStr);
            var            dt       = new DataTable();

            lock (Adapter2)
            {
                Adapter2.Fill(dt);
            }
            var           mdf     = dt.Rows[0][0].ToString();
            var           log     = dt.Rows[1][0].ToString();
            string        restore = string.Format(@"restore database {0} from disk = '{1}'
                                                with REPLACE
                                                , move '{2}' to 'D:\{3}.mdf'
                                                ,move '{4}' to 'D:\{5}.ldf'", dataBaseName, path, mdf, dataBaseName, log, dataBaseName);
            SqlConnection conn    = new SqlConnection(connectionStr);
            SqlCommand    cmd1    = new SqlCommand(restore, conn);

            conn.Open();  //k
            cmd1.ExecuteNonQuery();
            conn.Close(); //g
        }
Exemplo n.º 4
0
        /// <summary>
        /// 登陆后返回Token 和角色ID
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public BaseResponse <LoginResult> Login(LoginParameter parameter)
        {
            BaseResponse <LoginResult> response = new BaseResponse <LoginResult>();
            LoginResult result = new LoginResult();

            try
            {
                //密码Base64解密
                var encodePWD = MD5Helper.MD5Encrypt64(Utilitys.DecodeBase64("UTF-8", parameter.PWD));
                var user      = hbUserReosiory.GetDatas <HBUser>(t => t.UserToken.Equals(parameter.UserName) &&
                                                                 t.PWD.Equals(encodePWD) &&
                                                                 t.UseStatus && !t.IsDeleted, true).FirstOrDefault();
                if (user != null)
                {
                    result.RoleID    = user.RoleID;
                    result.UserID    = user.UserID;
                    result.UserToken = user.UserToken;
                    result.OrganID   = user.OrganizationID;

                    var organ = organRepository.GetDatas <Organization>(t => !t.IsDeleted && t.OrganID == result.OrganID, true).FirstOrDefault();
                    if (organ != null)
                    {
                        result.OrganTypeID = organ.OrganTypeID;
                        var organType = organTypeRepository.GetDatas <OrganType>(t => !t.IsDeleted && t.OrganTypeID == result.OrganTypeID, true).FirstOrDefault();
                        if (organType != null)
                        {
                            result.OrganCategoryID = organType.CategoryID;
                        }
                    }

                    var payload = new Dictionary <string, object>
                    {
                        { "name", user.UserToken },
                        { "exp", 1000 * 60 * 240 },    //超时时间 4个小时
                        { "role", user.RoleID },
                        { "date", DateTime.Now.ToString() }
                        //{"date",DateTime.Now }
                    };
                    var privateKey = Utilitys.GetAppConfig("PrivateKey");
                    //var privateKey = AppConfigHelper.GetConfigValue("PrivateKey");

                    result.Token = JsonWebToken.Encode(payload, privateKey, JwtHashAlgorithm.HS512);

                    response.Result = result;

                    return(response);
                }
                else
                {
                    response.IsSuccessful = false;
                    response.Reason       = "用户名或者密码错误";
                    return(response);
                }
            }
            catch (global::System.Exception e)
            {
                LogHelper.WriteLog(e);
                response.Reason       = "用户名或者密码错误";
                response.IsSuccessful = false;
                return(response);
            }
        }
Exemplo n.º 5
0
 public iCMSDbContext()
     : base(EcanSecurity.Decode(Utilitys.GetAppConfig("iCMS"), EcanSecurity.GetKey(Utilitys.GetAppConfig("DBSecret"))))
 {
     Database.SetInitializer <iCMSDbContext>(null);
 }
Exemplo n.º 6
0
 public iCMSDbContext()
     : base(EcanSecurity.Decode(Utilitys.GetAppConfig("iCMS"))) // 做手动推送时候,为了使更改的App.Config能够立即生效,故而将
 {                                                              // GetAppConfig => GetAppConfigForExe,若调试出错,请联系QXM, 2017/02/21
     Database.SetInitializer <iCMSDbContext>(null);
 }