Пример #1
0
        /// <summary>
        /// Deserializes the specified element.
        /// </summary>
        /// <param name="element">The element.</param>
        public override void Deserialize(System.Xml.XmlElement element)
        {
            if (string.Compare(element.Name, this.TypeName, false) != 0)
            {
                throw new InvalidCastException(string.Format("Unable to convert {0} to a {1}", element.Name, this.TypeName));
            }

            this.Username          = Util.GetElementOrAttributeValue("user", element);
            this.Password.Password = Util.GetElementOrAttributeValue("password", element);
        }
Пример #2
0
        /// <summary>
        /// Deserializes the specified element.
        /// </summary>
        /// <param name="element">The element.</param>
        public override void Deserialize(System.Xml.XmlElement element)
        {
            this._executable          = string.Empty;
            this.ServerConnect        = string.Empty;
            this._serverLoginUser     = string.Empty;
            this._serverLoginPassword = new HiddenPassword();
            this._branch           = string.Empty;
            this._repository       = string.Empty;
            this._workingDirectory = string.Empty;
            this.File                 = string.Empty;
            this.Recursive            = null;
            this.UseRegularExpression = null;
            this.Timeout              = new Timeout();

            this.Executable = Util.GetElementOrAttributeValue("executable", element);
            string s = Util.GetElementOrAttributeValue("serverlogin", element);

            string[] sl = s.Split(new char[] { ':' }, 2, StringSplitOptions.None);
            if (sl.Length == 2)
            {
                this.Username          = sl[0];
                this.Password.Password = sl[1];
            }

            s = Util.GetElementOrAttributeValue("serverconnect", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.ServerConnect = s;
            }

            this.Branch           = Util.GetElementOrAttributeValue("branch", element);
            this.Repository       = Util.GetElementOrAttributeValue("repository", element);
            this.WorkingDirectory = Util.GetElementOrAttributeValue("workingDirectory", element);

            s = Util.GetElementOrAttributeValue("recursive", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.Recursive = string.Compare(s, "1", true) == 0 || string.Compare(s, bool.TrueString, true) == 0;
            }

            s = Util.GetElementOrAttributeValue("searchregex", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.UseRegularExpression = string.Compare(s, "1", true) == 0 || string.Compare(s, bool.TrueString, true) == 0;
            }

            XmlElement ele = (XmlElement)element.SelectSingleNode("timeout");

            if (ele != null)
            {
                this.Timeout.Deserialize(ele);
            }
        }
Пример #3
0
 /// <summary>
 /// Converts the given object to the type of this converter, using the specified context and culture information.
 /// </summary>
 /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"></see> that provides a format context.</param>
 /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo"></see> to use as the current culture.</param>
 /// <param name="value">The <see cref="T:System.Object"></see> to convert.</param>
 /// <returns>
 /// An <see cref="T:System.Object"></see> that represents the converted value.
 /// </returns>
 /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception>
 public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
 {
     if (value != null && value.GetType() == typeof(String))
     {
         HiddenPassword pwd = new HiddenPassword();
         pwd.Password = (string)value;
         return(pwd);
     }
     else
     {
         throw new NotSupportedException(string.Format("Can not convert from {0} to {1}", value.GetType().ToString(), typeof(HiddenPassword).ToString()));
     }
 }
Пример #4
0
        /// <summary>
        /// Deserializes the specified element.
        /// </summary>
        /// <param name="element">The element.</param>
        public override void Deserialize(XmlElement element)
        {
            this.AutoGetSource    = null;
            this.Branch           = string.Empty;
            this._database        = string.Empty;
            this._userName        = string.Empty;
            this._password        = new HiddenPassword();
            this._project         = null;
            this._server          = string.Empty;
            this.LabelOnSuccess   = null;
            this.WorkingDirectory = string.Empty;
            if (string.Compare(element.GetAttribute("type"), this.TypeName, false) != 0)
            {
                throw new InvalidCastException(string.Format("Unable to convert {0} to a {1}", element.GetAttribute("type"), this.TypeName));
            }

            this.Server            = Util.GetElementOrAttributeValue("server", element);
            this.Database          = Util.GetElementOrAttributeValue("database", element);
            this.Username          = Util.GetElementOrAttributeValue("username", element);
            this.Password.Password = Util.GetElementOrAttributeValue("password", element);
            this.Project           = new AlienbrainUri(Util.GetElementOrAttributeValue("project", element));

            string s = Util.GetElementOrAttributeValue("autoGetSource", element);

            if (!string.IsNullOrEmpty(s))
            {
                this.AutoGetSource = string.Compare(s, bool.TrueString, true) == 0;
            }

            s = Util.GetElementOrAttributeValue("branch", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.Branch = s;
            }

            s = Util.GetElementOrAttributeValue("labelOnSuccess", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.LabelOnSuccess = string.Compare(s, bool.TrueString, true) == 0;
            }

            s = Util.GetElementOrAttributeValue("workingDirectory", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.WorkingDirectory = s;
            }
        }
