Exemple #1
0
 public static IEnumerable <Indexer> ForCollection(OdcmEntityClass odcmClass)
 {
     return(new Indexer[]
     {
         new CollectionGetByIdIndexer(odcmClass)
     });
 }
Exemple #2
0
 public static CollectionGetByIdIndexer ForCollectionClass(OdcmEntityClass odcmClass, OdcmProjection projection)
 {
     return(new CollectionGetByIdIndexer(odcmClass, projection)
     {
         DefiningInterface = NamesService.GetCollectionInterfaceName(odcmClass, projection)
     });
 }
Exemple #3
0
 public static IEnumerable <Class> ForUpcastMethods(OdcmEntityClass odcmClass)
 {
     return(new[]
     {
         Class.ForFetcherUpcastMethods(odcmClass)
     });
 }
Exemple #4
0
 public static IEnumerable <Attribute> ForConcrete(OdcmEntityClass odcmClass)
 {
     return(new[]
     {
         Attribute.ForMicrosoftOdataClientKey(odcmClass)
     });
 }
Exemple #5
0
 public static IEnumerable <IndexerSignature> ForCollectionInterface(OdcmEntityClass odcmClass, OdcmProjection projection)
 {
     return(new IndexerSignature[]
     {
         new CollectionGetByIdIndexer(odcmClass, projection)
     });
 }
Exemple #6
0
        public static OdcmEntityClass OdcmEntityClass(OdcmNamespace odcmNamespace, string name, Action <OdcmEntityClass> config = null)
        {
            var retVal = new OdcmEntityClass(name, odcmNamespace);

            EntityOrMediaOdcmClass(odcmNamespace, config, retVal);

            return(retVal);
        }
Exemple #7
0
 public static Feature ForUpcastMethods(OdcmEntityClass odcmClass)
 {
     return(new Feature
     {
         Classes = global::Vipr.Writer.CSharp.Lite.Classes.ForUpcastMethods(odcmClass),
         Interfaces = global::Vipr.Writer.CSharp.Lite.Interfaces.ForUpcastMethods(odcmClass)
     });
 }
Exemple #8
0
 public static Interface ForFetcherUpcastMethods(OdcmEntityClass odcmClass)
 {
     return(new Interface
     {
         Identifier = NamesService.GetFetcherInterfaceName(odcmClass),
         Methods = global::Vipr.Writer.CSharp.Methods.ForFetcherInterfaceUpcasts(odcmClass),
     });
 }
Exemple #9
0
 public static Feature ForOdcmClassEntity(OdcmEntityClass odcmClass)
 {
     return(new Feature
     {
         Classes = global::Vipr.Writer.CSharp.Classes.ForOdcmClassEntity(odcmClass),
         Interfaces = global::Vipr.Writer.CSharp.Interfaces.ForOdcmClassEntity(odcmClass),
     });
 }
Exemple #10
0
 public static Attribute ForMicrosoftOdataClientKey(OdcmEntityClass odcmClass)
 {
     return(new Attribute
     {
         Type = new Type(new Identifier("global::Microsoft.OData.Client", "Key")),
         Parameters = odcmClass.Key.ToDictionary <OdcmProperty, string, string>(p => p.Name, p => null)
     });
 }
Exemple #11
0
 internal static IEnumerable <Interface> ForOdcmClassEntity(OdcmEntityClass odcmClass)
 {
     return(new[]
     {
         Interface.ForConcrete(odcmClass),
         Interface.ForFetcher(odcmClass),
         Interface.ForCollection(odcmClass),
     });
 }
Exemple #12
0
 public static Class ForFetcherUpcastMethods(OdcmEntityClass odcmClass)
 {
     return(new Class
     {
         AccessModifier = "internal ",
         Identifier = NamesService.GetFetcherTypeName(odcmClass),
         Methods = global::Vipr.Writer.CSharp.Lite.Methods.ForFetcherUpcasts(odcmClass),
     });
 }
Exemple #13
0
 public static IEnumerable <Class> ForOdcmClassEntity(OdcmEntityClass odcmClass)
 {
     return(new[]
     {
         Class.ForConcrete(odcmClass),
         Class.ForFetcher(odcmClass),
         Class.ForCollection(odcmClass),
     });
 }
Exemple #14
0
 public static Class ForConcreteIFetcherUpcastMethods(OdcmEntityClass odcmClass)
 {
     return(new Class
     {
         AccessModifier = "public ",
         Identifier = NamesService.GetConcreteTypeName(odcmClass),
         Methods = global::Vipr.Writer.CSharp.Methods.ForConcreteUpcasts(odcmClass),
     });
 }
