Esempio n. 1
0
        public static Cartridge FromDescriptor(dynamic spec)
        {
            Cartridge cart = new Cartridge();

            cart.Spec            = spec;
            cart.OriginalName    = spec["Name"];
            cart.Version         = spec.ContainsKey("Version") ? spec["Version"] : "0.0";
            cart.Versions        = spec.ContainsKey("Versions") ? spec["Versions"] : new List <object>();
            cart.Architecture    = spec.ContainsKey("Architecture") ? spec["Architecture"] : "noarch";
            cart.DisplayName     = spec.ContainsKey("Display-Name") ? spec["Display-Name"] : string.Format("{0}-{1}-{2}", cart.OriginalName, cart.Version, cart.Architecture);
            cart.License         = spec["License"] ?? "unknown";
            cart.LicenseUrl      = spec["License-Url"] ?? "";
            cart.Vendor          = spec["Vendor"] ?? "unknown";
            cart.CartridgeVendor = spec["Cartridge-Vendor"] ?? "unknown";
            cart.Description     = spec["Description"] ?? "";
            if (spec.ContainsKey("Provides"))
            {
                if (spec["Provides"] is String)
                {
                    cart.Provides = new List <object>()
                    {
                        spec["Provides"]
                    };
                }
                else
                {
                    cart.Provides = spec["Provides"];
                }
            }
            else
            {
                cart.Provides = new List <object>()
                {
                };
            }
            if (spec.ContainsKey("Requires"))
            {
                if (spec["Requires"] is String)
                {
                    cart.Requires = new List <object>()
                    {
                        spec["Requires"]
                    };
                }
                else
                {
                    cart.Requires = spec["Requires"];
                }
            }
            else
            {
                cart.Requires = new List <object>()
                {
                };
            }
            if (spec.ContainsKey("Conflicts"))
            {
                if (spec["Conflicts"] is String)
                {
                    cart.Conflicts = new List <object>()
                    {
                        spec["Conflicts"]
                    };
                }
                else
                {
                    cart.Conflicts = spec["Conflicts"];
                }
            }
            else
            {
                cart.Conflicts = new List <object>()
                {
                };
            }
            if (spec.ContainsKey("Native-Requires"))
            {
                if (spec["Native-Requires"] is String)
                {
                    cart.NativeRequires = new List <object>()
                    {
                        spec["Native-Requires"]
                    };
                }
                else
                {
                    cart.NativeRequires = spec["Native-Requires"];
                }
            }
            else
            {
                cart.NativeRequires = new List <object>()
                {
                };
            }
            cart.Categories = spec["Categories"] ?? new List <object>()
            {
            };
            cart.Website     = spec["Website"] ?? "";
            cart.HelpTopics  = spec["Help-Topics"] ?? new object();
            cart.CartDataDef = spec["Cart-Data"] ?? new object();
            cart.AdditionalControlActions = spec.ContainsKey("Additional-Control-Actions") ? spec["Additional-Control-Actions"] : new List <object>()
            {
            };

            if (((Dictionary <object, object>)spec).ContainsKey("Endpoints"))
            {
                if (spec["Endpoints"] is List <object> )
                {
                    foreach (dynamic ep in spec["Endpoints"])
                    {
                        cart.Endpoints.Add(Endpoint.FromDescriptor(ep, string.Empty));
                    }
                }
            }

            if (((Dictionary <object, object>)spec).ContainsKey("Profiles"))
            {
                foreach (dynamic p in spec["Profiles"])
                {
                    KeyValuePair <string, dynamic> pair = (KeyValuePair <string, dynamic>)p;
                    Profile profile = Profile.FromDescriptor(cart, pair.Value);
                    profile.Name = pair.Key;
                    cart.Profiles.Add(profile);
                    cart.ProfileMap[pair.Key] = profile;
                }
            }
            else
            {
                Profile profile = Profile.FromDescriptor(cart, spec);
                profile.Name      = cart.Name;
                profile.Generated = true;
                cart.Profiles.Add(profile);
                cart.ProfileMap[profile.Name] = profile;
            }
            cart.DefaultProfile = spec.ContainsKey("Default-Profile") ? spec["Default-Profile"] : cart.Profiles[0].Name;

            return(cart);
        }
