Пример #1
0
 public List<KeyOperationResult> ExportDuplicatedCbr(Cbr cbr, string outputPath, string @operator)
 {
     var fileExt = Path.GetExtension(outputPath);
     if (!fileExt.EndsWith(XML, StringComparison.OrdinalIgnoreCase))
         throw new Exception("KeyProxy_CBRExportFormatNotSupported");
     try
     {
         string doc = SaveDuplicatedCbrToFile(cbr, outputPath);
         InsertExportLog(new KeyExportLog()
         {
             ExportTo = string.Empty,
             ExportType = Constants.ExportType.DuplicateCBR.ToString(),
             FileName = Path.GetFileName(outputPath),
             FileContent = doc,
             KeyCount = cbr.CbrKeys.Count(
                 k => k.ReasonCode == Constants.CBRAckReasonCode.DuplicateProductKeyId),
             IsEncrypted = false,
             CreateBy = @operator
         });
         return cbr.CbrKeys.Select(k => new KeyOperationResult()
         {
             Failed = false,
             Key = k.KeyInfo ?? new KeyInfo() { KeyId = k.KeyId }
         }).ToList();
     }
     catch (DirectoryNotFoundException ex)
     {
         ExceptionHandler.HandleException(ex);
         throw new DisException("Exception_FilePathNotFound");
     }
 }
Пример #2
0
        //offline CBR.ack
        public static DC.Cbr FromServiceContract(this ComputerBuildReportAck ack)
        {
            var cbr = new DC.Cbr()
            {
                MsReportUniqueId = ack.MSReportUniqueID,
                CbrUniqueId = ack.CustomerReportUniqueID,
                SoldToCustomerId = ack.SoldToCustomerID,
                ReceivedFromCustomerId = ack.ReceivedFromCustomerID,
                MsReceivedDateUtc = ack.MSReceivedDateUTC,
                CbrAckFileTotal = ack.CBRAckFileTotal,
                CbrAckFileNumber = ack.CBRAckFileNumber,
                CbrKeys = new List<DC.CbrKey>(),
            };

            ack.SuccessfulValidations.ToList().ForEach(r =>
                cbr.CbrKeys.Add(new DC.CbrKey()
                {
                    CustomerReportUniqueId = cbr.CbrUniqueId,
                    KeyId = r.ProductKeyID,
                    HardwareHash = r.HardwareHash,
                    ReasonCode = DC.Constants.CBRAckReasonCode.ActivationEnabled,
                }));

            ack.FailedValidations.ToList().ForEach(r =>
                cbr.CbrKeys.Add(new DC.CbrKey()
                {
                    CustomerReportUniqueId = cbr.CbrUniqueId,
                    KeyId = r.ProductKeyID,
                    HardwareHash = r.HardwareHash,
                    ReasonCode = r.ReasonCode,
                    ReasonCodeDescription = r.ReasonCodeDescription,
                }));

            return cbr;
        }
 public ExportDuplicateCBRNotificationView(Cbr duplicateCBR, IKeyProxy keyProxy)
 {
     InitializeComponent();
     VM = new ExportDuplicateCBRNotificationViewModel(duplicateCBR, keyProxy);
     VM.View = this;
     this.DataContext = VM;
 }
Пример #4
0
 public void DeleteCbrsDuplicated(Cbr cbr)
 {
     using (var context = GetContext())
     {
         var delCbr = context.CbrsDuplicated.FirstOrDefault(c => c.CbrUniqueId == cbr.CbrUniqueId);
         context.CbrsDuplicated.Remove(delCbr);
         context.SaveChanges();
     }
 }
Пример #5
0
 public void InsertCbrAndCbrKeys(Cbr cbr, KeyStoreContext context = null)
 {
     UsingContext(ref context, () =>
     {
         context.Configuration.AutoDetectChangesEnabled = false;
         cbr.CreatedDateUtc = cbr.ModifiedDateUtc = DateTime.UtcNow;
         context.Cbrs.Add(cbr);
         foreach (var key in cbr.CbrKeys)
         {
             context.CbrKeys.Add(key);
         }
         context.SaveChanges();
     });
 }
