Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
        //Import Return.Ack From MS
        public List<KeyOperationResult> ImportReturnAckKeys(string filePath, KeyStoreContext context = null)
        {
            if (!File.Exists(filePath))
                throw new ArgumentException("file path invalid!");

            ReturnAck returnAck = GetReturnKeyAckByFile(filePath);
            try
            {
                return ImportReturnAck(returnAck, context);
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                ExceptionHandler.HandleException(ex);
                throw new DisException("Exception_ImportFileInvalid");
            }
        }
Ejemplo n.º 3
0
        private KeyInfo GetKeyTransaction(KeySearchCriteria criteria)
        {
            KeyInfo key = null;

            bool failed = false;
            using (KeyStoreContext context = new KeyStoreContext(false))
            {
                ObjectContext oCtx = ((IObjectContextAdapter)context).ObjectContext;
                oCtx.Connection.Open();
                DbTransaction trans = oCtx.Connection.BeginTransaction(System.Data.IsolationLevel.Serializable);
                try
                {
                    IQueryable<KeyInfo> query = context.KeyInfoes.Include("KeyInfoEx").OrderBy(k => k.FulfilledDateUtc);
                    if (!string.IsNullOrEmpty(criteria.MsPartNumber))
                        query = query.Where(k => k.LicensablePartNumber.Contains(criteria.MsPartNumber));
                    if (!string.IsNullOrEmpty(criteria.OemPoNumber))
                        query = query.Where(k => k.OemPoNumber.Contains(criteria.OemPoNumber));
                    if (criteria.HasOemPartNumberNull && string.IsNullOrEmpty(criteria.OemPartNumber))
                        query = query.Where(k => k.OemPartNumber == null || k.OemPartNumber == string.Empty);
                    if (!string.IsNullOrEmpty(criteria.OemPartNumber))
                        query = query.Where(k => k.OemPartNumber.Contains(criteria.OemPartNumber));
                    key = query.FirstOrDefault(k => k.KeyStateId == (int)KeyState.Fulfilled && !k.KeyInfoEx.IsInProgress);

                    if (key == null)
                        throw new ApplicationException("No key available.");

                    key.FactoryFloorAssembleKey();
                    if (key.KeyStateChanged)
                        context.KeyHistories.Add(new KeyHistory()
                        {
                            KeyId = key.KeyId,
                            KeyStateId = key.KeyStateId,
                            StateChangeDate = DateTime.Now
                        });
                    context.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    failed = true;
                }
                if (!failed)
                    trans.Commit();

                oCtx.Connection.Close();
            }
            if (failed)
                key = GetKeyTransaction(criteria);

            return key;
        }
Ejemplo n.º 4
0
 private void UpdateReturnByAck(ReturnReport returnReport, ReturnReport dbReturnReport, KeyStoreContext context = null)
 {
     if (dbReturnReport == null)
         throw new DisException("Failed to get data from database to match the contents of this file!");
     if (dbReturnReport.ReturnReportStatus == ReturnReportStatus.Completed)
         throw new DisException("Return.ack has got and completed!");
     dbReturnReport.ReturnUniqueId =(returnReport.ReturnUniqueId==System.Guid.Empty?null: returnReport.ReturnUniqueId);
     dbReturnReport.MsReturnNumber = returnReport.MsReturnNumber;
     dbReturnReport.ReturnDateUTC = returnReport.ReturnDateUTC;
     dbReturnReport.OemRmaDateUTC = returnReport.OemRmaDateUTC;
     dbReturnReport.SoldToCustomerName = returnReport.SoldToCustomerName;
     dbReturnReport.ReturnReportStatus = ReturnReportStatus.Completed;
     if (dbReturnReport.ReturnReportKeys != null && dbReturnReport.ReturnReportKeys.Count > 0)
     {
         Func<ReturnReportKey, ReturnReportKey, ReturnReportKey> updateReturnReportAck =
         (k1, k2) =>
         {
             k1.MsReturnLineNumber = k2.MsReturnLineNumber;
             k1.OemRmaLineNumber = k2.OemRmaLineNumber;
             k1.LicensablePartNumber = k2.LicensablePartNumber;
             k1.ReturnReasonCode = k2.ReturnReasonCode;
             k1.ReturnReasonCodeDescription = k2.ReturnReasonCodeDescription;
             return k1;
         };
         var update = (from db in dbReturnReport.ReturnReportKeys
                       join ack in returnReport.ReturnReportKeys on db.KeyId equals ack.KeyId
                       select updateReturnReportAck(db, ack)).ToList();
     }
     returnKeyRepository.UpdateReturnKeyAck(dbReturnReport, context);
 }
Ejemplo n.º 5
0
 private List<KeyOperationResult> ImportReturnAck(ReturnAck returnAck, KeyStoreContext context)
 {
     if (returnAck == null || returnAck.ReturnAckLineItems.Count() <= 0)
         throw new ApplicationException("Passed in keys list is empty.");
     ReturnReport returnReport = returnAck.FromServiceContract();
     ReturnReport ReturnInDB = null;
     if (returnAck.ReturnUniqueID == System.Guid.Empty)
         ReturnInDB = returnKeyRepository.GetReturnKeyByOneKeyID(returnReport.ReturnReportKeys.Select(k => k.KeyId).FirstOrDefault(), context);
     else
         ReturnInDB = returnKeyRepository.GetReturnKey(returnAck.ReturnUniqueID, context);
     UpdateReturnByAck(returnReport, ReturnInDB, context);
     List<KeyOperationResult> result = UpdateKeysAfterRetrieveReturnReportAck(ReturnInDB, context);
     return result;
 }