Exemple #15
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");

            var identifier = NamesService.GetFetcherInterfaceName(Class);

            FetcherInterface = Proxy.GetInterface(Class.Namespace, identifier.Name);

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

            identifier          = NamesService.GetCollectionInterfaceName(Class);
            CollectionInterface = Proxy.GetInterface(Class.Namespace, identifier.Name);

            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
            };
        }
Exemple #16
0
        public CollectionGetByIdIndexer(OdcmEntityClass odcmClass, OdcmProjection projection)
        {
            ParameterToPropertyMap = odcmClass.Key.ToDictionary(Parameter.FromProperty, p => p);

            Parameters = global::Vipr.Writer.CSharp.Lite.Parameters.GetKeyParameters(odcmClass);
            ReturnType = new Type(NamesService.GetFetcherInterfaceName(odcmClass, projection));
            OdcmClass  = odcmClass;

            IsSettable = false;
            IsGettable = true;
        }
        private static EntityArtifacts GetEntityArtifactsFromNewNamespace(OdcmEntityClass @class, OdcmNamespace newNamespace,
                                                                          Assembly proxy, OdcmNamespace oldNamespace)
        {
            @class.Namespace = newNamespace;

            var entityArtifacts = @class.GetArtifactsFrom(proxy);

            @class.Namespace = oldNamespace;

            return(entityArtifacts);
        }
Exemple #18
0
        public static IEnumerable <Indexer> ForCollection(OdcmEntityClass odcmClass)
        {
            var retVal = new List <Indexer>();

            foreach (var projection in odcmClass.DistinctProjections())
            {
                retVal.Add(CollectionGetByIdIndexer.ForCollectionClass(odcmClass, projection));
            }

            return(retVal);
        }
Exemple #19
0
 public static Interface ForCollection(OdcmEntityClass odcmClass)
 {
     return(new Interface
     {
         Attributes = global::Vipr.Writer.CSharp.Attributes.ForCollectionInterface,
         Identifier = NamesService.GetCollectionInterfaceName(odcmClass),
         Namespace = NamesService.GetNamespaceName(odcmClass.Namespace),
         Methods = global::Vipr.Writer.CSharp.Methods.ForCollectionInterface(odcmClass),
         Indexers = IndexerSignature.ForCollectionInterface(odcmClass),
         Interfaces = new[] { new Type(NamesService.GetExtensionTypeName("IReadOnlyQueryableSetBase"), new Type(NamesService.GetConcreteInterfaceName(odcmClass))) }
     });
 }
Exemple #20
0
 public static Feature ForCountableCollection(OdcmEntityClass odcmClass)
 {
     return(new Feature
     {
         Classes = new[]
         {
             Class.ForCountableCollection(odcmClass)
         },
         Interfaces = new[]
         {
             Interface.ForCountableCollection(odcmClass)
         }
     });
 }
Exemple #21
0
 public static Class ForCollection(OdcmEntityClass odcmClass)
 {
     return(new Class
     {
         AccessModifier = "internal ",
         BaseClass = new Type(NamesService.GetExtensionTypeName("QueryableSet"),
                              new Type(NamesService.GetConcreteInterfaceName(odcmClass))),
         Constructors = global::Vipr.Writer.CSharp.Lite.Constructors.ForCollection(odcmClass),
         Interfaces = global::Vipr.Writer.CSharp.Lite.ImplementedInterfaces.ForCollectionClass(odcmClass),
         Identifier = NamesService.GetCollectionTypeName(odcmClass),
         Methods = global::Vipr.Writer.CSharp.Lite.Methods.ForCollectionClass(odcmClass),
         Indexers = global::Vipr.Writer.CSharp.Lite.Indexers.ForCollection(odcmClass)
     });
 }
Exemple #22
0
        public static EntityArtifacts GetArtifactsFrom(this OdcmEntityClass Class, Assembly Proxy)
        {
            var retVal = new EntityArtifacts
            {
                Class               = Class,
                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")
            };

            return(retVal);
        }
Exemple #23
0
        private static IEnumerable <Feature> ForOdcmClassEntity(OdcmEntityClass odcmClass)
        {
            var retVal = new List <Feature>
            {
                Feature.ForOdcmClassEntity(odcmClass),
                Feature.ForCountableCollection(odcmClass),
            };

            if (!ConfigurationService.Settings.OmitUpcastMethods && odcmClass.Base == null)
            {
                retVal.Add(Feature.ForUpcastMethods(odcmClass));
            }

            return(retVal);
        }
