Esempio n. 1
0
        private string GetData(string mac, StrType type)
        {
            SqlCommand sqlCommand = null;

            switch (type)
            {
            case StrType.EserverName:
                sqlCommand = new SqlCommand("SELECT (name) FROM [server_table] WHERE mac=@mac;", sqlConnect);
                sqlCommand.Parameters.AddWithValue("mac", mac);
                break;

            case StrType.EipAddress:
                sqlCommand = new SqlCommand("SELECT (ip) FROM [server_table] WHERE mac=@mac;", sqlConnect);
                sqlCommand.Parameters.AddWithValue("mac", mac);
                break;

            case StrType.Eport:
                sqlCommand = new SqlCommand("SELECT (port) FROM [settings] WHERE id=1;", sqlConnect);
                break;

            case StrType.EautoConn:
                sqlCommand = new SqlCommand("SELECT (auto_connection) FROM [settings] WHERE id=1;", sqlConnect);
                break;

            case StrType.ElastIP:
                sqlCommand = new SqlCommand("SELECT (prev_server) FROM [settings] WHERE id=1;", sqlConnect);
                break;
            }

            return(Convert.ToString(sqlCommand.ExecuteScalar()));
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the type of the given string. If the given string does not exist in the table than it inserts it with a given type.
        /// </summary>
        /// <param name="str">[in] The string.</param>
        /// <param name="type">[in] The type of the string.</param>
        public void setType(string str, StrType type)
        {
            if (str == null || str.Length == 0)
            {
                return;
            }

            uint key;

            ushort hashValue   = hash(str);
            uint   bucketIndex = hashValue % numberOfBuckets;

            if ((key = get(str, hashValue, bucketIndex)) == 0)
            {
                key = (((uint)hashValue) << 16) | count[bucketIndex]++;

                if (count[bucketIndex] == 0xFFFF)
                {
                    WriteMsg.WriteLine("StrTable: Bucket ({0}) is full!", WriteMsg.MsgLevel.Error, bucketIndex);
                }
                if (!strTable[bucketIndex].ContainsKey(key))
                {
                    strTable[bucketIndex].Add(key, new KeyValuePair <string, StrType>(str, type));
                }

#if (DOSTAT)
                statisticCounter[bucketIndex].ElementCount++;
#endif
            }
            else
            {
                strTable[bucketIndex][key] = new KeyValuePair <string, StrType>(strTable[bucketIndex][key].Key, type);
            }
        }
Esempio n. 3
0
        public Entity(int id, EntityType etype)
            : this(etype)
        {
            Id = id;

            HtmlDocument htmlDoc = LoadWowHeadEntity(StrType.ToLower(), id);
            Initialize(htmlDoc);
        }
Esempio n. 4
0
        /// <summary>
        /// Sets the type of the string stored in the string table with the given "unique" key.
        /// </summary>
        /// <param name="key">[in] The unique key.</param>
        /// <param name="type">[in] The type of the string.</param>
        public void setType(uint key, StrType type)
        {
            uint bucketIndex = (key >> 16) % numberOfBuckets;

            if (strTable[bucketIndex].ContainsKey(key))
            {
                strTable[bucketIndex][key] = new KeyValuePair <string, StrType>(strTable[bucketIndex][key].Key, type);
            }
        }
        /// <summary>
        /// 生成指定字符类型和个数的随机字符串
        /// </summary>
        /// <param name="strType">所需字符类型</param>
        /// <param name="n">字符个数</param>
        /// <returns></returns>
        public static string RandomStr(StrType strType, int n)//b:是否有复杂字符,n:生成的字符串长度
        {
            string numberStr            = "0123456789";
            string lowerCase            = "abcdefghijklmnopqrstuvwxyz";
            string upperCase            = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            string numberStrRemoveVague = "123456789";
            string lowerCaseRemoveVague = "abcdefghijkmnpqrstuvwxyz";
            string upperCaseRemoveVague = "ABCDEFGHJKLMNPQRSTUVWXYZ";
            string specialCharacter     = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";//复杂字符
            string str = string.Empty;

            switch (strType)
            {
            case StrType.Lowercase: str += lowerCase; break;

            case StrType.NumAndCase: str += numberStr + lowerCase + upperCase; break;

            case StrType.NumAndCaseRemoveVague:
                str += numberStrRemoveVague + lowerCaseRemoveVague + upperCaseRemoveVague; break;

            case StrType.NumAndCaseSpecialCharacter:
                str += numberStr + lowerCase + upperCase + specialCharacter; break;

            case StrType.NumAndLcaseRemoveVague:
                str += numberStrRemoveVague + lowerCaseRemoveVague; break;

            case StrType.NumAndLowercase:
                str += numberStr + lowerCase; break;

            case StrType.NumAndUcaseRemoveVague:
                str += numberStrRemoveVague + upperCaseRemoveVague; break;

            case StrType.NumAndUppercase: str += numberStr + upperCase; break;

            case StrType.OnlyNumber: str += numberStr; break;

            case StrType.Uppercase: str += upperCase; break;

            default:
                str += numberStrRemoveVague + lowerCaseRemoveVague + upperCaseRemoveVague + specialCharacter; break;
            }
            StringBuilder randStr = new StringBuilder();
            Random        rd      = new Random();

            for (int i = 0; i < n; i++)
            {
                randStr.Append(str.Substring(rd.Next(0, str.Length), 1));
            }
            return(randStr.ToString());
        }
Esempio n. 6
0
        /// <summary>
        /// Saves the string table to the given file.
        /// </summary>
        /// <param name="io">[in] The file writer.</param>
        /// <param name="filterType">[in] Type of the strings to save.</param>
        public void save(IO io, StrType filterType)
        {
            try {
                io.writeData("STRTBL", 6);
                io.writeUInt4(numberOfBuckets);

                for (int i = 0; i < numberOfBuckets; ++i)
                {
                    io.writeUShort2(count[i]);
                }

                for (int j = 0; j < numberOfBuckets; ++j)
                {
                    Dictionary <uint, KeyValuePair <string, StrType> > currentMap = strTable[j];

                    foreach (KeyValuePair <uint, KeyValuePair <string, StrType> > entry in currentMap)
                    {
                        if (filterType == StrType.strTmp)
                        {
                            if (entry.Value.Value == StrType.strTmp)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            if (filterType == StrType.strToSave)
                            {
                                if (entry.Value.Value != StrType.strToSave)
                                {
                                    continue;
                                }
                            }
                        }

                        io.writeUInt4(entry.Key);
                        io.writeUInt4((uint)entry.Value.Key.Length);
                        io.writeData(entry.Value.Key, entry.Value.Key.Length);
                    }
                }

                io.writeUInt4(0);
            } catch {
                WriteMsg.WriteLine("StrTable.save(): Error while writing!", WriteMsg.MsgLevel.Error);
            }
        }
Esempio n. 7
0
        public bool DoesExist(string macOrName, StrType type)
        {
            SqlCommand sqlCommand = null;

            switch (type)
            {
            case StrType.EserverName:
                sqlCommand = new SqlCommand("SELECT (name) FROM [server_table] WHERE name=@macOrName;", sqlConnect);
                break;

            case StrType.EmacAddress:
                sqlCommand = new SqlCommand("SELECT (name) FROM [server_table] WHERE mac=@macOrName;", sqlConnect);
                break;
            }

            sqlCommand.Parameters.AddWithValue("macOrName", macOrName);
            String result = Convert.ToString(sqlCommand.ExecuteScalar());

            return(!String.IsNullOrEmpty(result));
        }
Esempio n. 8
0
        //not tested yet! Need to make 5-th point first
        public async void ChangeRow(string strValue, StrType type)
        {
            SqlCommand sqlCommand = null;

            switch (type)
            {
            case StrType.Eport:
                sqlCommand = new SqlCommand("UPDATE [settings] SET port=@port WHERE id=1", sqlConnect);
                sqlCommand.Parameters.AddWithValue("port", strValue);
                break;

            case StrType.EautoConn:
                sqlCommand = new SqlCommand("UPDATE [settings] SET auto_connection=@auto WHERE id=1", sqlConnect);
                sqlCommand.Parameters.AddWithValue("auto", strValue);
                break;

            case StrType.ElastIP:
                sqlCommand = new SqlCommand("UPDATE [settings] SET prev_server=@auto WHERE id=1", sqlConnect);
                sqlCommand.Parameters.AddWithValue("auto", strValue);
                break;

            case StrType.EserverName:
                sqlCommand = new SqlCommand("UPDATE [server_table] SET name=@newName WHERE name=@name", sqlConnect);
                sqlCommand.Parameters.AddWithValue("newName", strValue);
                sqlCommand.Parameters.AddWithValue("name", listBox1.SelectedItem.ToString());
                break;

            case StrType.EipAddress:
                sqlCommand = new SqlCommand("UPDATE [server_table] SET ip=@new_ip WHERE ip=@old_ip", sqlConnect);
                sqlCommand.Parameters.AddWithValue("new_ip", strValue);
                sqlCommand.Parameters.AddWithValue("old_ip", listBox1.SelectedItem.ToString());
                break;
            }

            await sqlCommand.ExecuteNonQueryAsync();
        }
Esempio n. 9
0
        private bool Str_Decision(string str, int len, StrType st, OpeType ot)
        {
            switch (ot)
            {
                case OpeType.EQ:
                    if (str.Length == len)
                    {
                        break;
                    }
                    return false;

                case OpeType.GE:
                    if ((str.Length != 0) && (str.Length <= len))
                    {
                        break;
                    }
                    return false;

                case OpeType.GT:
                    if (str.Length >= len)
                    {
                        break;
                    }
                    return false;

                case OpeType.LE:
                    if ((str.Length != 0) && (str.Length < len))
                    {
                        break;
                    }
                    return false;

                case OpeType.LT:
                    if (str.Length > len)
                    {
                        break;
                    }
                    return false;
            }
            char[] chArray = str.ToUpper().ToCharArray();
            switch (st)
            {
                case StrType.IsDigit:
                    foreach (char ch in chArray)
                    {
                        if ((ch < '0') || (ch > '9'))
                        {
                            return false;
                        }
                    }
                    break;

                case StrType.IsLetter:
                    foreach (char ch2 in chArray)
                    {
                        if ((ch2 < 'A') || (ch2 > 'Z'))
                        {
                            return false;
                        }
                    }
                    break;

                case StrType.IsLetterOrDigit:
                    foreach (char ch3 in chArray)
                    {
                        if (((ch3 < '0') || (ch3 > '9')) && ((ch3 < 'A') || (ch3 > 'Z')))
                        {
                            return false;
                        }
                    }
                    break;

                case StrType.IsSymbol:
                    foreach (char ch4 in chArray)
                    {
                        if ((ch4 < ' ') || (ch4 > '\x007f'))
                        {
                            return false;
                        }
                    }
                    break;

                case StrType.IsNACCS:
                    foreach (char ch5 in chArray)
                    {
                        if ((ch5 < ' ') || (ch5 > ']'))
                        {
                            return false;
                        }
                        if (((ch5 == '$') || (ch5 == '%')) || ((ch5 == '\'') || (ch5 == '*')))
                        {
                            return false;
                        }
                    }
                    break;
            }
            return true;
        }
Esempio n. 10
0
        public static string readString(System.IO.BinaryReader data, StrType type)
        {
            uint len;
            if (type == StrType.LEN_Byte)
                len = data.ReadByte();
            else if (type == StrType.LEN_UShort)
                len = data.ReadUInt16();
            else
                len = data.ReadUInt32();

            byte[] tmp = data.ReadBytes((int)len);
            return System.Text.ASCIIEncoding.ASCII.GetString(tmp);
        }
 public StrTypePair(string s, StrType t)
 {
     str = s;
     type = t;
 }