Пример #5
0
        /// <summary>
        /// Deserializes the specified element.
        /// </summary>
        /// <param name="element">The element.</param>
        public override void Deserialize(System.Xml.XmlElement element)
        {
            this.Prefix   = null;
            this.Major    = 0;
            this.Minor    = 0;
            this.Password = new HiddenPassword();
            this.Url      = null;
            this.Username = null;

            // here we check that the element type value == the type name specified in the constructor.
            if (string.Compare(element.GetAttribute("type"), base.TypeName, false) != 0)
            {
                throw new InvalidCastException(string.Format("Unable to convert {0} to a {1}",
                                                             element.GetAttribute("type"), base.TypeName));
            }

            string s = Util.GetElementOrAttributeValue("url", element);

            this.Url = new Uri(s);

            s          = Util.GetElementOrAttributeValue("major", element);
            this.Major = int.Parse(s);

            s          = Util.GetElementOrAttributeValue("minor", element);
            this.Minor = int.Parse(s);

            s = Util.GetElementOrAttributeValue("prefix", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.Prefix = s;
            }

            s = Util.GetElementOrAttributeValue("password", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.Password.Password = s;
            }

            s = Util.GetElementOrAttributeValue("username", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.Username = s;
            }
        }
Пример #6
0
        public void EmailPublisherSerializerTest( )
        {
            Serializer <EmailPublisher> ser = new Serializer <EmailPublisher> ( );
            EmailPublisher ep = new EmailPublisher( );

            ep.From     = "*****@*****.**";
            ep.MailHost = "fake.mail.host.com";
            HiddenPassword hp = new HiddenPassword( );

            hp.Password         = "******";
            ep.MailHostPassword = hp;
            ep.MailHostUserName = "******";
            User u = new User( );

            u.Address = "*****@*****.**";
            u.Name    = "foo bar";
            ep.Users.Add(u);

            XmlElement ele = ser.Serialize(ep);

            Assert.IsNotNull(ele);
            Console.WriteLine(ele.OuterXml);
        }
Пример #7
0
        public void CheckRequiredTest( )
        {
            NullTask task = new NullTask( );

            // check alienbrain
            try {
                Assert.IsNotNull(Util.CheckRequired(task, "alienbrainUri", new AlienbrainUri("ab://google.com")));
                Assert.IsNotNull(Util.CheckRequired(task, "alienbrainUri", new AlienbrainUri("alienbrain://google.com")));
            } catch (Exception exception) {
                Assert.Fail(exception.Message);
            }

            try {
                Util.CheckRequired(task, "alienbrainUri", new AlienbrainUri("http://google.com"));
                Assert.Fail("http scheme not allowed. Should have failed.");
            } catch (Exception exception) {
                Assert.IsAssignableFrom(typeof(UriFormatException), exception);
            }

            // check valid values
            try {
                Assert.IsNotNull(Util.CheckRequired(task, "object", new object( )));
                Assert.IsNotEmpty(Util.CheckRequired(task, "string", "some string"));
                Assert.Greater(Util.CheckRequired(task, "DateTime", DateTime.Now), DateTime.MinValue);
                HiddenPassword hp = new HiddenPassword( );
                hp.Password = "******";
                Assert.IsNotNull(Util.CheckRequired(task, "HiddenPassword", hp));
            } catch (Exception exception) {
                Assert.Fail(exception.Message);
            }

            //check invalid values
            try {
                Assert.IsNull(Util.CheckRequired(task, "NotificationType", (Core.Enums.NotificationType? )null));
                Assert.LessOrEqual(Util.CheckRequired(task, "CloneableList", new CloneableList <string> ( )).Count, 0);
            } catch { }
        }
Пример #8
0
 public TwitterPublisher( ) : base("twitter")
 {
     _password = new HiddenPassword( );
 }
