예제 #1
0
        /// <summary>
        /// 通过枚举<paramref name="enumObj"/>得到该枚举的Description
        /// 如果该枚举没有对应的Description,则将返回该枚举的ToString()值
        /// </summary>
        /// <param name="enumObj">枚举</param>
        /// <returns>对应的Description</returns>
        public string GetName(Enum enumObj)
        {
            EnumObject obj = null;
            Type       t   = enumObj.GetType();

            testEnum(t);

            string             strType    = t.FullName;
            IList <EnumObject> list       = dicEnum[strType];
            string             testString = enumObj.ToString();

            foreach (EnumObject item in list)
            {
                if (item.ID == testString)
                {
                    obj = item;
                }
            }
            if (obj == null)
            {
                //throw new NeuException(string.Format( "所指定的类型值不存在[0]...",enumObj.ToString()))
                return(testString);
            }
            return(obj.GetNameByLanguage(this.language));
        }
예제 #2
0
        public void Filed_property_test()
        {
            EnumObject enumObject = MockFlagsEnum.A;
            var        aField     = typeof(MockFlagsEnum).GetField("A");

            Assert.Same(aField, enumObject.Filed);
        }
예제 #3
0
        public void IsFlag_property_test()
        {
            EnumObject enumObject     = MockEnum.A;
            EnumObject flagEnumObject = MockFlagsEnum.A;

            Assert.False(enumObject.IsFlag);
            Assert.True(flagEnumObject.IsFlag);
        }
예제 #4
0
        /// <summary>
        /// Find a window by a matching ClassName string
        /// </summary>
        /// <param name="classname">The classname that the window should match</param>
        /// <returns>The Handle of a matching window, if found</returns>
        public static IntPtr FindByClassName(string classname)
        {
            EnumObject endVals = new EnumObject();

            endVals.Data = classname;
            NativeMethods.EnumWindows(new EnumCallBack(FindByClassCallback), ref endVals);
            return(endVals.hWnd);
        }
예제 #5
0
        /// <summary>
        /// Find a child window of the given window, using a passed function
        /// </summary>
        /// <param name="hwndParent">The parent window to find a child window of</param>
        /// <param name="testFunc">Function used to test the child window; takes the child window handle in, returns True if match</param>
        /// <returns>The handle of a matching window, if found</returns>
        public static IntPtr FindChild(IntPtr hwndParent, Func <IntPtr, bool> testFunc)
        {
            EnumObject endVals = new EnumObject();

            endVals.Data = testFunc;
            NativeMethods.EnumChildWindows(hwndParent, new EnumCallBack(FindChildCallback), ref endVals);
            return(endVals.hWnd);
        }
예제 #6
0
        /// <summary>
        /// Find a window according to its Class Name, using a passed function
        /// </summary>
        /// <param name="testFunc">Function used to test the ClassName; takes ClassName in, returns True if match</param>
        /// <returns>The handle of a matching window, if found</returns>
        public static IntPtr FindByClassName(Func <string, bool> testFunc)
        {
            EnumObject endVals = new EnumObject();

            endVals.Data = testFunc;
            NativeMethods.EnumWindows(new EnumCallBack(FindByClassCallback), ref endVals);
            return(endVals.hWnd);
        }
예제 #7
0
        public void Description_property_test()
        {
            EnumObject hasDescriptionAttributeEnumObject = MockFlagsEnum.C;
            EnumObject noDescriptionAttributeEnumObject  = MockFlagsEnum.All;

            Assert.Null(noDescriptionAttributeEnumObject.Description);
            Assert.Equal("答案是C", hasDescriptionAttributeEnumObject.Description);
        }
예제 #8
0
        /// <summary>
        /// Find a window according to its caption, using a passed function
        /// </summary>
        /// <param name="testFunc">Function used to test the caption; takes Caption in, returns True if match</param>
        /// <returns>The handle of a matching window, if found</returns>
        public static IntPtr FindByCaption(Func <string, bool> testFunc)
        {
            NativeMethods.RegisterWindowMessage("WM_GETTEXT");
            EnumObject endVals = new EnumObject();

            endVals.Data = testFunc;
            NativeMethods.EnumWindows(new EnumCallBack(FindByCaptCallback), ref endVals);
            return(endVals.hWnd);
        }
