Esempio n. 1
0
        private static DataServiceMetadata ExtractMetadataInternal(XDocument schemaDocument)
        {
            var type = (from e in schemaDocument.Descendants()
                        where e.Name.LocalName == "EntityContainer"
                        let entitySet = Enumerable.FirstOrDefault <XElement>(e.Elements(), el => el.Name.LocalName == "EntitySet")
                                        let name = entitySet?.Attribute("Name").Value
                                                   where (name != null) && name.Equals("Packages", StringComparison.OrdinalIgnoreCase)
                                                   select new {
                Container = e,
                EntitySet = entitySet
            }).FirstOrDefault();

            if (type == null)
            {
                return(null);
            }
            XElement   container         = type.Container;
            XAttribute attribute         = type.EntitySet.Attribute("EntityType");
            string     packageEntityName = null;

            if (attribute != null)
            {
                packageEntityName = attribute.Value;
            }
            DataServiceMetadata metadata1 = new DataServiceMetadata();
            DataServiceMetadata metadata2 = new DataServiceMetadata();

            metadata2.SupportedMethodNames = new HashSet <string>(from e in container.Elements()
                                                                  where e.Name.LocalName == "FunctionImport"
                                                                  select e.Attribute("Name").Value, StringComparer.OrdinalIgnoreCase);
            DataServiceMetadata local8 = metadata2;

            local8.SupportedProperties = new HashSet <string>(ExtractSupportedProperties(schemaDocument, packageEntityName), StringComparer.OrdinalIgnoreCase);
            return(local8);
        }
            public static DataServiceMetadata Extract(XDocument schemaDocument)
            {
                // Get all entity containers
                var entityContainers = from e in schemaDocument.Descendants()
                                       where e.Name.LocalName == "EntityContainer"
                                       select e;

                // Find the entity container with the Packages entity set
                var result = (from e in entityContainers
                              let entitySet = e.Elements().FirstOrDefault(el => el.Name.LocalName == "EntitySet")
                                              let name = entitySet != null ? entitySet.Attribute("Name").Value : null
                                                         where name != null && name.Equals("Packages", StringComparison.OrdinalIgnoreCase)
                                                         select new { Container = e, EntitySet = entitySet }).FirstOrDefault();

                if (result == null)
                {
                    return(null);
                }

                var packageEntityContainer     = result.Container;
                var packageEntityTypeAttribute = result.EntitySet.Attribute("EntityType");

                string packageEntityName = null;

                if (packageEntityTypeAttribute != null)
                {
                    packageEntityName = packageEntityTypeAttribute.Value;
                }

                var methodNames =
                    from e in packageEntityContainer.Elements()
                    where e.Name.LocalName == "FunctionImport"
                    select e.Attribute("Name").Value;

                var metadata = new DataServiceMetadata
                {
                    SupportedMethodNames = new HashSet <string>(
                        methodNames,
                        StringComparer.OrdinalIgnoreCase),

                    SupportedProperties = new HashSet <string>(
                        ExtractSupportedProperties(schemaDocument, packageEntityName),
                        StringComparer.OrdinalIgnoreCase)
                };

                return(metadata);
            }
Esempio n. 3
0
        protected void UpdateAction(ResourceType resourceType, ResourceContainer resourceContainer, object entity)
        {
            AstoriaTestLog.WriteLine("Updating entity set :{0} , entity type :{1}", resourceContainer.Name, resourceType.Name);
            //Change any of the properties that make up the Etag
#if !ClientSKUFramework
            IEdmEntityType entityType = DataServiceMetadata.GetEntityType(entity);
            foreach (string eTagProperty in entityType.EtagProperties())
            {
                Type   propertyType = entity.GetType().GetProperty(eTagProperty).PropertyType;
                object newValue     = propertyType.GetTypedValue(eTagProperty, resourceType.Properties[eTagProperty].Facets.MaxSize);
                //entity.SetPropertyValue(eTagProperty, newValue);
            }
#endif

            CurrentContext.UpdateObject(entity);
            ExecuteAndValidate(() => { CurrentContext.SaveChanges(SaveChangeOption); });
        }
