private static void InternalNavigate(IMXView fromView, string url, Dictionary <string, string> parameters)
        {
            Console.WriteLine("InternalNavigation navigating to: " + url);

            MXContainer container = Instance;   // optimization for the server size, property reference is a hashed lookup

            // fetch and allocate a viable controller
            IMXController controller = container.GetController(url, parameters);

            // Initiate load for the associated controller passing all parameters
            if (controller != null)
            {
                container.OnControllerLoadBegin(controller);

                container.CancelLoad = false;

                // synchronize load layer to prevent collisions on web-based targets.
                lock (container)
                {
                    // Console.WriteLine("InternalNavigate: Locked");

                    // if there is no synchronization, don't launch a new thread
                    if (container.ThreadedLoad)
                    {
                        // new thread to execute the Load() method for the layer
//	                    new Thread((object args) =>
//	                    {
                        try
                        {
                            //Dictionary<string, string> parameters = (Dictionary<string, string>)args;
                            container.LoadController(fromView, controller, parameters);
                        }
                        catch (Exception ex)
                        {
                            container.OnControllerLoadFailed(controller, ex);
                        }
//
//						}).Start(parameters);
                    }
                    else
                    {
                        try
                        {
                            container.LoadController(fromView, controller, parameters);
                        }
                        catch (Exception ex)
                        {
                            container.OnControllerLoadFailed(controller, ex);
                        }
                    }

                    // Console.WriteLine("InternalNavigate: Unlocking");
                }
            }
        }
Example #2
0
 static void TryLoadController(MXContainer container, IMXView fromView, IMXController controller, Dictionary <string, string> parameters)
 {
     try
     {
         container.LoadController(fromView, controller, parameters);
     }
     catch (Exception ex)
     {
         container.OnControllerLoadFailed(controller, ex);
     }
 }
        protected static void InitializeContainer(MXContainer theContainer)
        {
            string sessionId = string.Empty;

            if (GetSessionId != null)
            {
                sessionId = GetSessionId();
            }

            instances[sessionId] = theContainer;
        }
Example #4
0
        private static void InternalNavigate(IMXView fromView, string url, Dictionary <string, string> parameters)
        {
            MXContainer container = Instance; // optimization for the server side; property reference is a hashed lookup

            // fetch and allocate a viable controller
            var controller = container.GetController(url, ref parameters);

            if (controller != null)
            {
                // Initiate load for the associated controller passing all parameters
                TryLoadController(container, fromView, controller, url, parameters);
            }
        }
Example #5
0
        static void TryLoadController(MXContainer container, IMXView fromView, IMXController controller, Dictionary <string, object> parameters)
        {
            try
            {
                NSObject nso = new NSObject();

                nso.InvokeOnMainThread(() => {
                    container.LoadController(fromView, controller, parameters);
                });
            }
            catch (Exception ex)
            {
                container.OnControllerLoadFailed(controller, ex);
            }
        }
Example #6
0
        /// <summary>
        /// Tries to execute the Load method of the specified controller using eventing.
        /// </summary>
        /// <param name="container">The container that loads the controller.</param>
        /// <param name="fromView">The view that activated the navigation.</param>
        /// <param name="controller">The controller to load.</param>
        /// <param name="navigatedUri">A <see cref="String"/> that represents the uri used to navigate to the controller.</param>
        /// <param name="parameters">The parameters to use with the controller's Load method.</param>
        protected static void TryLoadController(MXContainer container, IMXView fromView, IMXController controller, string navigatedUri, Dictionary <string, string> parameters)
        {
            // set last navigation
            container.LastNavigationDate = DateTime.Now;
            container.LastNavigationUrl  = navigatedUri;

            container.OnControllerLoadBegin(controller, fromView);
            container.CancelLoad = false;

            // synchronize load layer to prevent collisions on web-based targets.
            lock (container)
            {
                // Console.WriteLine("InternalNavigate: Locked");

                Action <object> load = (o) =>
                {
                    try
                    {
                        container.LoadController(fromView, controller, navigatedUri, parameters);
                    }
                    catch (Exception ex)
                    {
                        container.OnControllerLoadFailed(controller, ex);
                    }
                };

                // if there is no synchronization, don't launch a new thread
                if (container.ThreadedLoad)
                {
#if NETCF
                    // new thread to execute the Load() method for the layer
                    System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(load));
#else
                    System.Threading.Tasks.Task.Factory.StartNew(() => load(null));
#endif
                }
                else
                {
                    load(null);
                }

                // Console.WriteLine("InternalNavigate: Unlocking");
            }
        }
Example #7
0
 private static object AttemptConstruction(object[] parameters, IEnumerable <KeyValuePair <ConstructorInfo, ParameterInfo[]> > ctors, bool matchExactType)
 {
     foreach (var info in ctors)
     {
         var parametersCopy = new object[info.Value.Length];
         for (var i = 0; i < info.Value.Length; i++)
         {
             var param = info.Value[i];
             if (parameters != null && parameters.Length > i)
             {
                 var item = parameters[i];
                 if (item != null && (matchExactType ? param.ParameterType != item.GetType()
                     : !param.ParameterType.GetTypeInfo().IsAssignableFrom(item.GetType().GetTypeInfo())))
                 {
                     parametersCopy = null;
                     break;
                 }
                 parametersCopy[i] = item;
             }
             else if ((param.Attributes & ParameterAttributes.HasDefault) == ParameterAttributes.HasDefault)
             {
                 parametersCopy[i] = param.DefaultValue;
             }
             else
             {
                 parametersCopy[i] = MXContainer.Resolve(param.ParameterType, null, null);
                 if (parametersCopy[i] != null)
                 {
                     continue;
                 }
                 parametersCopy = null;
                 break;
             }
         }
         if (parametersCopy != null)
         {
             return(info.Key.Invoke(parametersCopy));
         }
     }
     return(null);
 }