예제 #9
0
        public string GetEnumName <T>(T enumObj)
        {
            EnumObject obj = this.GetEnum <T>(enumObj);

            if (obj != null)
            {
                return(obj.GetNameByLanguage(this.language));
            }
            return(enumObj.ToString());
        }
예제 #10
0
        public void NumberAsEnum()
        {
            var simple = FSBuilder.Take <EnumObject>("|", "A").Else((s, o) => { throw new InvalidOperationException(); }).Seal();

            var obj = new EnumObject();

            simple("2|", obj);

            Assert.AreEqual(EnumObject.Blah.Bar, obj.A);
        }
예제 #11
0
 protected override object ComputeValue()
 {
     if (typeof(EnumObject).IsAssignableFrom(_enumType))
     {
         return(EnumObject.FromString(_enumType, _enumLiteral));
     }
     else
     {
         return(Enum.Parse(_enumType, _enumLiteral));
     }
 }
예제 #12
0
 protected void Page_Load(object sender, EventArgs e)
 {
     _Presenter=new RegisterPresenter();
     _Presenter.Init(this);
     if (rdbCuuSinhVien.Checked == true)
         DoiTuong = EnumObject.User;
     else if (rdbGiaoVien.Checked == true)
         DoiTuong = EnumObject.User;
     else if (rdbNguoiNgoai.Checked == true)
         DoiTuong = EnumObject.OutUser;
 }
 static MetaGeneratorTokensSyntaxKind()
 {
     EnumObject.AutoInit <MetaGeneratorTokensSyntaxKind>();
     __FirstToken           = KNamespace;
     __FirstTokenValue      = (int)__FirstToken;
     __LastToken            = COMMENT_START;
     __LastTokenValue       = (int)__LastToken;
     __FirstFixedToken      = KNamespace;
     __FirstFixedTokenValue = (int)__FirstFixedToken;
     __LastFixedToken       = DoubleQuoteVerbatimStringLiteralStart;
     __LastFixedTokenValue  = (int)__LastFixedToken;
 }
예제 #14
0
 static MetaTokensSyntaxKind()
 {
     EnumObject.AutoInit <MetaTokensSyntaxKind>();
     __FirstToken           = KNamespace;
     __FirstTokenValue      = (int)__FirstToken;
     __LastToken            = LCommentStart;
     __LastTokenValue       = (int)__LastToken;
     __FirstFixedToken      = KNamespace;
     __FirstFixedTokenValue = (int)__FirstFixedToken;
     __LastFixedToken       = LCommentStart;
     __LastFixedTokenValue  = (int)__LastFixedToken;
 }
예제 #15
0
        public void ToString_method_test()
        {
            EnumObject hasDescriptionAttributeEnumObject = MockFlagsEnum.C;
            EnumObject noDescriptionAttributeEnumObject  = MockFlagsEnum.All;
            EnumObject enumObject1 = MockFlagsEnum.A | MockFlagsEnum.B | MockFlagsEnum.C | MockFlagsEnum.D;
            EnumObject enumObject2 = MockFlagsEnum.A | MockFlagsEnum.B | MockFlagsEnum.C;

            Assert.Equal("答案是C", hasDescriptionAttributeEnumObject.ToString());
            Assert.Equal("All", noDescriptionAttributeEnumObject.ToString());
            Assert.Equal("All", enumObject1.ToString());
            Assert.Equal("A, B, C", enumObject2.ToString());
        }
예제 #16
0
 static MetaSyntaxKind()
 {
     EnumObject.AutoInit <MetaSyntaxKind>();
     __FirstToken      = KNamespace;
     __LastToken       = LCommentStart;
     __FirstFixedToken = KNamespace;
     __LastFixedToken  = LCommentStart;
     __FirstRule       = Main;
     __FirstRuleValue  = (int)__FirstRule;
     __LastRule        = StringLiteral;
     __LastRuleValue   = (int)__LastRule;
 }
