Esempio n. 1
0
        public Task <MappingContent> CreateMapping(string templateName, string mappingName, Stream contents)
        {
            if (string.IsNullOrEmpty(templateName))
            {
                throw new ArgumentNullException(nameof(templateName));
            }
            if (string.IsNullOrEmpty(mappingName))
            {
                throw new ArgumentNullException(nameof(mappingName));
            }
            if (contents == null || contents.Length == 0)
            {
                throw new ArgumentNullException(nameof(contents));
            }

            var templateVersion = GetLatestTemplateVersion(templateName);

            if (templateVersion == null)
            {
                throw new ArgumentException($"Template {templateName} not found.");
            }
            var mappingFileName = $"{templateName}_{templateVersion}_{mappingName}_{DateTime.Now.Ticks}.xlsm";

            WriteContents(MappingsFolder, mappingFileName, contents);
            var result = ContentItemFactory.BuildMapping(MappingsFolder, mappingFileName, contents);

            return(Task.FromResult(result));
        }
Esempio n. 2
0
        public MappingContent GetLatestMapping(string templateName, string templateVersion, string mappingName)
        {
            if (string.IsNullOrEmpty(templateName))
            {
                throw new ArgumentNullException(nameof(templateName));
            }
            if (string.IsNullOrEmpty(mappingName))
            {
                throw new ArgumentNullException(nameof(mappingName));
            }

            if (string.IsNullOrEmpty(templateVersion))
            {
                templateVersion = GetLatestTemplateVersion(templateName);
            }
            if (string.IsNullOrEmpty(templateVersion))
            {
                throw new ArgumentNullException(nameof(templateName));
            }

            var mappingVersion = GetLatestMappingVersion(templateName, templateVersion, mappingName);

            if (mappingVersion == null)
            {
                return(null);
            }

            var mappingFileName = $"{templateName}_{templateVersion}_{mappingName}_{mappingVersion}.xlsm";
            var contents        = ReadContents(MappingsFolder, mappingFileName);

            return(ContentItemFactory.BuildMapping(MappingsFolder, mappingFileName, contents));
        }
Esempio n. 3
0
        public Task <MappingContent> GetMapping(string templateName, string templateVersion, string mappingName, string mappingVersion)
        {
            if (string.IsNullOrEmpty(templateName))
            {
                throw new ArgumentNullException(nameof(templateName));
            }
            if (string.IsNullOrEmpty(mappingName))
            {
                throw new ArgumentNullException(nameof(mappingName));
            }

            var fullName = Directory.GetFiles(MappingsFolder, $"{templateName}_{templateVersion ?? "*"}_{mappingName}_{mappingVersion ?? "*"}.xlsm")
                           .OrderByDescending(o => o)
                           .FirstOrDefault();
            MappingContent result = null;

            if (fullName != null && File.Exists(fullName))
            {
                result = ContentItemFactory.BuildMapping(fullName, ReadContents(fullName));
            }
            return(Task.FromResult(result));
        }
Esempio n. 4
0
        public IEnumerable <MappingContentSummary> GetMappings(string templateName, string templateVersion, string mappingName = null)
        {
            var mappings = Directory.GetFiles(MappingsFolder, $"{templateName ?? "*"}_{templateVersion ?? "*"}_{mappingName ?? "*"}_*.xlsm")
                           .Select(f => new { FullName = f, NameParts = Path.GetFileNameWithoutExtension(f).Split('_', 4) })
                           .Select(a => new { a.FullName, TemplateName = a.NameParts[0], TemplateVersion = a.NameParts[1], Name = a.NameParts[2], Version = a.NameParts[3] });

            if (mappingName == null)
            {
                return(mappings.GroupBy(a => a.Name)
                       .Select(ag => new { Name = ag.Key, Data = ag.OrderByDescending(o => o.Version).First() })
                       .OrderBy(a => a.Name).ThenBy(a => a.Data.Version)
                       .ToList()
                       .Select(a => ContentItemFactory.BuildMapping(a.Data.FullName, ReadContents(a.Data.FullName))));
            }
            else
            {
                return(mappings
                       .OrderBy(a => a.Version)
                       .ToList()
                       .Select(a => ContentItemFactory.BuildMapping(a.FullName, ReadContents(a.FullName))));
            }
        }