Beispiel #1
0
        /// <summary>
        /// Assert that the mock log in the engine contains a certain message based on a resource string and some parameters
        /// </summary>
        internal void AssertLogContainsMessageFromResource(GetStringDelegate getString, string resourceName, params string[] parameters)
        {
            string resource          = getString(resourceName);
            string stringToSearchFor = String.Format(resource, parameters);

            AssertLogContains(stringToSearchFor);
        }
Beispiel #2
0
 public static IList <T> FindClosestForms <T>(IEnumerable itemsToSearch,
                                              GetStringDelegate <T> itemFormExtractor,
                                              string notNormalizedFormToMatch,
                                              ApproximateMatcherOptions options)
 {
     return(FindClosestForms(itemsToSearch, itemFormExtractor, notNormalizedFormToMatch, options, 999));
 }
Beispiel #3
0
 public static void ChangeStrings(string[] strs, GetStringDelegate changeString)
 {
     for (int i = 0; i < strs.Length; i++)
     {
         strs[i] = changeString(strs[i]);
     }
 }
Beispiel #4
0
        static void Main22()
        {
            // GetSelfDefinedString方法被最后添加
            GetStringDelegate myDelegate1 = GetDateTimeString;

            myDelegate1 += GetTypeNameString;
            myDelegate1 += GetSelfDefinedString;
            //Console.WriteLine(myDelegate1());
            //Console.WriteLine();

            foreach (var item in myDelegate1.GetInvocationList())
            {
                Console.WriteLine(item.DynamicInvoke());
            }
            // GetDateTimeString方法被最后添加
            //GetStringDelegate myDelegate2 = GetSelfDefinedString;
            //myDelegate2 += GetTypeNameString;
            //myDelegate2 += GetDateTimeString;
            //Console.WriteLine(myDelegate2());
            //Console.WriteLine();
            //// GetTypeNameString方法被最后添加
            //GetStringDelegate myDelegate3 = GetSelfDefinedString;
            //myDelegate3 += GetDateTimeString;
            //myDelegate3 += GetTypeNameString;
            //Console.WriteLine(myDelegate3());

            Console.ReadKey();
        }
Beispiel #5
0
 /// <summary>
 /// ダウンロード先を取得する。(この関数は別スレッドからでも値を取得できる)
 /// </summary>
 /// <returns>ダウンロード先のURLとして登録されているディレクトリ</returns>
 protected string InvokeGetDownloadPath()
 {
     if (this.InvokeRequired)
     {
         GetStringDelegate func = new GetStringDelegate(this.InvokeGetDownloadPath);
         return((string)this.Invoke(func));
     }
     return(this.textDownloadPath.Text);
 }
Beispiel #6
0
        internal static void LoadEntryPoints()
        {
            if (Viewport == null)
            {
                Viewport = LoadFunction <ViewportDelegate>("glViewport");
            }
            if (Scissor == null)
            {
                Scissor = LoadFunction <ScissorDelegate>("glScissor");
            }
            //if (MakeCurrent == null)
            //	MakeCurrent = LoadFunction<MakeCurrentDelegate>("glMakeCurrent");

            GetError = LoadFunction <GetErrorDelegate>("glGetError");

            EnableVertexAttribArray  = LoadFunction <EnableVertexAttribArrayDelegate>("glEnableVertexAttribArray");
            DisableVertexAttribArray = LoadFunction <DisableVertexAttribArrayDelegate>("glDisableVertexAttribArray");

            _getStringInternal = LoadFunction <GetStringDelegate>("glGetString");

            ClearDepth = LoadFunction <ClearDepthDelegate>("glClearDepth")
                         ?? LoadFunction <ClearDepthDelegate>("glClearDepthf");

            Clear        = LoadFunction <ClearDelegate>("glClear");
            ClearColor   = LoadFunction <ClearColorDelegate>("glClearColor");
            ClearStencil = LoadFunction <ClearStencilDelegate>("glClearStencil");

            Enable  = LoadFunction <EnableDelegate>("glEnable");
            Disable = LoadFunction <DisableDelegate>("glDisable");

            BindBuffer = LoadFunction <BindBufferDelegate>("glBindBuffer");
            //DrawBuffers = LoadFunction<DrawBuffersDelegate>("glDrawBuffers");
            //DrawElements = LoadFunction<DrawElementsDelegate>("glDrawElements");
            DrawArrays = LoadFunction <DrawArraysDelegate>("glDrawArrays");
            //Uniform1i = LoadFunction<Uniform1iDelegate>("glUniform1i");
            //Uniform4fv = LoadFunction<Uniform4fvDelegate>("glUniform4fv");
            //ReadPixelsInternal = LoadFunction<ReadPixelsDelegate>("glReadPixels");

            CreateShader         = LoadFunction <CreateShaderDelegate>("glCreateShader");
            ShaderSourceInternal = LoadFunction <ShaderSourceDelegate>("glShaderSource");
            CompileShader        = LoadFunction <CompileShaderDelegate>("glCompileShader");

            ColorMask = LoadFunction <ColorMaskDelegate>("glColorMask");
            //TODO: DepthFunc = LoadFunction<DepthFuncDelegate>("glDepthFunc");
            DepthMask = LoadFunction <DepthMaskDelegate>("glDepthMask");

            StencilMask = LoadFunction <StencilMaskDelegate>("glStencilMask");

            GenBuffers = LoadFunction <GenBuffersDelegate>("glGenBuffers");
            BufferData = LoadFunction <BufferDataDelegate>("glBufferData");
            //MapBuffer = LoadFunction<MapBufferDelegate>("glMapBuffer");
            //UnmapBuffer = LoadFunction<UnmapBufferDelegate>("glUnmapBuffer");
            BufferSubData = LoadFunction <BufferSubDataDelegate>("glBufferSubData");
            //DeleteBuffers = LoadFunction<DeleteBuffersDelegate>("glDeleteBuffers");

            VertexAttribPointer = LoadFunction <VertexAttribPointerDelegate>("glVertexAttribPointer");
        }
 /// <summary>
 /// 设置多语音转换方法,需要在使用多语言前调用
 /// </summary>
 /// <param name="func">多语音转换方法</param>
 /// <param name="noLongerChanged">是否标记转换方法不再被修改</param>
 /// <returns>经过转换的多语言字符串</returns>
 public static bool SetGetString(GetStringDelegate func, bool noLongerChanged)
 {
     if (sLockDelegate)
     {
         return(false);
     }
     sGetString    = func;
     sLockDelegate = noLongerChanged;
     return(true);
 }
