Example #1
0
        private void _EnsureTargetNodeProperties()
        {
            // If the effect requires any properties, make sure the target nodes have those properties.
            if (TargetNodes == null || TargetNodes.Length == 0)
            {
                return;
            }

            if (!ApplicationServices.AreAllEffectRequiredPropertiesPresent(this))
            {
                EffectModuleDescriptorBase effectDescriptor = Modules.GetDescriptorById <EffectModuleDescriptorBase>(Descriptor.TypeId);

                List <string> message = new List <string> {
                    "The \"" + effectDescriptor.TypeName + "\" effect has property requirements that are missing:",
                    ""
                };
                foreach (ElementNode elementNode in TargetNodes)
                {
                    Guid[] missingPropertyIds = effectDescriptor.PropertyDependencies.Except(elementNode.Properties.Select(x => x.Descriptor.TypeId)).ToArray();
                    if (missingPropertyIds.Length > 0)
                    {
                        message.Add((elementNode.Children.Any() ? "Group " : "Element ") + elementNode.Name);
                        message.AddRange(missingPropertyIds.Select(x => " - Property " + Modules.GetDescriptorById(x).TypeName));
                    }
                }
                throw new InvalidOperationException(string.Join(Environment.NewLine, message));
            }
        }
Example #2
0
        private void _EnsureTargetNodeProperties()
        {
            // If the effect requires any properties, make sure the target nodes have those properties.
            if (TargetNodes == null || TargetNodes.Length == 0)
            {
                return;
            }

            if (!ApplicationServices.AreAllEffectRequiredPropertiesPresent(this))
            {
                EffectModuleDescriptorBase effectDescriptor =
                    Modules.GetDescriptorById <EffectModuleDescriptorBase>(Descriptor.TypeId);
                using (var ms = new MemoryStream())
                {
                    using (var sw = new StreamWriter(ms))
                    {
                        sw.WriteLine("The \"{0}\" effect has property requirements that are missing:\n", effectDescriptor.TypeName);

                        foreach (ElementNode elementNode in TargetNodes)
                        {
                            Guid[] missingPropertyIds =
                                effectDescriptor.PropertyDependencies.Except(elementNode.Properties.Select(x => x.Descriptor.TypeId)).ToArray();
                            if (missingPropertyIds.Length > 0)
                            {
                                sw.WriteLine((elementNode.Children.Any() ? "Group " : "Element ") + elementNode.Name);
                                missingPropertyIds.Select(x => string.Format(" - Property {0}", Modules.GetDescriptorById(x).TypeName)).ToList()
                                .ForEach(p => { sw.WriteLine(p); });
                            }
                        }
                        sw.Flush();
                        ms.Position = 0;
                        using (var sr = new StreamReader(ms))
                        {
                            throw new InvalidOperationException(sr.ReadToEnd());
                        }
                        // throw new InvalidOperationException(string.Join(Environment.NewLine, message));
                    }
                }
            }
        }