Ejemplo n.º 1
0
        public static void Delete(IStreamProvider streamProvider, string tableRootPath)
        {
            // Delete metadata first (the main marker we use to detect table presence)
            streamProvider.Delete(Path.Combine(tableRootPath, MetadataFileName));

            // Delete the table
            streamProvider.DeleteWithRetries(tableRootPath);
        }
        public static void Clean(this IStreamProvider streamProvider, bool reallyDelete, DateTime cutoff = default(DateTime))
        {
            // By default, keep data from the last week (so Now, Yesterday, and Last Week 'as of' data is all available)
            if (cutoff == default(DateTime))
            {
                cutoff = DateTime.UtcNow.AddDays(-8);
            }

            // Remove Sources and Tables older than the cutoff
            ItemVersions currentVersions;
            int          countLeft;

            foreach (string tableName in streamProvider.Tables())
            {
                // Find all Source versions
                currentVersions = streamProvider.ItemVersions(LocationType.Source, tableName);
                countLeft       = currentVersions.Versions.Count;

                // Delete ones older than the cutoff, keeping the last three
                foreach (var version in currentVersions.Versions)
                {
                    if (version.AsOfDate < cutoff)
                    {
                        if (countLeft <= 3)
                        {
                            break;
                        }
                        countLeft--;

                        Trace.WriteLine($"DELETE {version.Path}");
                        if (reallyDelete)
                        {
                            // Delete the source
                            streamProvider.DeleteWithRetries(version.Path);
                            version.LocationType = LocationType.Table;

                            // Delete the matching table, if found
                            streamProvider.DeleteWithRetries(version.Path);
                        }
                    }
                }

                // Find all Table versions
                currentVersions = streamProvider.ItemVersions(LocationType.Table, tableName);
                countLeft       = currentVersions.Versions.Count;

                // Delete ones older than the cutoff, keeping the last three
                foreach (var version in currentVersions.Versions)
                {
                    if (version.AsOfDate < cutoff)
                    {
                        if (countLeft <= 3)
                        {
                            break;
                        }
                        countLeft--;

                        Trace.WriteLine($"DELETE {version.Path}");
                        if (reallyDelete)
                        {
                            streamProvider.DeleteWithRetries(version.Path);
                        }
                    }
                }
            }
        }