Пример #1
0
        private static void GenerateCommand(CommandLineApplication command)
        {
            command.Name = "generate";
            command.HelpOption("-h|--help");
            command.Description = "Generate a cim model";
            var cimNamespaceArg   = command.Argument("cim namespace", "CIM namespace to generate the model from");
            var csNamespaceOption = command.Option("--cs-namespace|-n", "C# namespace", CommandOptionType.SingleValue);
            var outDirOption      = command.Option("--out|-o", "Output directory", CommandOptionType.SingleValue);

            command.OnExecute(() =>
            {
                if (cimNamespaceArg.Value == null)
                {
                    command.Error.WriteLine("cim namespace is not specified");
                    return(1);
                }
                var cimNamespace = cimNamespaceArg.Value;
                var options      = new ModelBuildingOptions
                {
                    CSharpNamespace = csNamespaceOption.Value() ?? ToCSNamespace(cimNamespace),
                    OutputDir       = outDirOption.Value() ?? Environment.CurrentDirectory,
                    Out             = command.Out,
                    Error           = command.Error,
                    CimNamespace    = cimNamespace,
                };
                using (var cimSession = CimSession.Create(null)) {
                    var modelBuilder = new ModelBuilder(cimSession, cimNamespace, options);
                    modelBuilder.Build();
                }

                return(0);
            });
        }
Пример #2
0
        internal AssociationBuilder(ModelBuildingOptions options, CimTypeDeclaration declaration, IDictionary <string, CimTypeDeclaration> typeRepository)
        {
            _options        = options;
            _declaration    = declaration;
            _typeRepository = typeRepository;

            var keyProperties = declaration.Properties.Where(p => p.IsKey()).ToList();

            if (keyProperties.Count == 0)
            {
                keyProperties = declaration.Properties.Where(p => p.IsReference()).ToList();
            }
            if (keyProperties.Count != 2)
            {
                throw new NotSupportedException($"{_declaration.Name} association type should have 2 key properties. Got {keyProperties.Count}");
            }
            _sourceProperty = keyProperties[0];
            _targetProperty = keyProperties[1];
        }
Пример #3
0
 public ModelBuilder(CimSession cimSession, string cimNamespace, ModelBuildingOptions options)
 {
     _cimSession   = cimSession;
     _cimNamespace = cimNamespace;
     _options      = options;
 }
Пример #4
0
 public ClassBuilder(ModelBuildingOptions options, CimTypeDeclaration declaration, IDictionary <string, CimTypeDeclaration> typeRepository)
 {
     _options        = options;
     _declaration    = declaration;
     _typeRepository = typeRepository;
 }