Example #1
0
        static ITT()
        {
            var initializator = CreateInitializator();

            initializator.Init();
            Native = initializator.CreateNative();
        }
Example #2
0
 private static void GenerateHandleInvokeCode(ILGenerator ilGenerator, INative native, NativeIlGenContext context, LocalBuilder argsLocal)
 {
     // NativeHandleInvokers.InvokeHandle(handle, args)
     ilGenerator.Emit(OpCodes.Ldc_I4, native.Handle);
     ilGenerator.Emit(OpCodes.Ldloc, argsLocal);
     ilGenerator.EmitCall(GetHandleInvokerMethod(context));
 }
Example #3
0
 public void Render(INative context)
 {
     if (Native != null)
     {
         (Native as CanvasView).Render();
     }
 }
Example #4
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="NativeObjectILGenerator" /> class.
 /// </summary>
 /// <param name="native">The native.</param>
 /// <param name="nativeObjectType">Type of the native object.</param>
 /// <param name="identifiers">The identifiers.</param>
 /// <param name="parameterTypes">The parameter types.</param>
 /// <param name="returnType">Type of the return.</param>
 /// <exception cref="ArgumentNullException">Thrown if nativeObjectType or idnetifiers is null.</exception>
 public NativeObjectILGenerator(INative native, Type nativeObjectType, string[] identifiers,
                                Type[] parameterTypes, Type returnType)
     : base(native, AddIdentifiersToParameterTypes(identifiers, parameterTypes), returnType)
 {
     _nativeObjectType = nativeObjectType ?? throw new ArgumentNullException(nameof(nativeObjectType));
     _identifiers      = identifiers ?? throw new ArgumentNullException(nameof(identifiers));
 }
Example #5
0
 internal Task(INative native, IntPtr domain, string name, ulong id, Task parent)
 {
     _native = native;
     _domain = domain;
     Id      = id;
     _native.BeginTask(domain, id, parent?.Id ?? 0, name, 0);
 }