Пример #6
0
        public void UpdateCbrAfterAckRetrieved(Cbr cbr, bool isDuplicated = false, KeyStoreContext context = null)
        {
            Cbr dbCbr = cbrRepository.GetCbr(cbr.CbrUniqueId);

            if (dbCbr == null)
                throw new DisException("Failed to get data from database to match the contents of this file!");
            if (dbCbr.CbrStatus == CbrStatus.Completed && !isDuplicated)
                throw new DisException("CBRs ack has got and completed!");
            if (isDuplicated)
            {
                var duplicatedLog = cbrRepository.GetDuplicatedCbr(cbr.CbrUniqueId);
                if (duplicatedLog == null)
                    throw new DisException("This duplicated cbr is not logged in the system !");
            }

            dbCbr.MsReportUniqueId = cbr.MsReportUniqueId;
            dbCbr.MsReceivedDateUtc = cbr.MsReceivedDateUtc;
            dbCbr.CbrAckFileTotal = cbr.CbrAckFileTotal;
            dbCbr.CbrAckFileNumber = cbr.CbrAckFileNumber;
            dbCbr.ModifiedDateUtc = DateTime.UtcNow;
            dbCbr.CbrStatus = CbrStatus.Completed;
            if (dbCbr.CbrKeys != null && dbCbr.CbrKeys.Count > 0)
            {
                Func<CbrKey, CbrKey, CbrKey> updateCbrKey = (k1, k2) =>
                {
                    k1.ReasonCode = k2.ReasonCode;
                    k1.ReasonCodeDescription = k2.ReasonCodeDescription;
                    return k1;
                };
                var update = (from db in dbCbr.CbrKeys
                              join key in cbr.CbrKeys on db.KeyId equals key.KeyId
                              select updateCbrKey(db, key)).ToList();
            }
            cbrRepository.UpdateCbrAck(dbCbr, isDuplicated, context);
        }
Пример #7
0
        public Cbr GenerateCbr(List<KeyInfo> keys, bool isExport = false, KeyStoreContext context = null)
        {
            if (keys.Count == 0 || keys.Count > Constants.BatchLimit)
                throw new ArgumentOutOfRangeException("Keys are invalid to generate CBR.");
            string soldTo = keys.First().SoldToCustomerId;
            if (keys.Any(k => k.SoldToCustomerId != soldTo))
                throw new ApplicationException("Keys are not sold to the same customer.");
            string shipTo = keys.First().ShipToCustomerId;
            if (keys.Any(k => k.ShipToCustomerId != shipTo))
                throw new ApplicationException("Keys are not shipped to the same customer.");

            Guid customerReportId = Guid.NewGuid();
            Cbr cbr = new Cbr()
            {
                CbrUniqueId = customerReportId,
                CbrStatus = (isExport ? CbrStatus.Reported : CbrStatus.Generated),
                SoldToCustomerId = soldTo,
                ReceivedFromCustomerId = shipTo,
                CbrKeys = keys.Select(k => new CbrKey()
                {
                    CustomerReportUniqueId = customerReportId,
                    KeyId = k.KeyId,
                    HardwareHash = k.HardwareHash,
                    OemOptionalInfo = k.OemOptionalInfo.ToString(),
                }).ToList()
            };
            cbrRepository.InsertCbrAndCbrKeys(cbr, context = null);
            return cbr;
        }
Пример #8
0
 public void UpdateCbrsDuplicated(Cbr cbr)
 {
     using (var context = GetContext()) {
         context.CbrsDuplicated.Where(c => c.CbrUniqueId == cbr.CbrUniqueId).ToList()
             .ForEach(c => c.IsExported = true);
         context.SaveChanges();
     }
 }
Пример #9
0
 private void UpdateCbr(KeyStoreContext context, Cbr cbr)
 {
     context.Cbrs.Attach(cbr);
     context.Entry(cbr).State = EntityState.Modified;
 }
Пример #10
0
        public void UpdateCbrAfterReported(Cbr cbr)
        {
            if (!cbr.MsReportUniqueId.HasValue || cbr.MsReportUniqueId == Guid.Empty)
                throw new ArgumentException("CBR is invalid.");

            cbr.CbrStatus = CbrStatus.Reported;
            cbrRepository.UpdateCbr(cbr);
        }
