Ejemplo n.º 1
0
        private bool IsMatchName(DataGridView grid, int rowIndex, UserSettings settings, bool seed)
        {
            if (grid != null && settings != null && settings.MatchingKeywords.Count > 0)
            {
                var isMatched = false;
                var target    = TypeParser.GetStringValue(grid.Rows[rowIndex].Cells[Namespace.GridColProjectTitleRaw].Value);
                foreach (var keyword in settings.MatchingKeywords)
                {
                    if (target.Contains(keyword))
                    {
                        isMatched = true;
                        break;
                    }
                }

                if (isMatched)
                {
                    seed = seed & true;
                }
                else
                {
                    seed = false;
                }
            }
            return(seed);
        }
Ejemplo n.º 2
0
 public string GetNamespance(Type typeOwner)
 {
     if (typeOwner != null)
     {
         return(EnableFullNamespace ?
                TypeParser.GetStringValue($"{typeOwner.Namespace}.{typeOwner.Name}").Replace(".", string.Empty) :
                TypeParser.GetStringValue(typeOwner.Name));
     }
     return(string.Empty);
 }
Ejemplo n.º 3
0
        public static string SubLeftString(this string str, int length, string fillMark = "")
        {
            var tmp = TypeParser.GetStringValue(str);

            if (str.Length > length)
            {
                str = $"{str.Substring(0, length - 1)}{fillMark}";
            }

            return(tmp);
        }
Ejemplo n.º 4
0
        public static string SubRightString(this string str, int length, string fillMark = "")
        {
            var tmp = TypeParser.GetStringValue(str);

            if (str.Length > length)
            {
                var diff = str.Length - length;
                str = $"{str.Substring(diff, length - diff)}{fillMark}";
            }

            return(tmp);
        }
Ejemplo n.º 5
0
 public static void TryRetriveFromConfig(this UserSettings setting)
 {
     if (setting == null)
     {
         setting = new UserSettings();
     }
     setting.SearchingKeywordsString = TypeParser.GetStringValue(ConfigurationManager.AppSettings[UserSettings.Namespance.SearchingKeyword]);
     setting.MatchingKeywordsString  = TypeParser.GetStringValue(ConfigurationManager.AppSettings[UserSettings.Namespance.MatchingKeyword]);
     setting.Yijia         = TypeParser.GetDouble(ConfigurationManager.AppSettings[UserSettings.Namespance.Yijia]);
     setting.Rate          = TypeParser.GetDouble(ConfigurationManager.AppSettings[UserSettings.Namespance.Rate]);
     setting.NextPayment   = TypeParser.GetInt(ConfigurationManager.AppSettings[UserSettings.Namespance.NextPayment]);
     setting.FreqTransfer  = TypeParser.GetInt32Value(ConfigurationManager.AppSettings[UserSettings.Namespance.FreqTransfer], 60);
     setting.DelayTransfer = TypeParser.GetInt32Value(ConfigurationManager.AppSettings[UserSettings.Namespance.DelayTransfer]);
     setting.PageFrom      = TypeParser.GetInt32Value(ConfigurationManager.AppSettings[UserSettings.Namespance.PageFrom]);
     setting.PageTo        = TypeParser.GetInt32Value(ConfigurationManager.AppSettings[UserSettings.Namespance.PageTo]);
     setting.AutoAcquire   = TypeParser.GetBoolValue(ConfigurationManager.AppSettings[UserSettings.Namespance.AutoAcquire]);
 }
Ejemplo n.º 6
0
        public async Task <IActionResult> Login([FromBody] vmLogin para)
        {
            using (var db = DbContextFactory.CreateSxhContext())
            {
                var targetUser = await db.User.FirstOrDefaultAsync(u => u.Id == para.UserName);

                if (targetUser != null)
                {
                    if (targetUser.Expired.HasValue)
                    {
                        if (DateTime.UtcNow > targetUser.Expired.Value.ToUniversalTime())
                        {
                            return(StatusCode((int)HttpStatusCode.Forbidden, "user expired"));
                        }
                    }

                    var pswEncrpyt = TypeParser.GetStringValue(para.Password).Md5Encrypt();
                    if (string.IsNullOrEmpty(targetUser.Psw) || targetUser.Psw == pswEncrpyt)
                    {
                        if (string.IsNullOrEmpty(targetUser.Psw))
                        {
                            //first time login
                            targetUser.Psw = pswEncrpyt;
                            db.User.Update(targetUser);
                            await db.SaveChangesAsync();
                        }

                        var mgr   = new JwtManager(AppSetting.Instance.SecretKey);
                        var token = mgr.TokenCreate(para.UserName, para.UserName, AppSetting.Instance.TokenExpiredHour);
                        return(Ok(token));
                    }
                    else
                    {
                        return(StatusCode((int)HttpStatusCode.Forbidden, "invalid user name or password"));
                    }
                }
            }

            return(Unauthorized());
        }