Example #6
0
 public bool Greater(INative b)
 {
     return(b switch
     {
         Array array => _natives.Count > array._natives.Count,
         Number number => _natives.Count > number,
         _ => false
     });
Example #7
0
 public bool Lesser(INative a)
 {
     if (a is Bool bol)
     {
         return(bol._value && !_value);
     }
     return(false);
 }
Example #8
0
 public bool Greater(INative b)
 {
     if (b is Bool bol)
     {
         return(!bol._value && _value);
     }
     return(false);
 }
Example #9
0
 public bool Greater(INative b)
 {
     return(b switch
     {
         Number number => this > number,
         Text text => this > text.Length,
         Date date => new Date(_value) > date,
         _ => false
     });
        public void Remove(INative value)
        {
            if (value.Native != null)
            {
                _ncanvas.Children.Remove(value.Native as UIElement);
            }

            Children.Remove(value);
        }
Example #11
0
        internal static object Create(Type type, INative parent, Locator locator)
        {
            var listType     = typeof(WebElementsCollection <>);
            var genericArgs  = type.GetGenericArguments();
            var concreteType = listType.MakeGenericType(genericArgs);
            var newList      = Activator.CreateInstance(concreteType, parent, locator);

            return(newList);
        }
        public void Add(INative value)
        {
            if (value.Native != null)
            {
                _ncanvas.Children.Add(value.Native as UIElement);
            }

            Children.Add(value);
        }
Example #13
0
        private static IHtmlElement Create(Type elementType, INative parent, Locator locator, int index = 0)
        {
            var htmlElement = (IHtmlElement)Activator.CreateInstance(elementType);

            htmlElement.Parent         = parent;
            htmlElement.SearchStrategy = new SearchStrategy(locator, index);
            InitProperties(htmlElement);
            return(htmlElement);
        }
Example #14
0
        private void Generate(ILGenerator ilGenerator, NativeIlGenContext context, INative native)
        {
            var argsLocal = GenerateArgsArray(ilGenerator, context);

            GenerateInvokeInputCode(ilGenerator, context, argsLocal);
            GenerateHandleInvokeCode(ilGenerator, native, context, argsLocal);
            GenerateInvokeOutputCode(ilGenerator, context, argsLocal);

            // return $0
            ilGenerator.Emit(OpCodes.Ret);
        }
Example #15
0
        /// <summary>
        /// 销毁INative, 也可以调用 Native的Dispose方法
        /// </summary>
        /// <param name="p_native"></param>
        public static void Free(INative p_native)
        {
            var native = p_native;

            if (native == null)
            {
                return;
            }

            native.Dispose();
        }
Example #16
0
        static Native()
        {
            Current = null;

            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                Current = new Win32Native();
            }
            else
            {
                Current = new PlatformIndependentNative();
            }
        }
Example #17
0
        public DynamicNative(INative p_native)
        {
            _native = p_native;

            if (_native == null)
            {
                throw new ArgumentNullException(nameof(p_native));
            }

            if (_native.HasDisposed)
            {
                throw new ArgumentException("INative can not be null or disposed.");
            }
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="NativeHandleBasedProxyGenerator" /> class.
        /// </summary>
        /// <param name="native">The native.</param>
        /// <param name="nativeObjectType">Type of the native object.</param>
        /// <param name="identifiers">The identifiers.</param>
        /// <param name="identifierIndex">The start index of the identifiers.</param>
        /// <param name="parameterTypes">The parameter types.</param>
        /// <param name="returnType">Type of the return.</param>
        /// <exception cref="ArgumentNullException">Thrown if nativeObjectType or identifiers is null.</exception>
        public NativeHandleBasedProxyGenerator(INative native, Type nativeObjectType, string[] identifiers, int identifierIndex,
                                               Type[] parameterTypes, Type returnType)
        {
            if (parameterTypes == null)
            {
                throw new ArgumentNullException(nameof(parameterTypes));
            }

            parameterTypes = AddIdentifiersToParameterTypes(identifiers, identifierIndex, parameterTypes);

            ParameterTypes    = parameterTypes;
            Native            = native ?? throw new ArgumentNullException(nameof(native));
            ReturnType        = returnType ?? throw new ArgumentNullException(nameof(returnType));
            _nativeObjectType = nativeObjectType ?? throw new ArgumentNullException(nameof(nativeObjectType));
            _identifiers      = identifiers ?? throw new ArgumentNullException(nameof(identifiers));
            _identifierIndex  = identifierIndex;
        }
Example #19
0
        public Task <INative> Deserialize(Scope scope, params INative[] args)
        {
            var value = args.ElementAtOrDefault(0);

            if (value == null || !value.Is <Text>(out var text))
            {
                throw new NativeException("Se requiere un texto para deserializar");
            }
            var     token  = JToken.Parse(text);
            INative result = token switch
            {
                JArray array => array.ToObject <Objects.Array>() !,
                JObject jObject => jObject.ToObject <Objects.Object>() !,
                _ => new Undefined()
            };

            return(Task.FromResult(result));
        }
Example #20
0
 public NativeILGenerator(INative native, Type[] parameterTypes, Type returnType)
 {
     if (native == null)
     {
         throw new ArgumentNullException(nameof(native));
     }
     if (parameterTypes == null)
     {
         throw new ArgumentNullException(nameof(parameterTypes));
     }
     if (returnType == null)
     {
         throw new ArgumentNullException(nameof(returnType));
     }
     ParameterTypes = parameterTypes;
     Native         = native;
     ReturnType     = returnType;
 }
 public INative Convert(INative native)
 {
     if (native is IPin)
     {
         return(Convert(native as IPin));
     }
     else if (native is ILine)
     {
         return(Convert(native as ILine));
     }
     else if (native is IBezier)
     {
         return(Convert(native as IBezier));
     }
     else if (native is IQuadraticBezier)
     {
         return(Convert(native as IQuadraticBezier));
     }
     else if (native is IArc)
     {
         return(Convert(native as IArc));
     }
     else if (native is IRectangle)
     {
         return(Convert(native as IRectangle));
     }
     else if (native is IEllipse)
     {
         return(Convert(native as IEllipse));
     }
     else if (native is IText)
     {
         return(Convert(native as IText));
     }
     else if (native is IBlock)
     {
         throw new NotImplementedException();
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Example #22
0
 public NativeObjectILGenerator(INative native, Type nativeObjectType, string[] identifiers,
                                Type[] parameterTypes, Type returnType)
     : base(
         native,
         Enumerable.Repeat(typeof(int), identifiers?.Length ?? 0)
         .Concat(parameterTypes ?? new Type[0])
         .ToArray(), returnType)
 {
     if (nativeObjectType == null)
     {
         throw new ArgumentNullException(nameof(nativeObjectType));
     }
     if (identifiers == null)
     {
         throw new ArgumentNullException(nameof(identifiers));
     }
     _nativeObjectType = nativeObjectType;
     _identifiers      = identifiers;
 }
Example #23
0
        public override async Task <ICompletion <INative> > ExecuteAsync(Scope scope)
        {
            var target = await Target.ExecuteAsync(scope).GetResult();

            if (!target.Is <Function>(out var function))
            {
                throw new NativeException($"'{Target}' no es una función", Position);
            }
            var args = new INative[Params.Count];

            for (var i = 0; i < args.Length; i++)
            {
                args[i] = await Params[i].ExecuteAsync(scope).GetResult();
            }

            if (IsAsync)
            {
                return(new Completion(new Promise(function.InvokeAsync(scope, args))));
            }
            return(await function.InvokeAsync(scope, args));
        }
Example #24
0
 private void Write(INative child)
 {
     if (child is IPin)
     {
         Write(child as IPin);
     }
     else if (child is ILine)
     {
         Write(child as ILine);
     }
     else if (child is IBezier)
     {
         Write(child as IBezier);
     }
     else if (child is IQuadraticBezier)
     {
         Write(child as IQuadraticBezier);
     }
     else if (child is IArc)
     {
         Write(child as IArc);
     }
     else if (child is IRectangle)
     {
         Write(child as IRectangle);
     }
     else if (child is IEllipse)
     {
         Write(child as IEllipse);
     }
     else if (child is IText)
     {
         Write(child as IText);
     }
     else if (child is IBlock)
     {
         Write(child as IBlock);
     }
 }
        internal static void InitProperties(INative native)
        {
            var properties = native.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            foreach (var property in properties)
            {
                if (property.HasLocatorAttribute() && property.IsWebElement())
                {
                    var element = Create(property.PropertyType, native, property.GetLocatorAttribute());
                    property.SetValue(native, element);
                }
                if (property.HasLocatorAttribute() && property.IsWebElementsCollection())
                {
                    var collection = WebElementsCollectionFactory.Create(property.PropertyType, native, property.GetLocatorAttribute());
                    property.SetValue(native, collection);
                }
                if (property.HasLocatorAttribute() && !(property.IsWebElement() || property.IsWebElementsCollection()))
                {
                    throw new InvalidOperationException($"Property {property.Name} has FindBy attribute but is not collection or element");
                }
            }
        }
Example #26
0
 public static INative Execute(INative left, string op, INative right)
 {
     return(op switch
     {
         "==" => Helpers.CompareEquality(left, op, right),
         "!=" => Helpers.CompareEquality(left, op, right),
         "<" => Helpers.CompareEquality(left, op, right),
         ">" => Helpers.CompareEquality(left, op, right),
         "<=" => Helpers.CompareEquality(left, op, right),
         ">=" => Helpers.CompareEquality(left, op, right),
         "+" => left + right,
         "+=" => left + right,
         "-" => left - right,
         "-=" => left - right,
         "*" => left * right,
         "*=" => left * right,
         "/" => left / right,
         "/=" => left / right,
         "&&" => (left.ToBool() && right.ToBool()).ToNative(),
         "||" => (left.ToBool() || right.ToBool()).ToNative(),
         "=" => right,
         _ => Number.NaN
     });
Example #27
0
        public App(
            string appHostBaseUrl,
            string appHostInitialUrl,
            string oneSignalIdentifier,
            ICollection <string> ignoreUrls)
        {
            _ignoreUrls  = ignoreUrls ?? new List <string>();
            _appMainPage = new AppMainPage($"{DDAppLocalUrl}{appHostInitialUrl}");
            MainPage     = _appMainPage;

            StartWebProxy();
            _nativeService = DependencyService.Get <INative>();
            var cacheBaseDir = _nativeService.GetCacheDir();

            _cache = new ApplicationCache(appHostBaseUrl, cacheBaseDir);

            Task.Run(async() =>
            {
                _nativeService.LoadPreCache();
                await Task.Delay(1000);

                Device.BeginInvokeOnMainThread(() =>
                {
                    _appMainPage.ToWebState();

                    if (!string.IsNullOrWhiteSpace(oneSignalIdentifier))
                    {
                        Task.Run(async() =>
                        {
                            await Task.Delay(3000);
                            OneSignal.Current.StartInit(oneSignalIdentifier).EndInit();
                        });
                    }
                });
            });
        }
Example #28
0
        public void Remove(INative value)
        {
            if (value.Native != null)
            {
                _ncanvas.Children.Remove(value.Native as UIElement);
            }

            Children.Remove(value);
        }
Example #29
0
 public PropertyData SetProperty(string name, INative value) => Helpers.SetProperty(this, name, value);
Example #30
0
 public bool Lesser(INative b) => false;
Example #31
0
 public void Render(INative context)
 {
 }
Example #32
0
 private void Reset(INative child)
 {
     if (child is IPin)
     {
         Reset(child as IPin);
     }
     else if (child is ILine)
     {
         Reset(child as ILine);
     }
     else if (child is IBezier)
     {
         Reset(child as IBezier);
     }
     else if (child is IQuadraticBezier)
     {
         Reset(child as IQuadraticBezier);
     }
     else if (child is IArc)
     {
         Reset(child as IArc);
     }
     else if (child is IRectangle)
     {
         Reset(child as IRectangle);
     }
     else if (child is IEllipse)
     {
         Reset(child as IEllipse);
     }
     else if (child is IText)
     {
         Reset(child as IText);
     }
     else if (child is IBlock)
     {
         Reset(child as IBlock);
     }
 }
Example #33
0
 private void HideSelected()
 {
     _selected.Bounds.Hide();
     _selected = null;
     _state = _state & ~State.Selected;
     Debug.Print("_state: {0}", _state);
 }
Example #34
0
        private void Down(Vector2 p)
        {
            bool render = false;

            if (IsState(State.Selected))
            {
                HideSelected();
                render = true;
            }

            if (IsState(State.Hover))
            {
                HideHover();
                render = true;
            }

            _selected = Helper.HitTest(_canvas.Children, p.X, p.Y);
            if (_selected != null)
            {
                ShowSelected();
                InitMove(p);
                _canvas.Capture();
                render = true;
            }

            if (render)
            {
                _canvas.Render(null);
            }
        }
Example #35
0
        public void Add(INative value)
        {
            if (value.Native != null)
            {
                _ncanvas.Children.Add(value.Native as UIElement);
            }

            Children.Add(value);
        }
Example #36
0
        private void Reset()
        {
            bool render = false;

            if (_hover != null)
            {
                _hover.Bounds.Hide();
                _hover = null;
                render = true;
            }

            if (_selected != null)
            {
                _selected.Bounds.Hide();
                _selected = null;
                render = true;
            }

            _state = State.None;
            Debug.Print("_state: {0}", _state);

            if (render)
            {
                _canvas.Render(null);
            }
        }
Example #37
0
 private void HideHover()
 {
     _hover.Bounds.Hide();
     _hover = null;
     _state = _state & ~State.Hover;
     Debug.Print("_state: {0}", _state);
 }
Example #38
0
 public void Render(INative context)
 {
     _panel.Invalidate();
 }
Example #39
0
 public void Remove(INative value)
 {
     Children.Remove(value);
 }
Example #40
0
 public void Add(INative value)
 {
     Children.Add(value);
 }
Example #41
0
 internal static IElementsCollection <T> Create <T>(INative parent, Locator locator) where T : IElement, new() => new WebElementsCollection <T>(parent, locator);
Example #42
0
        private void Drag(Vector2 p)
        {
            if (_canvas.IsCaptured)
            {
                if (IsState(State.Move))
                {
                    Move(p);
                }
            }
            else
            {
                bool render = false;
                var result = Helper.HitTest(_canvas.Children, p.X, p.Y);

                if (IsState(State.Hover))
                {
                    if (IsState(State.Selected))
                    {
                        if (_hover != _selected && _hover != result)
                        {
                            HideHover();
                            render = true;
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        if (result != _hover)
                        {
                            HideHover();
                            render = true;
                        }
                        else
                        {
                            return;
                        }
                    }
                }

                if (result != null)
                {
                    if (IsState(State.Selected))
                    {
                        if (result != _selected)
                        {
                            _hover = result;
                            ShowHover();
                            render = true;
                        }
                    }
                    else
                    {
                        _hover = result;
                        ShowHover();
                        render = true;
                    }
                }

                if (render)
                {
                    _canvas.Render(null);
                }
            }
        }