Пример #1
0
        internal ModelMetaData[] FindAllModels()
        {
            List <ModelMetaData> metaData = new List <ModelMetaData>();

            string[] prefabGUIDs = AssetDatabase.FindAssets("t:prefab", new[] { ProjectFolder });
            foreach (string guid in prefabGUIDs)
            {
                string     prefabPath = AssetDatabase.GUIDToAssetPath(guid);
                GameObject prefab     = AssetDatabase.LoadAssetAtPath <GameObject>(prefabPath);

                string        dataPath = prefabPath.Replace(".prefab", ".asset");
                ModelMetaData data     = AssetDatabase.LoadAssetAtPath <ModelMetaData>(dataPath);

                if (data == null)
                {
                    data       = ScriptableObject.CreateInstance <ModelMetaData>();
                    data.asset = prefab;
                    data.name  = prefab.name;
                    AssetDatabase.CreateAsset(data, dataPath);
                }

                metaData.Add(data);
            }

            AssetDatabase.SaveAssets();

            return(metaData.ToArray());
        }
Пример #2
0
        public void FromLambdaExpression_ModelSelfTest()
        {
            TestParticipantClass tpc = new TestParticipantClass();
            Expression <Func <TestParticipantClass, TestParticipantClass> > expression = p => p;

            ModelMetaData mmd = ModelMetaData.FromLambdaExpression(expression, tpc);

            Assert.AreEqual("", mmd.PropertyName);
            Assert.AreEqual(true, mmd.IsSelf);
            Assert.AreEqual(tpc, mmd.ModelAccessor());
        }
Пример #3
0
        public void FromLambdaExpression_StringProperty()
        {
            TestParticipantClass tpc = new TestParticipantClass();

            tpc.FirstName = "Michael";
            Expression <Func <TestParticipantClass, String> > expression = p => p.FirstName;

            ModelMetaData mmd = ModelMetaData.FromLambdaExpression(expression, tpc);

            Assert.AreEqual("FirstName", mmd.PropertyName);
            Assert.AreEqual(false, mmd.IsSelf);
            Assert.AreEqual(tpc.FirstName, mmd.ModelAccessor());
        }
Пример #4
0
        public void FromLambdaExpression_ChildObject()
        {
            TestParticipantClass tpc = new TestParticipantClass();
            Expression <Func <TestParticipantClass, TestParticipantAddressClass> > expression = p => p.Address;

            ModelMetaData mmd = ModelMetaData.FromLambdaExpression(expression, tpc);

            Assert.AreEqual("Address", mmd.PropertyName);
            Assert.AreEqual(false, mmd.IsSelf);
            Assert.AreEqual(tpc.Address, mmd.ModelAccessor());

            tpc.Address = new TestParticipantAddressClass();
            mmd         = ModelMetaData.FromLambdaExpression(expression, tpc);
            Assert.AreEqual("Address", mmd.PropertyName);
            Assert.AreEqual(false, mmd.IsSelf);
            Assert.AreEqual(tpc.Address, mmd.ModelAccessor());
        }
Пример #5
0
        public virtual async Task <ModelMetaData> Train(TAgent agent, TrainingCorpus corpus, BotTrainOptions options)
        {
            if (String.IsNullOrEmpty(options.AgentDir))
            {
                options.AgentDir = Path.Combine(AppDomain.CurrentDomain.GetData("DataPath").ToString(), "Projects", agent.Id);
            }

            if (String.IsNullOrEmpty(options.Model))
            {
                options.Model = "model_" + DateTime.UtcNow.ToString("yyyyMMdd");
            }

            ModelMetaData meta = null;

            // train by contexts
            corpus.UserSays.GroupBy(x => x.ContextHash).Select(g => new
            {
                Context = g.Key,
                Corpus  = new TrainingCorpus
                {
                    Entities = corpus.Entities,
                    UserSays = corpus.UserSays.Where(x => x.ContextHash == g.Key).ToList()
                }
            })
            .ToList()
            .ForEach(async c =>
            {
                var trainer  = new BotTrainer(settings);
                agent.Corpus = c.Corpus;

                meta = await trainer.Train(agent, new BotTrainOptions
                {
                    AgentDir = options.AgentDir,
                    Model    = options.Model + $"{Path.DirectorySeparatorChar}{c.Context}"
                });
            });

            meta.Pipeline.Clear();
            meta.Model = options.Model;

            return(meta);
        }
Пример #6
0
        /// <summary>
        /// Obtiene la metadata de un modelo
        /// </summary>
        /// <param name="assembly">Assembly donde se encuentra el modelo connect</param>
        /// <param name="version"></param>
        /// <param name="versionStructure"></param>
        /// <returns></returns>
        public static ModelMetaData GetMdm(Assembly assembly, string version, VersionStructure versionStructure)
        {
            // obtenemos global filter para asignar si es globalfilter la entidad.
            var globalFilters = GlobalFilter.GetGlobalFilter(assembly);

            // obtiene la metadata de las entidades
            var entitiesFirstStep = GetFirstStepEntityCollection(assembly, globalFilters);

            // obtiene la documentación de las entidades.
            var mainDocumentation = GetMainDocumentation(assembly, entitiesFirstStep);


            // obtiene la documentación de los filtros.
            var filterProcess = GetFilterProcessDocs(assembly);

            // asigna documentación a las entidades.
            var entitiesWithDocumentation = entitiesFirstStep.Select(s => Docs.GetEntityWithDocumentation(s, mainDocumentation)).ToList();

            // asigna los procesos.
            var entitiesWithProcess = entitiesWithDocumentation.Select(s => GetEntityWithProcess(assembly, globalFilters, s, filterProcess)).ToList();

            // obtiene las descripciones de las enumeraciones en el assembly.
            var enumDescriptions = GetEnumDescriptions(assembly);



            // falta asignar los deletes a entities
            var md = new ModelMetaData
            {
                Version           = version,
                VersionStructure  = versionStructure,
                GlobalFilters     = globalFilters,
                EnumDescriptions  = enumDescriptions,
                DocFilters        = filterProcess,
                MdmEntities       = entitiesWithProcess.ToArray(),
                MainDocumentation = mainDocumentation,
                Menu = new GroupMenuViewer[] { }
            };

            return(md);
        }
