Esempio n. 1
0
        /// <summary>
        /// Deletes the list.
        /// </summary>
        /// <param name="listId">The list identifier.</param>
        /// <param name="tenantId">The tenant identifier.</param>
        public override void DeleteList(string listId, string tenantId)
        {
            var tenantFolder      = Directory.EnumerateDirectories(ListFolder).First(path => path.EndsWith(tenantId));
            var listMetadataFiles = Directory.GetFiles(tenantFolder, $"*.{ListMetaDataExtension}");

            foreach (var file in listMetadataFiles)
            {
                var metadata = ListMetadata.DeserializeFromFile(file);

                if (metadata.ListId != listId)
                {
                    continue;
                }

                File.Delete(Path.Combine(tenantFolder, metadata.Location));
                File.Delete(file);

                break;
            }
        }
Esempio n. 2
0
        public override void SaveList(List list)
        {
            var existingListMetadata = new ListMetadata();
            var existingMetadataFile = string.Empty;

            var tenantFolder = Directory.EnumerateDirectories(ListFolder).FirstOrDefault(path => path.EndsWith(list.TenantId));

            if (tenantFolder == null)
            {
                tenantFolder = Path.Combine(ListFolder, list.TenantId);
                Directory.CreateDirectory(tenantFolder);
            }
            else
            {
                var listMetadataFiles = Directory.GetFiles(tenantFolder, $"*.{ListMetaDataExtension}");

                foreach (var file in listMetadataFiles)
                {
                    var metadata = ListMetadata.DeserializeFromFile(file);

                    if (metadata.ListId != list.ListId)
                    {
                        continue;
                    }

                    existingListMetadata = metadata;
                    existingMetadataFile = file;

                    break;
                }
            }

            var invalidFilenameCharacters = new Regex("[\\\\/:*?\"<>|]");
            var newListLoaded             = list.FileData.Length > 0;
            var existingMetadata          = existingListMetadata.ListId != null;
            var newMetaData = existingListMetadata.Name != list.Name ||
                              existingListMetadata.Description != list.Description ||
                              existingListMetadata.Separator != list.Separator ||
                              existingListMetadata.Location != $"{invalidFilenameCharacters.Replace(list.Name, "")}_{list.ListId}.{ListExtension}";

            var listMetadata = new ListMetadata
            {
                ListId      = list.ListId,
                Name        = list.Name,
                Description = list.Description,
                Location    = newListLoaded ?
                              $"{invalidFilenameCharacters.Replace(list.Name, "")}_{list.ListId}.{ListExtension}" :
                              existingListMetadata.Location,
                Type        = TranslateMetaType(list.Function),
                Separator   = list.Separator,
                UpdatedBy   = "MaritzCX",
                LastUpdated = DateTime.UtcNow
            };

            if (newListLoaded)
            {
                if (existingMetadata)
                {
                    File.Delete(Path.Combine(tenantFolder, existingListMetadata.Location));
                }

                File.WriteAllBytes(Path.Combine(tenantFolder, listMetadata.Location ?? $"missing_{listMetadata.ListId}"), list.FileData);
            }

            if (newMetaData)
            {
                if (existingMetadata)
                {
                    File.Delete(existingMetadataFile);
                }

                listMetadata.SerializeToFile(Path.Combine(tenantFolder, $"{invalidFilenameCharacters.Replace(list.Name, "")}_{list.ListId}.{ListMetaDataExtension}"));
            }
        }