Exemplo n.º 1
0
        private static LicenseBase ParseLicensesAll(List <TokenEntry> tokens)
        {
            LicenseBase la = ParseLicense(tokens);

            if ((tokens.Count > 0) && (tokens[0].Token == LicenseToken.And))
            {
                var lic = new List <LicenseBase>()
                {
                    la
                };

                while ((tokens.Count > 0) && (tokens[0].Token == LicenseToken.And))
                {
                    tokens.RemoveAt(0);

                    lic.Add(ParseLicense(tokens));
                }

                return(new LicenseAll(lic.ToArray()));
            }
            else
            {
                return(la);
            }
        }
Exemplo n.º 2
0
        private static string PrintLicense(LicenseBase license, bool humanReadable)
        {
            if (license is LicenseAll)
            {
                List <string> outputs = (license as LicenseAll).Licenses.Select(l =>
                {
                    string output = PrintLicense(l, humanReadable);
                    if (l is LicenseAny && !string.IsNullOrEmpty(output))
                    {
                        output = "(" + output + ")";
                    }
                    return(output);
                }
                                                                                ).ToList();

                // If two licenses are required (&) and one of them is "secret" (not printed), then the other one should not be printed either.
                // For example: KS8000A&{BenchVue} should yield no output, as {BenchVue} is hidden and KS8000A will not work on its own.
                if (outputs.Any(s => string.IsNullOrEmpty(s)))
                {
                    return("");
                }
                else
                {
                    return(string.Join(humanReadable ? " and " : "&", outputs));
                }
            }
            else if (license is LicenseAny)
            {
                return(string.Join(humanReadable ? " or " : "|", (license as LicenseAny).Licenses.Select(l =>
                {
                    string output = PrintLicense(l, humanReadable);
                    if (l is LicenseAll && !string.IsNullOrEmpty(output))
                    {
                        output = "(" + output + ")";
                    }
                    return output;
                }
                                                                                                         ).Where(x => x != "")));
            }
            else if (license is LicenseRequired)
            {
                string featureSeed = (license as LicenseRequired).FeatureSeed;

                if (humanReadable && featureSeed.Contains("-INT")) // hide -INT licenses only when printing to the user, when printing to an xml file we need to keep the int license
                {
                    return("");
                }
                else
                {
                    return(featureSeed);
                }
            }

            return("");
        }
Exemplo n.º 3
0
        private static LicenseBase Prune(LicenseBase real)
        {
            if (real is LicenseAll)
            {
                var all = (real as LicenseAll).Licenses.Select(Prune).ToArray();

                if (all.Any(l => l == null))
                {
                    return(null);
                }

                all = all.Where(l => !(l is LicenseProcess)).ToArray();

                if (all.Length == 1)
                {
                    return(all.First());
                }
                else if (all.Length == 0)
                {
                    return(null);
                }
                else
                {
                    return(new LicenseAll(all));
                }
            }
            else if (real is LicenseAny)
            {
                var all = (real as LicenseAny).Licenses.Select(Prune).Where(x => x != null).ToArray();

                if (all.OfType <LicenseProcess>().Any())
                {
                    return(all.OfType <LicenseProcess>().First());
                }

                if (all.Length == 1)
                {
                    return(all.First());
                }
                else if (all.Length == 0)
                {
                    return(null);
                }
                else
                {
                    return(new LicenseAny(all));
                }
            }
            else if (real is LicenseProcess)
            {
                if ((real as LicenseProcess).ProcessName.ToLowerInvariant().Contains("keysight.opentap"))
                {
                    return(real);
                }
                else
                {
                    return(null);
                }
            }

            return(real);
        }