Exemple #1
0
        /// <summary>
        /// Make the supplied Promotion Path "Unused" by looping through the Promotion Group Shares in the list
        /// </summary>
        /// <param name="promotionItemRelativePath">The relative pathname within a Promotion Group i.e. without drive specifier</param>
        /// <returns></returns>
        static bool MakeUnused(PromotionGroupDetails promotionGroupDetails, string promotionItemRelativePath)
        {
            // Assume success unless something fails
            bool success = true;

            // Tidy up the entry and, if necessary, convert to a Windows suitable format
            promotionItemRelativePath = promotionItemRelativePath.Replace("/", "\\");
            // No leading or trailing backslashes
            promotionItemRelativePath = promotionItemRelativePath.Trim(new char[] { '\\' });

            string promotionGroupPath = promotionGroupDetails.PromotionGroupSharePath;

            string sourceFullPath = Path.Combine(promotionGroupPath, promotionItemRelativePath);

            if (File.Exists(sourceFullPath))
            {
                bool fileSuccess = MoveFile(promotionGroupPath, promotionItemRelativePath);
                if (!fileSuccess)
                {
                    Console.WriteLine("On Promotion Path {0} move of file \"{1}\" failed",
                                      promotionGroupPath, promotionItemRelativePath);
                }
                success = fileSuccess && success;
            }
            else if (Directory.Exists(sourceFullPath))
            {
                bool dirSuccess = MoveDirectory(promotionGroupPath, promotionItemRelativePath);
                if (!dirSuccess)
                {
                    Console.WriteLine("On Promotion Path {0} move of directory \"{1}\" failed",
                                      promotionGroupPath, promotionItemRelativePath);
                }
                success = dirSuccess && success;
            }
            else
            {
                // A non-existent item still represents a successful "move"
                Console.WriteLine("    Item \"{0}\" does not exist", sourceFullPath);
            }

            return(success);
        }
Exemple #2
0
        static int Main(string[] args)
        {
            int error = 1;

            if (args.Length < 2)
            {
                Console.WriteLine();
                Console.WriteLine("Usage: MakeUnused PromotionGroupName ItemRelativePath|@FilenameList {ItemRelativePath|@FilenameList ...}");
            }
            else
            {
                // Sufficient arguments

                string selectedPromotionGroup = args[0];

                if (!_PromotionGroupDetailsSortedDictionary.Keys.Contains(selectedPromotionGroup))
                {
                    Console.WriteLine();
                    Console.WriteLine("Promotion Group \"{0}\" does not exist", selectedPromotionGroup);
                }
                else
                {
                    // Selected Promotion Group exists

                    Console.WriteLine();
                    Console.WriteLine("Selected Promotion Group is {0}", selectedPromotionGroup);

                    PromotionGroupDetails selectedPromotionGroupDetails = _PromotionGroupDetailsSortedDictionary[selectedPromotionGroup];

                    // Assume overall success unless otherwise determined
                    error = 0;

                    for (int argId = 1; argId < args.Length; ++argId)
                    {
                        // Work out whether the supplied argument is the name of a file to be made unused, or, a file containing a list of files
                        if (!args[argId].StartsWith("@"))
                        {
                            // A filename or directory name

                            string promotionItemRelativePath = args[argId].Trim();

                            if (MakeUnused(selectedPromotionGroupDetails, promotionItemRelativePath))
                            {
                                Console.WriteLine();
                                Console.WriteLine("Making unused of \"{0}\" succeeded", promotionItemRelativePath);
                            }
                            else
                            {
                                Console.WriteLine();
                                Console.WriteLine("Making unused of \"{0}\" failed", promotionItemRelativePath);
                                error = 1;
                            }
                        } // A filename or directory name
                        else
                        {
                            // A file containing a list of files

                            // Skip the "@" symbol
                            string inputFilename = args[argId].Substring(1);

                            inputFilename = Path.GetFullPath(inputFilename);

                            if (!File.Exists(inputFilename))
                            {
                                Console.WriteLine("File \"{0}\" does not exist", inputFilename);
                            }
                            else
                            {
                                // Input file exists
                                bool success = true;

                                Console.WriteLine();

                                using (StreamReader fileInput = new StreamReader(inputFilename))
                                {
                                    string line = null;
                                    while ((line = fileInput.ReadLine()) != null)
                                    {
                                        string listEntry = line;

                                        // Trim all white space (tabs and spaces)
                                        listEntry = listEntry.Trim();

                                        // Skip lines beginning with a hash character
                                        if ((listEntry.Length > 0) && (listEntry[0] != '#'))
                                        {
                                            success = MakeUnused(selectedPromotionGroupDetails, listEntry) && success;
                                        }
                                    } // while
                                }

                                if (success)
                                {
                                    Console.WriteLine();
                                    Console.WriteLine("Making unused from files listed in \"{0}\" succeeded", inputFilename);
                                }
                                else
                                {
                                    Console.WriteLine();
                                    Console.WriteLine("Making unused from files listed in \"{0}\" failed", inputFilename);
                                    error = 1;
                                }
                            } // Input file exists
                        }     // A file containing a list of files
                    }         // for
                }             // Selected Promotion Group exists
            }                 // Sufficient arguments

            return(error);
        }