public virtual IRoleData ReadSerializedRole(Stream dataStream, string serializedItemId)
        {
            Assert.ArgumentNotNull(dataStream, nameof(dataStream));

            try
            {
                using (var reader = new YamlReader(dataStream, 4096, true))
                {
                    string roleName = reader.ReadExpectedMap("Role");

                    var memberOfRoles = new List<string>();

                    var roleMembershipNode = reader.PeekMap();
                    if (roleMembershipNode.HasValue && roleMembershipNode.Value.Key.Equals("MemberOf"))
                    {
                        reader.ReadMap();
                        while (true)
                        {
                            var memberOfRole = reader.PeekMap();
                            if (!memberOfRole.HasValue || !memberOfRole.Value.Key.Equals("Role", StringComparison.Ordinal)) break;

                            reader.ReadMap();

                            memberOfRoles.Add(memberOfRole.Value.Value);
                        }
                    }

                    return new SerializedRoleData(roleName, memberOfRoles.ToArray(), serializedItemId);
                }
            }
            catch (Exception exception)
            {
                throw new YamlFormatException("Error parsing YAML " + serializedItemId, exception);
            }
        }
Ejemplo n.º 2
0
        public IItemMetadata ReadSerializedItemMetadata(Stream dataStream, string serializedItemId)
        {
            Assert.ArgumentNotNull(dataStream, "dataStream");

            try
            {
                using (var reader = new YamlReader(dataStream, 4096, true))
                {
                    var item = new YamlItemMetadata();
                    item.ReadYaml(reader, serializedItemId);

                    return(item);
                }
            }
            catch (Exception exception)
            {
                throw new YamlFormatException("Error parsing YAML " + serializedItemId, exception);
            }
        }
Ejemplo n.º 3
0
        public virtual IItemData ReadSerializedItem(Stream dataStream, string serializedItemId)
        {
            Assert.ArgumentNotNull(dataStream, "dataStream");

            try
            {
                using (var reader = new YamlReader(dataStream, 4096, true))
                {
                    var item = new YamlItem();
                    item.ReadYaml(reader);

                    return(new YamlItemData(item, serializedItemId, FieldFormatters.ToArray(), ParentDataStore));
                }
            }
            catch (Exception exception)
            {
                throw new YamlFormatException("Error parsing YAML " + serializedItemId, exception);
            }
        }
		public IItemMetadata ReadSerializedItemMetadata(Stream dataStream, string serializedItemId)
		{
			Assert.ArgumentNotNull(dataStream, "dataStream");

			try
			{
				using (var reader = new YamlReader(dataStream, 4096, true))
				{
					var item = new YamlItemMetadata();
					item.ReadYaml(reader, serializedItemId);

					return item;
				}
			}
			catch (Exception exception)
			{
				throw new YamlFormatException("Error parsing YAML " + serializedItemId, exception);
			}
		}
		public virtual IItemData ReadSerializedItem(Stream dataStream, string serializedItemId)
		{
			Assert.ArgumentNotNull(dataStream, "dataStream");

			try
			{
				using (var reader = new YamlReader(dataStream, 4096, true))
				{
					var item = new YamlItem();
					item.ReadYaml(reader);

					return new YamlItemData(item, serializedItemId, FieldFormatters.ToArray(), ParentDataStore);
				}
			}
			catch (Exception exception)
			{
				throw new YamlFormatException("Error parsing YAML " + serializedItemId, exception);
			}
		}
        public virtual SyncUser ReadSerializedUser(Stream dataStream, string serializedItemId)
        {
            Assert.ArgumentNotNull(dataStream, nameof(dataStream));

            try
            {
                using (var reader = new YamlReader(dataStream, 4096, true))
                {
                    var user = new SyncUser();

                    user.UserName = reader.ReadExpectedMap("Username");
                    user.Email = reader.ReadExpectedMap("Email");
                    user.Comment = reader.ReadExpectedMap("Comment");
                    user.CreationDate = DateTime.ParseExact(reader.ReadExpectedMap("Created"), "o", CultureInfo.InvariantCulture, DateTimeStyles.None);
                    user.IsApproved = bool.Parse(reader.ReadExpectedMap("IsApproved"));

                    var propertiesNode = reader.PeekMap();
                    if (propertiesNode.HasValue && propertiesNode.Value.Key.Equals("Properties"))
                    {
                        reader.ReadMap();
                        while (true)
                        {
                            var propertyName = reader.PeekMap();

                            if (propertyName == null || !propertyName.Value.Key.Equals("Key")) break;

                            reader.ReadMap();

                            var rawValue = reader.ReadExpectedMap("Value");
                            var valueTypeString = reader.ReadExpectedMap("ValueType");

                            var value = ReadPropertyValueObject(propertyName.Value.Value, valueTypeString, rawValue);

                            bool propertyIsCustom = bool.Parse(reader.ReadExpectedMap("IsCustom"));

                            user.ProfileProperties.Add(new SyncProfileProperty(propertyName.Value.Value, value, propertyIsCustom));
                        }
                    }

                    var rolesNode = reader.PeekMap();

                    if (rolesNode.HasValue && rolesNode.Value.Key.Equals("Roles"))
                    {
                        reader.ReadMap();

                        while (true)
                        {
                            var roleName = reader.ReadMap();

                            if (string.IsNullOrWhiteSpace(roleName?.Value)) break;

                            user.Roles.Add(roleName.Value.Value);
                        }
                    }

                    return user;
                }
            }
            catch (Exception exception)
            {
                throw new YamlFormatException("Error parsing YAML " + serializedItemId, exception);
            }
        }