Ejemplo n.º 1
0
        /// <summary>
        /// Prints a user-friendly message explaining how to use the program.
        /// </summary>
        /// <param name="caches">The caches the program is using.</param>
        private static void Usage(CacheState caches)
        {
            string containers = string.Empty;
            foreach (ItemCacheContainer container in caches.GetAllContainers)
            {
                containers += container.ToString() + " | ";
            }

            containers += " *";

            Console.WriteLine("Usage: ItemCacheTool <command> <cache> <container> [<date> | <item hash>]");
            Console.WriteLine("\t <command> = Check | Cleanup | Compare | Delete | List | Status");
            Console.WriteLine("\t <cache> = Cloud | Local | *");
            Console.WriteLine("\t <container> = {0}", containers);
            Console.WriteLine("\t [<date> | <item hash>] = specifies item(s) to delete.");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Program entry point.
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        private static void Main(string[] args)
        {
            CacheState caches = new CacheState();
            string query;
            IItemCache[] queriedCaches;
            ItemCacheContainer[] queriedContainers;
            string queriedItems;
            DateTimeOffset queriedDate;

            // -
            // Default values.
            // This corresponds to "status * *".
            // -
            query = "status";
            queriedCaches = caches.GetAllCaches;
            queriedContainers = caches.GetAllContainers;
            queriedItems = string.Empty;
            queriedDate = DateTimeOffset.MinValue;

            // -
            // Parse arguments.
            // -
            if (args.Length != 0)
            {
                if (args.Length != 3)
                {
                    if (args.Length == 4)
                    {
                        if (!DateTimeOffset.TryParse(args[3], out queriedDate))
                        {
                            queriedItems = args[3];
                        }
                    }
                    else
                    {
                        Usage(caches);
                        return;
                    }
                }

                query = args[0];
                queriedCaches = caches.ParseCacheName(args[1]);
                queriedContainers = caches.ParseContainerName(args[2]);

                if ((queriedCaches == null) || (queriedContainers == null))
                {
                    Usage(caches);
                    return;
                }
            }

            // -
            // Process request.
            // -
            switch (query)
            {
                case "list":
                case "List":
                    {
                        CacheStatus(queriedCaches, queriedContainers, true);
                        break;
                    }

                case "compare":
                case "Compare":
                    {
                        if (queriedCaches.Length < 2)
                        {
                            Console.WriteLine("Error: can't compare fewer than two caches!");
                            Usage(caches);
                            return;
                        }

                        CompareCacheContainers(queriedCaches, queriedContainers);
                        break;
                    }

                case "status":
                case "Status":
                    {
                        CacheStatus(queriedCaches, queriedContainers, false);
                        break;
                    }

                case "delete":
                case "Delete":
                    {
                        if (args.Length < 4)
                        {
                            Console.WriteLine("Error: missing argument.  Need date earlier than or specific item(s) to delete.");
                            Usage(caches);
                            return;
                        }

                        if (queriedDate == DateTimeOffset.MinValue)
                        {
                            DeleteItems(queriedCaches, queriedContainers, queriedItems);
                        }
                        else
                        {
                            DeleteItems(queriedCaches, queriedContainers, queriedDate);
                        }

                        break;
                    }

                case "check":
                case "Check":
                    {
                        CheckResults(queriedCaches, false);
                        break;
                    }

                case "cleanup":
                case "Cleanup":
                    {
                        CheckResults(queriedCaches, true);
                        break;
                    }

                case "dump":
                case "Dump":
                    {
                        DumpItems(queriedCaches, queriedContainers, queriedItems);
                        break;
                    }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Program entry point.
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        private static void Main(string[] args)
        {
            CacheState caches = new CacheState();
            string     query;

            IItemCache[]         queriedCaches;
            ItemCacheContainer[] queriedContainers;
            string         queriedItems;
            DateTimeOffset queriedDate;

            // -
            // Default values.
            // This corresponds to "status * *".
            // -
            query             = "status";
            queriedCaches     = caches.GetAllCaches;
            queriedContainers = caches.GetAllContainers;
            queriedItems      = string.Empty;
            queriedDate       = DateTimeOffset.MinValue;

            // -
            // Parse arguments.
            // -
            if (args.Length != 0)
            {
                if (args.Length != 3)
                {
                    if (args.Length == 4)
                    {
                        if (!DateTimeOffset.TryParse(args[3], out queriedDate))
                        {
                            queriedItems = args[3];
                        }
                    }
                    else
                    {
                        Usage(caches);
                        return;
                    }
                }

                query             = args[0];
                queriedCaches     = caches.ParseCacheName(args[1]);
                queriedContainers = caches.ParseContainerName(args[2]);

                if ((queriedCaches == null) || (queriedContainers == null))
                {
                    Usage(caches);
                    return;
                }
            }

            // -
            // Process request.
            // -
            switch (query)
            {
            case "list":
            case "List":
            {
                CacheStatus(queriedCaches, queriedContainers, true);
                break;
            }

            case "compare":
            case "Compare":
            {
                if (queriedCaches.Length < 2)
                {
                    Console.WriteLine("Error: can't compare fewer than two caches!");
                    Usage(caches);
                    return;
                }

                CompareCacheContainers(queriedCaches, queriedContainers);
                break;
            }

            case "status":
            case "Status":
            {
                CacheStatus(queriedCaches, queriedContainers, false);
                break;
            }

            case "delete":
            case "Delete":
            {
                if (args.Length < 4)
                {
                    Console.WriteLine("Error: missing argument.  Need date earlier than or specific item(s) to delete.");
                    Usage(caches);
                    return;
                }

                if (queriedDate == DateTimeOffset.MinValue)
                {
                    DeleteItems(queriedCaches, queriedContainers, queriedItems);
                }
                else
                {
                    DeleteItems(queriedCaches, queriedContainers, queriedDate);
                }

                break;
            }

            case "check":
            case "Check":
            {
                CheckResults(queriedCaches, false);
                break;
            }

            case "cleanup":
            case "Cleanup":
            {
                CheckResults(queriedCaches, true);
                break;
            }

            case "dump":
            case "Dump":
            {
                DumpItems(queriedCaches, queriedContainers, queriedItems);
                break;
            }
            }
        }