private RouterBase GetRouter(RouterType routerType)
        {
            RouterBase router = this.routerDic[routerType];

            Trace.WriteLine(router != null, "Selected router can't be null!");
            return(router);
        }
示例#2
0
        /// <summary>
        /// Get the RouterType using IP Address of the Router.
        /// </summary>
        /// <param name="ipAddress">IP Address of the Router.</param>
        /// <param name="userName">User name credentials to the router.</param>
        /// <param name="password">Password credentials to the router.</param>
        /// <returns><see cref="RouterType"/></returns>
        private static RouterType GetRouterType(IPAddress ipAddress, string userName, string password)
        {
            TelnetIpc  telnet     = new TelnetIpc(ipAddress.ToString(), 23);
            RouterType routerType = RouterType.None;

            try
            {
                telnet.Connect();
                telnet.SendLine(" ");
                Thread.Sleep(TimeSpan.FromSeconds(5));
                telnet.SendLine(userName);
                Thread.Sleep(TimeSpan.FromSeconds(5));
                telnet.SendLine(password);
                Thread.Sleep(TimeSpan.FromSeconds(20));
                string data = telnet.ReceiveUntilMatch("$");

                // HP manufactured router can contain any of the strings.
                // ProCurve, Hewlett-Packard, Hewlett Packard
                if (data.Contains("ProCurve", StringComparison.CurrentCultureIgnoreCase) || data.Contains("Hewlett-Packard", StringComparison.CurrentCultureIgnoreCase) || data.Contains("Hewlett Packard", StringComparison.CurrentCultureIgnoreCase))
                {
                    routerType = RouterType.HP;
                }
            }
            finally
            {
                telnet.Dispose();
                Thread.Sleep(1000);
            }

            return(routerType);
        }
示例#3
0
 public async Task <RRouteSegment[]> GetRoute(RouterType routerType, params RPoint[] waypoints)
 {
     return(await exec <RRouteSegment[]>("GetRoute", new Dictionary <string, object>()
     {
         { "id", (int)routerType },
         { "waypoints", waypoints
           .Select(p => p.Lat.ToString(CultureInfo.InvariantCulture) + "," + p.Lng.ToString(CultureInfo.InvariantCulture))
           .Aggregate((acc, sel) => acc + ";" + sel) }
     }));
 }
示例#4
0
        /// <summary>
        /// 路由类型转换
        /// </summary>
        /// <param name="routerType"></param>
        /// <returns></returns>
        public static RouterType Parse(string routerType)
        {
            RouterType r = RouterType.Hash;

            if (Enum.TryParse <RouterType>(routerType, out r))
            {
                r = RouterType.Hash;
            }
            return(r);
        }
示例#5
0
        public RouterItem GetRouterItem()
        {
            #region  Router

            RouterItem    routerItem = new RouterItem();
            StringBuilder sb         = new StringBuilder();
            int           i          = 1;

            RouterType routerType = (RouterType)this.comboRouter.SelectedValue;
            routerItem.RouterType = routerType;

            string routerIp = this.txtRounterIp.Text.Trim();
            if (!string.IsNullOrEmpty(routerIp) && TextHelper.IsIP(routerIp))
            {
                routerItem.IP = routerIp;
            }
            else
            {
                sb.AppendLine(string.Format("{0}、您录入的不是有效的路由器IP地址!", i++));
            }

            string routerUser = this.txtRouterUser.Text.Trim();
            if (!string.IsNullOrEmpty(routerUser))
            {
                routerItem.User = routerUser;
            }
            else
            {
                sb.AppendLine(string.Format("{0}、请录入正确的路由器登录用户名!", i++));
            }

            string routerPwd = this.txtRouterPwd.Text.Trim();
            if (!string.IsNullOrEmpty(routerPwd))
            {
                routerItem.Password = routerPwd;
            }
            else
            {
                sb.AppendLine(string.Format("{0}、请录入正确的路由器登录密码!", i++));
            }

            if (sb.Length > 0)
            {
                MessageBox.Show(sb.ToString());
                return(null);
            }

            return(routerItem);

            #endregion
        }
示例#6
0
        public static RouterReader Create(RouterType routerType, string address, string user, string pass)
        {
            RouterReader router = null;

            switch (routerType)
            {
            case RouterType.Tomato:
                router = new TomatoRouter();
                break;
            }
            if (router != null)
            {
                router.Address = address;
                router.User    = user;
                router.Pass    = pass;
            }
            return(router);
        }
示例#7
0
        public static IRouter Create(IPAddress address, string userName, string password)
        {
            RouterType routerType = GetRouterType(address, userName, password);
            IRouter    iRouter    = null;

            switch (routerType)
            {
            case RouterType.None:
                Logger.LogInfo("Router manufacturer can't be identified or it is not implemented");
                break;

            case RouterType.HP:
                Logger.LogInfo("HP Procurve Router instance is created with IP Address : {0}".FormatWith(address));
                iRouter = new HPProcurveRouter(address, userName, password);
                break;

            case RouterType.Cisco:
                Logger.LogInfo("Cisco Network Switch is not implemented");
                break;
            }

            return(iRouter);
        }