Ejemplo n.º 6
0
 public ReturnReport UpdateReturnAfterAckRetrieved(ReturnReport returnReport, KeyStoreContext context)
 {
     ReturnReport dbReturnReport = returnKeyRepository.GetReturnKey(returnReport.ReturnUniqueId.Value, context);
     UpdateReturnByAck(returnReport, dbReturnReport, context);
     return dbReturnReport;
 }
Ejemplo n.º 7
0
 //invoke during get keys and report cbrs
 public void UpdateSyncState(List<KeyInfo> keys, bool isInProgress, KeyStoreContext context = null)
 {
     keyRepository.UpdateKeys(keys, isInProgress, null, context:context);
 }
Ejemplo n.º 8
0
 public void UpdateKeysToCarbonCopy(List<KeyInfo> keys, bool shouldCarbonCopy, KeyStoreContext context = null)
 {
     if (keys != null && keys.Count > 0)
         keyRepository.UpdateKeys(keys, null, null, false, shouldCarbonCopy, context);
 }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
0
 public void UpdateFulfillmentToCompleted(FulfillmentInfo info, KeyStoreContext context)
 {
     info.FulfillmentStatus = FulfillmentStatus.Completed;
     fulfillRepository.UpdateFulfillment(info, context);
 }
Ejemplo n.º 11
0
 protected void InsertOrUpdateKeySyncNotifiction(List<KeyInfo> keys, KeyStoreContext context = null)
 {
     var keysToSync = new List<KeyInfo>();
     var keysGroupBySsId = keys.Where(k => k.KeyInfoEx.SsId != null).GroupBy(k => k.KeyInfoEx.SsId);
     var validSubsidiaries = GetValidSubsidiaries();
     foreach (var keysBySsId in keysGroupBySsId)
     {
         if (IsValidSubsidary(validSubsidiaries, keysBySsId.Key.Value))
         {
             keysToSync.AddRange(keysBySsId);
         }
     }
     miscRepository.InsertOrUpdateKeySyncNotifiction(keysToSync, context);
 }
Ejemplo n.º 12
0
        public List<KeyOperationResult> UpdateKeysAfterRetrieveReturnReportAck(ReturnReport returnReport, KeyStoreContext context = null)
        {
            var keys = returnReport.ReturnReportKeys;
            List<KeyInfo> keysInDb = GetKeysInDb(keys.Select(k => k.KeyId));
            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 = KeyState.Returned
                },
                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.UlsReceivingReturnAck(keys.Single(k => k.KeyId == key.KeyId));
                }
                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 except fulfilled keys return
                List<long> fulfilledKeyIds = keys.Where(k => k.PreProductKeyStateId == (byte)KeyState.Fulfilled).Select(k => k.KeyId).ToList();
                List<KeyInfo> keysToSync = keysToUpdate.Where(k => k.KeyState == KeyState.Returned && (!fulfilledKeyIds.Contains(k.KeyId))).ToList();
                if (keysToSync.Count > 0)
                    InsertOrUpdateKeySyncNotifiction(keysToSync, context);
            }
            results.ForEach(k => k.Key.ProductKey = (k.KeyInDb == null ? null : k.KeyInDb.ProductKey));
            return results;
        }
Ejemplo n.º 13
0
        public List<KeyOperationResult> SaveKeysAfterGetting(List<KeyInfo> keys, bool isInProgress, bool? shouldBeCarbonCopy = null, KeyStoreContext context = null)
        {
            ValidateIfEmpty(keys);

            List<KeyInfo> keysToAdd = new List<KeyInfo>();
            List<KeyOperationResult> result = new List<KeyOperationResult>();

            List<KeyInfo> keysInDb = GetKeysInDb(keys);
            List<KeyTypeConfiguration> keyTypeConfigs = keyTypeRepository.GetKeyTypeConfigurations(CurrentHeadQuarterId);
            foreach (var key in keys)
            {
                KeyTypeConfiguration keyTypeConfig = keyTypeConfigs.SingleOrDefault(k => k.LicensablePartNumber == key.LicensablePartNumber);
                KeyErrorType keyErrorType = KeyErrorType.None;
                if (key.KeyInfoEx == null)
                {
                    key.KeyInfoEx = new KeyInfoEx();
                }
                key.KeyInfoEx.IsInProgress = isInProgress;
                key.KeyInfoEx.KeyInfo = key;
                key.KeyInfoEx.HqId = CurrentHeadQuarterId;
                key.KeyInfoEx.ShouldCarbonCopy = shouldBeCarbonCopy;
                if (key.KeyInfoEx.KeyType == null)
                {
                    key.KeyInfoEx.KeyType = (keyTypeConfig == null ? null : keyTypeConfig.KeyType);
                }
                var currentKey = GetKey(key.KeyId, keysInDb);
                try
                {
                    key.RetrievingKeys();
                }
                catch (Exception ex)
                {
                    ExceptionHandler.HandleException(ex);
                    keyErrorType = KeyErrorType.StateInvalid;
                }
                if (currentKey == null)
                    keysToAdd.Add(key);
                else
                {
                    MessageLogger.LogSystemError(MessageLogger.GetMethodName(),
                        string.Format("Key {0} already exist.", key.ProductKey));
                    keyErrorType = KeyErrorType.Invalid;
                }
                result.Add(new KeyOperationResult
                {
                    Failed = (keyErrorType != KeyErrorType.None),
                    FailedType = keyErrorType,
                    Key = key,
                    KeyInDb = currentKey
                });
            }

            if (keysToAdd.Count > 0)
                keyRepository.InsertKeys(keysToAdd, context);
            return result;
        }
Ejemplo n.º 14
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);
        }