Пример #11
0
 public void UpdateKeysAfterReportBinding(Cbr cbr)
 {
     List<KeyInfo> keys = GetKeysInDb(cbr.CbrKeys.Select(k => k.KeyId));
     if (keys != null && keys.Count > 0)
     {
         foreach (KeyInfo key in keys)
         {
             try
             {
                 key.UlsReportingBoundKeyToMs();
             }
             catch (Exception ex)
             {
                 ExceptionHandler.HandleException(ex);
             }
         }
         keyRepository.UpdateKeys(keys, false, null);
     }
 }
Пример #12
0
        public List<KeyOperationResult> UpdateKeysAfterRetrieveCbrAck(Cbr cbr, bool isDuplicated = false, KeyStoreContext context = null)
        {
            var keys = cbr.CbrKeys;
            List<KeyInfo> keysInDb = GetKeysInDb(keys.Select(k => k.KeyId).ToArray());
            if (keysInDb == null || keysInDb.Count == 0)
                throw new ApplicationException("Update keys after retrieve cbr ack are not found.");

            List<KeyOperationResult> results = keys.Select(key => GenerateKeyOperationResult(
                 new KeyInfo()
                 {
                     KeyId = key.KeyId,
                     KeyState = (key.ReasonCode == Constants.CBRAckReasonCode.ActivationEnabled ? KeyState.ActivationEnabled : KeyState.ActivationDenied)
                 },
                keysInDb, (k1, k2) => ValidateKeyAfterRetrieveAck(k1, k2))).ToList();

            List<KeyInfo> validKeys = results.Where(r => !r.Failed).Select(r => r.KeyInDb ?? r.Key).ToList();
            foreach (KeyInfo key in validKeys)
            {
                try
                {
                    key.UlsReceivingCbrAck(keys.Single(k => k.KeyId == key.KeyId).ReasonCode == Constants.CBRAckReasonCode.ActivationEnabled, isDuplicated);
                }
                catch (Exception ex)
                {
                    ExceptionHandler.HandleException(ex);
                    KeyOperationResult result = results.Single(r => r.Key.KeyId == key.KeyId);
                    result.Failed = true;
                    result.FailedType = KeyErrorType.StateInvalid;
                }
            }
            List<KeyInfo> keysToUpdate = results.Where(r => !r.Failed).Select(r => r.KeyInDb ?? r.Key).ToList();
            if (keysToUpdate.Count > 0)
            {
                keyRepository.UpdateKeys(keysToUpdate, false, null, false, null, context);
                //Insert key sync notification data
                InsertOrUpdateKeySyncNotifiction(keysToUpdate, context);
            }
            results.ForEach(k => k.Key.ProductKey = (k.KeyInDb == null ? null : k.KeyInDb.ProductKey));
            return results;
        }
Пример #13
0
        public static DC.Cbr FromServiceContract(this ComputerBuildReportRequest request)
        {
            var cbr = new DC.Cbr()
            {
                CbrUniqueId = request.CustomerReportUniqueID,
                SoldToCustomerId = request.SoldToCustomerID,
                ReceivedFromCustomerId = request.ReceivedFromCustomerID,
                CbrKeys = request.Bindings.Select(b=>b.FromServiceContract()).ToList(),
            };

            return cbr;
        }
Пример #14
0
 public void UpdateCbr(Cbr cbr)
 {
     using (var context = GetContext()) {
         cbr.ModifiedDateUtc = DateTime.UtcNow;
         UpdateCbr(context, cbr);
         context.SaveChanges();
     }
 }
Пример #15
0
 private string SaveCbrToFile(Cbr cbr, string outputPath)
 {
     Serializer.WriteToXml(cbr.ToBindingReport(), outputPath);
     string fileName = Path.GetFileName(outputPath);
     XmlDocument xDoc = new XmlDocument();
     xDoc.Load(outputPath);
     return xDoc.DocumentElement.OuterXml;
 }
Пример #16
0
 public void UpdateCbrWhenAckFailed(Cbr cbr)
 {
     cbr.CbrStatus = CbrStatus.Failed;
     cbrRepository.UpdateCbr(cbr);
 }
Пример #17
0
        public void UpdateCbrsAfterImported(Cbr cbr)
        {
            if (cbr == null)
                throw new ArgumentNullException("Key IDs cannot be empty.");

            cbrRepository.DeleteCbrsDuplicated(cbr);
        }