Пример #9
0
        /// <summary>
        /// Deserializes the specified element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="baseObject">The base object.</param>
        public void Deserialize(XmlElement element, T baseObject)
        {
            // this dynamically resets all the reflector properties only if they
            // are writeable and public
            Util.ResetObjectProperties <T> (baseObject);
            Type type = baseObject.GetType();

            // get the reflector name for the type
            string rootTypeName = Util.GetReflectorNameAttributeValue(type);
            // get the version info for the type
            Version versionInfo = Util.GetTypeDescriptionProviderVersion(typeof(T));

            // throw exception if we can not convert from the element to the type.
            if (string.Compare(element.Name, rootTypeName, false) != 0)
            {
                throw new InvalidCastException(string.Format("Unable to convert {0} to a {1}", element.Name, rootTypeName));
            }

            List <PropertyInfo> props = GetReflectorProperies(baseObject);

            foreach (PropertyInfo pi in props)
            {
                string            rname = Util.GetReflectorNameAttributeValue(pi);
                RequiredAttribute ra    = Util.GetCustomAttribute <RequiredAttribute> (pi);
                Type    valType         = pi.PropertyType;
                XmlNode subElement      = null;
                if (string.Compare(element.Name, rname, false) == 0)
                {
                    subElement = element;
                }
                else
                {
                    subElement = element.SelectSingleNode(rname) as XmlNode;
                }
                if (subElement == null)
                {
                    subElement = element.SelectSingleNode(string.Format("@{0}", rname));
                }
                bool required = ra != null;
                // property is required but it doesn't exist
                if (required && subElement == null)
                {
                    throw new RequiredAttributeException(baseObject, rname);
                }
                // element doesn't exist but it's not required so we can move on
                if (subElement == null)
                {
                    continue;
                }

                if (Util.IsNullable(valType))
                {
                    Type nullType = Nullable.GetUnderlyingType(valType);
                    valType = nullType;
                }

                if (valType.IsPrimitive || valType == typeof(string) || valType == typeof(DateTime) || valType.IsEnum)
                {
                    pi.SetValue(baseObject, StringTypeConverter.Convert(subElement.InnerText, valType), null);
                }
                else
                {
                    if (valType.GetInterface(typeof(ICCNetObject).FullName) != null)
                    {
                        ConstructorInfo ci = valType.GetConstructor(new Type[] { });
                        if (ci == null)
                        {
                            throw new ArgumentException(string.Format("Unable to locate default constructor for type {0}", valType.Name));
                        }
                        else
                        {
                            ICCNetObject valObject = ci.Invoke(null) as ICCNetObject;
                            valObject.Deserialize(subElement as XmlElement);
                            pi.SetValue(baseObject, valObject, null);
                        }
                    }
                    else if (valType.IsGenericType && valType.GetGenericTypeDefinition().Equals(typeof(CloneableList <>)))
                    {
                        IList vlist = pi.GetValue(baseObject, null) as IList;
                        Type  gtype = valType.GetGenericArguments()[0];

                        if (vlist == null)
                        {
                            // create a new instance since it's null
                            ConstructorInfo ci = valType.GetConstructor(new Type[] { });
                            if (ci == null)
                            {
                                throw new ArgumentException(string.Format("Unable to locate default constructor for type {0}", valType.Name));
                            }
                            else
                            {
                                vlist = ci.Invoke(null) as IList;
                            }
                        }

                        ReflectorArrayAttribute raa = Util.GetCustomAttribute <ReflectorArrayAttribute> (pi);
                        if (raa != null)
                        {
                            XmlNodeList nodes = subElement.SelectNodes(raa.ItemName);
                            foreach (XmlElement itemElement in nodes)
                            {
                                if (gtype.IsPrimitive || gtype == typeof(string))
                                {
                                    vlist.Add(StringTypeConverter.Convert(itemElement.InnerText, gtype));
                                }
                                else if (gtype.GetInterface(typeof(ICCNetObject).FullName) != null)
                                {
                                    ICCNetObject    obj = null;
                                    ConstructorInfo ci  = gtype.GetConstructor(new Type[] { });
                                    if (ci == null)
                                    {
                                        throw new ArgumentException(string.Format("Unable to locate default constructor for type {0}", valType.Name));
                                    }
                                    else
                                    {
                                        obj = ci.Invoke(null) as ICCNetObject;
                                    }

                                    obj.Deserialize(itemElement);
                                    vlist.Add(obj);
                                }
                            }
                        }
                        else
                        {
                            // it doesn't have an reflector array attribute, so we can assume that all items are ICCNetObects.
                            XmlNodeList nodes = subElement.SelectNodes("*");
                            foreach (XmlElement itemElement in nodes)
                            {
                                if (gtype.GetInterface(typeof(ICCNetObject).FullName) != null)
                                {
                                    ICCNetObject    obj = null;
                                    ConstructorInfo ci  = gtype.GetConstructor(new Type[] { });
                                    if (ci == null)
                                    {
                                        throw new ArgumentException(string.Format("Unable to locate default constructor for type {0}", valType.Name));
                                    }
                                    else
                                    {
                                        obj = ci.Invoke(null) as ICCNetObject;
                                    }

                                    obj.Deserialize(itemElement);
                                    vlist.Add(obj);
                                }
                                else
                                {
                                    throw new ArgumentException(string.Format("Type {0} is not assignable from {1}", gtype.Name, typeof(ICCNetObject).Name));
                                }
                            }
                        }
                        pi.SetValue(baseObject, vlist, null);
                    }
                    else if (valType == typeof(HiddenPassword))
                    {
                        HiddenPassword hp = pi.GetValue(baseObject, null) as HiddenPassword;
                        if (hp == null)
                        {
                            // need to create it.
                            ConstructorInfo ci = valType.GetConstructor(new Type[] { });
                            if (ci == null)
                            {
                                throw new ArgumentException(string.Format("Unable to locate default constructor for type {0}", valType.Name));
                            }
                            else
                            {
                                hp = ci.Invoke(null) as HiddenPassword;
                            }
                        }
                        hp.Password = subElement.InnerText;
                        pi.SetValue(baseObject, hp, null);
                    }
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Deserializes the specified element.
        /// </summary>
        /// <param name="element">The element.</param>
        public override void Deserialize(XmlElement element)
        {
            this._executable   = string.Empty;
            this._username     = string.Empty;
            this._password     = new HiddenPassword();
            this._project      = string.Empty;
            this.Host          = string.Empty;
            this.Port          = null;
            this.Path          = string.Empty;
            this.AutoGetSource = null;
            this.OverrideFolderWorkingDirectory = string.Empty;
            this.OverrideViewWorkingDirectory   = string.Empty;
            this.FolderRegularExpression        = string.Empty;
            this.FileHistoryRegularExpression   = string.Empty;
            this.FileRegularExpression          = string.Empty;
            this.Timeout = new Timeout();

            string s = Util.GetElementOrAttributeValue("executable", element);

            if (!string.IsNullOrEmpty(s))
            {
                this.Executable = s;
            }

            s = Util.GetElementOrAttributeValue("username", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.Username = s;
            }

            s = Util.GetElementOrAttributeValue("password", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.Password.Password = s;
            }

            s = Util.GetElementOrAttributeValue("project", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.Project = s;
            }

            s = Util.GetElementOrAttributeValue("host", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.Host = s;
            }

            s = Util.GetElementOrAttributeValue("port", element);
            if (!string.IsNullOrEmpty(s))
            {
                int port = 0;
                if (int.TryParse(s, out port))
                {
                    this.Port = port;
                }
            }

            s = Util.GetElementOrAttributeValue("path", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.Path = s;
            }

            s = Util.GetElementOrAttributeValue("autoGetSource", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.AutoGetSource = string.Compare(s, bool.TrueString, true) == 0;
            }

            // workitem: 14757
            s = Util.GetElementOrAttributeValue("overrideFolderWorkingDir", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.OverrideFolderWorkingDirectory = s;
            }
            // workitem: 14757
            s = Util.GetElementOrAttributeValue("overrideViewWorkingDir", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.OverrideViewWorkingDirectory = s;
            }

            s = Util.GetElementOrAttributeValue("folderRegEx", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.FolderRegularExpression = s;
            }

            s = Util.GetElementOrAttributeValue("fileRegEx", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.FileRegularExpression = s;
            }

            s = Util.GetElementOrAttributeValue("fileHistoryRegEx", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.FileHistoryRegularExpression = s;
            }

            XmlElement ele = (XmlElement)element.SelectSingleNode("timeout");

            if (ele != null)
            {
                this.Timeout.Deserialize(ele);
            }
        }
Пример #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JediVcsSourceControl"/> class.
 /// </summary>
 public JediVcsSourceControl( )
     : base("jedivcs")
 {
     this._password = new HiddenPassword( );
 }