コード例 #1
0
ファイル: Program.cs プロジェクト: yopichoi/qv-user-manager
        static void Main(string[] args)
        {
            var list    = "";
            var add     = "";
            var remove  = "";
            var docs    = "";
            var prefix  = "";
            var version = false;
            var help    = false;

            try
            {
                var p = new OptionSet {
                    { "l|list=", "List CALs, users or documents [{CAL|DMS|DOCS}]", v => list = v.ToLower() },
                    { "a|add=", "Add users or assign CALs [{CAL|DMS}]", v => add = v.ToLower() },
                    { "r|remove=", "Remove specified users or inactive CALs [{CAL|DMS}]", v => remove = v.ToLower() },
                    { "d|document=", "QlikView document(s) to perform actions on", v => docs = v.ToLower() },
                    { "p|prefix=", "Use specified prefix for all users and CALs", v => prefix = v },
                    { "V|version", "Show version information", v => version = v != null },
                    { "?|h|help", "Show usage information", v => help = v != null },
                };

                p.Parse(args);

                if (help || args.Length == 0)
                {
                    Console.WriteLine("Usage: qv-user-manager [options]");
                    Console.WriteLine("Handles QlikView CALs and DMS user authorizations.");
                    Console.WriteLine();
                    Console.WriteLine("Options:");
                    p.WriteOptionDescriptions(Console.Out);
                    Console.WriteLine();
                    Console.WriteLine("Options can be in the form -option, /option or --long-option");
                    return;
                }

                if (version)
                {
                    Console.WriteLine("qv-user-manager 20120118\n");
                    Console.WriteLine("This program comes with ABSOLUTELY NO WARRANTY.");
                    Console.WriteLine("This is free software, and you are welcome to redistribute it");
                    Console.WriteLine("under certain conditions.\n");
                    Console.WriteLine("Code: git clone git://github.com/braathen/qv-user-manager.git");
                    Console.WriteLine("Home: <https://github.com/braathen/qv-user-manager>");
                    Console.WriteLine("Bugs: <https://github.com/braathen/qv-user-manager/issues>");
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            // Split list of multiple documents
            var documents = new List <string>(docs.Split(new[] { ';', ',', '|', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));

            // Remove possible duplicate documents
            documents = documents.Distinct().ToList();

            var users = new List <string>();

            // Look for console redirection or piped data
            try
            {
                var isKeyAvailable = Console.KeyAvailable;
            }
            catch (InvalidOperationException)
            {
                string s;
                while ((s = Console.ReadLine()) != null)
                {
                    if (!s.StartsWith("#"))
                    {
                        users.Add(prefix + s.Trim());
                    }
                }
            }

            // Remove possible duplicate users
            users = users.Distinct().ToList();

            switch (remove)
            {
            case "dms":
                DocumentMetadataService.Remove(documents, users);
                break;

            case "cal":
                ClientAccessLicenses.Remove();
                break;
            }

            switch (add)
            {
            case "dms":
                DocumentMetadataService.Add(documents, users);
                break;

            case "cal":
                ClientAccessLicenses.Add(documents, users);
                break;
            }

            switch (list)
            {
            case "dms":
                DocumentMetadataService.List(documents);
                break;

            case "cal":
                ClientAccessLicenses.List();
                break;

            case "docs":
                DocumentMetadataService.DocInfo(documents);
                break;

            case "calinfo":
                ClientAccessLicenses.CalInfo();
                break;
            }

            Environment.ExitCode = (int)ExitCode.Success;
        }
コード例 #2
0
        static void Main(string[] args)
        {
            if (!VerifyServerConfig())
            {
                Environment.ExitCode = (int)ExitCode.Error;
                return;
            }

            var list    = "";
            var add     = "";
            var remove  = "";
            var docs    = "";
            var prefix  = "";
            var version = false;
            var help    = false;
            var days    = 30;

            try
            {
                var p = new OptionSet {
                    { "l|list=", "List CALs, users or documents [{CAL|DMS|DOCS}]", v => list = v.ToLower() },
                    { "a|add=", "Add users or assign CALs [{CAL|DMS}]", v => add = v.ToLower() },
                    { "r|remove=", "Remove specified users or inactive CALs [{CAL|DMS}]", v => remove = v.ToLower() },
                    { "D|days=", "Days of inactivity for CAL users. if combined with r CAL removes those who have been inactive for more than the stated amount of days.", v => days = Convert.ToInt16(v) },
                    { "d|document=", "QlikView document(s) to perform actions on", v => docs = v.ToLower() },
                    { "p|prefix=", "Use specified prefix for all users and CALs", v => prefix = v },
                    { "V|version", "Show version information", v => version = v != null },
                    { "?|h|help", "Show usage information", v => help = v != null },
                };

                p.Parse(args);

                if (help || args.Length == 0)
                {
                    Console.WriteLine("Usage: qv-user-manager [options]");
                    Console.WriteLine("Handles QlikView CALs and DMS user authorizations.");
                    Console.WriteLine();
                    Console.WriteLine("Options:");
                    p.WriteOptionDescriptions(Console.Out);
                    Console.WriteLine();
                    Console.WriteLine("Options can be in the form -option, /option or --long-option");
                    return;
                }

                if (version)
                {
                    Console.WriteLine("Forked version of qv-user-manager (20111028) from 20141013\n");
                    Console.WriteLine("This program comes with ABSOLUTELY NO WARRANTY.");
                    Console.WriteLine("This is free software, and you are welcome to redistribute it");
                    Console.WriteLine("under certain conditions. Find the original version at\n");
                    Console.WriteLine("Home: <https://github.com/braathen/qv-user-manager>");
                    Console.WriteLine("This fork: <https://github.com/johankristenson/qv-manager-11-mod>");
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            // Split list of multiple documents
            var documents = new List <string>(docs.Split(new[] { ';', ',', '|', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries));

            // Remove possible duplicate documents
            documents = documents.Distinct().ToList();

            var users = new List <string>();

            // Look for console redirection or piped data
            try
            {
                var isKeyAvailable = Console.KeyAvailable;
            }
            catch (InvalidOperationException)
            {
                string s;
                while ((s = Console.ReadLine()) != null)
                {
                    users.Add(prefix + s.Trim());
                }
            }

            // Remove possible duplicate users
            users = users.Distinct().ToList();

            switch (remove)
            {
            case "dms":
                DocumentMetadataService.Remove(documents, users);
                break;

            case "cal":
                Console.WriteLine("Removing CAls that have not been used for {0} days", days);
                ClientAccessLicenses.Remove(days);
                break;
            }

            switch (add)
            {
            case "dms":
                DocumentMetadataService.Add(documents, users);
                break;

            case "cal":
                ClientAccessLicenses.Add(documents, users);
                break;
            }

            switch (list)
            {
            case "dms":
                DocumentMetadataService.List(documents);
                break;

            case "cal":
                ClientAccessLicenses.List();
                break;

            case "docs":
                DocumentMetadataService.DocInfo(documents);
                break;

            case "calinfo":
                ClientAccessLicenses.CalInfo();
                break;
            }

            Environment.ExitCode = (int)ExitCode.Success;
        }