Esempio n. 1
0
 public static IEnumerable<Field> ForEntityContainer(OdcmClass odcmContainer)
 {
     return new[]
     {
         new Field("_path", new Type(new Identifier("System", "String")), "\"\"", true),
     }.Concat(GetFetcherFields(odcmContainer));
 }
Esempio n. 2
0
 public static IEnumerable<Field> ForConcrete(OdcmClass odcmClass)
 {
     return GetNavigationFields(odcmClass)
         .Concat(GetFetcherFields(odcmClass))
         .Concat(GetStructuralFields(odcmClass))
         .Concat(GetCollectionFields(odcmClass));
 }
Esempio n. 3
0
 public static FetcherExpandMethod ForConcrete(OdcmClass odcmClass)
 {
     return new FetcherExpandMethod(odcmClass)
     {
         DefiningInterface = NamesService.GetFetcherInterfaceName(odcmClass)
     };
 }
        public Given_an_OdcmClass_Entity_Derived()
        {
            base.Init(m =>
            {
                var @namespace = m.Namespaces[0];
                var derivedClass = @namespace.Classes.First();
                _baseClass = Any.OdcmEntityClass(@namespace);
                @namespace.Types.Add(_baseClass);
                derivedClass.Base = _baseClass;
                if (!_baseClass.Derived.Contains(derivedClass))
                {
                    _baseClass.Derived.Add(derivedClass);
                }
            });

            _baseConcreteType = Proxy.GetClass(_baseClass.Namespace, _baseClass.Name);

            _baseConcreteInterface = Proxy.GetInterface(_baseClass.Namespace, "I" + _baseClass.Name);

            _baseFetcherType = Proxy.GetClass(_baseClass.Namespace, _baseClass.Name + "Fetcher");

            _baseFetcherInterface = Proxy.GetInterface(_baseClass.Namespace, "I" + _baseClass.Name + "Fetcher");

            _baseCollectionType = Proxy.GetClass(_baseClass.Namespace, _baseClass.Name + "Collection");

            _baseCollectionInterface = Proxy.GetInterface(_baseClass.Namespace, "I" + _baseClass.Name + "Collection");

            _toDerivedMethodName = "To" + ConcreteType.Name;
        }
Esempio n. 5
0
 public static Feature ForOdcmClassComplex(OdcmClass odcmClass)
 {
     return new Feature
     {
         Classes = global::Vipr.Writer.CSharp.Classes.ForOdcmClassComplex(odcmClass),
     };
 }
Esempio n. 6
0
 public EnsureQueryMethod(OdcmClass odcmClass)
 {
     Visibility = Visibility.Private;
     Name = "EnsureQuery";
     FetchedType = new Type(NamesService.GetConcreteTypeName(odcmClass));
     FetchedTypeInterface = new Type(NamesService.GetConcreteInterfaceName(odcmClass));
     ReturnType = new Type(NamesService.GetExtensionTypeName("IReadOnlyQueryableSet"), new Type(NamesService.GetConcreteInterfaceName(odcmClass)));
 }
Esempio n. 7
0
 public static Interface ForCountableCollection(OdcmClass odcmClass)
 {
     return new Interface
     {
         Identifier = NamesService.GetCollectionInterfaceName(odcmClass),
         Methods = global::Vipr.Writer.CSharp.Methods.ForCountableCollectionInterface(odcmClass)
     };
 }
Esempio n. 8
0
 public static IEnumerable<Property> ForConcrete(OdcmClass odcmClass)
 {
     return ForConcreteInterface(odcmClass)
         .Concat(GetObsoletedStructuralProperties(odcmClass))
         .Concat(GetObsoletedNavigationProperties(odcmClass))
         .Concat(GetImplicitPropertiesForConcrete(odcmClass))
         .Concat(GetIFetcherPropertiesForConcrete(odcmClass));
 }
 public CollectionExecuteAsyncMethod(OdcmClass odcmClass)
 {
     Name = "ExecuteAsync";
     Parameters = Parameter.Empty;
     ReturnType = new Type(new Identifier("global::System.Threading.Tasks", "Task"),
         new Type(NamesService.GetExtensionTypeName("IPagedCollection"),
             new Type(NamesService.GetConcreteInterfaceName(odcmClass))));
 }
Esempio n. 10
0
 public static IEnumerable<Property> ForEntityContainer(OdcmClass odcmContainer)
 {
     return Properties.ForEntityContainerInterface(odcmContainer)
         .Concat(new Property[]
         {
             new AutoProperty("Context", new Type(NamesService.GetExtensionTypeName("DataServiceContextWrapper")),
                 privateSet: true)
         });
 }