Пример #18
0
        public void UpdateCbrsAfterExported(Cbr cbr)
        {
            if (cbr == null)
                throw new ArgumentNullException("CBR cannot be empty.");

            cbrRepository.UpdateCbrsDuplicated(cbr);
        }
Пример #19
0
        public void UpdateCbrAck(Cbr cbr, bool IsDuplicateImport = false, KeyStoreContext context = null)
        {
            UsingContext(ref context, () =>
            {
                context.Configuration.AutoDetectChangesEnabled = false;
                UpdateCbr(context, cbr);

                foreach (CbrKey key in cbr.CbrKeys)
                {
                    context.CbrKeys.Attach(key);
                    context.Entry(key).State = EntityState.Modified;
                }
                if (cbr.CbrKeys.Any(k => k.ReasonCode == Constants.CBRAckReasonCode.DuplicateProductKeyId) && !IsDuplicateImport)
                {
                    context.CbrsDuplicated.Add(new CbrDuplicated()
                    {
                        CbrUniqueId = cbr.CbrUniqueId,
                        IsExported = false
                    });
                }
                if (IsDuplicateImport)
                {
                    var delCbr = context.CbrsDuplicated.FirstOrDefault(c => c.CbrUniqueId == cbr.CbrUniqueId);
                    context.CbrsDuplicated.Remove(delCbr);
                }
                context.Configuration.AutoDetectChangesEnabled = true;
            });
        }
Пример #20
0
 //export duplicated CBR
 public new List<KeyOperationResult> ExportDuplicatedCbr(Cbr cbr, string outputPath, string @operator)
 {
     var result = base.ExportDuplicatedCbr(cbr, outputPath, @operator);
     this.cbrManager.UpdateCbrsAfterExported(cbr);
     return result;
 }
Пример #21
0
 private string SaveDuplicatedCbrToFile(Cbr cbr, string outputPath)
 {
     //XNamespace ms = "http://schemas.ms.it.oem/digitaldistribution/2010/10";
     //XElement doc = new XElement(ms + "ComputerBuildReportAckResponse",
     //    new XElement(ms + "ComputerBuildReportAcks",
     //        from cbr in cbrs
     //        select new XElement(ms + "ComputerBuildReportAck",
     //            new XElement(ms + "MSReportUniqueID", cbr.CbrUniqueId),
     //            new XElement(ms + "CustomerReportUniqueID", cbr.CbrUniqueId),
     //            new XElement(ms + "MSReceivedDateUTC", cbr.MsReceivedDateUtc),
     //            new XElement(ms + "SoldToCustomerID", cbr.SoldToCustomerId),
     //            new XElement(ms + "ReceivedFromCustomerID", cbr.ReceivedFromCustomerId),
     //            new XElement(ms + "CBRAckFileTotal", cbr.CbrAckFileTotal),
     //            new XElement(ms + "CBRAckFileNumber", cbr.CbrAckFileNumber),
     //            new XElement(ms + "FailedValidations",
     //                from failedKey in cbr.CbrKeys.Where(k => k.ReasonCode == Constants.CBRAckReasonCode.DuplicateProductKeyId)
     //                select new XElement(ms + "FailedValidationResult",
     //                    new XElement(ms + "ProductKeyID", failedKey.KeyId),
     //                    new XElement(ms + "HardwareHash", failedKey.HardwareHash),
     //                    new XElement(ms + "ReasonCode", failedKey.ReasonCode),
     //                    new XElement(ms + "ReasonCodeDescription", failedKey.ReasonCodeDescription))))));
     //doc.Save(outputPath);
     Serializer.WriteToXml(cbr.ToBindingReport(), outputPath);
     string fileName = Path.GetFileName(outputPath);
     XmlDocument xDoc = new XmlDocument();
     xDoc.Load(outputPath);
     return xDoc.DocumentElement.OuterXml;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="duplicateCBRs"></param>
 /// <param name="keyProxy"></param>
 public ExportDuplicateCBRNotificationViewModel(Cbr duplicateCBRs, IKeyProxy keyProxy)
 {
     this.keyProxy = keyProxy;
     this.allCBR = duplicateCBRs;
     this.CBRCollection = new ObservableCollection<CbrKey>(allCBR.CbrKeys);
 }