Exemplo n.º 1
0
            private void WriteProperty(OdcmClass odcmClass, IEdmEntitySet entitySet)
            {
                var odcmProperty = new OdcmProperty(entitySet.Name)
                {
                    Type         = ResolveType(entitySet.ElementType.Name, entitySet.ElementType.Namespace),
                    IsCollection = true,
                    IsLink       = true,
                    Class        = odcmClass
                };

                odcmClass.Properties.Add(odcmProperty);
            }
Exemplo n.º 2
0
 public static Interface ForCollection(OdcmClass odcmClass)
 {
     return(new Interface
     {
         Attributes = new[] { Attribute.ForLowerCaseProperty() },
         Identifier = NamesService.GetCollectionInterfaceName(odcmClass),
         Namespace = odcmClass.Namespace,
         Methods = global::CSharpWriter.Methods.ForCollectionInterface(odcmClass),
         Indexers = IndexerSignature.ForCollectionInterface(odcmClass),
         Interfaces = new[] { new Type(NamesService.GetExtensionTypeName("IReadOnlyQueryableSetBase"), new Type(NamesService.GetConcreteInterfaceName(odcmClass))) }
     });
 }
Exemplo n.º 3
0
        private OdcmProperty FindProperty(OdcmClass odcmClass, IEdmStructuralProperty keyProperty)
        {
            foreach (OdcmProperty property in odcmClass.Properties)
            {
                if (property.Name.Equals(keyProperty.Name, StringComparison.OrdinalIgnoreCase))
                {
                    return(property);
                }
            }

            return(null);
        }
Exemplo n.º 4
0
        private OdcmField WriteField(OdcmClass odcmClass, IEdmProperty property)
        {
            OdcmField odcmField = new OdcmField(property.Name);

            odcmField.Class = odcmClass;
            odcmClass.Fields.Add(odcmField);

            odcmField.Type         = ResolveType(property.Type);
            odcmField.IsCollection = property.Type.IsCollection();

            return(odcmField);
        }
Exemplo n.º 5
0
 private FetcherUpdateMethod(OdcmClass odcmClass)
 {
     Visibility = Visibility.Public;
     Name       = "UpdateAsync";
     Parameters = new[]
     {
         new Parameter(new Type(NamesService.GetConcreteInterfaceName(odcmClass)), "item"),
         new Parameter(new Type(NamesService.GetPrimitiveTypeName("Boolean")), "deferSaveChanges", "false")
     };
     ReturnType = new Type(Identifier.Task);
     OdcmClass  = odcmClass;
 }
Exemplo n.º 6
0
 public static IEnumerable <Method> ForEntityContainer(OdcmClass odcmContainer)
 {
     return(Methods.ForEntityContainerInterface(odcmContainer)
            .Concat(Methods.ForContainerAddToCollection(odcmContainer))
            .Concat(new Method[]
     {
         new ContainerTypeFromNameMethod(odcmContainer),
         new ContainerNameFromTypeMethod(odcmContainer),
         new ContainerGetPathMethod(),
         new ContainerGetUrlMethod()
     }));
 }
Exemplo n.º 7
0
 public static IEnumerable <OdcmProperty> NavigationProperties(this OdcmClass odcmClass, bool includeBaseProperties = false)
 {
     if (includeBaseProperties && odcmClass.Base != null)
     {
         return(odcmClass.Base.NavigationProperties(includeBaseProperties)
                .Union(odcmClass.Properties.Where(prop => prop.IsNavigation())));
     }
     else
     {
         return(odcmClass.Properties.Where(prop => prop.IsNavigation()));
     }
 }
Exemplo n.º 8
0
        public CollectionAddAsyncMethod(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);
        }
Exemplo n.º 9
0
        private OdcmField FindField(OdcmClass odcmClass, IEdmStructuralProperty keyProperty)
        {
            foreach (OdcmField field in odcmClass.Fields)
            {
                if (field.Name.Equals("_" + keyProperty.Name, StringComparison.OrdinalIgnoreCase))
                {
                    return(field);
                }
            }

            return(null);
        }
Exemplo n.º 10
0
 public static Interface ForFetcher(OdcmClass odcmClass)
 {
     return(new Interface
     {
         Attributes = new[] { Attribute.ForLowerCaseProperty() },
         Identifier = NamesService.GetFetcherInterfaceName(odcmClass),
         Interfaces = global::CSharpWriter.Interfaces.ForFetcherInterface(odcmClass),
         Methods = global::CSharpWriter.Methods.ForFetcherInterface(odcmClass),
         Namespace = odcmClass.Namespace,
         Properties = global::CSharpWriter.Properties.ForFetcherInterface(odcmClass)
     });
 }