Esempio n. 11
0
 public FetcherExecuteAsyncMethod(OdcmClass odcmClass)
 {
     IsAsync = true;
     IsOverriding = odcmClass.Base is OdcmClass && !((OdcmClass)odcmClass.Base).IsAbstract;
     Name = "ExecuteAsync";
     Parameters = Parameter.Empty;
     ReturnType = new Type(new Identifier("global::System.Threading.Tasks", "Task"),
          new Type(NamesService.GetConcreteInterfaceName(odcmClass)));
 }
Esempio n. 12
0
 public ContainerTypeFromNameMethod(OdcmClass odcmContainer)
 {
     ClientNamespace = NamesService.GetNamespaceName(odcmContainer.Namespace);
     Visibility = Visibility.Private;
     Name = "ResolveTypeFromName";
     Parameters = new[] { new Parameter(new Type(new Identifier("System", "String")), "typeName"), };
     ReturnType = new Type(new Identifier("global::System", "Type"));
     ServerNamespace = odcmContainer.Namespace.Name;
 }
Esempio n. 13
0
        public static IEnumerable<Type> ForConcrete(OdcmClass odcmClass)
        {
            var retVal = new List<Type>
            {
                new Type(NamesService.GetConcreteInterfaceName(odcmClass)),
                new Type(NamesService.GetFetcherInterfaceName(odcmClass))
            };

            return retVal;
        }
Esempio n. 14
0
        public static IEnumerable<Method> ForFetcher(OdcmClass odcmClass)
        {
            var retVal = Methods.ForFetcherInterface(odcmClass).ToList();

            if (!odcmClass.IsAbstract)
            {
                retVal.Add(new EnsureQueryMethod(odcmClass));
            }

            return retVal;
        }
Esempio n. 15
0
 public static Interface ForEntityContainer(OdcmClass odcmContainer)
 {
     return new Interface
     {
         Identifier = NamesService.GetEntityContainerInterfaceName(odcmContainer),
         Description = odcmContainer.Description,
         Interfaces = null,
         Methods = global::Vipr.Writer.CSharp.Methods.ForEntityContainerInterface(odcmContainer),
         Properties = global::Vipr.Writer.CSharp.Properties.ForEntityContainerInterface(odcmContainer),
         Namespace = NamesService.GetNamespaceName(odcmContainer.Namespace),
     };
 }
Esempio n. 16
0
 public static Interface ForFetcher(OdcmClass odcmClass)
 {
     return new Interface
     {
         Attributes = global::Vipr.Writer.CSharp.Attributes.ForFetcherInterface,
         Identifier = NamesService.GetFetcherInterfaceName(odcmClass),
         Interfaces = global::Vipr.Writer.CSharp.ImplementedInterfaces.ForFetcherInterface(odcmClass),
         Methods = global::Vipr.Writer.CSharp.Methods.ForFetcherInterface(odcmClass),
         Namespace = NamesService.GetNamespaceName(odcmClass.Namespace),
         Properties = global::Vipr.Writer.CSharp.Properties.ForFetcherInterface(odcmClass)
     };
 }
Esempio n. 17
0
        public AddAsyncMethod(OdcmClass odcmClass)
        {
            Name = "Add" + odcmClass.Name + "Async";

            Parameters = new[]
            {
                new Parameter(new Type(NamesService.GetConcreteInterfaceName(odcmClass)), "item"),
                new Parameter(new Type(NamesService.GetPrimitiveTypeName("Boolean")), "deferSaveChanges", "false")
            };

            ReturnType = new Type(Identifier.Task);
        }
Esempio n. 18
0
        public static IEnumerable<Type> ForFetcherInterface(OdcmClass odcmClass)
        {
            var retVal = new List<Type>();

            var baseClass = odcmClass.Base as OdcmClass;

            if (baseClass != null)
            {
                retVal.Add(new Type(NamesService.GetFetcherInterfaceName(baseClass)));
            }

            return retVal;
        }
Esempio n. 19
0
 public static Interface ForConcrete(OdcmClass odcmClass)
 {
     return new Interface
     {
         Attributes = global::Vipr.Writer.CSharp.Attributes.ForConcreteInterface,
         Identifier = NamesService.GetConcreteInterfaceName(odcmClass),
         Description = odcmClass.Description,
         Methods = global::Vipr.Writer.CSharp.Methods.ForConcreteInterface(odcmClass),
         Namespace = NamesService.GetNamespaceName(odcmClass.Namespace),
         Properties = global::Vipr.Writer.CSharp.Properties.ForConcreteInterface(odcmClass),
         Interfaces = global::Vipr.Writer.CSharp.ImplementedInterfaces.ForConcreteInterface(odcmClass)
     };
 }
