Beispiel #1
0
        public GifskiInterop()
        {
            #region Get Gifski version

            var info = new FileInfo(UserSettings.All.GifskiLocation);
            info.Refresh();

            //I really need another way to differentiate gifski versions.
            switch (info.Length)
            {
            case 524_752:
                Version = new Version(1, 2, 0);
                break;

            case 502_720:
                Version = new Version(0, 10, 2);
                break;

            case 502_208:
                Version = new Version(0, 9, 3);
                break;

            default:
                Version = new Version(0, 0);
                break;
            }

            #endregion

            #region Load functions

            _new         = (NewDelegate)FunctionLoader.LoadFunction <NewDelegate>(UserSettings.All.GifskiLocation, "gifski_new");
            _addPngFrame = (AddPngFrameDelegate)FunctionLoader.LoadFunction <AddPngFrameDelegate>(UserSettings.All.GifskiLocation, "gifski_add_frame_png_file");
            //_addRgbaFrame = (AddRgbaFrameDelegate)FunctionLoader.LoadFunction<AddRgbaFrameDelegate>(UserSettings.All.GifskiLocation, "gifski_add_frame_rgba");

            if (Version.Major == 0 && Version.Minor < 10)
            {
                _addRgbFrame = (AddRgbFrameDelegate)FunctionLoader.LoadFunction <AddRgbFrameDelegate>(UserSettings.All.GifskiLocation, "gifski_add_frame_rgb");
            }
            else
            {
                _addRgb2Frame = (AddRgb2FrameDelegate)FunctionLoader.LoadFunction <AddRgb2FrameDelegate>(UserSettings.All.GifskiLocation, "gifski_add_frame_rgb");
            }

            if (Version.Major == 0 && Version.Minor < 9)
            {
                //Older versions of the library.
                _endAddingFrames = (EndAddingFramesDelegate)FunctionLoader.LoadFunction <EndAddingFramesDelegate>(UserSettings.All.GifskiLocation, "gifski_end_adding_frames");
                _write           = (WriteDelegate)FunctionLoader.LoadFunction <WriteDelegate>(UserSettings.All.GifskiLocation, "gifski_write");
                _drop            = (DropDelegate)FunctionLoader.LoadFunction <DropDelegate>(UserSettings.All.GifskiLocation, "gifski_drop");
            }
            else
            {
                //Newer versions.
                _setFileOutput = (SetFileOutputDelegate)FunctionLoader.LoadFunction <SetFileOutputDelegate>(UserSettings.All.GifskiLocation, "gifski_set_file_output");
                _finish        = (FinishDelegate)FunctionLoader.LoadFunction <FinishDelegate>(UserSettings.All.GifskiLocation, "gifski_finish");
            }

            #endregion
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            List <int> lst = new List <int>()
            {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            FilterInt  filterOdd = new FilterInt(IsOdd);
            List <int> result1   = FilterInts(lst, filterOdd);
            List <int> result2   = FilterInts(lst, IsEven);

            MyDelegate lamda = (i, s) =>
            {
                if (i > s.Length)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            };

            NewDelegate newLambda = () => { return(true); };

            //List<int> result = FilterInts(lst, i => (i % 2) == 1);

            List <int> result = FilterInts(lst, i => (i & 1) == 1);

            foreach (var item in result)
            {
                Console.WriteLine(item);
            }
        }
Beispiel #3
0
        public GifskiInterop()
        {
            #region Get Gifski version

            var info = new FileInfo(UserSettings.All.GifskiLocation);
            info.Refresh();

            Version = info.Length == 502_208 ? new Version(0, 9, 3) : new Version(0, 0);

            #endregion

            #region Load functions

            _new          = (NewDelegate)FunctionLoader.LoadFunction <NewDelegate>(UserSettings.All.GifskiLocation, "gifski_new");
            _addPngFrame  = (AddPngFrameDelegate)FunctionLoader.LoadFunction <AddPngFrameDelegate>(UserSettings.All.GifskiLocation, "gifski_add_frame_png_file");
            _addRgbaFrame = (AddRgbaFrameDelegate)FunctionLoader.LoadFunction <AddRgbaFrameDelegate>(UserSettings.All.GifskiLocation, "gifski_add_frame_rgba");

            if (Version.Major == 0 && Version.Minor < 9)
            {
                //Older versions of the library.
                _endAddingFrames = (EndAddingFramesDelegate)FunctionLoader.LoadFunction <EndAddingFramesDelegate>(UserSettings.All.GifskiLocation, "gifski_end_adding_frames");
                _write           = (WriteDelegate)FunctionLoader.LoadFunction <WriteDelegate>(UserSettings.All.GifskiLocation, "gifski_write");
                _drop            = (DropDelegate)FunctionLoader.LoadFunction <DropDelegate>(UserSettings.All.GifskiLocation, "gifski_drop");
            }
            else
            {
                //Newer versions.
                _setFileOutput = (SetFileOutputDelegate)FunctionLoader.LoadFunction <SetFileOutputDelegate>(UserSettings.All.GifskiLocation, "gifski_set_file_output");
                _finish        = (FinishDelegate)FunctionLoader.LoadFunction <FinishDelegate>(UserSettings.All.GifskiLocation, "gifski_finish");
            }

            #endregion
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            List <int> lst = new List <int> {
                0, 1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            FilterInt  filterOdd = new FilterInt(IsOdd);
            List <int> result    = FilterInts(lst, IsOdd);
            //posso fare il filtro IsEven, senza cambiare FilterInts
            //non creo il delegate, lo crea direttamente il compilatore
            //List<int> result = FilterInts(lst, IsEven);
            //terzo metodo
            //List<int> result = FilterInts(lst, i => (i % 2) == 1);

            MyDelegate lambda = (i, s) =>
            {
                if (i > s.Length)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            };

            NewDelegate newlambda = () => { return(true); };

            foreach (var item in result)
            {
                Console.WriteLine(item);
            }

            Console.ReadLine();
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            // Delegate keyword
            var myDelegate = new NewDelegate(new Program().ParseInput);

            // Anonymous delegate
            var myDelegate2 = new NewDelegate(delegate(string input)
                {
                    return Int32.Parse(input);
                });

            // Func
            Func<string, int> myFunc = i => Int32.Parse(i);

            // Action
            Action<int> myAction = i => Console.WriteLine(i);

            // Predicate
            Predicate<int> myPredicate = i => i == 0;

            // Output
            Console.WriteLine("Delegate keyword - {0}", myDelegate("10"));
            Console.WriteLine("Delegate invocation list - {0}", myDelegate.GetInvocationList());

            Console.WriteLine("Anonymous delegate keyword - {0}", myDelegate2("10"));

            Console.WriteLine("Func - {0}", myFunc("10"));

            Console.WriteLine("Action Executed:");
            myAction(10);

            Console.WriteLine("Predicate executed:");
            if (myPredicate(0))
            {
                Console.WriteLine("Invoked and true");
            }
            else
            {
                Console.WriteLine("Invoked and false");
            }

            Console.WriteLine(Environment.NewLine);

            // Set second delegate to the first delegate's invocation list
            myDelegate += myDelegate2;

            // Can we add a Func, Action, and Predicate to it as well?
            // Nope, it won't compile.

            // myDelegate += myFunc + myAction + myPredicate;

            foreach (Delegate item in myDelegate.GetInvocationList())
            {
                Console.WriteLine("Delegate method - {0}", item.Method.Name);
            }

            Console.ReadLine();
        }
Beispiel #6
0
        public virtual void WriteNewDelegate(NewDelegate s, ExpressionUsage u)
        {
            Write("new ");
            WriteStaticType(s.Source, s.ReturnType);
            Write("(");
            WriteMemberBase(s.Source, s.Method.DeclaringType, s.Object, s.Method.Name);

            if (s.Method.IsGenericParameterization)
            {
                WriteGenericList(s.Source, s.Method.GenericArguments);
            }

            Write(")");
        }
Beispiel #7
0
        static void Main()
        {
            int summand1 = 1, summand2 = 2, sum;

            MyDelegate myDelegate = delegate(ref int a, ref int b, out int c) { a++; b++; c = a + b; };

            myDelegate(ref summand1, ref summand2, out sum);

            Console.WriteLine("{0} + {1} = {2}", summand1, summand2, sum);

            NewDelegate newDelegate = delegate(int a, int b, int c) { return((a + b + c) / 2); };

            Console.WriteLine(newDelegate(2, 3, 4));

            // Delay.
            Console.ReadKey();
        }
Beispiel #8
0
 private void ThreadFunction()
 {
     if (this.MPB.InvokeRequired)
     {
         NewDelegate newdel = new NewDelegate(ThreadFunction);
         this.Invoke(newdel);
         //Console.WriteLine("ThreadFunction");
     }
     else
     {
         ShowListBox();
         MPB.Hide();
         BtnGrasp.Show();
         BtnSelectAll.Show();
         BtnUngrasp.Show();
         //Console.WriteLine("ShowTreeView");
     }
 }
Beispiel #9
0
        public override void WriteNewDelegate(NewDelegate s, ExpressionUsage u)
        {
            Write("$CreateDelegate(");

            if (s.Object != null)
            {
                WriteExpression(s.Object);
                Write(", ");

                if (s.Method.DeclaringType.IsInterface)
                {
                    // FIXME: Potential side effect
                    WriteExpression(s.Object, ExpressionUsage.Object);

                    var name = Backend.GetGlobal(s.Method);
                    Write(name.IsValidJsIdentifier()
                        ? "." + name
                        : "[" + name.ToLiteral() + "]");
                }
                else if (s.Method.IsVirtual)
                {
                    // FIXME: Potential side effect
                    WriteExpression(s.Object, ExpressionUsage.Object);
                    Write("." + Backend.GetMember(s.Method));
                }
                else
                {
                    Write(Backend.GetGlobal(s.Method.DeclaringType) + ".prototype." + Backend.GetMember(s.Method));
                }
            }
            else
            {
                Write("null, " + Backend.GetGlobal(s.Method));
            }

            Write(", " + Backend.GetTypeId(s.Source, Function, s.ReturnType));

            if (s.ReturnType.IsGenericParameterization)
            {
                Write(", " + Backend.GetTypeIds(s.Source, Function, s.ReturnType.FlattenedArguments));
            }

            Write(")");
        }
Beispiel #10
0
        private Expression RegisterTest(TestMethod testMethod, Expression registryArgument, NewDelegate invokeDelegate)
        {
            var testNameExpr     = new Constant(_source, Essentials.String, testMethod.Name);
            var ignoreExpr       = new Constant(_source, Essentials.Bool, testMethod.Ignored);
            var ignoreReasonExpr = new Constant(_source, Essentials.String, testMethod.IgnoreReason);

            return(ILFactory.CallMethod(_source, registryArgument, "Add", invokeDelegate,
                                        testNameExpr, ignoreExpr, ignoreReasonExpr));
        }
Beispiel #11
0
        public override void End(ref Expression e, ExpressionUsage u)
        {
            switch (e.ExpressionType)
            {
            case ExpressionType.Lambda:
            {
                if (e == _lambda)
                {
                    var lambda = (Lambda)e;
                    e = new NewDelegate(
                        e.Source,
                        (DelegateType)lambda.ReturnType,
                        _closureStack.Peek().Expression,
                        _lambdaMethod);

                    _lambda       = null;
                    _lambdaMethod = null;
                }
                break;
            }

            case ExpressionType.LoadLocal:
            {
                var load = (LoadLocal)e;

                if (_closureVars.Contains(load.Variable))
                {
                    e = _lambda == null
                            ? _closureStack.Peek().Load(load.Variable)
                            : _closureStack.Peek().LoadInside(load.Variable);
                }
                break;
            }

            case ExpressionType.LoadArgument:
            {
                var load = (LoadArgument)e;
                if (_closureVars.Contains(load.Parameter))
                {
                    e = _lambda == null
                            ? _closureStack.Peek().Load(load.Parameter)
                            : _closureStack.Peek().LoadInside(load.Parameter);
                }
                else if (load.Function.Match(_ => false, lam => lam == _lambda))
                {
                    e = new LoadArgument(load.Source, _lambdaMethod, load.Index);
                }
                break;
            }

            case ExpressionType.This:
            {
                if (_closureVars.This && _lambda != null)
                {
                    e = _closureStack.Peek().ThisInside();
                }
                break;
            }

            case ExpressionType.StoreLocal:
            {
                var store = (StoreLocal)e;
                if (_closureVars.Contains(store.Variable))
                {
                    e = _lambda == null
                            ? _closureStack.Peek().Store(store.Variable, store.Value)
                            : _closureStack.Peek().StoreInside(store.Variable, store.Value);
                }
                break;
            }

            case ExpressionType.StoreArgument:
            {
                var store = (StoreArgument)e;
                if (_closureVars.Contains(store.Parameter))
                {
                    e = _lambda == null
                            ? _closureStack.Peek().Store(store.Parameter, store.Value)
                            : _closureStack.Peek().StoreInside(store.Parameter, store.Value);
                }
                else if (store.Function.Match(_ => false, lam => lam == _lambda))
                {
                    e = new StoreArgument(store.Source, _lambdaMethod, store.Index, store.Value);
                }
                break;
            }

            case ExpressionType.StoreThis:
            {
                var store = (StoreThis)e;
                if (_closureVars.This)
                {
                    e = _lambda == null
                            ? _closureStack.Peek().StoreThis(store.Value)
                            : _closureStack.Peek().StoreThisInside(store.Value);
                }
                break;
            }
            }
        }
Beispiel #12
0
 public static void StringMagic(string string1, string string2, NewDelegate delegate1)
 {
     Console.WriteLine($"{string1} , {string2}, {delegate1(string1, string2)}");
 }
Beispiel #13
0
        public static void StringMagic(string str1, string str2, NewDelegate funk)
        {
            var result = funk(str1, str2);

            Console.WriteLine(str1 + " " + str2 + " " + result.ToString());
        }
Beispiel #14
0
 /// <summary>
 /// 构造函数。
 /// </summary>
 /// <param name="size">缓存大小。</param>
 public CachePool(int size = 10, NewDelegate newfun = null)
 {
     m_Size        = size;
     m_NewFunction = newfun;
 }
Beispiel #15
0
 public void DestroryWindow()
 {
     dele = null;
     this.Close();
 }
Beispiel #16
0
 public void AddDelegate(NewDelegate newDelegate)
 {
     dele = newDelegate;
 }