Esempio n. 1
0
 public List<KeyOperationResult> ExportCbr(ExportParameters exportParameters, Func<List<KeyInfo>, string> generateCbrToFile)
 {
     return Execute(exportParameters,
         k => generateCbrToFile(k),
         (k1, k2) => ValidateReportedBoundKey(k1, k2),
         k => keyRepository.UpdateKeys(k, false, null));
 }
Esempio n. 2
0
 //export keys:fulfilled,report,toolkey,CBR
 public List<KeyOperationResult> ExportKeys(ExportParameters exportParameters)
 {
     List<KeyOperationResult> result = null;
     switch (exportParameters.ExportType)
     {
         case Constants.ExportType.CBR:
             return base.ExportCbr(exportParameters,
                 k => cbrManager.GenerateCbrToFile(k, exportParameters.OutputPath));
         case Constants.ExportType.FulfilledKeys:
             return base.ExportFulfilledKeys(exportParameters);
         case Constants.ExportType.ReportKeys:
             return base.ExportBoundKeys(exportParameters);
         case Constants.ExportType.ToolKeys:
             return base.ExportToolKeys(exportParameters);
     }
     return result;
 }
Esempio n. 3
0
        //Export Return Keys to MS
        public List<KeyOperationResult> ExportReturnKeys(ReturnReport request, ExportParameters exportParameters)
        {
            if (request == null || request.ReturnReportKeys.Count() <= 0)
                throw new ArgumentException("export keys is null!");
            var keys = request.ReturnReportKeys.Select(k => new KeyInfo()
            {
                KeyId = k.KeyId
            }).ToList();

            var result = ValidateKeys(keys, ValidExportReturnKey);
            if (result.All(r => !r.Failed))
            {
                string fileContent = GenerateReturnKeysToFile(request, exportParameters);
                List<KeyInfo> keysToUpdate = result.Select(r => r.KeyInDb).ToList();
                returnKeyRepository.InsertReturnReportAndKeys(request);
                keyRepository.UpdateKeys(keysToUpdate, false, null);
                RecordExportLog(keysToUpdate, exportParameters, fileContent, exportParameters.OutputPath);
            }
            result.ForEach(r =>
            {
                r.Key = r.KeyInDb;
            });
            return result;
        }
Esempio n. 4
0
 private string GenerateReturnKeysToFile(ReturnReport report, ExportParameters exportParameters)
 {
     ReturnRequest request = new ReturnRequest()
     {
         OEMRMANumber = report.OemRmaNumber,
         OEMRMADate = report.OemRmaDate,
         SoldToCustomerID = report.SoldToCustomerId,
         ReturnNoCredit = report.ReturnNoCredit,
         ReturnLineItems = report.ReturnReportKeys.Select(k => new ReturnLineItem()
         {
             OEMRMALineNumber = k.OemRmaLineNumber,
             ProductKeyID = k.KeyId,
             ReturnTypeID = k.ReturnTypeId
         }).ToArray()
     };
     KeyManagerHelper.CreateFilePath(exportParameters.OutputPath);
     Serializer.WriteToXml(request, exportParameters.OutputPath);
     return KeyManagerHelper.GetXmlResult(request);
 }