Esempio n. 20
0
        public static IEnumerable<Method> ForFetcherInterface(OdcmClass odcmClass)
        {
            var retVal = new List<Method>();

            retVal.AddRange(Methods.ForEntityType(odcmClass));

            if (!odcmClass.IsAbstract)
            {
                retVal.Add(new FetcherExecuteAsyncMethod(odcmClass));
                retVal.Add(FetcherExpandMethod.ForFetcher(odcmClass));
            }

            return retVal;
        }
Esempio n. 21
0
 private FetcherExpandMethod(OdcmClass odcmClass)
 {
     Visibility = Visibility.Public;
     Name = "Expand";
     GenericParameters = new[] { "TTarget" };
     Parameters = new[]
     {
         new Parameter(new Type(new Identifier("System.Linq.Expressions", "Expression"),
             new Type(new Identifier("System", "Func"), new Type(NamesService.GetConcreteInterfaceName(odcmClass)),
                 new Type(new Identifier(null, "TTarget")))), "navigationPropertyAccessor"),
     };
     ReturnType = new Type(NamesService.GetFetcherInterfaceName(odcmClass));
     OdcmClass = odcmClass;
 }
Esempio n. 22
0
        public static IEnumerable<Method> ForConcrete(OdcmClass odcmClass)
        {
            var retVal = Methods.ForConcreteInterface(odcmClass).ToList();

            retVal.Add(new EnsureQueryMethod(odcmClass));

            if (!odcmClass.IsAbstract)
            {
                retVal.Add(new ConcreteExecuteAsyncMethod(odcmClass));
                retVal.Add(FetcherExpandMethod.ForConcrete(odcmClass));
            }

            return retVal;
        }
Esempio n. 23
0
        public static IEnumerable<Type> ForConcreteInterface(OdcmClass odcmClass)
        {
            var retVal = new List<Type>();

            var baseClass = odcmClass.Base;

            var interfaceIdentifier = baseClass == null ?
                NamesService.GetExtensionTypeName("IEntityBase") :
                NamesService.GetConcreteInterfaceName(baseClass);

            retVal.Add(new Type(interfaceIdentifier));

            return retVal;
        }
Esempio n. 24
0
        public void Init(Action<OdcmModel> config = null, bool generateMocks = false)
        {
            Model = new OdcmModel(Any.ServiceMetadata());

            Namespace = Any.EmptyOdcmNamespace();

            Model.Namespaces.Add(Namespace);

            Class = Any.OdcmEntityClass(Namespace);

            Model.AddType(Class);

            OdcmContainer = Any.ServiceOdcmClass(Namespace);

            Model.AddType(OdcmContainer);

            if (config != null) config(Model);

            Model.ServiceMetadata["$metadata"] = Model.ToEdmx(true);

            Proxy = GetProxy(Model, ConfigurationProvider, generateMocks ? new[] { "DynamicProxyGenAssembly2" } : null);

            ConcreteType = Proxy.GetClass(Class.Namespace, Class.Name);

            ConcreteInterface = Proxy.GetInterface(Class.Namespace, "I" + Class.Name);

            FetcherType = Proxy.GetClass(Class.Namespace, Class.Name + "Fetcher");

            FetcherInterface = Proxy.GetInterface(Class.Namespace, "I" + Class.Name + "Fetcher");

            CollectionType = Proxy.GetClass(Class.Namespace, Class.Name + "Collection");

            CollectionInterface = Proxy.GetInterface(Class.Namespace, "I" + Class.Name + "Collection");

            EntityContainerType = Proxy.GetClass(Model.EntityContainer.Namespace, Model.EntityContainer.Name);

            EntityContainerInterface = Proxy.GetInterface(Model.EntityContainer.Namespace, "I" + Model.EntityContainer.Name);

            TargetEntity = new EntityArtifacts()
            {
                Class = Class,
                ConcreteType = ConcreteType,
                ConcreteInterface = ConcreteInterface,
                FetcherType = FetcherType,
                FetcherInterface = FetcherInterface,
                CollectionType = CollectionType,
                CollectionInterface = CollectionInterface
            };
        }