예제 #17
0
 static Antlr4RoslynTokensSyntaxKind()
 {
     EnumObject.AutoInit <Antlr4RoslynTokensSyntaxKind>();
     __FirstToken           = TOKEN_REF;
     __FirstTokenValue      = (int)__FirstToken;
     __LastToken            = DOC_COMMENT_STAR;
     __LastTokenValue       = (int)__LastToken;
     __FirstFixedToken      = OPTIONS;
     __FirstFixedTokenValue = (int)__FirstFixedToken;
     __LastFixedToken       = NULL;
     __LastFixedTokenValue  = (int)__LastFixedToken;
 }
        public void TestEnumObjectSerialization()
        {
            EnumTestPatternBuffer patternBuffer = new EnumTestPatternBuffer();
            EnumObject            u             = new EnumObject(SomeEnum.value1);

            byte[] bytes = patternBuffer.Energize(u);
            Assert.AreEqual(3, bytes.Length);
            object o = patternBuffer.Energize(bytes);

            Assert.IsTrue(o is EnumObject);
            Assert.AreEqual(u.SomeEnumValue, ((EnumObject)o).SomeEnumValue);
            Assert.IsFalse(u == o);
        }
예제 #19
0
 /// <summary>
 /// Private function used to find a Child Window -- Callback for EnumChildWindows
 /// </summary>
 /// <param name="hWnd">The window currently being tested</param>
 /// <param name="param">EnumWindowsObject passed to EnumChildWindows</param>
 /// <returns>Whether to continue procesing windows or exit with this one</returns>
 private static bool FindChildCallback(IntPtr hWnd, ref EnumObject param)
 {
     if (param.Data is Func <IntPtr, bool> )
     {
         Func <IntPtr, bool> testFunc = (Func <IntPtr, bool>)param.Data;
         if (testFunc(hWnd))
         {
             param.hWnd = hWnd;
             return(false);
         }
     }
     return(true);
 }
예제 #20
0
        /// <summary>
        /// 身份证识别
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <IDCardResponse> DetectAsync(IDCardRequest request)
        {
            Throws.ArgumentNullException(request, nameof(request));
            Throws.ArgumentNullException(request.ImgUrl, nameof(request.ImgUrl));
            try
            {
                var httpClient = this._options.HttpClient;

                var httpRequest = BuildHttpRequestMessage(request);

                var response = await httpClient.RequestJsonAsync <TencentOCRResponse>(httpRequest);

                var    result     = response.Result_List.First();
                var    resultData = result.Data;
                var    validDate  = resultData.Valid_date.Default("").Split('-');
                string startDate  = null;
                string endDate    = null;
                if (validDate?.Length == 2)
                {
                    startDate = validDate[0];
                    endDate   = validDate[1];
                }
                return(new IDCardResponse
                {
                    Success = result.Code == 0,
                    Message = result.Message,
                    Result = new IDCard
                    {
                        //正面
                        Address = resultData.Address,
                        Birth = resultData.Birth,
                        Id = resultData.Id,
                        Name = resultData.Name,
                        Nation = resultData.Nation,
                        Gender = EnumObject.GetNullableEnumFromDescription <Gender>(resultData.Sex),
                        //反面
                        Authority = resultData.Authority,
                        StartDate = startDate,
                        EndDate = endDate
                    }
                });
            }
            catch (Exception ex)
            {
                return(new IDCardResponse
                {
                    Success = false,
                    Message = ex.Message
                });
            }
        }
예제 #21
0
        public Page GetPage(PageTypes pageType)
        {
            for (int i = 0; i < pages.Length; i++)
            {
                EnumObject enumObject = pages [i];
                if (( PageTypes )enumObject.enumAsInt == pageType)
                {
                    Page page = (( GameObject )enumObject._object).GetComponent <Page>();
                    return(page);
                }
            }

            return(null);
        }
