Ejemplo n.º 1
0
        public static bool Set(this Path path, IObject allorsObject, IAccessControlListFactory aclFactory, object value)
        {
            var acl = aclFactory.Create(allorsObject);

            if (path.ExistNext)
            {
                if (acl.CanRead(path.PropertyType))
                {
                    var property = path.PropertyType.Get(allorsObject.Strategy) as IObject;
                    if (property != null)
                    {
                        path.Next.Set(property, aclFactory, value);
                        return(true);
                    }
                }

                return(false);
            }

            var roleType = path.PropertyType as RoleType;

            if (roleType != null)
            {
                if (acl.CanWrite(roleType))
                {
                    roleType.Set(allorsObject.Strategy, value);
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        public static void Ensure(this Path path, IObject allorsObject, IAccessControlListFactory aclFactory)
        {
            var acl = aclFactory.Create(allorsObject);

            var roleType = path.PropertyType as RoleType;

            if (roleType != null)
            {
                if (roleType.IsMany)
                {
                    throw new NotSupportedException("RoleType with muliplicity many");
                }

                if (roleType.ObjectType.IsComposite)
                {
                    if (acl.CanRead(roleType))
                    {
                        var role = roleType.Get(allorsObject.Strategy);
                        if (role == null)
                        {
                            if (acl.CanWrite(roleType))
                            {
                                role = allorsObject.Strategy.Session.Create((Class)roleType.ObjectType);
                                roleType.Set(allorsObject.Strategy, role);
                            }
                        }

                        if (path.ExistNext)
                        {
                            var next = role as IObject;
                            if (next != null)
                            {
                                path.Next.Ensure(next, aclFactory);
                            }
                        }
                    }
                }
            }
            else
            {
                var associationType = (AssociationType)path.PropertyType;
                if (associationType.IsMany)
                {
                    throw new NotSupportedException("AssociationType with muliplicity many");
                }

                if (acl.CanRead(associationType))
                {
                    var association = associationType.Get(allorsObject.Strategy) as IObject;
                    if (association != null)
                    {
                        if (path.ExistNext)
                        {
                            path.Next.Ensure(association, aclFactory);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static void Ensure(this Path path, IObject allorsObject, IAccessControlListFactory aclFactory)
        {
            var acl = aclFactory.Create(allorsObject);

            var roleType = path.PropertyType as RoleType;
            if (roleType != null)
            {
                if (roleType.IsMany)
                {
                    throw new NotSupportedException("RoleType with muliplicity many");
                }

                if (roleType.ObjectType.IsComposite)
                {
                    if (acl.CanRead(roleType))
                    {
                        var role = roleType.Get(allorsObject.Strategy);
                        if (role == null)
                        {
                            if (acl.CanWrite(roleType))
                            {
                                role = allorsObject.Strategy.Session.Create((Class)roleType.ObjectType);
                                roleType.Set(allorsObject.Strategy, role);
                            }
                        }

                        if (path.ExistNext)
                        {
                            var next = role as IObject;
                            if (next != null)
                            {
                                path.Next.Ensure(next, aclFactory);
                            }
                        }
                    }
                }
            }
            else
            {
                var associationType = (AssociationType)path.PropertyType;
                if (associationType.IsMany)
                {
                    throw new NotSupportedException("AssociationType with muliplicity many");
                }

                if (acl.CanRead(associationType))
                {
                    var association = associationType.Get(allorsObject.Strategy) as IObject;
                    if (association != null)
                    {
                        if (path.ExistNext)
                        {
                            path.Next.Ensure(association, aclFactory);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public string Write(Extent extent, CultureInfo cultureInfo, IAccessControlListFactory aclFactory)
        {
            var actualRecordSeparator = this.RecordSeparator ?? Environment.NewLine;
            var actualFieldSeparator  = this.FieldSeparator ?? cultureInfo.TextInfo.ListSeparator;

            var stringBuilder = new StringBuilder();

            for (var i = 0; i < this.Columns.Count; i++)
            {
                var column = this.Columns[i];
                stringBuilder.Append("\"");
                stringBuilder.Append(column.Header);
                stringBuilder.Append("\"");

                if (i < this.Columns.Count - 1)
                {
                    stringBuilder.Append(actualFieldSeparator);
                }
            }

            stringBuilder.Append(Environment.NewLine);

            for (var objectCounter = 0; objectCounter < extent.Count; objectCounter++)
            {
                var obj = extent[objectCounter];

                for (var columnCounter = 0; columnCounter < this.Columns.Count; columnCounter++)
                {
                    var column = this.Columns[columnCounter];
                    column.Write(this, cultureInfo, stringBuilder, obj, aclFactory);

                    if (columnCounter < this.Columns.Count - 1)
                    {
                        stringBuilder.Append(actualFieldSeparator);
                    }
                }

                if (objectCounter < extent.Count - 1)
                {
                    stringBuilder.Append(actualRecordSeparator);
                }
            }

            return(stringBuilder.ToString());
        }
Ejemplo n.º 5
0
        public string Write(Extent extent, CultureInfo cultureInfo, IAccessControlListFactory aclFactory)
        {
            var actualRecordSeparator = this.RecordSeparator ?? Environment.NewLine;
            var actualFieldSeparator = this.FieldSeparator ?? cultureInfo.TextInfo.ListSeparator;

            var stringBuilder = new StringBuilder();
            for (var i = 0; i < this.Columns.Count; i++)
            {
                var column = this.Columns[i];
                stringBuilder.Append("\"");
                stringBuilder.Append(column.Header);
                stringBuilder.Append("\"");

                if (i < this.Columns.Count - 1)
                {
                    stringBuilder.Append(actualFieldSeparator);
                }
            }

            stringBuilder.Append(Environment.NewLine);

            for (var objectCounter = 0; objectCounter < extent.Count; objectCounter++)
            {
                var obj = extent[objectCounter];

                for (var columnCounter = 0; columnCounter < this.Columns.Count; columnCounter++)
                {
                    var column = this.Columns[columnCounter];
                    column.Write(this, cultureInfo, stringBuilder, obj, aclFactory);

                    if (columnCounter < this.Columns.Count - 1)
                    {
                        stringBuilder.Append(actualFieldSeparator);
                    }
                }

                if (objectCounter < extent.Count - 1)
                {
                    stringBuilder.Append(actualRecordSeparator);
                }
            }

            return stringBuilder.ToString();
        }
Ejemplo n.º 6
0
        public override void Write(CsvExport file, CultureInfo cultureInfo, StringBuilder stringBuilder, IObject obj, IAccessControlListFactory aclFactory)
        {
            var value = this.Path.Get(obj, aclFactory) ?? this.EmptyValue;

            if (value != null)
            {
                var actualFormatProvider = this.FormatProvider ?? cultureInfo;

                var set = value as ISet<object>;
                if (set != null)
                {
                    stringBuilder.Append("\"");

                    var actualSubfieldSeparator = this.SubfieldSeparator ?? file.SubfieldSeparator ?? cultureInfo.TextInfo.ListSeparator;

                    var first = true;
                    foreach (var item in set)
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            stringBuilder.Append(actualSubfieldSeparator);
                        }

                        var escapedStringValue = this.GetEscapedStringValue(actualFormatProvider, item);
                        stringBuilder.Append(escapedStringValue);
                    }

                    stringBuilder.Append("\"");
                }
                else
                {
                    stringBuilder.Append("\"");

                    var escapedStringValue = this.GetEscapedStringValue(actualFormatProvider, value);
                    stringBuilder.Append(escapedStringValue);

                    stringBuilder.Append("\"");
                }
            }
        }
Ejemplo n.º 7
0
        public static object Get(this Path path, IObject allorsObject, IAccessControlListFactory aclFactory)
        {
            var acl = aclFactory.Create(allorsObject);

            if (acl.CanRead(path.PropertyType))
            {
                if (path.ExistNext)
                {
                    var currentValue = path.PropertyType.Get(allorsObject.Strategy);

                    if (currentValue != null)
                    {
                        if (currentValue is IObject)
                        {
                            return(path.Next.Get((IObject)currentValue, aclFactory));
                        }

                        var results = new HashSet <object>();
                        foreach (var item in (IEnumerable)currentValue)
                        {
                            var nextValueResult = path.Next.Get((IObject)item, aclFactory);
                            if (nextValueResult is HashSet <object> )
                            {
                                results.UnionWith((HashSet <object>)nextValueResult);
                            }
                            else
                            {
                                results.Add(nextValueResult);
                            }
                        }

                        return(results);
                    }
                }

                if (path.ExistPropertyType)
                {
                    return(path.PropertyType.Get(allorsObject.Strategy));
                }
            }

            return(null);
        }
 public abstract void Write(CsvExport file, CultureInfo cultureInfo, StringBuilder stringBuilder, IObject obj, IAccessControlListFactory aclFactory);
Ejemplo n.º 9
0
        public static object Get(this Path path, IObject allorsObject, IAccessControlListFactory aclFactory)
        {
            var acl = aclFactory.Create(allorsObject);
            if (acl.CanRead(path.PropertyType))
            {
                if (path.ExistNext)
                {
                    var currentValue = path.PropertyType.Get(allorsObject.Strategy);

                    if (currentValue != null)
                    {
                        if (currentValue is IObject)
                        {
                            return path.Next.Get((IObject)currentValue, aclFactory);
                        }

                        var results = new HashSet<object>();
                        foreach (var item in (IEnumerable)currentValue)
                        {
                            var nextValueResult = path.Next.Get((IObject)item, aclFactory);
                            if (nextValueResult is HashSet<object>)
                            {
                                results.UnionWith((HashSet<object>)nextValueResult);
                            }
                            else
                            {
                                results.Add(nextValueResult);
                            }
                        }

                        return results;
                    }
                }

                if (path.ExistPropertyType)
                {
                    return path.PropertyType.Get(allorsObject.Strategy);
                }
            }

            return null;
        }
Ejemplo n.º 10
0
        public static bool Set(this Path path, IObject allorsObject, IAccessControlListFactory aclFactory, object value)
        {
            var acl = aclFactory.Create(allorsObject);
            if (path.ExistNext)
            {
                if (acl.CanRead(path.PropertyType))
                {
                    var property = path.PropertyType.Get(allorsObject.Strategy) as IObject;
                    if (property != null)
                    {
                        path.Next.Set(property, aclFactory, value);
                        return true;
                    }
                }

                return false;
            }

            var roleType = path.PropertyType as RoleType;
            if (roleType != null)
            {
                if (acl.CanWrite(roleType))
                {
                    roleType.Set(allorsObject.Strategy, value);
                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 11
0
 public static object Get(this Fetch fetch, IObject allorsObject, IAccessControlListFactory aclFactory)
 {
     return(fetch.Step == null ? allorsObject : fetch.Step.Get(allorsObject, aclFactory));
 }
Ejemplo n.º 12
0
 public string Write(Extent extent, Domain.Locale locale, IAccessControlListFactory aclFactory)
 {
     return(this.Write(extent, new CultureInfo(locale.Name), aclFactory));
 }
Ejemplo n.º 13
0
 public abstract void Write(CsvExport file, CultureInfo cultureInfo, StringBuilder stringBuilder, IObject obj, IAccessControlListFactory aclFactory);
Ejemplo n.º 14
0
        public override void Write(CsvExport file, CultureInfo cultureInfo, StringBuilder stringBuilder, IObject obj, IAccessControlListFactory aclFactory)
        {
            var value = this.ObjectFunction != null?this.ObjectFunction((T)obj, aclFactory) : this.ObjectAndCultureInfoFunction((T)obj, aclFactory, cultureInfo);

            if (this.AutoEscape)
            {
                value = CsvExport.Escape(value);
            }

            stringBuilder.Append(value);
        }
Ejemplo n.º 15
0
 public static void Ensure(this Fetch fetch, IObject allorsObject, IAccessControlListFactory aclFactory)
 {
     fetch.Step.Ensure(allorsObject, aclFactory);
 }
Ejemplo n.º 16
0
 public static bool Set(this Fetch fetch, IObject allorsObject, IAccessControlListFactory aclFactory, object value)
 {
     return(fetch.Step != null && fetch.Step.Set(allorsObject, aclFactory, value));
 }
Ejemplo n.º 17
0
 public string Write(Extent extent, Domain.Locale locale, IAccessControlListFactory aclFactory)
 {
     return this.Write(extent, new CultureInfo(locale.Name), aclFactory);
 }
Ejemplo n.º 18
0
        public override void Write(CsvExport file, CultureInfo cultureInfo, StringBuilder stringBuilder, IObject obj, IAccessControlListFactory aclFactory)
        {
            var value = this.Path.Get(obj, aclFactory) ?? this.EmptyValue;

            if (value != null)
            {
                var actualFormatProvider = this.FormatProvider ?? cultureInfo;

                var set = value as ISet <object>;
                if (set != null)
                {
                    stringBuilder.Append("\"");

                    var actualSubfieldSeparator = this.SubfieldSeparator ?? file.SubfieldSeparator ?? cultureInfo.TextInfo.ListSeparator;

                    var first = true;
                    foreach (var item in set)
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            stringBuilder.Append(actualSubfieldSeparator);
                        }

                        var escapedStringValue = this.GetEscapedStringValue(actualFormatProvider, item);
                        stringBuilder.Append(escapedStringValue);
                    }

                    stringBuilder.Append("\"");
                }
                else
                {
                    stringBuilder.Append("\"");

                    var escapedStringValue = this.GetEscapedStringValue(actualFormatProvider, value);
                    stringBuilder.Append(escapedStringValue);

                    stringBuilder.Append("\"");
                }
            }
        }