Пример #1
0
        static string getAssemblyName(ITypeData _x)
        {
            var asm = _x.AsTypeData()?.Type?.Assembly;

            if (asm == null)
            {
                Log.Warning("Unable to find source of type {0}. No package dependency will be recorded for this type in the xml file.", _x.Name);
                return(null);
            }

            // dynamic or assemblies loaded from bytes cannot be located.
            if (asm.IsDynamic || string.IsNullOrWhiteSpace(asm.Location))
            {
                return(null);
            }

            try
            {
                return(Path.GetFileName(asm.Location.Replace("\\", "/")));
            }
            catch
            {
                return(null);
            }
        }
Пример #2
0
        /// <summary> Deserialization implementation. </summary>
        public override bool Deserialize(XElement elem, ITypeData _t, Action <object> setter)
        {
            var t = _t.AsTypeData()?.Type;

            if (t != null && t.DescendsTo(typeof(IResource)) && ComponentSettingsList.HasContainer(t))
            {
                var    srcattr = elem.Attribute("Source");
                string src     = null;
                if (srcattr != null)
                {
                    src = srcattr.Value;
                }

                if (elem.HasElements || src == "")
                {
                    return(false);
                }
                else
                {
                    var content = elem.Value.Trim();

                    Serializer.DeferLoad(() =>
                    {
                        // we need to load this asynchronously to avoid recursively
                        // serializing another ComponentSettings.
                        if (string.IsNullOrWhiteSpace(content))
                        {
                            setter(null);
                            return;
                        }
                        var obj = fetchObject(t, (o, i) => (o as IResource).Name.Trim() == content, src);
                        if (obj != null)
                        {
                            if (obj is IResource resource && resource.Name != content && !string.IsNullOrWhiteSpace(content))
                            {
                                TestPlanChanged = true;
                                var msg         = $"Missing '{content}'. Using '{resource.Name}' instead.";
                                if (elem.Parent.Element("Name") != null)
                                {
                                    msg = $"Missing '{content}' used by '{elem.Parent.Element("Name").Value}.{elem.Name.ToString()}. Using '{resource.Name}' instead.'";
                                }
                                Serializer.PushError(elem, msg);
                            }
                            setter(obj);
                        }
                        else
                        {
                            TestPlanChanged = true;
                            var msg         = $"Missing '{content}'.";
                            if (elem.Parent.Element("Name") != null)
                            {
                                msg = $"Missing '{content}' used by '{elem.Parent.Element("Name").Value}.{elem.Name.ToString()}'";
                            }
                            Serializer.PushError(elem, msg);
                        }
                    });
                    return(true);
                }
            }
            return(false);
        }