예제 #22
0
        public bool InsertReview(Review review)
        {
            List <ParmStruct> parms = new List <ParmStruct>();

            parms.Add(new ParmStruct("@EmployeeId", review.EmployeeId, SqlDbType.Int));
            parms.Add(new ParmStruct("@SupervisorId", review.SupervisorId, SqlDbType.Int));
            parms.Add(new ParmStruct("@Date", review.Date, SqlDbType.Date));
            parms.Add(new ParmStruct("@Performance", EnumObject.GetDescription(review.Performance), SqlDbType.NVarChar, size: 50));
            parms.Add(new ParmStruct("@Comment", review.Comment, SqlDbType.Text));

            DataAccess db = new DataAccess();

            return(db.ExecuteNonQuery("InsertReview", CommandType.StoredProcedure, parms) > 0);
        }
예제 #23
0
 protected override void Awake()
 {
     base.Awake();
     audioSources = new EnumObject [audioDatas.Length];
     for (int i = 0; i < audioSources.Length; i++)
     {
         EnumObject  enumObject  = new EnumObject();
         AudioSource audioSource = new GameObject($"AudioSource {i}").AddComponent <AudioSource>();
         audioSource.transform.SetParent(gameObject.transform);
         audioSource.clip     = audioDatas [i]._object as AudioClip;
         enumObject.enumAsInt = audioDatas [i].enumAsInt;
         enumObject._object   = audioSource;
         audioSources [i]     = enumObject;
     }
 }
예제 #24
0
        public void Deserialize_EnumObject_WorksCorrectly()
        {
            var source = new EnumObject
            {
                TestEnumProperty        = FixtureUtils.FromEnum <TestEnum>(),
                ChildEnumObjectProperty = new ChildEnumObject {
                    TestEnumProperty = FixtureUtils.FromEnum <TestEnum>()
                }
            };

            var serialized   = AzureTableSerializer.Serialize(source);
            var deserialized = AzureTableSerializer.Deserialize <EnumObject>(Entity(serialized));

            deserialized.Should().BeEquivalentTo(source, options => options
                                                 .Excluding(o => o.Timestamp));
        }
예제 #25
0
        /// <summary>
        /// 身份证识别
        /// </summary>
        /// <param name='request'></param>
        /// <returns></returns>
        public async Task <IDCardResponse> DetectAsync(IDCardRequest request)
        {
            Throws.ArgumentNullException(request, nameof(request));
            Throws.ArgumentNullException(request.ImgUrl, nameof(request.ImgUrl));

            try
            {
                var httpClient = this._options.HttpClient;

                var httpRequest = await BuildHttpRequestMessage(request);

                var response = await httpClient.RequestJsonAsync <AliyunOCRResponse>(httpRequest);

                var result = response
                             .Outputs
                             .FirstOrDefault()
                             .OutputValue
                             .DataValue;

                return(new IDCardResponse
                {
                    Success = result.Success,
                    Result = new IDCard
                    {
                        //正面
                        Id = result.Num,
                        Address = result.Address,
                        Birth = result.Birth,
                        Name = result.Name,
                        Nation = result.Nationality,
                        Gender = EnumObject.GetNullableEnumFromDescription <Gender>(result.Sex),
                        //反面
                        Authority = result.Issue,
                        StartDate = result.Start_date,
                        EndDate = result.End_date
                    }
                });
            }
            catch (Exception ex)
            {
                return(new IDCardResponse
                {
                    Success = false,
                    Message = ex.Message
                });
            }
        }
예제 #26
0
 /// <summary>
 /// 为枚举帮助集合中对应的枚举类型enumType添加新的Description
 /// </summary>
 /// <param name="enumType">枚举类型enumType</param>
 /// <param name="item">添加项</param>
 public void Add(string enumType, EnumObject item)
 {
     lock (myLock)
     {
         IList <EnumObject> list = null;
         if (dicEnum.ContainsKey(enumType))
         {
             list = new List <EnumObject>();
             dicEnum.Add(enumType, list);
         }
         else
         {
             list = dicEnum[enumType];
         }
         list.Add(item);
     }
 }