Beispiel #8
0
        private string GetText()
        {
            if (!InvokeRequired)
            {
                return(base.Text);
            }
            GetStringDelegate del = GetText;

            return(Invoke(del) as string);
        }
Beispiel #9
0
        private string GetText()
        {
            if (Parent == null || !Parent.InvokeRequired)
            {
                return(base.Text);
            }
            GetStringDelegate del = GetText;

            return(Parent.Invoke(del) as string);
        }
Beispiel #10
0
            public ControlValidater(
                ErrorProvider errorProvider,
                Control control,
                GetStringDelegate getError)
            {
                _errorProvider = errorProvider;
                _control       = control;
                _getError      = getError;

                _depErrorText = new Dependent(UpdateControlError);
            }
Beispiel #11
0
        public PostgresOptions(GetStringDelegate getter)
        {
            keys = flagValues.Keys.ToList();

            foreach (var(key, currentValue) in flagValues)
            {
                var value = getter(key, currentValue);

                if (!string.IsNullOrEmpty(value))
                {
                    flagValues[key] = value;
                }
            }
        }
Beispiel #12
0
        internal static string GetString(GetStringDelegate pInvokeAction)
        {
            IntPtr pStr   = IntPtr.Zero;
            int    result = pInvokeAction(ref pStr);

            ThrowIfResult(result);
#if _WINDOWS
            string str = Marshal.PtrToStringUni(pStr);
#else
            string str = Marshal.PtrToStringAnsi(pStr);
#endif
            Marshal.FreeCoTaskMem(pStr);
            return(str);
        }
Beispiel #13
0
 /// <summary>
 /// ダウンロードする対象のURLを取得する。(この関数は別スレッドからでも値を取得できる)
 /// </summary>
 /// <returns>URL一覧に登録されているURL
 /// URLが1件も登録されていない場合には 空文字列が帰る</returns>
 protected string InvokeGetURL()
 {
     if (this.InvokeRequired)
     {
         GetStringDelegate func = new GetStringDelegate(this.InvokeGetURL);
         return((string)this.Invoke(func));
     }
     if (this.listURLList.Items.Count > 0)
     {
         string url = this.listURLList.Items[0].ToString();
         //this.listBox1.Items.RemoveAt(0);
         return(url);
     }
     return("");
 }
Beispiel #14
0
        static JSCompileOptions()
        {
            GetElement = getElement;
            GetElementAttributeName = getElementAttributeName;
            GetIntroductionScript   = getIntroductionScript;

            DefaultVTable = new VTable {
                element = Marshal.GetFunctionPointerForDelegate(GetElement),
                elementAttributeName = Marshal.GetFunctionPointerForDelegate(GetElementAttributeName),
                introductionScript   = Marshal.GetFunctionPointerForDelegate(GetIntroductionScript),
            };

            pDefaultVTable = Marshal.AllocHGlobal(Marshal.SizeOf(DefaultVTable));
            Marshal.StructureToPtr(DefaultVTable, pDefaultVTable, false);

            Default = new JSCompileOptions();
        }
Beispiel #15
0
        public static void Main1(string[] args)
        {
            //TestClass tc = new TestClass();
            //WriteTimeDelegate writeTime = new WriteTimeDelegate(WritrTimeToFile);
            //WriteTimeDelegate writeTime = new WriteTimeDelegate(PrintTimeToConsole);
            //tc.DoSomething(writeTime);
            //Console.WriteLine("OK");

            string[]          names        = new string[] { "Tim", "Tom" };
            GetStringDelegate changeString = new GetStringDelegate(ChangeStrings);

            Program.ChangeStrings(names, changeString);
            for (int i = 0; i < names.Length; i++)
            {
                Console.WriteLine(names[i]);
            }
        }