Example #8
0
        /// <summary>
        /// Tries to execute the Load method of the specified controller using eventing.
        /// </summary>
        /// <param name="container">The container that loads the controller.</param>
        /// <param name="fromView">The view that activated the navigation.</param>
        /// <param name="controller">The controller to load.</param>
        /// <param name="navigatedUri">A <see cref="String"/> that represents the uri used to navigate to the controller.</param>
        /// <param name="parameters">The parameters to use with the controller's Load method.</param>
        protected static void TryLoadController(MXContainer container, IMXView fromView, IMXController controller, string navigatedUri, Dictionary <string, string> parameters)
        {
            // set last navigation
            container.LastNavigationDate = DateTime.Now;
            container.LastNavigationUrl  = navigatedUri;

            container.OnControllerLoadBegin(controller, fromView);
            container.CancelLoad = false;

            // synchronize load layer to prevent collisions on web-based targets.
            lock (container)
            {
                // Console.WriteLine("InternalNavigate: Locked");

                Action load = () =>
                {
                    try
                    {
                        container.LoadController(fromView, controller, navigatedUri, parameters);
                    }
                    catch (Exception ex)
                    {
                        container.OnControllerLoadFailed(controller, ex);
                    }
                };

                // if there is no synchronization, don't launch a new thread
                if (container.ThreadedLoad)
                {
                    // new thread to execute the Load() method for the layer
                    Device.Thread.QueueWorker(a => load());
                }
                else
                {
                    load();
                }

                // Console.WriteLine("InternalNavigate: Unlocking");
            }
        }
Example #9
0
        private static void InternalNavigate(IMXView fromView, string url, Dictionary <string, string> parameters)
        {
            MXContainer container = Instance;   // optimization for the server size, property reference is a hashed lookup

            // fetch and allocate a viable controller
            IMXController controller = container.GetController(url, ref parameters);

            // Initiate load for the associated controller passing all parameters
            if (controller != null)
            {
                container.OnControllerLoadBegin(controller);

                container.CancelLoad = false;

                // synchronize load layer to prevent collisions on web-based targets.
                lock (container)
                {
                    // Console.WriteLine("InternalNavigate: Locked");

                    // if there is no synchronization, don't launch a new thread
                    if (container.ThreadedLoad)
                    {
                        // new thread to execute the Load() method for the layer
#if NETFX_CORE
                        System.Threading.Tasks.Task.Factory.StartNew(() => TryLoadController(container, fromView, controller, parameters), System.Threading.Tasks.TaskCreationOptions.LongRunning);
#else
                        new Thread(() => TryLoadController(container, fromView, controller, parameters)).Start();
#endif
                    }
                    else
                    {
                        TryLoadController(container, fromView, controller, parameters);
                    }

                    // Console.WriteLine("InternalNavigate: Unlocking");
                }
            }
        }
 public static void Navigate(this IMXView view, string url, Dictionary <string, string> parameters)
 {
     MXContainer.Navigate(view, url, parameters);
 }
 public static void Navigate(this IMXView view, string url)
 {
     MXContainer.Navigate(view, url);
 }
Example #12
0
 /// <summary>
 /// Initializes the <see cref="Instance"/>.
 /// </summary>
 /// <param name="theContainer">The container instance.</param>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="theContainer"/> is <c>null</c>.</exception>
 protected static void InitializeContainer(MXContainer theContainer)
 {
     Instance = theContainer;
 }
Example #13
0
        /// <summary>
        /// Returns the managed instance.
        /// </summary>
        /// <param name="parameters">An array of constructor parameters for initialization.</param>
        /// <returns>The object instance.</returns>
        public object Load(params object[] parameters)
        {
            if (_instanceType == null)
            {
                return(null);
            }

            if (Instance != null)
            {
                return(Instance);
            }

            object retval;

            if (_initialize == null)
            {
                try
                {
                    var ctors = _instanceType.GetTypeInfo().DeclaredConstructors;
                    if (parameters == null || parameters.Length == 0)
                    {
                        var info = ctors.Select(c => new { ctor = c, param = c.GetParameters() })
                                   .OrderBy(i => i.param.Length)
                                   .Select(p => new { p.ctor, param = p.param.Select(res => MXContainer.Resolve(res.ParameterType, null, null)) })
                                   .FirstOrDefault(v => v.param.All(o => o != null));

                        retval = info != null?info.ctor.Invoke(info.param.ToArray()) : Activator.CreateInstance(_instanceType);
                    }
                    else
                    {
                        var ctor = ctors.FirstOrDefault(c =>
                        {
                            var p = c.GetParameters();
                            return(p.Length == parameters.Length && !p.Where((t, i) => parameters[i] != null && !t.ParameterType.GetTypeInfo().IsAssignableFrom(parameters[i].GetType().GetTypeInfo())).Any());
                        });
                        retval = ctor == null?Activator.CreateInstance(_instanceType) : ctor.Invoke(parameters);
                    }
                }
                catch (MissingMemberException)
                {
                    retval = Activator.CreateInstance(_instanceType);
                }
            }
            else
            {
                retval = _initialize(parameters);
            }

            if (_singletonInstance)
            {
                _instance = retval;
            }

            return(retval);
        }
Example #14
0
 public static Task Navigate(this IMXView view, string url, Dictionary <string, object> parameters)
 {
     return(MXContainer.Navigate(view, url, parameters));
 }
Example #15
0
 public static Task Navigate(this IMXView view, string url)
 {
     return(MXContainer.Navigate(view, url));
 }