예제 #27
0
        private static void AdpaterGObject(string file, string content)
        {
            List <string> classs = Matcher.MatchClass(content);

            foreach (string item in classs)
            {
                ClassObject gobject = new ClassObject(file, item);
                TryAddGObject(gobject);
            }

            List <string> enums = Matcher.MatchEnum(content);

            foreach (string item in enums)
            {
                EnumObject gobject = new EnumObject(file, item);
                TryAddGObject(gobject);
            }
        }
예제 #28
0
        public static int NormalizeEnumJson(string repoRoot, string[] jsonInputFile, string jsonOutputFile, string[] rename, string[] exclude)
        {
            var renames = CommandLineUtils.ConvertValuePairsToDictionary(rename);

            HashSet <string>  excludes    = new HashSet <string>(exclude);
            List <EnumObject> enumObjects = new List <EnumObject>();

            foreach (var inputFile in jsonInputFile)
            {
                enumObjects.AddRange(EnumObject.LoadFromFile(inputFile));
            }

            var newObjects = EnumObjectUtils.NormalizeEnumObjects(repoRoot, enumObjects, renames, excludes).ToArray();

            JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings();

            jsonSerializerSettings.NullValueHandling    = NullValueHandling.Ignore;
            jsonSerializerSettings.DefaultValueHandling = DefaultValueHandling.Ignore;

            var jsonText = JsonConvert.SerializeObject(newObjects, Formatting.Indented, jsonSerializerSettings);

            File.WriteAllText(jsonOutputFile, jsonText);

            Regex containsLowerCase = new Regex(@"[a-z]+");

            foreach (var obj in newObjects)
            {
                if (obj.name != null && containsLowerCase.IsMatch(obj.name))
                {
                    Console.WriteLine($"Warning: {obj.name} enum contains lower case. Add a better name or exclude it.");
                    Console.Write("  Members: ");
                    foreach (var member in obj.members.Take(3))
                    {
                        Console.Write(member.name);
                        Console.Write(' ');
                    }

                    Console.WriteLine();
                }
            }

            return(0);
        }
예제 #29
0
 /// <summary>
 /// Private function used to find a Window by it's ClassNAme -- Callback for EnumWindows
 /// </summary>
 /// <param name="hWnd">The window currently being tested</param>
 /// <param name="param">EnumWindowsObject passed to EnumWindows</param>
 /// <returns>Whether to continue procesing windows or exit with this one</returns>
 private static bool FindByClassCallback(IntPtr hWnd, ref EnumObject param)
 {
     if (param.Data is string)
     {
         if (GetClassName(hWnd).Equals((string)param.Data))
         {
             param.hWnd = hWnd;
             return(false);
         }
     }
     else if (param.Data is Func <string, bool> )
     {
         Func <string, bool> testFunc = (Func <string, bool>)param.Data;
         if (testFunc(GetClassName(hWnd)))
         {
             param.hWnd = hWnd;
             return(false);
         }
     }
     return(true);
 }
예제 #30
0
        public void FlagEunms_property_test()
        {
            EnumObject flagEnumObject1 = MockFlagsEnum.A | MockFlagsEnum.C;
            EnumObject flagEnumObject2 = MockFlagsEnum.All | MockFlagsEnum.A;

            Assert.Null(flagEnumObject1.Name);

            Assert.Equal(new Enum[]
            {
                MockFlagsEnum.A,
                MockFlagsEnum.C
            }, flagEnumObject1.FlagEnums);

            Assert.Equal(new Enum[]
            {
                MockFlagsEnum.A,
                MockFlagsEnum.B,
                MockFlagsEnum.C,
                MockFlagsEnum.D,
                MockFlagsEnum.All
            }, flagEnumObject2.FlagEnums);
        }
