Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new instance of the <see cref="ORConnection"/> class.
        /// </summary>
        /// <param name="line">The line which was received from the control connection.</param>
        /// <returns>
        ///   <c>ORConnection</c> the new instance.
        /// </returns>
        public static ORConnection FromLine(string line)
        {
            string   target;
            ORStatus status;

            string[] parts = StringHelper.GetAll(line, ' ');

            if (parts.Length < 2)
            {
                return(null);
            }

            target = parts[0];
            status = ReflectionHelper.GetEnumerator <ORStatus, DescriptionAttribute>(attr => parts[1].Equals(attr.Description, StringComparison.CurrentCultureIgnoreCase));

            ORConnection connection = new ORConnection();

            connection.Status = status;
            connection.Target = target;

            for (int i = 2; i < parts.Length; i++)
            {
                string data = parts[i].Trim();

                if (!data.Contains("="))
                {
                    continue;
                }

                string[] values = data.Split(new[] { '=' }, 2);

                if (values.Length < 2)
                {
                    continue;
                }

                string name  = values[0].Trim();
                string value = values[1].Trim();

                if ("REASON".Equals(name, StringComparison.CurrentCultureIgnoreCase))
                {
                    connection.Reason = ReflectionHelper.GetEnumerator <ORReason, DescriptionAttribute>(attr => value.Equals(attr.Description, StringComparison.CurrentCultureIgnoreCase));
                    continue;
                }

                if ("NCIRCS".Equals(name, StringComparison.CurrentCultureIgnoreCase))
                {
                    int circuits;

                    if (int.TryParse(value, out circuits))
                    {
                        connection.CircuitCount = circuits;
                    }

                    continue;
                }

                if ("ID".Equals(name, StringComparison.CurrentCultureIgnoreCase))
                {
                    int id;

                    if (int.TryParse(value, out id))
                    {
                        connection.ID = id;
                    }

                    continue;
                }
            }
            return(connection);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ORConnectionEventArgs"/> class.
 /// </summary>
 /// <param name="connection">The connection which was changed.</param>
 public ORConnectionEventArgs(ORConnection connection)
 {
     this.connection = connection;
 }