Esempio n. 4
0
        protected void InsertReferenceNavProperty()
        {
            ForEachResourceType(
                (resourceType, resourceContainer, workspace) =>
            {
                CreateContext(resourceType, workspace);
#if !ClientSKUFramework
                object entity = ExecuteURI(resourceType, String.Format("/{0}", resourceContainer.Name));
                Uri entityUri = null;


                IEdmEntityType entityType = DataServiceMetadata.GetEntityType(entity);
                if (entityType == null)
                {
                    return;
                }
                CurrentContext.TryGetUri(entity, out entityUri);
                foreach (string refNavProperty in entityType.ReferenceNavigationProperties())
                {
                    ResourceType navResType = workspace.ServiceContainer.ResourceTypes.FirstOrDefault(rt => rt.Name == refNavProperty);
                    if (navResType != null)
                    {
                        object navEntity      = navResType.CreateInstance(false);
                        string navPropertyURI = String.Format("{0}/{1}", entityUri.Segments[entityUri.Segments.Length - 1], refNavProperty);
                        CurrentContext.AddObject(navPropertyURI, navEntity);
                        CurrentContext.EnsureInsert(navEntity, navResType);
                    }
                }
                ExecuteAndValidate(() => CurrentContext.SaveChanges(SaveChangeOption));
                if (ContinueTest)
                {
                    if (ChainedFunction != null)
                    {
                        ChainedFunction();
                    }
                }
#endif
            }, true);
        }
Esempio n. 5
0
        protected void EnsureInsert(DataServiceContext context, object entity, string entitySetName, Workspace workspace, string skipEntitySet)
        {
#if !ClientSKUFramework
            IEdmEntityType entityType = null;
            if (DataServiceMetadata.ServiceMetadata == null)
            {
                DataServiceMetadata.LoadServiceMetadata(workspace.ServiceUri);
            }
            if (DataServiceMetadata.EntityTypes.Any(eType => eType.Name == entitySetName))
            {
                entityType = DataServiceMetadata.EntityTypes.First(eType => eType.Name == entitySetName);
            }
            if (entityType == null && DataServiceMetadata.EntityTypes.Any(eType => eType.Name == entity.GetType().Name))
            {
                entityType    = DataServiceMetadata.EntityTypes.First(eType => eType.Name == entity.GetType().Name);
                entitySetName = entity.GetType().Name;
            }
            if (entityType == null)
            {
                return;
            }
            foreach (IEdmNavigationProperty navProperty in entityType.NavigationProperties())
            {
                if (context.Links.All(ld => (ld.SourceProperty != navProperty.Name)))
                {
                    if (navProperty.TargetMultiplicity() == EdmMultiplicity.One && navProperty.Name != skipEntitySet)
                    {
                        IEdmEntityType navProperyEntityType = DataServiceMetadata.GetEntityType(navProperty);
                        ResourceType   resourceType         = workspace.ServiceContainer.ResourceTypes.First(rt => rt.Name == navProperyEntityType.Name);
                        object         instance             = resourceType.CreateInstance(false);
                        context.AddObject(navProperyEntityType.Name == "College" ? "Colleges" : navProperyEntityType.Name, instance);
                        context.SetLink(entity, navProperty.Name, instance);
                        context.SaveChangesDefaultOptions = SaveChangesOptions.BatchWithSingleChangeset;
                    }
                }
            }
#endif
        }
        public virtual void ForEachResourceType(Action <ResourceType, ResourceContainer, Workspace> someAction, bool workspaceShouldUpdate)
        {
            Func <ResourceType, bool> typeHasConcurrencyTokens = (resourceType) =>
            {
                bool hasConcurrencyTokens = false;
                foreach (ResourceProperty property in resourceType.Properties.OfType <ResourceProperty>())
                {
                    if (property.Facets.ConcurrencyMode == ConcurrencyMode.Fixed)
                    {
                        hasConcurrencyTokens = true;
                        break;
                    }
                }
                return(hasConcurrencyTokens);
            };

            foreach (Workspace workspace in this)
            {
                bool doneProcessing = false;
                DataServiceMetadata.LoadServiceMetadata(workspace.ServiceUri);
                if (workspaceShouldUpdate && !workspace.Settings.SupportsUpdate)
                {
                    throw (new TestSkippedException("Workspace does not support updating"));
                }
                foreach (ResourceContainer container in workspace.ServiceContainer.ResourceContainers)
                {
                    foreach (ResourceType resourceType in
                             container.ResourceTypes.Where(rType => (!workspaceShouldUpdate || rType.IsInsertable) && typeHasConcurrencyTokens(rType)))
                    {
                        try
                        {
                            //Filter only types which have base types , if required
                            if (!SkipType(resourceType, workspaceShouldUpdate))
                            {
                                doneProcessing = true;
                                someAction(resourceType, container, workspace);
                            }
                        }
                        catch (OptimisticConcurrencyException oException)
                        {
                            throw oException;
                        }
                        catch (Exception exception)
                        {
                            if (!(exception is OptimisticConcurrencyException))
                            {
                                AstoriaTestLog.FailAndContinue(exception);
                            }
                        }
                        if (doneProcessing)
                        {
                            break;
                        }
                    }
                    if (doneProcessing)
                    {
                        break;
                    }
                }
            }
        }