예제 #31
0
        public void Register(string Username, string Password, string Email, EnumObject Object,
                             string Captcha)
        {
            if (Captcha == _webContext.CaptchaImageText)
            {
                SPKTCore.Core.Domain.Account a =
                    new SPKTCore.Core.Domain.Account();
                a.Email       = Email;
                a.UserName    = Username;
                a.DisplayName = a.UserName;
                a.CreateDate  = DateTime.Now;
                a.Password    = Password.Encrypt(Username);
                a.UseAuthenticationService = false;

                if (_accountService.EmailInUse(Email))
                {
                    _view.ShowErrorMessage("Mail đã được sử dụng");
                }
                else if (_accountService.UsernameInUse(Username))
                {
                    _view.ShowErrorMessage("Tên đăng nhập này đã được sử dụng");
                }
                else
                {
                    string permission = Object.ToString();
                    _accountRepository.SaveAccount(a);
                    if (friendInvitation != null)
                    {
                        _friendService.CreateFriendFromFriendInvitation(new Guid(_webContext.FriendshipRequest), a);
                    }
                    _accountService.Register(a, permission);
                    _redirector.GoToAccountLoginPage();
                }
            }
            else
            {
                _view.ShowErrorMessage("CAPTCHA bạn nhập không đúng! Vui lòng nhập lại");
            }
        }
예제 #32
0
        public void Register(string Username, string Password,string Email, EnumObject Object,
             string Captcha)
        {
            if (Captcha == _webContext.CaptchaImageText)
            {
                SPKTCore.Core.Domain.Account a =
                    new SPKTCore.Core.Domain.Account();
                a.Email = Email;
                a.UserName = Username;
                a.DisplayName = a.UserName;
                a.CreateDate = DateTime.Now;
                a.Password = Password.Encrypt(Username);

                if (_accountService.EmailInUse(Email))
                {
                    _view.ShowErrorMessage("Mail đã được sử dụng");
                }
                else if (_accountService.UsernameInUse(Username))
                {
                    _view.ShowErrorMessage("Tên đăng nhập này đã được sử dụng");

                }
                else
                {
                    string permission = Object.ToString();
                    _accountService.Register(a, permission);
                    _redirector.GoToAccountLoginPage();
                }
            }
            else
            {
                _view.ShowErrorMessage("CAPTCHA bạn nhập không đúng! Vui lòng nhập lại");
            }
        }
예제 #33
0
파일: Register.aspx.cs 프로젝트: SPKT/MHX2
 protected void Page_Load(object sender, EventArgs e)
 {
     _Presenter=new RegisterPresenter();
     _Presenter.Init(this);
     DoiTuong = EnumObject.OutSider;
 }
예제 #34
0
        public void Register(string Username, string Password,string Email, EnumObject Object,
             string Captcha)
        {
            if (Captcha == _webContext.CaptchaImageText)
            {
                SPKTCore.Core.Domain.Account a =
                    new SPKTCore.Core.Domain.Account();
                a.Email = Email;
                a.UserName = Username;
                a.DisplayName = a.UserName;
                a.CreateDate = DateTime.Now;
                a.Password = Password.Encrypt(Username);
                a.UseAuthenticationService = false;

                if (_accountService.EmailInUse(Email))
                {
                    _view.ShowErrorMessage("Mail đã được sử dụng");
                }
                else if (_accountService.UsernameInUse(Username))
                {
                    _view.ShowErrorMessage("Tên đăng nhập này đã được sử dụng");

                }
                else
                {
                    string permission = Object.ToString();
                    _accountRepository.SaveAccount(a);
                    if (friendInvitation != null)
                    {
                        _friendService.CreateFriendFromFriendInvitation(new Guid(_webContext.FriendshipRequest),a);
                    }
                    _accountService.Register(a, permission);
                    _redirector.GoToAccountLoginPage();
                }
            }
            else
            {
                _view.ShowErrorMessage("CAPTCHA bạn nhập không đúng! Vui lòng nhập lại");
            }
        }