Beispiel #1
0
 /// <summary>
 /// Determines if the specified object is equal to this instance.
 /// </summary>
 /// <param name="mapping">The object to test for equality.</param>
 /// <returns><c>true</c> if the object is equal to this instance; otherwise <c>false</c>.</returns>
 public bool Equals(MXNavigation mapping)
 {
     if (ReferenceEquals(mapping, null))
     {
         return(false);
     }
     if (ReferenceEquals(this, mapping))
     {
         return(true);
     }
     if (Parts.Length != mapping.Parts.Length)
     {
         return(false);
     }
     for (int part = 0; part < Parts.Length; part++)
     {
         if (Parts[part].IsParameter != mapping.Parts[part].IsParameter)
         {
             return(false);
         }
         if (!Parts[part].IsParameter && Parts[part].SegmentValue != mapping.Parts[part].SegmentValue)
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #2
0
        /// <summary>
        /// Gets the controller.
        /// </summary>
        /// <param name="url">The URL pattern of the controller.</param>
        /// <param name="parameters">The parameters to load into the controller.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">url</exception>
        public virtual IMXController GetController(string url, ref Dictionary <string, string> parameters)
        {
            IMXController controller = null;

            // return if no url provided
            if (url == null)
            {
                throw new ArgumentNullException("url");
            }

            // initialize parameter dictionary if not provided
            parameters = parameters ?? new Dictionary <string, string>();

            // for debug
            // Console.WriteLine("Navigating to: " + url);

            // get map object
            MXNavigation navigation = App.NavigationMap.MatchUrl(url);

            // If there is no result, assume the URL is external and create a new Browser View
            if (navigation != null)
            {
                controller = navigation.Controller;
                navigation.ExtractParameters(url, parameters);

                //Add default view parameters without overwriting current ones
                if (navigation.Parameters != null)
                {
                    foreach (var param in navigation.Parameters)
                    {
                        if (!parameters.ContainsKey(param.Key))
                        {
                            parameters.Add(param.Key, param.Value);
                        }
                    }
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("No controller loaded for URI: " + url);
            }

            return(controller);
        }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NavAddedEventArgs"/> class.
 /// </summary>
 /// <param name="navItem">The added navigation item.</param>
 public NavAddedEventArgs(MXNavigation navItem)
 {
     NavigationItem = navItem;
 }
        public virtual IMXController GetController(string url, Dictionary <string, string> parameters)
        {
            IMXController controller = null;
            MXNavigation  navigation = null;

            // return if no url provided
            if (url == null)
            {
                throw new ArgumentException("url is NULL");
            }

            // set last navigation
            LastNavigationDate = DateTime.Now;
            LastNavigationUrl  = url;

            // initialize parameter dictionary if not provided
            parameters = (parameters ?? new Dictionary <string, string>());

            // for debug
            // Console.WriteLine("Navigating to: " + url);

            // get map object
            navigation = MatchUrl(url);

            // If there is no result, assume the URL is external and create a new Browser View
            if (navigation != null)
            {
                controller = navigation.Controller;

                // Now that we know which mapping the URL matches, determine the parameter names for any Values in URL string
                Match           match = Regex.Match(url, navigation.RegexPattern());
                MatchCollection args  = Regex.Matches(navigation.Pattern, @"{(?<Name>\w+)}*");

                // If there are any parameters in the URL string, add them to the parameters dictionary
                if (match != null && args.Count > 0)
                {
                    foreach (Match arg in args)
                    {
                        if (parameters.ContainsKey(arg.Groups["Name"].Value))
                        {
                            parameters.Remove(arg.Groups["Name"].Value);
                        }
                        parameters.Add(arg.Groups["Name"].Value, match.Groups[arg.Groups["Name"].Value].Value);
                    }
                }

                //Add default view parameters without overwriting current ones new comment here
                if (navigation.Parameters.Count > 0)
                {
                    foreach (KeyValuePair <string, string> param in navigation.Parameters)
                    {
                        if (!parameters.ContainsKey(param.Key))
                        {
                            parameters.Add(param.Key, param.Value);
                        }
                    }
                }
            }
            else
            {
#if DEBUG
                throw new Exception("URI match not found for: " + url);
#else
                // should log the message at least
#endif
            }

            controller.Uri        = url;
            controller.Parameters = parameters;

            return(controller);
        }