Example #1
0
        private List<KeyOperationResult> ReportKeysToUls(List<KeyInfo> keys)
        {
            if (!GetIsCentralizeMode())
                throw new ApplicationException("system is decentralize mode and it's invalid.");
            List<KeyOperationResult> results = new List<KeyOperationResult>();

            base.UpdateSyncState(keys, true);
            KeyInfoComparer comparer = new KeyInfoComparer();

            List<KeyInfo> failedKeys = ulsClient.ReportKeys(keys.Select(key => new KeyInfo(key.KeyState)
            {
                KeyId = key.KeyId,
                HardwareHash = key.HardwareHash,
                OemOptionalInfo = key.OemOptionalInfo,
                TrackingInfo = key.TrackingInfo,
            }).ToList());
            if (failedKeys != null && failedKeys.Count > 0)
                MessageLogger.LogSystemError("Report Failed",
                    string.Format("{0} cannot be reported.", string.Join(", ", failedKeys.Select(k => k.ProductKey).ToArray())));

            base.UpdateSyncState(keys, false);

            results.AddRange(failedKeys.Select(k => new KeyOperationResult()
            {
                Key = k,
                Failed = true,
                FailedType = KeyErrorType.SsIdInvalid
            }));

            List<KeyInfo> succeedKeys = keys.Where(k => !failedKeys.Contains(k, comparer)).ToList();
            base.UpdateKeysAfterReporting(succeedKeys);

            results.AddRange(succeedKeys.Select(k => new KeyOperationResult()
            {
                Key = k,
                Failed = false,
                FailedType = KeyErrorType.None
            }));

            return results;
        }
Example #2
0
        public List<KeyOperationResult> ReceiveBoundKeys(List<KeyInfo> keys, int fromSsId)
        {
            if (keys.Any(k => k.KeyState != KeyState.Bound))
                throw new ApplicationException("Received keys are invalid.");

            KeyInfoComparer comparer = new KeyInfoComparer();

            List<KeyInfo> succeedKeys = UpdateKeysAfterBeingReported(keys, fromSsId);
            return keys.Select(k => new KeyOperationResult()
            {
                Failed = !succeedKeys.Contains(k, comparer),
                Key = new KeyInfo() { KeyId = k.KeyId },
                FailedType = succeedKeys.Contains(k, comparer) ? KeyErrorType.None : KeyErrorType.SsIdInvalid
            }).ToList();
        }