Ejemplo n.º 7
0
        private void LoadFromFile(string fileName)
        {
            Clear();

            if (File.Exists(fileName))
            {
                var xmlDoc = new XmlDocument();
                xmlDoc.Load(fileName);

                var selectSingleNode = xmlDoc.SelectSingleNode(Namespace.Root);
                if (selectSingleNode != null)
                {
                    foreach (XmlElement childNode in selectSingleNode.ChildNodes)
                    {
                        var proxy = new UserProxy();
                        proxy.UserName = TypeParser.GetStringValue(childNode.GetAttribute(Namespace.Id));
                        proxy.Password = TypeParser.GetStringValue(childNode.GetAttribute(Namespace.Password));
                        Add(proxy);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private void LoadFromFile()
        {
            Clear();

            if (File.Exists(Namespace.FileName))
            {
                var xmlDoc = new XmlDocument();
                xmlDoc.Load(Namespace.FileName);

                var selectSingleNode = xmlDoc.SelectSingleNode(Namespace.Root);
                if (selectSingleNode != null)
                {
                    foreach (XmlElement childNode in selectSingleNode.ChildNodes)
                    {
                        var account = new UserAccount();
                        account.UserName     = TypeParser.GetStringValue(childNode.GetAttribute(Namespace.Id));
                        account.Password     = TypeParser.GetStringValue(childNode.GetAttribute(Namespace.Password));
                        account.PasswordTran = TypeParser.GetStringValue(childNode.GetAttribute(Namespace.Tranword));
                        Add(account);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        private ServerSettings CheckVersion(ServerSettings serverSettings, ClientSettings clientSettings)
        {
            if (clientSettings == null || serverSettings == null)
            {
                return(serverSettings);
            }

            var ret = new ServerSettings();

            ret.TargetServer = ServerSettings.TargetServer;

            var versionLocal = TypeParser.GetStringValue(clientSettings.LocalVersion).Split('.');

            foreach (var serverSettingItem in serverSettings.Items)
            {
                var versionServer = TypeParser.GetStringValue(serverSettingItem.ReleaseVersion).Split('.');

                if (versionLocal.Length != versionServer.Length)
                {
                    ret.Items.Add(serverSettingItem);
                    continue;
                }

                for (var i = 0; i < versionLocal.Length; i++)
                {
                    var valLocal  = TypeParser.GetInt32Value(versionLocal[i]);
                    var valServer = TypeParser.GetInt32Value(versionServer[i]);
                    if (valLocal < valServer)
                    {
                        ret.Items.Add(serverSettingItem);
                        break;
                    }
                }
            }
            return(ret);
        }
Ejemplo n.º 10
0
 public static void TrySaveToConfig(this UserSettings setting)
 {
     if (setting != null)
     {
         var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
         config.AppSettings.Settings[UserSettings.Namespance.SearchingKeyword].Value = setting.SearchingKeywordsString;
         config.AppSettings.Settings[UserSettings.Namespance.MatchingKeyword].Value  = setting.MatchingKeywordsString;
         config.AppSettings.Settings[UserSettings.Namespance.Yijia].Value            = TypeParser.GetStringValue(setting.Yijia);
         config.AppSettings.Settings[UserSettings.Namespance.Rate].Value             = TypeParser.GetStringValue(setting.Rate);
         config.AppSettings.Settings[UserSettings.Namespance.NextPayment].Value      = TypeParser.GetStringValue(setting.NextPayment);
         config.AppSettings.Settings[UserSettings.Namespance.FreqTransfer].Value     = TypeParser.GetStringValue(setting.FreqTransfer);
         config.AppSettings.Settings[UserSettings.Namespance.DelayTransfer].Value    = TypeParser.GetStringValue(setting.DelayTransfer);
         config.AppSettings.Settings[UserSettings.Namespance.PageFrom].Value         = TypeParser.GetStringValue(setting.PageFrom);
         config.AppSettings.Settings[UserSettings.Namespance.PageTo].Value           = TypeParser.GetStringValue(setting.PageTo);
         config.AppSettings.Settings[UserSettings.Namespance.AutoAcquire].Value      = TypeParser.GetStringValue(setting.AutoAcquire);
         config.Save(ConfigurationSaveMode.Modified);
     }
 }
Ejemplo n.º 11
0
        private string FormatMatchingKeywords(string inputKeyword)
        {
            var outputKeyword = TypeParser.GetStringValue(inputKeyword).Trim().TrimStart(new char[] { ';' }).TrimEnd(new char[] { ';' });

            return(outputKeyword);
        }