Exemplo n.º 11
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
            };
        }
Exemplo n.º 12
0
 private FetcherSaveChangesAsyncMethod(OdcmClass odcmClass)
 {
     Visibility   = Visibility.Public;
     IsOverriding = odcmClass.Base is OdcmClass && !((OdcmClass)odcmClass.Base).IsAbstract;
     Name         = "SaveChangesAsync";
     Parameters   = new[]
     {
         new Parameter(new Type(NamesService.GetPrimitiveTypeName("Boolean")), "deferSaveChanges", "false"),
         new Parameter(new Type(new Identifier("Microsoft.OData.Client", "SaveChangesOptions")), "saveChangesOption", "SaveChangesOptions.None")
     };
     ReturnType = new Type(Identifier.Task);
     OdcmClass  = odcmClass;
 }
Exemplo n.º 13
0
        public CollectionGetByIdIndexer(OdcmClass odcmClass)
        {
            var keyProperties = odcmClass.Key;

            ParameterToPropertyMap = keyProperties.ToDictionary(Parameter.FromProperty, p => p);

            Parameters = ParameterToPropertyMap.Keys;
            ReturnType = new Type(NamesService.GetFetcherInterfaceName(odcmClass));
            OdcmClass  = odcmClass;

            IsSettable = false;
            IsGettable = true;
        }
Exemplo n.º 14
0
 private FetcherDeleteLinkMethod(OdcmClass odcmClass)
 {
     Visibility   = Visibility.Public;
     IsOverriding = odcmClass.Base is OdcmClass && !((OdcmClass)odcmClass.Base).IsAbstract;
     Name         = "DeleteLinkAsync";
     Parameters   = new[]
     {
         new Parameter(new Type(new Identifier("System", "Object")), "source"),
         new Parameter(new Type(NamesService.GetPrimitiveTypeName("Boolean")), "deferSaveChanges", "false")
     };
     ReturnType = new Type(Identifier.Task);
     OdcmClass  = odcmClass;
 }
Exemplo n.º 15
0
            private void WriteProperty(OdcmClass odcmClass, IEdmSingleton singleton)
            {
                var odcmProperty = new OdcmProperty(singleton.Name)
                {
                    Class  = odcmClass,
                    Type   = ResolveType(singleton.EntityType().Name, singleton.EntityType().Namespace),
                    IsLink = true
                };

                AddVocabularyAnnotations(odcmProperty, singleton);

                odcmClass.Properties.Add(odcmProperty);
            }
Exemplo n.º 16
0
            private void WriteProperty(OdcmClass odcmClass, IEdmEntitySet entitySet)
            {
                var odcmProperty = new OdcmProperty(entitySet.Name)
                {
                    Class = odcmClass,
                    Type  = ResolveType(entitySet.EntityType().Name, entitySet.EntityType().Namespace,
                                        TypeKind.Entity),
                    IsCollection = true,
                    IsLink       = true
                };

                odcmClass.Properties.Add(odcmProperty);
            }
Exemplo n.º 17
0
 private FetcherSetMethod(OdcmClass odcmClass)
 {
     Visibility = Visibility.Public;
     Name       = "SetAsync";
     Parameters = new[]
     {
         new Parameter(new Type(new Identifier("System", "Object")), "source"),
         new Parameter(new Type(NamesService.GetConcreteInterfaceName(odcmClass)), "target"),
         new Parameter(new Type(NamesService.GetPrimitiveTypeName("Boolean")), "deferSaveChanges", "false")
     };
     ReturnType = new Type(Identifier.Task);
     OdcmClass  = odcmClass;
 }
Exemplo n.º 18
0
        private static OdcmClass ComplexOdcmType(OdcmNamespace odcmNamespace, Action <OdcmClass> config = null)
        {
            var retVal = new OdcmClass(Any.CSharpIdentifier(), odcmNamespace.Name, OdcmClassKind.Complex);

            retVal.Properties.AddRange(Any.Sequence(i => Any.PrimitiveOdcmProperty(p => p.Class = retVal)));

            if (config != null)
            {
                config(retVal);
            }

            return(retVal);
        }
Exemplo n.º 19
0
        private OdcmField WriteField(OdcmClass odcmClass, IEdmSingleton singleton)
        {
            OdcmField odcmField = new OdcmField("_" + singleton.Name);

            odcmField.Class = odcmClass;
            odcmClass.Fields.Add(odcmField);

            odcmField.Type = ResolveType(singleton.EntityType().Name, singleton.EntityType().Namespace, TypeKind.Entity);

            odcmField.IsLink = true;

            return(odcmField);
        }
