/// <summary> /// /// </summary> /// <param name="objRMASwapRequest"></param> /// <param name="objRMASwapResponse"></param> /// <returns></returns> public bool ValidateRequest(RMASwapRequest objRMASwapRequest, RMASwapResponse objRMASwapResponse) { bool ValidationStatus = true; if (!objRMASwapRequest.RequestID.IsValidString() && ValidationStatus) { objRMASwapResponse.ResponseStatus = (int)Constants.ResponseStatus.InvalidParameter; objRMASwapResponse.ResponseMessage = Constants.ResponseStatus.InvalidParameter.ToString(); ValidationStatus = false; } if (!objRMASwapRequest.RequestingSystem.IsValidString() && ValidationStatus) { objRMASwapResponse.ResponseStatus = (int)Constants.ResponseStatus.InvalidParameter; objRMASwapResponse.ResponseMessage = Constants.ResponseStatus.InvalidParameter.ToString(); ValidationStatus = false; } if (objCommonValidationBL.DupCheckRequestId(objRMASwapRequest.RequestID, objRMASwapRequest.RequestingSystem) && ValidationStatus) { objRMASwapResponse.ResponseStatus = (int)Constants.ResponseStatus.AmbigousRequest; objRMASwapResponse.ResponseMessage = Constants.ResponseMessage[3].ToString(); ValidationStatus = false; } if (!objRMASwapRequest.SourceLicenseSNum.IsValidSNumFormat()) { objRMASwapResponse.ResponseStatus = (int)Constants.ResponseStatus.InvSrcLicensableSNum; objRMASwapResponse.ResponseMessage = Constants.ResponseMessage[9].ToString(); ValidationStatus = false; } if (!objRMASwapRequest.DestLicenseSNum.IsValidSNumFormat()) { objRMASwapResponse.ResponseStatus = (int)Constants.ResponseStatus.InvDstLicensableSNum; objRMASwapResponse.ResponseMessage = Constants.ResponseMessage[10].ToString(); ValidationStatus = false; } return(ValidationStatus); }
/// <summary> /// /// </summary> /// <param name="objLicenseRequest"></param> /// <returns></returns> public RMASwapResponse RMASwap(RMASwapRequest objRMASwapRequest) { var objRMASwapResponse = new RMASwapResponse(); #region DUMMY RESPONSE /* * objRMASwapResponse.RequestID = objRMASwapRequest.RequestID; * objRMASwapResponse.ResponseID = objRMASwapRequest.RequestID; * objRMASwapResponse.ResponseDateTime = DateTime.UtcNow; * objRMASwapResponse.ResponseStatus = (int)Constants.ResponseStatus.Success; * objRMASwapResponse.ResponseMessage = Constants.ResponseStatus.Success.ToString(); * #region Creating Dummy Response * * LicenseInfo[] licenseList = new LicenseInfo[2]; * * for (int i = 0; i < licenseList.Length; i++) * { * licenseList[i] = new LicenseInfo(); * licenseList[i].ImageUrl = "https://cisco.com/downloads"; * licenseList[i].IsShippedVersion = (i == 0) ? true : false; ; * licenseList[i].Qty = i + 1; * licenseList[i].ReleaseDate = DateTime.Now.AddDays(-2).ToUniversalTime(); * licenseList[i].SKUType = "SOFTWARE"; * licenseList[i].Version = "LatestMajorRelease"; * licenseList[i].VersionSeqNo = 0; * licenseList[i].VersionType = "DOT MAJOR"; * licenseList[i].SKUID = "11233" + i.ToString(); * * } * * objRMASwapResponse.Licenses = licenseList; #endregion * */ #endregion //Start RMASwap try { //ASSIGNING ID'S objRMASwapResponse.RequestID = objRMASwapRequest.RequestID; objRMASwapResponse.ResponseID = objRMASwapRequest.RequestID; //INPUT DATA VALIDATION if (objRMASwapBL.ValidateRequest(objRMASwapRequest, objRMASwapResponse)) { //PROCESS DATA & RETURN RESPONSE objRMASwapBL.ProcessRequest(objRMASwapRequest, objRMASwapResponse); } } catch (Exception ex) { //SET FAILURE STATUS objRMASwapResponse.ResponseStatus = (int)Constants.ResponseStatus.ServiceUnavailable; objRMASwapResponse.ResponseMessage = Constants.ResponseMessage[1000].ToString(); //LOG EXCEPTION objEventLogger.WriteLog(ex.Message + Environment.NewLine + ex.StackTrace, objRMASwapRequest.RequestingSystem, DateTime.UtcNow, objRMASwapRequest.RequestID); } finally { objRMASwapResponse.ResponseDateTime = DateTime.UtcNow; //SERIALIZE REQUEST/RESPONSE string request = "RMASwapRequest"; string response = "RMASwapResponse"; try { request = Util.SerializeObject(objRMASwapRequest); response = Util.SerializeObject(objRMASwapResponse); } catch (Exception ex) { objEventLogger.WriteLog("Request/Response Object Serialization Error: " + ex.Message + Environment.NewLine + ex.StackTrace, objRMASwapRequest.RequestingSystem, DateTime.UtcNow, objRMASwapRequest.RequestID); } if (!request.IsValidString()) { request = "RMASwapRequest"; } if (!response.IsValidString()) { response = "RMASwapResponse"; } //LOG REQUEST/RESPONSE objTransactionLogger.LogTransaction(objRMASwapRequest.RequestID, objRMASwapRequest.RequestDateTime, objRMASwapRequest.RequestingSystem, request, objRMASwapResponse.ResponseID, objRMASwapResponse.ResponseDateTime, response, objRMASwapResponse.ResponseStatus, objRMASwapResponse.ResponseMessage, 0); //End Processing RMASwap } //RMASwap ends return(objRMASwapResponse); }
/// <summary> /// /// </summary> /// <param name="objRMASwapRequest"></param> /// <param name="objRMASwapResponse"></param> /// <returns></returns> public bool ProcessRequest(RMASwapRequest objRMASwapRequest, RMASwapResponse objRMASwapResponse) { // START PROCESSING bool flag = false; string[] SKUList = null; SKUInfo[] SKUInfoList = null; string ParentSNum = string.Empty; string message = string.Empty; SKUDetailInfo[] skuDetailList; DataTable SNumAssocation; try { if (objRMASwapRequest.SourceLicenseSNum.IsValidString() && objRMASwapRequest.DestLicenseSNum.IsValidString()) { //GET SKULIST FOR GIVEN SERIAL NO SKUInfoList = objCommonBL.GetSKUListForGivenSNum(objRMASwapRequest.SourceLicenseSNum, string.Empty); if (SKUInfoList == null || SKUInfoList.Length < 1) { objRMASwapResponse.ResponseStatus = (int)Constants.ResponseStatus.NoLicSNUMFound; objRMASwapResponse.ResponseMessage = Constants.ResponseMessage[7].ToString(); return(flag); } //FIND ALL PARENT SERIAL NUM AND SKULIST USING PARENTCHILD METHOD #region FIND PARENTCHILD RECORDS FOR BOTH SERIAL NO SNumAssocation = GetUpdatedSNumAssocation(objRMASwapRequest); #endregion #region CHECK ASSOCIATION RESPONSE if (SNumAssocation == null || SNumAssocation.Rows.Count == 0) { objRMASwapResponse.ResponseStatus = (int)Constants.ResponseStatus.NoParentChildFound; objRMASwapResponse.ResponseMessage = Constants.ResponseMessage[8].ToString(); return(flag); } #endregion #region CHECK DESTINATION LICENSABLE SNUM IS AVAILABLE IN TST OR NOT if (!CheckTSTRecord(objRMASwapRequest.DestLicenseSNum)) { objRMASwapResponse.ResponseStatus = (int)Constants.ResponseStatus.InvalidParameter; objRMASwapResponse.ResponseMessage = "Destination Licensable SNum is Not available in System."; return(flag); } #endregion #region Old Code //// REPLACE LICENSABLE SOURCE SNUM WITH DESTINATION SNUM IN TST TABLE //if (ReplaceSourceLicenseSNumWithDestLicenseSNum(SNumAssocation)) //{ // if (SKUInfoList != null) // SKUList = SKUInfoList.Select(o => o.SKUID).ToArray<string>(); // if (SKUList != null && SKUList.Length > 0) // { // // FIND ALL SKU DETAILS (SOFTWARE & OPTION) FOR GIVEN ID. // skuDetailList = objCommonBL.GetSKUDetailInfo(SKUList, objRMASwapRequest.SourceLicenseSNum); // //CHECK RETURN OBJECT AND GENERATED LICENSE AS PER VERSION FILTER IF REQUIRED // if (skuDetailList != null && skuDetailList.Length > 0) // { // List<LicenseInfo> LicenseInfoList = new List<LicenseInfo>(); // for (int j = 0; j < skuDetailList.Length; j++) // { // string releaseKey = string.Empty; // //FOR SOFTWARE // if (skuDetailList[j].SKUType != Constants.SKUType.OPTION.ToString()) // { // VersionInfoWithLicense[] versions = skuDetailList[j].VersionList; // //remove all old keys. // for (int k = 0; k < versions.Length; k++) // { // versions[k].IsShippedVersion = false; // versions[k].LicenseKey = ""; // } // if (versions != null && versions.Length > 0) // { // VersionInfoWithLicense latestVersion = versions.OrderByDescending(o => o.VersionSeqNo).FirstOrDefault<VersionInfoWithLicense>(); // // CALL GET LICENSE FOR GIVEN SKU AND GET LICENSE KEY // if (latestVersion != null && string.IsNullOrEmpty(latestVersion.LicenseKey)) // { // releaseKey = string.Empty; // releaseKey = objCommonBL.GetLicenseKey(objRMASwapRequest.DestLicenseSNum, skuDetailList[j].SKUID, skuDetailList[j].SKUType, skuDetailList[j].Qty, 1, latestVersion.Version, DateTime.MinValue, 1); // latestVersion.LicenseKey = releaseKey; // latestVersion.IsShippedVersion = true; // } // } // //add it to response licenseinfo object // LicenseInfo obj = CreateLicenseInfo(skuDetailList[j]); // LicenseInfoList.Add(obj); // } // else if (skuDetailList[j].SKUType == Constants.SKUType.OPTION.ToString()) //FOR OPTION // { // skuDetailList[j].OptionLicenseKey = ""; // releaseKey = objCommonBL.GetLicenseKey(objRMASwapRequest.DestLicenseSNum, skuDetailList[j].SKUID, skuDetailList[j].SKUType, skuDetailList[j].Qty, 1, "", DateTime.MinValue, 1); // skuDetailList[j].OptionLicenseKey = releaseKey; // //add it to response licenseinfo object // LicenseInfo obj = CreateLicenseInfo(skuDetailList[j]); // LicenseInfoList.Add(obj); // } // } // objRMASwapResponse.Licenses = LicenseInfoList.ToArray(); // } // else // { // objRMASwapResponse.ResponseStatus = (int)Constants.ResponseStatus.UnKnownSKU; // objRMASwapResponse.ResponseMessage = Constants.ResponseMessage[2].ToString(); // } // } //} //else //{ // objRMASwapResponse.ResponseStatus = (int)Constants.ResponseStatus.InvalidParameter; // objRMASwapResponse.ResponseMessage = "Invalid TST Record for SNum.Fail to Replace SNum."; //} #endregion #region NEW CR // REPLACE LICENSABLE SOURCE SNUM WITH DESTINATION SNUM IN TST TABLE if (ReplaceSourceLicenseSNumWithDestLicenseSNum(SNumAssocation)) { if (SKUInfoList != null) { SKUList = SKUInfoList.Select(o => o.SKUID).ToArray <string>(); } if (SKUList != null && SKUList.Length > 0) { // FIND ALL SKU DETAILS (SOFTWARE & OPTION) FOR GIVEN ID. skuDetailList = objCommonBL.GetSKUDetailInfo(SKUList, objRMASwapRequest.SourceLicenseSNum); //CHECK RETURN OBJECT AND GENERATED LICENSE AS PER VERSION FILTER IF REQUIRED if (skuDetailList.Length > 0) { DataTable dtChkLicenseData = null; //RMA SWAP CR - Get the records with SKUS deleted=0 for options and for softwares get the latest SKU record DataSet dsChkLicenseData = objCommonBL.FindLicenseHistoryForRMASWAP(objRMASwapRequest.SourceLicenseSNum); if (dsChkLicenseData != null && dsChkLicenseData.Tables != null && dsChkLicenseData.Tables.Count > 0) { dtChkLicenseData = dsChkLicenseData.Tables[0]; } List <LicenseInfo> LicenseInfoList = new List <LicenseInfo>(); string releaseKey = string.Empty; foreach (DataRow row in dtChkLicenseData.Rows) { string strSKUID = (row["PartName"] != DBNull.Value) ? row["PartName"].ToString() : string.Empty; string strSKUType = (row["ProductType"] != DBNull.Value) ? row["ProductType"].ToString() : string.Empty; if (strSKUType == "2") { strSKUType = "OPTION"; } else { strSKUType = "SW"; } int intQty = (row["Qty"] != DBNull.Value) ? Convert.ToInt16(row["Qty"]) : 1; int intIndex = (row["Index"] != DBNull.Value) ? Convert.ToInt16(row["Index"]) : 1; //Do not pass Version as we need to fetch the latest version for the SKU //string strVersion = (row["VersionName"] != DBNull.Value) ? row["VersionName"].ToString() : string.Empty; //For Software if (strSKUType != Constants.SKUType.OPTION.ToString()) { // CALL GET LICENSE FOR GIVEN SKU AND GET LICENSE KEY releaseKey = string.Empty; //pass the version as empty here /*new CR user logging 08/2013*/ releaseKey = objCommonBL.CallRMASwapLicense(objRMASwapRequest.DestLicenseSNum, strSKUID, strSKUType, intQty, intIndex, string.Empty, DateTime.MinValue, 1, objRMASwapRequest.RequestingSystem); //skuDetailList[j].OptionLicenseKey = releaseKey; if (string.IsNullOrEmpty(releaseKey) || releaseKey.Equals("Fail to Generate Key")) { flag = false; } else { flag = true; } LicenseInfo obj = new LicenseInfo(); obj.SKUID = strSKUID; obj.SKUType = strSKUType; obj.Qty = intQty; //obj.QtySpecified = skuDetail.QtySpecified; VersionInfoWithLicense[] versions = null; VersionInfoWithLicense latestVersion = null; for (int i = 0; i < skuDetailList.Length; i++) { if (skuDetailList[i].SKUID.Equals(strSKUID)) { versions = skuDetailList[i].VersionList; break; } } if (versions != null) { latestVersion = versions.OrderByDescending(o => o.VersionSeqNo).FirstOrDefault <VersionInfoWithLicense>(); } if (latestVersion != null) { obj.ImageUrl = latestVersion.ImageUrl; obj.IsShippedVersion = latestVersion.IsShippedVersion; obj.Version = latestVersion.Version; obj.VersionSeqNo = latestVersion.VersionSeqNo; obj.VersionType = latestVersion.VersionType; obj.LicenseKey = releaseKey; } //add it to response licenseinfo object LicenseInfoList.Add(obj); } else { LicenseInfo obj = new LicenseInfo(); obj.SKUID = strSKUID; obj.SKUType = strSKUType; obj.Qty = intQty; //obj.QtySpecified = skuDetail.QtySpecified; /*new CR user logging 08/2013*/ releaseKey = objCommonBL.CallRMASwapLicense(objRMASwapRequest.DestLicenseSNum, strSKUID, strSKUType, intQty, intIndex, "", DateTime.MinValue, 1, objRMASwapRequest.RequestingSystem); obj.VersionSeqNo = -1; obj.LicenseKey = releaseKey; obj.ReleaseDateSpecified = false; //add it to response licenseinfo object LicenseInfoList.Add(obj); if (string.IsNullOrEmpty(releaseKey) || releaseKey.Equals("Fail to Generate Key")) { flag = false; } else { flag = true; } } } objRMASwapResponse.Licenses = LicenseInfoList.ToArray(); } else { objRMASwapResponse.ResponseStatus = (int)Constants.ResponseStatus.UnKnownSKU; objRMASwapResponse.ResponseMessage = Constants.ResponseMessage[2].ToString(); } } } else { objRMASwapResponse.ResponseStatus = (int)Constants.ResponseStatus.InvalidParameter; objRMASwapResponse.ResponseMessage = "Invalid TST Record for SNum.Fail to Replace SNum."; } #endregion //flag = true; } //NEW CR #region Soft Delete the Source Serial Number //Soft delete the Source Serial number if (flag) { var objSoftDeleteLicensesResponse = new SoftDeleteLicensesResponse(); var objSoftDeleteLicensesRequest = new SoftDeleteLicensesRequest(); objSoftDeleteLicensesRequest.RequestID = objRMASwapRequest.RequestID; objSoftDeleteLicensesRequest.RequestDateTime = objRMASwapRequest.RequestDateTime; objSoftDeleteLicensesRequest.RequestingSystem = objRMASwapRequest.RequestingSystem; objSoftDeleteLicensesRequest.SNum = objRMASwapRequest.SourceLicenseSNum; objSoftDeleteLicensesResponse.RequestID = objSoftDeleteLicensesRequest.RequestID; objSoftDeleteLicensesResponse.ResponseID = objSoftDeleteLicensesRequest.RequestID; objSoftDeleteLicensesResponse.ResponseDateTime = DateTime.UtcNow; objSoftDeleteLicensesResponse.ResponseStatus = (int)Constants.ResponseStatus.Success; objSoftDeleteLicensesResponse.ResponseMessage = Constants.ResponseStatus.Success.ToString(); objSoftDeleteLicensesResponse.SNum = objSoftDeleteLicensesRequest.SNum; objSoftDeleteLicensesBL.ProcessRequest(objSoftDeleteLicensesRequest, objSoftDeleteLicensesResponse); if (objSoftDeleteLicensesResponse.ResponseStatus != (int)Constants.ResponseStatus.Success) { objRMASwapResponse.ResponseMessage += objSoftDeleteLicensesResponse.ResponseMessage.ToString(); } } #endregion } catch (Exception ex) { throw new Exception("Error Occured While Processing RMASwap. " + ex.Message + Environment.NewLine + ex.StackTrace); } return(flag); }