Esempio n. 5
0
        private List<KeyOperationResult> ExportKeys()
        {
            List<KeyOperationResult> results = null;
            object target = null;
            string UserName = string.Empty;
            string AccessKey = string.Empty;
            if (this.exportType == Constants.ExportType.FulfilledKeys)
            {
                target = SelectedSubsidiary;
                UserName = SelectedSubsidiary.UserName;
                AccessKey = SelectedSubsidiary.AccessKey;
            }
            else if (this.exportType == Constants.ExportType.ReportKeys)
            {
                target = SelectedHeadQuarter;
                UserName = SelectedHeadQuarter.UserName;
                AccessKey = selectedHeadQuarter.AccessKey;
            }
            if (this.exportType == Constants.ExportType.ToolKeys || this.exportType == Constants.ExportType.CBR || this.exportType == Constants.ExportType.ReturnKeys)
                IsEncryptChecked = false;
            ExportParameters exportParameters = new ExportParameters()
            {
                ExportType = exportType,
                OutputPath = FileName,
                IsEncrypted = IsEncryptChecked,
                To = target,
                UserName = UserName,
                AccessKey = AccessKey,
                CreateBy = KmtConstants.LoginUser,
            };

            //export return keys
            if (this.exportType == Constants.ExportType.ReturnKeys)
                results = keyProxy.ExportReturnKeys(this.ReturnKeysListModelVM.ReturnKeys.ToReturnReport(this.ReturnKeysListModelVM.OemRmaNumber, this.ReturnKeysListModelVM.OemRmaDate.Value, this.ReturnKeysListModelVM.ReturnNoCredit), exportParameters);
            else
            {
                if (TabIndex == 0)
                    exportParameters.Keys = KeyGroups.Where(k => k.KeyGroup.Quantity > 0).Select(k => k.KeyGroup).ToList();
                else if (TabIndex == 1)
                    exportParameters.Keys = Keys.Where(k => k.IsSelected).Select(k => k.keyInfo).ToList();
                results = base.keyProxy.ExportKeys(exportParameters);
            }

            if (results.Any(k => k.Failed))
            {
                this.FileName = string.Empty;
            }
            if (!results.Any(k => k.Failed) && EncryptCheckedVisibility)
                configProxy.UpdateEncryptExportedFileSwitch(this.IsEncryptChecked);
            return results;
        }
Esempio n. 6
0
 //Export Tool Key in the Factoryfloor
 public List<KeyOperationResult> ExportToolKeys(ExportParameters exportParameters)
 {
     return Execute(exportParameters,
          (k1, k2) => ValidExportConsumedKey(k1, k2),
          k => keyRepository.UpdateKey(k, false, null, null, null));
 }
Esempio n. 7
0
 //Export Fulfilled Keys to DLS
 public List<KeyOperationResult> ExportFulfilledKeys(ExportParameters exportParameters)
 {
     return Execute(exportParameters,
         (k1, k2) => ValidExportFulfilledKeyInUls(k1, k2),
         k => keyRepository.UpdateKeys(k, false, GetExportToSsId(exportParameters)));
 }
Esempio n. 8
0
 private void RecordExportLog(KeyInfo key, ExportParameters exportParameters, string fileContent, string fileName)
 {
     RecordExportLog(new List<KeyInfo>() { key }, exportParameters, fileContent, fileName);
 }
Esempio n. 9
0
 private void RecordExportLog(List<KeyInfo> keys, ExportParameters exportParameters, string fileContent, string fileName)
 {
     KeyExportLog exportLog = new KeyExportLog()
     {
         ExportTo = GetExportTo(exportParameters),
         KeyCount = keys.Count,
         IsEncrypted = exportParameters.IsEncrypted,
         ExportType = exportParameters.ExportType.ToString(),
         FileName = Path.GetFileName(fileName),
         FileContent = fileContent,
         CreateBy = exportParameters.CreateBy.LoginId,
         CreateDate = DateTime.Now
     };
     miscRepository.InsertExportLog(exportLog);
 }
Esempio n. 10
0
        private int GetExportToSsId(ExportParameters exportParameters)
        {
            if (exportParameters.To == null || (exportParameters.To.GetType() != typeof(Subsidiary)))
                throw new ArgumentException("Argument subsidiary not valid");

            return ((Subsidiary)exportParameters.To).SsId;
        }
Esempio n. 11
0
        private string GetExportTo(ExportParameters exportParameters)
        {
            if (exportParameters.ExportType == Constants.ExportType.CBR || exportParameters.ExportType == Constants.ExportType.ReturnKeys)
                return "MS";
            if (exportParameters.ExportType == Constants.ExportType.ToolKeys)
                return "OA3Tool";
            if (exportParameters.To == null)
                throw new ArgumentNullException("Argument ExportParameters:To is null");

            if (exportParameters.To.GetType() == typeof(Subsidiary))
            {
                var target = (Subsidiary)exportParameters.To;
                return target.DisplayName;
            }
            else if (exportParameters.To.GetType() == typeof(HeadQuarter))
            {
                var target = (HeadQuarter)exportParameters.To;
                return target.DisplayName;
            }
            else
                throw new ArgumentException("Argument ExportParameters:To is not valid");
        }