Exemplo n.º 20
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)
     });
 }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
0
        public static IEnumerable <OdcmProperty> GetKeyProperties(this OdcmClass odcmClass)
        {
            var keyProperties = Enumerable.Empty <OdcmProperty>();

            var baseClass = odcmClass.Base as OdcmClass;

            if (baseClass != null)
            {
                keyProperties = baseClass.GetKeyProperties();
            }

            return(keyProperties
                   .Concat(odcmClass.Properties.Where(p => odcmClass.Key.Contains(p.Field))));
        }
Exemplo n.º 23
0
 public static bool TryFindProperty(this OdcmClass odcmClass, string propertyPath, out OdcmProperty odcmProperty)
 {
     while (odcmClass != null)
     {
         odcmProperty = odcmClass.Properties.SingleOrDefault(p => p.Name == propertyPath);
         if (odcmProperty != null)
         {
             return(true);
         }
         odcmClass = odcmClass.Base;
     }
     odcmProperty = null;
     return(false);
 }
Exemplo n.º 24
0
        public void When_proxied_then_the_proxy_class_has_a_Fetcher_interface()
        {
            _class = new OdcmClass(Any.CSharpIdentifier(), _namespace.Name, OdcmClassKind.Entity);

            var interfaceName = _namespace.Name + ".I" + _class.Name + "Fetcher";

            _model.AddType(_class);

            var proxy = GetProxy(_model);

            var classType = proxy.GetClass(_class.Namespace, _class.Name);

            classType.GetInterface(interfaceName).Should().NotBeNull();
        }
Exemplo n.º 25
0
        private OdcmField WriteField(OdcmClass odcmClass, IEdmEntitySet entitySet)
        {
            OdcmField odcmField = new OdcmField("_" + entitySet.Name);

            odcmField.Class = odcmClass;
            odcmClass.Fields.Add(odcmField);

            odcmField.Type = ResolveType(entitySet.EntityType().Name, entitySet.EntityType().Namespace, TypeKind.Entity);

            odcmField.IsCollection = true;
            odcmField.IsLink       = true;

            return(odcmField);
        }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
0
        public string GetInterfaceLine(OdcmClass e)
        {
            string baseEntity = e.Base == null ? "MSOrcBaseEntity"
                              : GetPrefix() + e.Base.Name.Substring(e.Base.Name.LastIndexOf(".") + 1);

            var s = new StringBuilder();

            s.AppendFormat("#import \"{0}.h\"", baseEntity);

            s.AppendLine().AppendLine().AppendLine(GetHeaderDoc(e.Name))
            .AppendFormat("@interface {0}{1} : {2}", GetPrefix(), e.Name, baseEntity);

            return(s.ToString());
        }
Exemplo n.º 28
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;
 }
Exemplo n.º 29
0
 public static Class ForCollection(OdcmClass odcmClass)
 {
     return(new Class
     {
         AccessModifier = "internal ",
         BaseClass = new Type(NamesService.GetExtensionTypeName("QueryableSet"),
                              new Type(NamesService.GetConcreteInterfaceName(odcmClass))),
         Constructors = global::CSharpWriter.Constructors.ForCollection(odcmClass),
         Interfaces = global::CSharpWriter.Interfaces.ForCollection(odcmClass),
         Identifier = NamesService.GetCollectionTypeName(odcmClass),
         Methods = global::CSharpWriter.Methods.ForCollection(odcmClass),
         Indexers = global::CSharpWriter.Indexers.ForCollection(odcmClass)
     });
 }
Exemplo n.º 30
0
 internal static Class ForEntityContainer(OdcmModel odcmModel, OdcmClass odcmContainer)
 {
     return(new Class
     {
         AccessModifier = "public ",
         Constructors = global::CSharpWriter.Constructors.ForEntityContainer(odcmContainer),
         Fields = global::CSharpWriter.Fields.ForEntityContainer(odcmContainer),
         Interfaces = global::CSharpWriter.Interfaces.ForEntityContainer(odcmContainer),
         Identifier = NamesService.GetEntityContainerTypeName(odcmContainer),
         NestedClasses = new[] { ForGeneratedEdmModel(odcmModel) },
         Methods = global::CSharpWriter.Methods.ForEntityContainer(odcmContainer),
         Properties = global::CSharpWriter.Properties.ForEntityContainer(odcmContainer)
     });
 }