示例#1
0
 private ModelStep FirstApplicableStep(ModelInstance instance, ModelStepList steps)
 {
     if (instance == null)
     {
         return(steps.FirstOrDefault());
     }
     else
     {
         return(steps.Where(s => s.Property.DeclaringType.IsInstanceOfType(instance)).FirstOrDefault());
     }
 }
示例#2
0
文件: Page.cs 项目: vc3/ExoWeb
 private ModelStep FirstApplicableStep(ModelInstance instance, ModelStepList steps)
 {
     if (instance == null)
         return steps.FirstOrDefault();
     else
         return steps.Where(s => s.Property.DeclaringType.IsInstanceOfType(instance)).FirstOrDefault();
 }
示例#3
0
文件: ModelPath.cs 项目: vc3/ExoModel
        /// <summary>
        /// Recursively loads a path in the model by walking steps.
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="step"></param>
        /// <param name="model"></param>
        void GetInstances(ModelInstance instance, ModelStepList steps, HashSet<ModelInstance> model)
        {
            // Add the instance to the model
            model.Add(instance);

            // Process each child step
            foreach (var step in steps)
            {
                // Process each instance
                foreach (var child in step.GetInstances(instance))
                    GetInstances(child, step.NextSteps, model);
            }
        }
示例#4
0
文件: ModelPath.cs 项目: vc3/ExoModel
 /// <summary>
 /// Recursively unsubscribes to path changes.
 /// </summary>
 /// <param name="steps"></param>
 static void Unsubscribe(ModelStepList steps)
 {
     foreach (var step in steps)
     {
         step.Property.Observers.Remove(step);
         Unsubscribe(step.NextSteps);
     }
 }
示例#5
0
文件: ModelPath.cs 项目: vc3/ExoModel
 /// <summary>
 /// Recursively subscribes to path changes.
 /// </summary>
 /// <param name="steps"></param>
 static void Subscribe(ModelStepList steps)
 {
     foreach (var step in steps)
     {
         step.Property.Observers.Add(step);
         Subscribe(step.NextSteps);
     }
 }
示例#6
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);
                }
            }
        }
示例#7
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);
            }
        }