Esempio n. 12
0
        private string GenerateKeysToFile(List<KeyInfo> keys, ExportParameters exportParameters)
        {
            KeyManagerHelper.CreateFilePath(exportParameters.OutputPath);
            List<ExportKeyInfo> exportKeys = keys.ToExportFulfilledKey();
            var exportKeyList = new ExportKeyList()
            {
                Keys = exportKeys,
                UserName = exportParameters.UserName,
                AccessKey = GenerateHmacValue(exportParameters.AccessKey, exportKeys),
                CreatedDate = DateTime.UtcNow
            };

            string result;
            if (exportParameters.IsEncrypted)
            {
                EncryptedExportKeyList export = KeyManagerHelper.EncryptExportFile(exportKeyList.ToXml(true,true));
                Serializer.WriteToXml(export, exportParameters.OutputPath);
                result = KeyManagerHelper.GetXmlResult(export);
            }
            else
            {
                Serializer.WriteToXml(exportKeyList, exportParameters.OutputPath);
                result = KeyManagerHelper.GetXmlResult(exportKeyList);
            }
            return result;
        }
Esempio n. 13
0
        private List<KeyOperationResult> Execute(ExportParameters exportParameters,
            Func<KeyInfo, KeyInfo, KeyErrorType> validateKey,
            Action<KeyInfo> updateKeysState)
        {
            var keys = ConvertKeyGroupsToKeys(exportParameters);
            var keysInDb = GetKeysInDb(keys);
            return keys.Select(key =>
                {
                    var subFullFillName = exportParameters.OutputPath;
                    var result = GenerateKeyOperationResult(key, keysInDb, validateKey);

                    if (!result.Failed)
                    {
                        var fileContent = GenerateKeysToFile(key, subFullFillName, out subFullFillName);
                        KeyInfo keyToUpdate = result.KeyInDb;
                        updateKeysState(keyToUpdate);
                        RecordExportLog(keyToUpdate, exportParameters, fileContent, subFullFillName);
                    }
                    return result;
                }).ToList();
        }
Esempio n. 14
0
 private List<KeyOperationResult> Execute(ExportParameters exportParameters,
     Func<KeyInfo, KeyInfo, KeyErrorType> validateKey,
     Action<List<KeyInfo>> updateKeysState)
 {
     return Execute(exportParameters,
         k => GenerateKeysToFile(k, exportParameters),
         (k1, k2) => validateKey(k1, k2),
         k => updateKeysState(k));
 }
Esempio n. 15
0
 private List<KeyOperationResult> Execute(ExportParameters exportParameters,
     Func<List<KeyInfo>, string> generateKeysToFile,
     Func<KeyInfo, KeyInfo, KeyErrorType> validateKey,
     Action<List<KeyInfo>> updateKeysState)
 {
     var keys = ConvertKeyGroupsToKeys(exportParameters);
     var result = ValidateKeys(keys, validateKey);
     if (result.All(r => !r.Failed))
     {
         var fileContent = generateKeysToFile(keys);
         List<KeyInfo> keysToUpdate = result.Select(r => r.KeyInDb).ToList();
         updateKeysState(keysToUpdate);
         RecordExportLog(keysToUpdate, exportParameters, fileContent, exportParameters.OutputPath);
     }
     return result;
 }
Esempio n. 16
0
        private List<KeyInfo> ConvertKeyGroupsToKeys(ExportParameters exportParameters)
        {
            List<KeyInfo> keys = null;

            if (exportParameters.Keys.GetType() == typeof(List<KeyGroup>))
            {
                var keyGroups = (List<KeyGroup>)exportParameters.Keys;
                if (keyGroups == null || keyGroups.Count < 0)
                    throw new ArgumentException("export keys is null!");

                keys = keyRepository.SearchKeys(keyGroups);
                if (keys == null || keys.Count <= 0 || keys.Count != keyGroups.Sum(k => k.Quantity))
                    throw new DisException("ExportKeys_DataChangeError");
            }
            else
                keys = (List<KeyInfo>)exportParameters.Keys;

            if (keys == null || keys.Count <= 0)
                throw new ArgumentException("export keys is null!");
            return keys;
        }