Beispiel #16
0
        public static void RegisterEnum(Type t, BubbleLua state)
        {
            string randName = "_" + rand.Next();
            //create table
            var typeName = LowerFirst(t.Name);

            state.Lua.NewTable(randName);
            var table = (LuaTable)state.Lua [randName];

            //values
            foreach (var val in Enum.GetValues(t))
            {
                var n = Enum.GetName(t, val);
                table [LowerFirst(n)] = (int)val;
            }
            //getString function
            table ["getString"] = new GetStringDelegate((v) => LowerFirst(Enum.GetName(t, v)));
            var result = state.Lua.DoString(string.Format(@"return bubbleinternal.readonlytable({0})", randName));

            state.Bubble [typeName] = (LuaTable)result [0];
            state.Lua.DoString(string.Format("{0} = nil", randName));
        }
 static StringsTestClass()
 {
     GetStringByDelegate = GetString;
 }
Beispiel #18
0
 /// <summary>
 /// Assert that the mock log in the engine contains a certain message based on a resource string and some parameters
 /// </summary>
 internal void AssertLogContainsMessageFromResource(GetStringDelegate getString, string resourceName, params string[] parameters)
 {
     string resource = getString(resourceName);
     string stringToSearchFor = String.Format(resource, parameters);
     AssertLogContains(stringToSearchFor);
 }
 static StringsTestClass()
 {
     GetStringByDelegate = GetString;
 }
 /// <summary>
 /// Assert that the mock log in the engine contains a certain message based on a resource string and some parameters
 /// </summary>
 public void AssertLogContainsMessageFromResource(GetStringDelegate getString, string resourceName, params string[] parameters)
 {
     string resource = getString(resourceName);
     string stringToSearchFor = String.Format(CultureInfo.CurrentCulture, resource, parameters);
     AssertLogContains(stringToSearchFor);
 }
            public ControlValidater(
                ErrorProvider errorProvider,
                Control control,
                GetStringDelegate getError)
            {
                _errorProvider = errorProvider;
                _control = control;
                _getError = getError;

                _depErrorText = new Dependent(UpdateControlError);
            }
Beispiel #22
0
        // would like to have IEnumerable<T> but IBindingList isn't strong typed
        public static IList <T> FindClosestForms <T>(IEnumerable itemsToSearch,
                                                     GetStringDelegate <T> itemFormExtractor,
                                                     string notNormalizedFormToMatch,
                                                     ApproximateMatcherOptions options,
                                                     int maxDistance)
        {
            string formToMatch        = notNormalizedFormToMatch.Normalize(NormalizationForm.FormD);
            bool   includeNextClosest = (options & ApproximateMatcherOptions.IncludeNextClosestForms) ==
                                        ApproximateMatcherOptions.IncludeNextClosestForms;
            bool includeApproximatePrefixedForms = (options &
                                                    ApproximateMatcherOptions.IncludePrefixedForms) ==
                                                   ApproximateMatcherOptions.IncludePrefixedForms;

            List <T> bestMatches       = new List <T>();
            List <T> secondBestMatches = new List <T>();

            int bestEditDistance       = int.MaxValue;
            int secondBestEditDistance = int.MaxValue;

            foreach (T item in itemsToSearch)
            {
                string originalForm = itemFormExtractor(item);
                if (!string.IsNullOrEmpty(originalForm))
                {
                    string form = originalForm.Normalize(NormalizationForm.FormD);
                    if (!string.IsNullOrEmpty(form))
                    {
                        int editDistance;
                        editDistance = EditDistance(formToMatch,
                                                    form,
                                                    secondBestEditDistance,
                                                    includeApproximatePrefixedForms);
                        if (editDistance > maxDistance)
                        {
                            continue;
                        }

                        if (editDistance < bestEditDistance)
                        {
                            if (includeNextClosest && bestEditDistance != int.MaxValue)
                            {
                                // best becomes second best
                                secondBestMatches.Clear();
                                secondBestMatches.AddRange(bestMatches);
                                secondBestEditDistance = bestEditDistance;
                            }
                            bestMatches.Clear();
                            bestEditDistance = editDistance;
                        }
                        else if (includeNextClosest && editDistance > bestEditDistance &&
                                 editDistance < secondBestEditDistance)
                        {
                            secondBestEditDistance = editDistance;
                            secondBestMatches.Clear();
                        }
                        if (editDistance == bestEditDistance)
                        {
                            bestMatches.Add(item);
                        }
                        else if (includeNextClosest && editDistance == secondBestEditDistance)
                        {
                            secondBestMatches.Add(item);
                        }
                        Debug.Assert(bestEditDistance != secondBestEditDistance);
                    }
                }
            }
            if (includeNextClosest)
            {
                bestMatches.AddRange(secondBestMatches);
            }
            return(bestMatches);
        }