コード例 #1
0
        /// <summary>
        /// Check all Licenses for eligible Phone Activation and prompt for the Activation Code
        /// </summary>
        /// <param name="licenses">List of All Licenses</param>
        /// <param name="window">Active GUI Window</param>
        /// <returns>Activation Result of all Licenses</returns>
        private static string PhoneActivationQuery(LicenseList licenses, IWin32Window window)
        {
            using (StringWriter output = new StringWriter())
            {
                // Get Unactivated Licenses
                List <LicenseInstance> licenseFilter = licenses.GetListUnactivated();

                // Remove KMS Licenses
                foreach (LicenseInstance license in licenses.GetListKMS())
                {
                    if (licenseFilter.Contains(license))
                    {
                        licenseFilter.Remove(license);
                    }
                }

                // Remove Unlicensed Licenses
                foreach (LicenseInstance license in licenses.GetListUnlicensed())
                {
                    if (licenseFilter.Contains(license))
                    {
                        licenseFilter.Remove(license);
                    }
                }

                // Activate Each License and Save ConfirmationID
                output.WriteLine("---Processing--------------------------");
                output.Write("----------------------------------------");

                // Return if No Licenses are Applicable
                if (licenseFilter.Count == 0)
                {
                    output.WriteLine();
                    output.Write("<No applicable products detected>" + Environment.NewLine + "----------------------------------------");
                    return(output.ToString());
                }

                // Phone Activate All Licenses
                foreach (LicenseInstance license in licenseFilter)
                {
                    // Set Activation Success Flag
                    bool success = false;

                    // Get Confirmation ID
                    string currentCID = AskForConfirmationID(license.OfflineInstallationID, window);
                    if (String.IsNullOrWhiteSpace(currentCID))
                    {
                        output.WriteLine();
                        output.Write("Blank or invalid Confirmation ID!" + Environment.NewLine + "----------------------------------------");
                        continue;
                    }

                    output.WriteLine();
                    output.WriteLine("Installed product key detected - attempting to activate the following product:");
                    output.WriteLine("Name: " + license.LicenseName);
                    output.WriteLine("Description: " + license.LicenseDescription);
                    output.WriteLine("SKU ID: " + license.SKUID);
                    output.WriteLine("Last 5 characters of installed product key: " + license.PartialProductKey);

                    if (licenses is LicenseListOffice)
                    {
                        success = PhoneActivationOffice(currentCID, license.OfflineInstallationID, license.SKUID);
                    }
                    else if (licenses is LicenseListWindows)
                    {
                        success = PhoneActivationWindows(currentCID, license.OfflineInstallationID, license.SKUID);
                    }

                    // Check if Successful Activation
                    if (success)
                    {
                        SaveConfirmationID(license.OfflineInstallationID, currentCID);
                        output.Write("<Product activation successful>" + Environment.NewLine + "----------------------------------------");
                    }
                    else
                    {
                        output.Write("<Product activation failed>" + Environment.NewLine + "----------------------------------------");
                    }
                }

                return(output.ToString());
            }
        }