Beispiel #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     userApp = new UserApplication();
     if (!IsPostBack)
     {
         try
         {
             IEncrypt encrypt           = UtilFactory.GetEncryptProvider(EncryptType.DES);
             string   username          = encrypt.Decrypt(UtilFactory.Helpers.CookieHelper.Get(encrypt.Encrypt("Login_UserName_")));
             string   password          = encrypt.Decrypt(UtilFactory.Helpers.CookieHelper.Get(encrypt.Encrypt("Login_Password_")));
             string   preFailedUserName = QS("uname");
             if (!string.IsNullOrEmpty(preFailedUserName))//如果前一次登陆成功过,那么就保存cookie, 否则就重新赋值为上一次失败的用户名。
             {
                 txtUserName.Text = preFailedUserName;
                 txtPassword.Focus();
             }
             else
             {
                 txtUserName.Text = username;
                 txtPassword.Text = password;
             }
             chkRemember.Checked = true;
         }
         catch
         {
             txtUserName.Text    = "*****@*****.**";
             txtPassword.Text    = "jacK1234";
             chkRemember.Checked = false;
         }
     }
 }
        protected UsersEntity GetEntity()
        {
            IEncrypt encrypt = UtilFactory.GetEncryptProvider(EncryptType.DES);

            string[] items = encrypt.Decrypt(Request.Params["link"]).Split("_".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            if (items.Length != 2)
            {
                return(null);
            }
            int      userid;
            DateTime date;

            if (!int.TryParse(items[0], out userid) || !DateTime.TryParse(items[1], out date))
            {
                return(null);
            }
            if (date.Date != DateTime.Now.Date)
            {
                return(null);
            }
            UserApplication userApp = new UserApplication();
            UsersEntity     user    = userApp.GetUser(userid, false);

            return(user);
        }
        public void Load(string filename)
        {
            string jsonData;
            string filePath = GetFilePath(filename);

            _ = Directory.CreateDirectory(GetFolderPath());

            using (StreamReader reader = new StreamReader(filePath))
                jsonData = reader.ReadToEnd();

            if (_encrypt)
            {
                jsonData = _encryptor.Decrypt(jsonData);
            }

            Dictionary <string, byte[]> gameData = _dataHandler.ConvertToObject <Dictionary <string, byte[]> >(jsonData);

            foreach (KeyValuePair <string, byte[]> data in gameData)
            {
                if (_gameData.ContainsKey(data.Key))
                {
                    _gameData[data.Key].LoadData(data.Value);
                }
                else
                {
                    Debug.LogError($"Unexpected data received from file. key '{data.Key}' was not found in the configured data layout.");
                }
            }
        }
        private void Decrypt_Click(object sender, RoutedEventArgs e)
        {
            if (!CheckInputFields())
            {
                return;
            }
            if (!File.Exists(FileLocation))
            {
                return;
            }

            var encryptedBytes  = File.ReadAllBytes(FileLocation);
            var decryptedBytes  = _encrypter.Decrypt(encryptedBytes, Password);
            var memoryStream    = new MemoryStream();
            var binaryFormatter = new BinaryFormatter();

            memoryStream.Write(decryptedBytes, 0, decryptedBytes.Length);
            memoryStream.Position = 0;
            try
            {
                var deserialised = (SortedObservableCollection <Entry>)binaryFormatter.Deserialize(memoryStream);
                Entries.Clear();
                Entries.AddAll(deserialised);
                FileOpen = true;
            }
            catch (Exception ex) when(ex is DecoderFallbackException || ex is SerializationException)
            {
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            int eventID;

            if (int.TryParse(context.Request.Form["id"], out eventID))
            {
                IEncrypt encrypt   = UtilFactory.GetEncryptProvider(EncryptType.DES);
                string   strUserID = encrypt.Decrypt(UtilFactory.Helpers.CookieHelper.Get(encrypt.Encrypt("LoginUserID")));
                if (string.IsNullOrEmpty(strUserID))
                {
                    context.Response.Write("0");
                }
                int userID = int.Parse(strUserID);

                EventEntity entity = new EventsApplication().GetEventInfo(eventID);
                if (entity == null || entity.CreatedBy != userID)
                {
                    context.Response.Write("0");
                }

                if (new EventsApplication().Delete(eventID, entity.FromDay.Date))
                {
                    context.Response.Write("1");
                }
                else
                {
                    context.Response.Write("0");
                }
            }
            else
            {
                context.Response.Write("0");
            }
        }
Beispiel #6
0
        public string Login(string desUserName, string desPassword, bool rememberMe, out string id)
        {
            id = string.Empty;
            IEncrypt encrypt  = UtilFactory.GetEncryptProvider(EncryptType.DES);
            string   userName = encrypt.Decrypt(desUserName);
            string   password = encrypt.Decrypt(desPassword);

            if ((string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password)))
            {
                return("failure");
            }
            UsersEntity usersEntity = userApplication.Login(userName, password);

            if (usersEntity == null)
            {
                return(FormatMessages(userApplication.BrokenRuleMessages));
            }
            id = usersEntity.UserID.ToString();
            return("successful");
        }
Beispiel #7
0
        protected BaseController()
        {
            ViewBag.LoginUserName = LoginUserName;
            IEncrypt encrypt = UtilFactory.GetEncryptProvider(EncryptType.DES);
            string   userId  = encrypt.Decrypt(UtilFactory.Helpers.CookieHelper.Get(encrypt.Encrypt("LoginUserID")));

            if (string.IsNullOrEmpty(userId))
            {
                IsOut = true;
            }
            ResumeCookie();
        }
Beispiel #8
0
 public override List <ICardDetails> Select()
 {
     try
     {
         bool Response = new Security(UserProfileObj).AuthenticateUser();
         if (Response == true)
         {
             List <ICardDetails> DecryptedCardDetailsList = new List <ICardDetails>();
             foreach (ICardDetails EncryptedCardObj in CardDetailsDataLayerObj.Select())
             {
                 ICardDetails DecryptedCardDetails = new CardDetails();
                 AESObj.SetIV(EncryptedCardObj.GetIV());
                 AESObj.SetKey(EncryptedCardObj.GetDecryptionKey());
                 DecryptedCardDetails.SetCardID(EncryptedCardObj.GetCardID());
                 DecryptedCardDetails.SetName(AESObj.Decrypt(EncryptedCardObj.GetName()));
                 DecryptedCardDetails.SetCardNumber(AESObj.Decrypt(EncryptedCardObj.GetCardNumber()).ToString());
                 DecryptedCardDetails.SetExpiryMonth(AESObj.Decrypt(EncryptedCardObj.GetExpiryMonth()));
                 DecryptedCardDetails.SetExpiryYear(AESObj.Decrypt(EncryptedCardObj.GetExpiryYear()));
                 DecryptedCardDetails.SetCvv(AESObj.Decrypt(EncryptedCardObj.GetCvv()));
                 DecryptedCardDetailsList.Add(DecryptedCardDetails);
             }
             return(DecryptedCardDetailsList);
         }
         else
         {
             return(null);
         }
     }
     catch (NullReferenceException nex)
     {
         Logger.Instance().Log(Warn.Instance(), new LogInfo("Received null reference while fetching card details (Routine : AuthenticateUser), might be token manipulation. Check token : " + UserProfileObj.GetToken()));
         throw nex;
     }
     catch (Exception ex)
     {
         Logger.Instance().Log(Fatal.Instance(), ex);
         throw ex;
     }
 }
Beispiel #9
0
        public static MAP Load(byte[] data)
        {
            encrypt.Decrypt(ref data);
            string __temp = Encoding.UTF8.GetString(data);
            MAP    map    = new MAP();

            map.Terrains = JsonReader.Deserialize <List <TERRAIN> >(__temp);
            foreach (var item in map.Terrains)
            {
                item.SetData();
                item.SetHits();
            }
            return(map);
        }
Beispiel #10
0
        private void ResumeCookie()
        {
            IEncrypt encrypt  = UtilFactory.GetEncryptProvider(EncryptType.DES);
            string   userType = encrypt.Decrypt(UtilFactory.Helpers.CookieHelper.Get(encrypt.Encrypt("UserType")));

            if (userType != "SUNNET")
            {
                UtilFactory.Helpers.CookieHelper.Resume(encrypt.Encrypt("LoginUserID"), 30);
                UtilFactory.Helpers.CookieHelper.Resume(encrypt.Encrypt("FirstName"), 30);
                UtilFactory.Helpers.CookieHelper.Resume(encrypt.Encrypt("LastName"), 30);
                UtilFactory.Helpers.CookieHelper.Resume(encrypt.Encrypt("CompanyID"), 30);
                UtilFactory.Helpers.CookieHelper.Resume(encrypt.Encrypt("UserType"), 30);
                UtilFactory.Helpers.CookieHelper.ResumeExpire(encrypt.Encrypt("ExpireTime"), 30);
            }
        }
Beispiel #11
0
        public byte[] UnEscape(byte[] bodyBuffer, IEncrypt encrypt)
        {
            List <byte> dataList = new List <byte>();

            dataList.Add(bodyBuffer[0]);
            for (int i = 1; i < bodyBuffer.Length - 1; i++)
            {
                byte first  = bodyBuffer[i];
                byte second = bodyBuffer[i + 1];
                if (first == 0x5a && second == 0x01)
                {
                    dataList.Add(0x5b);
                    i++;
                }
                else if (first == 0x5a && second == 0x02)
                {
                    dataList.Add(0x5a);
                    i++;
                }
                else if (first == 0x5e && second == 0x01)
                {
                    dataList.Add(0x5d);
                    i++;
                }
                else if (first == 0x5e && second == 0x02)
                {
                    dataList.Add(0x5e);
                    i++;
                }
                else
                {
                    dataList.Add(first);
                }
            }
            dataList.Add(bodyBuffer[bodyBuffer.Length - 1]);
            var tempBuffe = dataList.ToArray();

            if (encrypt != null)
            {
                encrypt.Decrypt(tempBuffe);
            }
            return(tempBuffe);
        }
Beispiel #12
0
 public static bool Decrypt(ref string value)
 {
     return(_instance.Decrypt(ref value));
 }
Beispiel #13
0
        static void Main(string[] args)
        {
            IoC.Init();

            string filePath = string.IsNullOrEmpty(ConfigurationManager.AppSettings["UploadFile"]) ?
                              "C:/log/cli/Upload/data_Process/" : ConfigurationManager.AppSettings["UploadFile"];

            BUPProcessBusiness            _bupProcessBusiness   = new BUPProcessBusiness();
            BUPTaskBusiness               _bupTaskBusiness      = new BUPTaskBusiness();
            AutomationSettingBusiness     _autoBusiness         = new AutomationSettingBusiness();
            List <AutomationSettingModel> processingAutomations = _autoBusiness.GetProcessingAutomationSettings();
            UserBusiness _userBusiness = new UserBusiness();
            ISunnetLog   LoggerHelper  = ObjectFactory.GetInstance <ISunnetLog>();

            LoggerHelper.Info("start ......");
            Console.WriteLine("start ......");

            if (processingAutomations != null && processingAutomations.Count > 0)
            {
                List <UserBaseEntity> users = _userBusiness.GetUsers(processingAutomations.Select(r => r.CreatedBy).ToList());
                foreach (AutomationSettingModel item in processingAutomations)
                {
                    IEncrypt   encrypt = ObjectFactory.GetInstance <IEncrypt>();
                    SFTPHelper sftp    = new SFTPHelper(item.HostIp, item.Port, item.UserName, encrypt.Decrypt(item.PassWord), LoggerHelper);

                    bool bconn = sftp.Connect();
                    if (bconn)
                    {
                        try
                        {
                            UserBaseEntity user = users.Find(r => r.ID == item.CreatedBy);
                            if (user != null)
                            {
                                Dictionary <string, dynamic> dicType = GetDictionary(item);

                                foreach (var type in dicType)
                                {
                                    if (sftp.DirExist(type.Key))
                                    {
                                        string localPath = filePath + (item.CommunityName + "/" + type.Key.Replace("/", "").Replace("\\", ""))
                                                           + "/" + DateTime.Now.ToString("MM-dd-yyyy") + "/";
                                        string failedPath  = type.Key + "/Failed/" + DateTime.Now.ToString("MM-dd-yyyy") + "/";
                                        string successPath = type.Key + "/Processed/" + DateTime.Now.ToString("MM-dd-yyyy") + "/";

                                        //从sftp获取文件到本地目录
                                        List <string> objList       = new List <string>();
                                        List <string> LocalFileList = new List <string>();
                                        objList = sftp.GetFileList(type.Key, new string[] { ".xls", ".xlsx" });
                                        if (objList.Count > 0)
                                        {
                                            Helper.CheckAndCreatePath(localPath);
                                            foreach (object obj in objList)
                                            {
                                                string fileUrl     = obj.ToString();
                                                string newFileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "--" + fileUrl;
                                                sftp.Get(type.Key + "/" + fileUrl, localPath + "/" + newFileName);
                                                LocalFileList.Add(newFileName);
                                                sftp.DeleteFile(type.Key + "/" + fileUrl);
                                            }

                                            if (Directory.Exists(localPath))
                                            {
                                                DirectoryInfo dr = new DirectoryInfo(localPath);
                                                foreach (FileInfo file in dr.GetFiles()
                                                         .Where(r => r.Extension.ToLower() == ".xls" || r.Extension.ToLower() == ".xlsx" &&
                                                                LocalFileList.Contains(r.Name)))
                                                {
                                                    Console.WriteLine(string.Format("Start processing {0}", file.FullName));
                                                    LoggerHelper.Info(string.Format("Start processing {0}", file.FullName));
                                                    //导入数据到BUP表
                                                    DataTable dt       = new DataTable();
                                                    string    errorMsg = "";
                                                    errorMsg = _bupProcessBusiness.InvalidateFile(file.FullName, type.Value.Count, type.Value.Type, out dt);
                                                    if (!string.IsNullOrEmpty(errorMsg))
                                                    {
                                                        Console.WriteLine(string.Format("Result: Error. Message: {0}", errorMsg));
                                                        LoggerHelper.Info(string.Format("Result: Error. Message: {0}", errorMsg));
                                                        WriteErrorMsg(sftp, localPath, failedPath, file, errorMsg);
                                                        continue;
                                                    }

                                                    int    identity       = 0;
                                                    string originFileName = file.Name.Substring(file.Name.IndexOf("--") + 2);
                                                    //Automation   默认发送邀请
                                                    switch ((BUPType)type.Value.Type)
                                                    {
                                                    case BUPType.School:
                                                        errorMsg = _bupProcessBusiness.ProcessSchool(dt, user.ID, originFileName, file.Name, user,
                                                                                                     out identity, BUPProcessType.Automation, item.CommunityId);
                                                        break;

                                                    case BUPType.Classroom:
                                                        errorMsg = _bupProcessBusiness.ProcessClassroom(dt, user.ID, originFileName, file.Name, user,
                                                                                                        item.CommunityId, out identity, BUPProcessType.Automation);
                                                        break;

                                                    case BUPType.Class:
                                                        errorMsg = _bupProcessBusiness.ProcessClass(dt, user.ID, originFileName, file.Name, user,
                                                                                                    out identity, BUPProcessType.Automation, item.CommunityId);
                                                        break;

                                                    case BUPType.Teacher:
                                                        errorMsg = _bupProcessBusiness.ProcessTeacher(dt, user.ID, "1", originFileName, file.Name, user,
                                                                                                      out identity, BUPProcessType.Automation, item.CommunityId);
                                                        break;

                                                    case BUPType.Student:
                                                        errorMsg = _bupProcessBusiness.ProcessStudent(dt, user.ID, originFileName, file.Name, user,
                                                                                                      out identity, BUPProcessType.Automation, item.CommunityId);
                                                        break;

                                                    case BUPType.CommunityUser:
                                                        errorMsg = _bupProcessBusiness.ProcessCommunityUser(dt, user.ID, false, "1", originFileName, file.Name,
                                                                                                            user, item.CommunityId, out identity, BUPProcessType.Automation);
                                                        break;

                                                    case BUPType.CommunitySpecialist:
                                                        errorMsg = _bupProcessBusiness.ProcessCommunityUser(dt, user.ID, true, "1", originFileName, file.Name,
                                                                                                            user, item.CommunityId, out identity, BUPProcessType.Automation);
                                                        break;

                                                    case BUPType.Principal:
                                                        errorMsg = _bupProcessBusiness.ProcessPrincipal(dt, user.ID, false, originFileName, file.Name, "1",
                                                                                                        user, item.CommunityId, out identity, BUPProcessType.Automation);
                                                        break;

                                                    case BUPType.SchoolSpecialist:
                                                        errorMsg = _bupProcessBusiness.ProcessPrincipal(dt, user.ID, true, originFileName, file.Name, "1",
                                                                                                        user, item.CommunityId, out identity, BUPProcessType.Automation);
                                                        break;

                                                    case BUPType.Parent:
                                                        errorMsg = _bupProcessBusiness.ProcessParent(dt, user.ID, originFileName, file.Name,
                                                                                                     out identity, BUPProcessType.Automation);
                                                        break;

                                                    default:
                                                        errorMsg = "Can not find this action: " + type.Value.Type;
                                                        break;
                                                    }
                                                    if (!string.IsNullOrEmpty(errorMsg))
                                                    {
                                                        Console.WriteLine(string.Format("Result: Error. Message: {0}", errorMsg));
                                                        LoggerHelper.Info(string.Format("Result: Error. Message: {0}", errorMsg));
                                                        WriteErrorMsg(sftp, localPath, failedPath, file, errorMsg);
                                                        continue;
                                                    }

                                                    //执行数据导入操作
                                                    try
                                                    {
                                                        if (identity > 0)
                                                        {
                                                            ProcessHandler handler     = new ProcessHandler(BUPTaskBusiness.Start);
                                                            IAsyncResult   asyncResult = handler.BeginInvoke(identity, user.ID, null, null);
                                                            handler.EndInvoke(asyncResult);  //此方法会等待异步执行完成后再往下执行
                                                            ProcessData(identity, user, LoggerHelper, sftp, successPath, file);
                                                        }
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Console.WriteLine(string.Format("Result: Error. Message: {0}", ex.Message));
                                                        LoggerHelper.Info(string.Format("Result: Error. Message: {0}", errorMsg));
                                                        WriteErrorMsg(sftp, localPath, failedPath, file, ex.Message);
                                                        continue;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                sftp.Disconnect();
                            }
                            else
                            {
                                LoggerHelper.Debug("Can not find user with the ID: " + item.CreatedBy + ". DateTime: " + DateTime.Now.ToString());
                            }
                        }
                        catch (Exception ex)
                        {
                            if (sftp.IsConnected)
                            {
                                sftp.Disconnect();
                            }
                            Console.WriteLine(ex.Message);
                            LoggerHelper.Info(string.Format("Result: Error. Message: {0}", ex.Message));
                            LoggerHelper.Debug(ex);
                        }
                    }
                    else
                    {
                        LoggerHelper.Info("can not connect to the sftp server");
                        Console.WriteLine("can not connect to the sftp server");
                    }
                }
            }
            LoggerHelper.Info("end ......");
            Console.WriteLine("end ......");
        }
Beispiel #14
0
        public static bool SaveWorkerRole(B_WORKER_ROLE entity)
        {
            using (MainDataContext dbContext = new MainDataContext())
            {
                using (MainDataContext dsContext = new MainDataContext(AppConfig.ConnectionStringDispatch))
                {
                    try
                    {
                        //同步Tperson
                        if (!string.IsNullOrEmpty(entity.EmpNo))
                        {
                            B_WORKER       worker = GetWorkerById(entity.WorkerID);
                            B_ORGANIZATION unit   = Organize.GetUnit(entity.OrgID);

                            if (dsContext.TPerson.Count(t => t.编码 == entity.TPerson编码) == 0)
                            {
                                //string empNo = GetCoding();
                                IApplicationContext ctx     = ContextRegistry.GetContext();
                                IEncrypt            encrypt = ctx["Encrypt"] as IEncrypt;

                                TPerson person = new TPerson();
                                person.编码    = entity.TPerson编码;
                                person.单位编码  = unit.Type == (int)OrgType.Branch ? unit.编码 : "-1";
                                person.通话号码  = worker.Tel ?? string.Empty;
                                person.短信号码  = worker.Mobile ?? string.Empty;
                                person.分站编码  = unit.Type == (int)OrgType.Station ? unit.编码 : AppConfig.GetStringConfigValue("VirtualCode");
                                person.类型编码  = entity.RoleID;
                                person.姓名    = worker.Name;
                                person.工号    = entity.EmpNo;
                                person.口令    = new HashEncrypt().DESEncrypt(encrypt.Decrypt(worker.PassWord), "");
                                person.次操作时间 = DateTime.Now;
                                person.顺序号   = int.Parse(entity.TPerson编码);
                                person.是否有效  = true;

                                dsContext.TPerson.InsertOnSubmit(person);
                            }
                            else
                            {
                                var tp = dsContext.TPerson.FirstOrDefault(t => t.编码 == entity.TPerson编码);

                                tp.单位编码 = unit.Type == (int)OrgType.Branch ? unit.编码 : "-1";
                                tp.分站编码 = unit.Type == (int)OrgType.Station ? unit.编码 : AppConfig.GetStringConfigValue("VirtualCode");
                                tp.类型编码 = entity.RoleID;
                                tp.工号   = entity.EmpNo;
                            }
                        }

                        //人员
                        if (entity.ID == 0)
                        {
                            var  list  = from a in dbContext.B_WORKER_ROLE select a.ID;
                            long total = list.LongCount();
                            if (total == 0)
                            {
                                entity.ID = 1;
                            }
                            else
                            {
                                entity.ID = dbContext.B_WORKER_ROLE.Max(a => a.ID) + 1;
                            }

                            entity.EmpNo     = entity.EmpNo ?? string.Empty;
                            entity.TPerson编码 = entity.TPerson编码 ?? string.Empty;

                            dbContext.B_WORKER_ROLE.InsertOnSubmit(entity);
                        }
                        else
                        {
                            var model = dbContext.B_WORKER_ROLE.FirstOrDefault(b => b.ID == entity.ID);

                            model.OrgID     = entity.OrgID;
                            model.WorkerID  = entity.WorkerID;
                            model.RoleID    = entity.RoleID;
                            model.EmpNo     = entity.EmpNo ?? string.Empty;
                            model.ID        = entity.ID;
                            model.TPerson编码 = entity.TPerson编码 ?? string.Empty;
                        }

                        dbContext.SubmitChanges();
                        dsContext.SubmitChanges();
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        Log4Net.LogError("SaveWorkerRole", ex.ToString());
                        return(false);
                    }
                }
            }
        }