예제 #1
0
 public FindContext(string ConnectionString)
 {
     this._ConnectionString = ConnectionString;
     if (find != null)
     {
         find = new FindString();
     }
     dbhelper = new DbHelper(ConnectionString);
     jss      = new JavaScriptSerializer();
 }
        private void UpdateFindResults()
        {
            if (FindString == null || FindString.Trim().Length < 2)
            {
                FPopupIsOpen = false;
                return;
            }
            var res = GetFindResults(FindString);

            if (res.Count == 0)
            {
                InfoText           = "Соответствий не найдено";
                InfoTextVisibility = Visibility.Visible;
            }
            else
            {
                InfoTextVisibility = Visibility.Collapsed;
            }

            FindTextCollection = res;
            FPopupIsOpen       = true;
        }
예제 #3
0
        void ApproveEnumCommon <T>(string label, StringBuilder sb, bool expectGenerated, GenerateLookup generateLookup, FindString findString)
        {
            var buffer = new byte[1024];

            for (int i = 0; i < buffer.Length; i++)
            {
                buffer[i] = 255;
            }
            var values = StringEnum.SortValues(typeof(T));

            fixed(byte *ptr = buffer)
            {
                var lookup = generateLookup(values, ptr, buffer.Length);

                if (!expectGenerated)
                {
                    Assert.False(lookup.HasValue, "lookup must not have been generated");
                    return;
                }

                Assert.True(lookup.HasValue, "lookup must have been generated");
                var stringStart = (int)(lookup.Value.StringStart - ptr);


                sb.AppendLine("# " + label + " " + SchemaTest.HumanName(typeof(T)));
                sb.AppendLine();
                sb.AppendLine(String.Format("GetLookupType: {0}", StringEnum.GetLookupType(values)));
                sb.AppendLine(String.Format("Values count: {0}", values.Length));
                sb.AppendLine(String.Format("Max value: {0}", values.LastOrDefault().Key));
                sb.AppendLine();
                sb.AppendLine("## Lookups");
                Util.Hex.Dump(sb, buffer.Take(stringStart));
                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine("## Strings");
                Util.Hex.Dump(sb, buffer.Skip(stringStart).Take((int)lookup.Value.StringLength));


                bool signed = false;

                switch (Type.GetTypeCode(typeof(T)))
                {
                case TypeCode.SByte:
                case TypeCode.Int16:
                case TypeCode.Int32:
                case TypeCode.Int64:
                    signed = true;
                    break;
                }

                var chars = new char[64];

                foreach (T dow in Enum.GetValues(typeof(T)))
                {
                    byte *str;
                    int   len;
                    ulong enumValue = signed ? (ulong)Convert.ToInt64(dow) : Convert.ToUInt64(dow);
                    findString(lookup.Value, enumValue, out str, out len);
                    Assert.True(str != null, "string must not be null");
                    var dowString = dow.ToString();
                    Assert.Equal(Encoding.UTF8.GetByteCount(dowString), len);

                    string actualString;
                    fixed(char *ch = chars)
                    {
                        var strLen = Encoding.UTF8.GetChars(str, len, ch, chars.Length);

                        actualString = new string(ch, 0, strLen);
                    }

                    Assert.Equal(dowString, actualString);
                }
            }
        }