Пример #7
0
 protected override void PopulateMetadata(ModelMetaData data, IEnumerable <Attribute> attributes, Type containerType, Func <object> modelAccessor, Type modelType, string propertyName)
 {
     base.PopulateMetaData(extended, attributes, containerType, modelAccessor, modelType, propertyName);
     //populate extended properties.
 }
Пример #8
0
        /// <summary>
        /// Genera modelo de datos desde una dll de un proyecto
        /// que implemente trifenix connect.
        /// </summary>
        /// <param name="assembly">dll de donde obtendrá los valores</param>
        /// <param name="modelNamespace">namespace donde se encuentra el modelo</param>
        /// <param name="inputNamespace">namespace donde se encuentra el input-model</param>
        /// <param name="index_model_namespace">namespace del diccionario mdm</param>
        /// <param name="documentNamespace">namespace donde se encuentra la implementación de IMDMDocumentation</param>
        /// <param name="gitRepo">repositorio donde se subirá la información</param>
        /// <param name="user">nombre de usuario git</param>
        /// <param name="email">correo git</param>
        /// <param name="branch">rama</param>
        public static void GenerateDataMdm(string assembly, string modelNamespace, string inputNamespace, string index_model_namespace, string documentNamespace, string gitRepo, string user, string email, string branch)
        {
            // assembly
            var assemblyInput = Assembly.LoadFrom(assembly);

            // carpeta temporal, donde se creará el modelo
            var folder = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), $"mdm-data-{Guid.NewGuid()}")).FullName;

            // carpeta código fuente.
            var srcFolder = Path.Combine(folder, "src");

            // modelo
            var modelTypes = GetTypesFromNameSpace(assemblyInput, modelNamespace);

            // input types
            var inputTypes = GetTypesFromNameSpace(assemblyInput, inputNamespace);

            // enum types

            var enumTypes = GetTypesFromNameSpace(assemblyInput, index_model_namespace);



            // documentación
            var documentation = GetDocumentation(assemblyInput, documentNamespace);


            // metadata de los tipos
            var propSearchinfos = modelTypes.Where(s => s.GetTypeInfo().GetCustomAttributes <EntityIndexAttribute>(true).Any()).Select(s => {
                // metadata de la entidad
                var infoHeader = s.GetTypeInfo().GetCustomAttributes <EntityIndexAttribute>(true).FirstOrDefault();

                // busca si existen metadatas de menú.
                var grp = s.GetCustomAttributes(typeof(EntityGroupMenuAttribute), true).Select(s => (EntityGroupMenuAttribute)s).ToList();


                // objeto anónimo con metadata.
                return(new
                {
                    index = infoHeader.Index,
                    visible = infoHeader.Visible,
                    pathName = infoHeader.PathName,
                    kindEntity = infoHeader.Kind,
                    propInfos = GetPropertySearchInfo(s, assemblyInput, inputNamespace, documentation),
                    className = s.Name,
                    GroupMenu = grp?.Select(s => s.Grupo).ToArray() ?? Array.Empty <GroupMenu>()
                });
            }).ToList();


            // metadata en colección de EntityMetadata
            var modelDict = propSearchinfos.Select(s =>
            {
                var model         = GetModel(s.propInfos, documentation, s.index);
                model.Visible     = s.visible;
                model.PathName    = s.pathName;
                model.EntityKind  = s.kindEntity;
                model.ClassName   = s.className;
                model.AutoNumeric = s.propInfos.Any(a => a.AutoNumeric);
                model.Menus       = s.GroupMenu;
                return(model);
            }).ToList();

            // mdm agro
            var modelDate = new ModelMetaData {
                Indexes = modelDict.ToArray()
            };

            // serialización de datos
            var json = JsonConvert.SerializeObject(modelDate, new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });



            // archivo a generar.
            var file = Path.Combine(srcFolder, "metadata/mdm.ts");



            // commit y envío.
            GenUtil.Git.StageCommitPush(gitRepo, email, user, folder, branch, new Dictionary <string, Func <bool> > {
                { "Eliminando archivos generados anteriormente", () => GenUtil.RecursiveDelete(new DirectoryInfo(srcFolder)) },
                { "creando modelo", () => {
                      GenerateModelStructure(modelTypes, inputTypes, enumTypes, srcFolder);
                      return(true);
                  } },
                { "datos cargados", () => {
                      File.WriteAllText(file, $"import {{ ModelMetaData }} from \"@trifenix/mdm\"; \nexport const mdm:ModelMetaData = {json} as ModelMetaData");
                      return(true);
                  } }
            });;


            // genera el json con datos
        }