Esempio n. 1
0
        /// <summary>
        /// Recursively builds up a list of instances to serialize.
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="instances"></param>
        /// <param name="paths"></param>
        /// <param name="path"></param>
        static void ProcessInstance(ModelInstance instance, ModelStepList steps, bool includeInResponse, bool inScope, bool forLoad, ServiceResponse response)
        {
            // Avoid processing cached instances not included in the response
            if (instance.IsCached && !includeInResponse)
            {
                return;
            }

            ModelInstanceInfo instanceInfo = null;

            // Track the instance if the query represents a load request
            if (includeInResponse)
            {
                // Fetch or initialize the dictionary of instances for the type of the current instance
                ModelTypeInfo typeInfo = response.GetModelTypeInfo(instance.Type);

                // Add the current instance to the dictionary if it is not already there
                if (!typeInfo.Instances.TryGetValue(instance.Id, out instanceInfo))
                {
                    typeInfo.Instances[instance.Id] = instanceInfo = new ModelInstanceInfo(instance);
                }

                // Track in scope instances to limit conditions
                if (inScope && !instance.IsCached)
                {
                    response.inScopeInstances.Add(instance);
                }
            }

            // Exit immediately if there are no child steps to process
            if (steps == null)
            {
                return;
            }

            // Process query steps for the current instance
            foreach (var step in steps)
            {
                // Recursively process child instances
                foreach (var childInstance in step.GetInstances(instance))
                {
                    ProcessInstance(childInstance, step.NextSteps, includeInResponse, inScope, forLoad, response);
                }

                // Mark value lists to be included during serialization
                if (step.Property.IsList && includeInResponse)
                {
                    instanceInfo.IncludeList(step.Property);
                }
            }

            // Run all property get rules on the instance
            if (inScope)
            {
                if (forLoad)
                {
                    instance.RunPendingPropertyGetRules(p => p is ModelValueProperty || steps.Any(s => s.Property == p));
                }
                else
                {
                    instance.RunPendingPropertyGetRules(p => p is ModelValueProperty);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Recursively builds up a list of instances to serialize.
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="instances"></param>
        /// <param name="paths"></param>
        /// <param name="path"></param>
        static void ProcessInstance(ModelInstance instance, ModelStepList steps, bool includeInResponse, bool inScope, bool forLoad, ServiceResponse response)
        {
            // Avoid processing cached instances not included in the response
            if (instance.IsCached && !includeInResponse)
                return;

            ModelInstanceInfo instanceInfo = null;

            // Track the instance if the query represents a load request
            if (includeInResponse)
            {
                // Fetch or initialize the dictionary of instances for the type of the current instance
                ModelTypeInfo typeInfo = response.GetModelTypeInfo(instance.Type);

                // Add the current instance to the dictionary if it is not already there
                if (!typeInfo.Instances.TryGetValue(instance.Id, out instanceInfo))
                    typeInfo.Instances[instance.Id] = instanceInfo = new ModelInstanceInfo(instance);

                // Track in scope instances to limit conditions
                if (inScope && !instance.IsCached)
                    response.inScopeInstances.Add(instance);
            }

            // Exit immediately if there are no child steps to process
            if (steps == null)
                return;

            // Process query steps for the current instance
            foreach (var step in steps)
            {
                // Recursively process child instances
                foreach (var childInstance in step.GetInstances(instance))
                    ProcessInstance(childInstance, step.NextSteps, includeInResponse, inScope, forLoad, response);

                // Mark value lists to be included during serialization
                if (step.Property.IsList && includeInResponse)
                    instanceInfo.IncludeList(step.Property);
            }

            // Run all property get rules on the instance
            if (inScope)
            {
                if (forLoad)
                    instance.RunPendingPropertyGetRules(p => p is ModelValueProperty || steps.Any(s => s.Property == p));
                else
                    instance.RunPendingPropertyGetRules(p => p is ModelValueProperty);
            }
        }