Exemple #24
0
        private static string GetKeyNode(OdcmEntityClass odcmClass)
        {
            if (!odcmClass.Key.Any())
            {
                return(string.Empty);
            }

            var sb = new StringBuilder();

            sb.Append("<Key>");
            sb.Append(odcmClass.Key.Select(ToPropertyRef).Aggregate((c, n) => c + "\n" + n));
            sb.Append("</Key>");

            return(sb.ToString());
        }
Exemple #25
0
 public static Class ForConcrete(OdcmEntityClass odcmClass)
 {
     return(new Class
     {
         AbstractModifier = odcmClass.IsAbstract ? "abstract " : string.Empty,
         AccessModifier = "public ",
         Attributes = global::Vipr.Writer.CSharp.Lite.Attributes.ForConcrete(odcmClass),
         BaseClass =
             new Type(odcmClass.Base == null
                 ? NamesService.GetExtensionTypeName("EntityBase")
                 : NamesService.GetConcreteTypeName(odcmClass.Base)),
         Constructors = global::Vipr.Writer.CSharp.Lite.Constructors.ForConcrete(odcmClass),
         Description = odcmClass.Description,
         Fields = global::Vipr.Writer.CSharp.Lite.Fields.ForConcrete(odcmClass),
         Identifier = NamesService.GetConcreteTypeName(odcmClass),
         Interfaces = global::Vipr.Writer.CSharp.Lite.ImplementedInterfaces.ForConcrete(odcmClass),
         Properties = global::Vipr.Writer.CSharp.Lite.Properties.ForConcrete(odcmClass)
     });
 }
Exemple #26
0
        public static JObject GetSampleJObject(this OdcmEntityClass entityClass, IEnumerable <Tuple <string, object> > keyArguments, bool dontSalt = false)
        {
            var retVal = new JObject();

            foreach (var keyArgument in keyArguments)
            {
                retVal.Add(keyArgument.Item1, new JValue(keyArgument.Item2));
            }

            foreach (var collectionProperty in entityClass.Properties.Where(p => p.IsCollection))
            {
                retVal.Add(collectionProperty.Name, new JArray());
            }

            if (!dontSalt)
            {
                retVal.Add(Any.Word(), new JValue(Any.Int()));
            }

            return(retVal);
        }
Exemple #27
0
        public static IEnumerable <Interface> ForCollection(OdcmEntityClass odcmClass)
        {
            var interfaces = new List <Interface>();

            foreach (var projection in odcmClass.DistinctProjections())
            {
                var @interface = new Interface
                {
                    Attributes = global::Vipr.Writer.CSharp.Lite.Attributes.ForCollectionInterface,
                    Identifier = NamesService.GetCollectionInterfaceName(odcmClass, projection),
                    Namespace  = NamesService.GetNamespaceName(odcmClass.Namespace),
                    Methods    = global::Vipr.Writer.CSharp.Lite.Methods.ForCollectionInterface(odcmClass, projection),
                    Indexers   = IndexerSignature.ForCollectionInterface(odcmClass, projection),
                    Interfaces = new[] { new Type(NamesService.GetExtensionTypeName("IReadOnlyQueryableSetBase"), new Type(NamesService.GetConcreteInterfaceName(odcmClass))) }
                };

                interfaces.Add(@interface);
            }

            return(interfaces);
        }
Exemple #28
0
        public static string ToEdmx(this OdcmEntityClass odcmClass)
        {
            if (odcmClass is OdcmMediaClass)
            {
                return(((OdcmMediaClass)odcmClass).ToEdmx());
            }

            var sb = new StringBuilder();

            var tagName = GetTagName(odcmClass);

            sb.AppendFormat("<{0} Name=\"{1}\">", tagName, odcmClass.Name);
            sb.Append(GetKeyNode(odcmClass));
            if (odcmClass.Properties.Any())
            {
                sb.Append(odcmClass.Properties.Select(ToEdmx).Aggregate((c, n) => c + "\n" + n));
            }
            sb.AppendFormat("</{0}>", tagName);

            return(sb.ToString());
        }
Exemple #29
0
 internal static IEnumerable <Interface> ForUpcastMethods(OdcmEntityClass odcmClass)
 {
     return(new[] { Interface.ForFetcherUpcastMethods(odcmClass) });
 }
Exemple #30
0
 internal static IEnumerable <Interface> ForOdcmClassEntity(OdcmEntityClass odcmClass)
 {
     return(Interface.ForConcrete(odcmClass)
            .Concat(Interface.ForFetcher(odcmClass))
            .Concat(Interface.ForCollection(odcmClass)));
 }