Esempio n. 2
0
        public static Cartridge FromDescriptor(dynamic spec)
        {
            Cartridge cart = new Cartridge();

            cart.Spec            = spec;
            cart.Id              = spec.ContainsKey("Id") ?  spec["Id"] :  "";
            cart.OriginalName    = spec["Name"];
            cart.Version         = spec.ContainsKey("Version") ? spec["Version"] : "0.0";
            cart.Versions        = spec.ContainsKey("Versions") ? spec["Versions"] : new List <object>();
            cart.Architecture    = spec.ContainsKey("Architecture") ? spec["Architecture"] : "noarch";
            cart.DisplayName     = spec.ContainsKey("Display-Name") ? spec["Display-Name"] : string.Format("{0}-{1}-{2}", cart.OriginalName, cart.Version, cart.Architecture);
            cart.License         = spec["License"] ?? "unknown";
            cart.LicenseUrl      = spec["License-Url"] ?? "";
            cart.Vendor          = spec["Vendor"] ?? "unknown";
            cart.CartridgeVendor = spec["Cartridge-Vendor"] ?? "unknown";
            cart.Description     = spec["Description"] ?? "";

            if (spec.ContainsKey("Provides"))
            {
                if (spec["Provides"] is String)
                {
                    cart.Provides = new List <object>()
                    {
                        spec["Provides"]
                    };
                }
                else
                {
                    cart.Provides = spec["Provides"];
                }
            }
            else
            {
                cart.Provides = new List <object>()
                {
                };
            }
            if (spec.ContainsKey("Requires"))
            {
                if (spec["Requires"] is String)
                {
                    cart.Requires = new List <object>()
                    {
                        spec["Requires"]
                    };
                }
                else
                {
                    cart.Requires = spec["Requires"];
                }
            }
            else
            {
                cart.Requires = new List <object>()
                {
                };
            }
            if (spec.ContainsKey("Conflicts"))
            {
                if (spec["Conflicts"] is String)
                {
                    cart.Conflicts = new List <object>()
                    {
                        spec["Conflicts"]
                    };
                }
                else
                {
                    cart.Conflicts = spec["Conflicts"];
                }
            }
            else
            {
                cart.Conflicts = new List <object>()
                {
                };
            }
            if (spec.ContainsKey("Native-Requires"))
            {
                if (spec["Native-Requires"] is String)
                {
                    cart.NativeRequires = new List <object>()
                    {
                        spec["Native-Requires"]
                    };
                }
                else
                {
                    cart.NativeRequires = spec["Native-Requires"];
                }
            }
            else
            {
                cart.NativeRequires = new List <object>()
                {
                };
            }
            cart.Categories = spec["Categories"] ?? new List <object>()
            {
            };
            cart.Website     = spec["Website"] ?? "";
            cart.HelpTopics  = spec["Help-Topics"] ?? new object();
            cart.CartDataDef = spec["Cart-Data"] ?? new object();
            cart.AdditionalControlActions = spec.ContainsKey("Additional-Control-Actions") ? spec["Additional-Control-Actions"] : new List <object>()
            {
            };
            cart.CartridgeVersion = spec["Cartridge-Version"] ?? "0.0.0";
            cart.Platform         = spec["Platform"] ?? "Windows";

            if (((Dictionary <object, object>)spec).ContainsKey("Endpoints"))
            {
                if (spec["Endpoints"] is List <object> )
                {
                    foreach (dynamic ep in spec["Endpoints"])
                    {
                        cart.Endpoints.Add(Endpoint.FromDescriptor(ep, string.Empty));
                    }
                }
            }

            if (spec.ContainsKey("Start-Order"))
            {
                if (spec["Start-Order"] is String)
                {
                    cart.StartOrder = new List <object>()
                    {
                        spec["Start-Order"]
                    };
                }
                else
                {
                    cart.StartOrder = spec["Start-Order"];
                }
            }
            else
            {
                cart.StartOrder = new List <object>()
                {
                };
            }

            if (spec.ContainsKey("Stop-Order"))
            {
                if (spec["Stop-Order"] is String)
                {
                    cart.StopOrder = new List <object>()
                    {
                        spec["Stop-Order"]
                    };
                }
                else
                {
                    cart.StopOrder = spec["Stop-Order"];
                }
            }
            else
            {
                cart.StopOrder = new List <object>()
                {
                };
            }

            if (spec.ContainsKey("Configure-Order"))
            {
                if (spec["Configure-Order"] is String)
                {
                    cart.ConfigureOrder = new List <object>()
                    {
                        spec["Configure-Order"]
                    };
                }
                else
                {
                    cart.ConfigureOrder = spec["Configure-Order"];
                }
            }
            else
            {
                cart.ConfigureOrder = new List <object>()
                {
                };
            }

            if (((Dictionary <object, object>)spec).ContainsKey("Components"))
            {
                foreach (dynamic c in spec["Components"])
                {
                    KeyValuePair <string, dynamic> pair = (KeyValuePair <string, dynamic>)c;
                    Component component = Component.FromDescriptor(cart, pair.Value);
                    component.Name = pair.Key;
                    cart.Components.Add(component);
                    cart.ComponentNameMap[component.Name] = component;
                }
            }
            else
            {
                Component component = Component.FromDescriptor(cart, spec);
                component.Generated = true;
                cart.Components.Add(component);
                cart.ComponentNameMap[component.Name] = component;
            }

            if (((Dictionary <object, object>)spec).ContainsKey("Connections"))
            {
                foreach (dynamic c in spec["Connections"])
                {
                    KeyValuePair <string, dynamic> pair = (KeyValuePair <string, dynamic>)c;
                    cart.Connections.Add(Connection.FromDescriptor(pair.Key, pair.Value));
                }
            }

            if (((Dictionary <object, object>)spec).ContainsKey("Group-Overrides"))
            {
                foreach (dynamic c in spec["Group-Overrides"])
                {
                    cart.GroupOverrides.Add(c);
                }
            }

            cart.Obsolete = spec.ContainsKey("Obsolete") ?  spec["spec"] : false;


            return(cart);
        }