Esempio n. 1
0
        /// <summary>
        /// Gets the module icon URL.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="moduleFilePath">The module file path.</param>
        /// <param name="metaTomlFilePath">The meta toml file path.</param>
        /// <returns></returns>
        private static string GetModuleIconUrl(ModuleReadModel module, string moduleFilePath, string metaTomlFilePath)
        {
            EnsureArg.IsNotNull(module);
            var iconUrl = string.Empty;

            var moduleFolder = FileReaderExtensions.GetSubDirectoryPath(moduleFilePath, module.Name);

            if (string.IsNullOrWhiteSpace(moduleFolder))
            {
                return(string.Empty);
            }

            var metaTomlFile = Path.Combine(moduleFolder, metaTomlFilePath);

            try
            {
                if (File.Exists(metaTomlFile))
                {
                    var tml = Toml.ReadFile(metaTomlFile, TomlFileReader.LoadLowerCaseTomlSettings());

                    var dict         = tml.ToDictionary();
                    var moduleValues = dict["module"];

                    if (moduleValues is Dictionary <string, object> )
                    {
                        var moduleFromToml = (Dictionary <string, object>)dict["module"];
                        if (moduleFromToml != null && (string)moduleFromToml["name"] == module.Name)
                        {
                            iconUrl = moduleFromToml["iconUrl"].ToString();

                            if (!iconUrl.IsPathUrl())
                            {
                                return(string.Empty);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                iconUrl = string.Empty;
            }

            return(iconUrl);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the proto files.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <returns></returns>
        public string GetProtoFiles(ModuleReadModel module)
        {
            EnsureArg.IsNotNull(module);

            string moduleFilePath = _moduleGitConnectionOptions.GitLocalFolder;
            var    moduleFolder   = FileReaderExtensions.GetSubDirectoryPath(moduleFilePath, module.Name);

            if (string.IsNullOrWhiteSpace(moduleFolder))
            {
                return(string.Empty);
            }

            var uuidFolder = FileReaderExtensions.GetSubDirectoryPath(moduleFolder, module.UUID);

            if (!string.IsNullOrWhiteSpace(uuidFolder))
            {
                foreach (var file in Directory.EnumerateFiles(uuidFolder, protoFileName))
                {
                    return(file);
                }
            }

            return(string.Empty);
        }
Esempio n. 3
0
        private async Task MergeDefaultValuesWithModuleAsync(string defaultValueFromTomlFile, ModuleReadModel module)
        {
            EnsureArg.IsNotNull(module);

            _logger.LogInformation($"{Prefix}: method name: {nameof(MergeDefaultValuesWithModuleAsync)} Getting proto file for {module.Name}");

            // get proto files for corresponding module and their uuid
            var protoFilePath = _moduleServiceManager.GetProtoFiles(module);

            _logger.LogInformation($"{Prefix}: method name: {nameof(MergeDefaultValuesWithModuleAsync)} Retrieved proto file for {module.Name}");
            if (!string.IsNullOrWhiteSpace(protoFilePath))
            {
                // get proto parsed messages from the proto files.
                var message = await _protoParser.GetCustomMessage(protoFilePath).ConfigureAwait(false);

                var formattedMessage = _customMessageParser.Format(message.Message);
                formattedMessage.Name = module.Name;

                _logger.LogInformation($"{Prefix}: method name: {nameof(MergeDefaultValuesWithModuleAsync)} Getting config values from default.toml file for {module.Name}");
                var configValues = GetConfigValues(defaultValueFromTomlFile, module.Name);

                _logger.LogInformation($"{Prefix}: method name: {nameof(MergeDefaultValuesWithModuleAsync)} Merging config values with protoparsed message for {module.Name}");
                var jsonModels = _moduleParser.MergeTomlWithProtoMessage(configValues, formattedMessage);
                module.Config = jsonModels;

                message.Message = null;
                message         = null;

                formattedMessage.ClearData(formattedMessage);
                formattedMessage = null;
            }
        }