Esempio n. 25
0
        public Given_an_OdcmClass_Complex()
        {
            _model = new OdcmModel(Any.ServiceMetadata());

            _namespace = Any.EmptyOdcmNamespace();

            _model.Namespaces.Add(_namespace);

            _class = Any.OdcmComplexClass(e => e.Namespace = _namespace);

            _model.AddType(_class);

            _proxy = GetProxy(_model);

            _classType = _proxy.GetClass(_class.Namespace, _class.Name);
        }
Esempio n. 26
0
        public static IEnumerable<Method> ForCollectionInterface(OdcmClass odcmClass)
        {
            var odcmMediaClass = odcmClass as OdcmMediaClass;
            if (odcmMediaClass != null)
            {
                return ForMediaCollectionInterface(odcmMediaClass);
            }

            return Methods.GetMethodsBoundToCollection(odcmClass)
                .Concat(new Method[]
                {
                    new CollectionGetByIdMethod(odcmClass),
                    new CollectionExecuteAsyncMethod(odcmClass),
                    new AddAsyncMethod(odcmClass)
                });
        }
Esempio n. 27
0
        public static IEnumerable<Feature> ForOdcmClass(OdcmClass odcmClass)
        {
            switch (odcmClass.Kind)
            {
                case OdcmClassKind.Complex:
                    return Features.ForOdcmClassComplex((OdcmComplexClass)odcmClass);

                case OdcmClassKind.MediaEntity:
                case OdcmClassKind.Entity:
                    return Features.ForOdcmClassEntity((OdcmEntityClass)odcmClass);

                case OdcmClassKind.Service:
                    return Enumerable.Empty<Feature>();
            }

            throw new NotImplementedException(string.Format("OdcmClassKind {0} is not recognized", odcmClass.Kind));
        }
Esempio n. 28
0
 public static Class ForFetcher(OdcmClass odcmClass)
 {
     return new Class
     {
         AccessModifier = "internal ",
         BaseClass =
             new Type(odcmClass.Base == null
                 ? NamesService.GetExtensionTypeName("RestShallowObjectFetcher")
                 : NamesService.GetFetcherTypeName(odcmClass.Base)),
         Constructors = global::Vipr.Writer.CSharp.Constructors.ForFetcher(odcmClass),
         Fields = global::Vipr.Writer.CSharp.Fields.ForFetcher(odcmClass),
         Identifier = NamesService.GetFetcherTypeName(odcmClass),
         Interfaces = global::Vipr.Writer.CSharp.ImplementedInterfaces.ForFetcher(odcmClass),
         Methods = global::Vipr.Writer.CSharp.Methods.ForFetcher(odcmClass),
         Properties = global::Vipr.Writer.CSharp.Properties.ForFetcher(odcmClass),
     };
 }
Esempio n. 29
0
 public static Class ForComplex(OdcmClass odcmClass)
 {
     return new Class
     {
         AbstractModifier = odcmClass.IsAbstract ? "abstract " : string.Empty,
         AccessModifier = "public ",
         Constructors = global::Vipr.Writer.CSharp.Constructors.ForComplex(odcmClass),
         BaseClass =
             new Type(odcmClass.Base == null
                 ? NamesService.GetExtensionTypeName("ComplexTypeBase")
                 : NamesService.GetPublicTypeName(odcmClass.Base)),
         Description = odcmClass.Description,
         Fields = global::Vipr.Writer.CSharp.Fields.ForComplex(odcmClass),
         Identifier = NamesService.GetConcreteTypeName(odcmClass),
         Properties = global::Vipr.Writer.CSharp.Properties.ForComplex(odcmClass),
     };
 }
Esempio n. 30
0
        public AddAsyncMediaMethod(OdcmClass odcmClass)
        {
            Name = "Add" + odcmClass.Name + "Async";

            Parameters = new[]
            {
                new Parameter(new Type(NamesService.GetConcreteInterfaceName(odcmClass)), "item"),
                new Parameter(new Type(NamesService.GetPrimitiveTypeName("IStream")), "stream"),
                new Parameter(new Type(NamesService.GetPrimitiveTypeName("String")), "contentType"),
                new Parameter(new Type(NamesService.GetPrimitiveTypeName("Boolean")), "deferSaveChanges", "false"),
                new Parameter(new Type(NamesService.GetPrimitiveTypeName("Boolean")), "closeStream", "false")
            };

            ReturnType = new Type(Identifier.Task);

            Visibility = ConfigurationService.Settings.MediaEntityAddAsyncVisibility;
        }