Exemple #1
0
        public static DataboundAsset FindChildOfType <T>(this DataboundContainterAsset containerAsset) where T : DataboundAsset
        {
            if (containerAsset.Children?.Value == null)
            {
                return(null);
            }

            DataboundAsset correctChild = containerAsset.Children.Value.FirstOrDefault(t => t is T);

            if (correctChild != null)
            {
                return(correctChild);
            }

            foreach (DataboundContainterAsset child in containerAsset.Children.Value.OfType <DataboundContainterAsset>())
            {
                DataboundAsset procChild = child.FindChildOfType <T>();
                if (procChild is T sorted)
                {
                    return(sorted);
                }
            }

            return(null);
        }
Exemple #2
0
        public static List <DataboundAsset> FindChildrenOfType <T>(this DataboundContainterAsset containerAsset) where T : DataboundAsset
        {
            List <DataboundAsset> result = new List <DataboundAsset>();

            if (containerAsset.Children?.Value == null)
            {
                return(result);
            }

            result.AddRange(containerAsset.Children.Value.Where(t => t is T));

            foreach (DataboundContainterAsset child in containerAsset.Children.Value.OfType <DataboundContainterAsset>())
            {
                DataboundAsset procChild = child.FindChildOfType <T>();
                if (procChild is T sorted)
                {
                    result.Add(sorted);
                }
            }

            return(result);
        }
Exemple #3
0
        public static void FixParentChildRelationship(this DataboundAsset asset)
        {
            if (asset is DataboundContainterAsset containerAsset)
            {
                if (containerAsset.Children?.Value != null)
                {
                    foreach (DataboundAsset child in containerAsset.Children.Value)
                    {
                        child.ParentAsset = asset;
                        FixParentChildRelationship(child);

                        if (child.VirtualizedDataContext.Screen == null)
                        {
                            if (asset?.ParentAsset?.VirtualizedDataContext?.Screen != null)
                            {
                                child.VirtualizedDataContext.Screen = asset?.ParentAsset?.VirtualizedDataContext?.Screen;
                            }
                        }
                    }
                }
            }
        }
Exemple #4
0
        public static DataboundAsset CreateFromXml(XmlAttributeCollection childNodeAttributes, Type type, DataboundAsset parentAsset, BaseScreen baseScreen)
        {
            DataboundAsset asset = (DataboundAsset)Activator.CreateInstance(type);

            var assetType = asset.GetType();

            PropertyInfo[] tprops = assetType.GetProperties();

            PropertyInfo[] props = tprops.Where(propertyInfo => propertyInfo.GetMethod.ReturnType.AssemblyQualifiedName.Contains("DataboundValue")).ToArray();

            List <string> childNodeNames = new List <string>();

            foreach (object childNodeAttribute in childNodeAttributes)
            {
                childNodeNames.Add(((XmlAttribute)childNodeAttribute).Name);
            }

            Dictionary <string, PropertyInfo> prps = new Dictionary <string, PropertyInfo>();

            foreach (PropertyInfo propertyInfo in props)
            {
                AssetAttribute attr = propertyInfo.GetCustomAttribute <AssetAttribute>();

                string name = propertyInfo.Name;
                if (attr != null)
                {
                    name = attr.XMLName;
                }

                prps.Add(name, propertyInfo);
            }

            Breeze.VirtualizedDataContext embeddedDataContext = new VirtualizedDataContext();

            foreach (string s in childNodeNames)
            {
                if (prps.ContainsKey(s))
                {
                    PropertyInfo p = prps[s];

                    string temp = childNodeAttributes.GetNamedItem(s)?.Value;
                    if (temp != null)
                    {
                        DataboundValue temp3 = (DataboundValue)DataboundAssetExtensions.GetDBerValue(temp, p.PropertyType.GenericTypeArguments.First());

                        p.SetValue(asset, temp3);
                    }
                }
                else
                {
                    if (s.StartsWith("x_"))
                    {
                        string propName = s.Substring(2);

                        string temp = childNodeAttributes.GetNamedItem(s)?.Value;

                        string propType = temp.Split('|').First();
                        string value    = temp.Split('|').Last();

                        Type deftype = Type.GetType(propType) ?? Type.GetType("System." + propType);

                        if (temp != null)
                        {
                            DataboundValue temp3 = (DataboundValue)DataboundAssetExtensions.GetDBerValue(value, deftype);

                            embeddedDataContext.Store.Add(propName, value);
                        }
                    }
                    else
                    {
                        throw new Exception("Could not find prop: " + s);
                    }
                }
            }

            if (embeddedDataContext.Store.Count > 0)
            {
                asset.VirtualizedDataContext        = embeddedDataContext;
                asset.VirtualizedDataContext.Screen = baseScreen;
            }

            return(asset);
        }