using System.Net; using System.Runtime.Serialization.Json; using GB5Shared.DTO.Framework.Enum; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GoodBooks.FrameworkBLL.Authentication; namespace FrameworkSL.ServiceFunction { public class RestServiceHandler : IRestServiceHandler { public ResponseStandardDTO FillResponseDTO(string From, string To, FrameworkEnumDTO.ResponseStatus Status, string Body, string Etag = "", LoginDTO LoginDTO = null) { try { //if (LoginDTO == null) //{ // LoginDTO = new LoginDTO(); // IncomingWebRequestContext Request = WebOperationContext.Current.IncomingRequest; // WebHeaderCollection Header = Request.Headers; // string HeaderValue = Header.Get("Login"); // if (HeaderValue != null) // { // if (HeaderValue != "") // { // try // { // LoginDTO = GetHeaderForLog(Request); // } // catch // { // LoginDTO = null; // } // } // else // { // LoginDTO = null; // } // } //} ResponseStandardDTO ResponseStandard = new (); ResponseStandard.From = From; ResponseStandard.To = To; ResponseStandard.Status = Status; ResponseStandard.Body = Body; ResponseStandard.ETag = Etag; if ((int)Status != 401) { // ResponseStandard = UpdateResponseStandardDTO(ResponseStandard); } if (LoginDTO == null) { // ResponseStandard = Comprssed(ResponseStandard); } else { if (LoginDTO.DeveloperId == -1) { // ResponseStandard = Comprssed(ResponseStandard); } else if (LoginDTO.DeveloperId == 100) { //New case addded by Vikash..Skip We dont want..Added by Vikash as per Discussion with VV Sir .For Postman checking we dont have to compress data on 17th May 2019 } else { // ResponseStandard = EncryptDataWithSecretKey(ResponseStandard, LoginDTO); } } return ResponseStandard; } catch (Exception) { throw; } } //private ResponseStandardDTO UpdateResponseStandardDTO(ResponseStandardDTO ResponseStandardDTO) //{ // //IAuthenticationBLL IAuthenticationBLL = null; // //PooledCommonFunctionFrameDAL Common = new PooledCommonFunctionFrameDAL(); // //try // //{ // // IncomingWebRequestContext Request = WebOperationContext.Current.IncomingRequest; // // WebHeaderCollection Header = Request.Headers; // // string HeaderValue = Header.Get("Login"); // // if (HeaderValue != null) // // { // // if (HeaderValue != "") // // { // // LoginDTO LoginDTO = JsonDeserializerString(HeaderValue); // // if (LoginDTO != null) // // { // // LoginDTO.BaseUri = GetBaseUri(Request); // // LoginDTO.MachineIP = GetMachineIP(Request); // // string ExpiryTime = LoginDTO.ExpiryTime.ToString(); //System.Configuration.ConfigurationManager.AppSettings["ExpiryTime"]; // // int AddValue = Convert.ToInt32(ExpiryTime); // // System.TimeSpan Duration = new System.TimeSpan(0, AddValue, 0); // // DateTime Validtodate = DateTime.UtcNow.Add(Duration); // // string ValidToTime = Common.Base64Encode(Validtodate.ToString()); // // LoginDTO.ValidToTime = ValidToTime; // // //string ValidationSessionData = LoginDTO.UserId + LoginDTO.ServerId + LoginDTO.RoleId + LoginDTO.AppId + LoginDTO.DeviceId + ValidToTime + LoginDTO.BaseUri + LoginDTO.MachineIP; // // string ValidityOfSession = Common.CreateValidityOfSession(LoginDTO); //Common.Base64Encode(ValidationSessionData); // // ResponseStandardDTO.ValidToTime = ValidToTime; // // ResponseStandardDTO.ValidityOfSession = ValidityOfSession; // // if (LoginDTO.LastLoginUsedTime != null && (int)ResponseStandardDTO.Status == 200) // // { // // string LastUsed = Common.Base64Decode(LoginDTO.LastLoginUsedTime); // // DateTime LastUsedDateAndTime = Convert.ToDateTime(LastUsed); // // int HalfAddValue = Convert.ToInt32(Math.Floor(Convert.ToDouble(AddValue / 2))) - 1; ; // // System.TimeSpan HalfDuration = new System.TimeSpan(0, HalfAddValue, 0); // // DateTime LastUsedValidTill = LastUsedDateAndTime.Add(HalfDuration); // // if (DateTime.UtcNow > LastUsedValidTill) // // { // // IAuthenticationBLL = new AuthenticationBLL(); // // //If Current Time is More than LastUsedValidTill then ResponseStandardDTO LastUsedValidTill will be CurrentTime // // ResponseStandardDTO.LastLoginUsedTime = Common.Base64Encode(DateTime.UtcNow.ToString()); // // LoginDTO.LastLoginUsedTime = ResponseStandardDTO.LastLoginUsedTime;//This is required to used same during Update in Session Table // // IAuthenticationBLL.UpdateSession(LoginDTO); // // } // // else // // { // // ResponseStandardDTO.LastLoginUsedTime = LoginDTO.LastLoginUsedTime; // // } // // } // // else // // { // // ResponseStandardDTO.LastLoginUsedTime = LoginDTO.LastLoginUsedTime; // // } // // } // // } // // } // // return ResponseStandardDTO; // //} // //catch (Exception Error) // //{ // // throw Error; // //} // //finally // //{ // // IAuthenticationBLL = null; // // Common = null; // //} //} //private ResponseStandardDTO Comprssed(ResponseStandardDTO ResponseStandardDTO) //{ // //ICommonFunctionFrameDAL Common = new CommonFunctionFrameDAL(); // //try // //{ // // ResponseStandardDTO.Body = Common.GZipCompress(ResponseStandardDTO.Body); // // return ResponseStandardDTO; // //} // //catch (Exception Error) // //{ // // throw Error; // //} // //finally // //{ // // Common = null; // //} //} //private ResponseStandardDTO EncryptDataWithSecretKey(ResponseStandardDTO ResponseStandardDTO, LoginDTO LoginDTO) //{ // ICommonFunctionFrameDAL Common = new CommonFunctionFrameDAL(); // ApplicationConnection Connection = new ApplicationConnection(); // try // { // if (LoginDTO.IsDeveloperEncryptionRequired == 0)////Added by Vikash on 15 Apr 2020//This will come from MDeveloper New fields // { // DeveloperAuthDTO DeveloperAuthDTO = Connection.GetDeveloperAuthDTO(LoginDTO.DeveloperAccessKeyId, LoginDTO); // string SecretKey = Common.DecryptMd5(DeveloperAuthDTO.SecretKey); // ResponseStandardDTO = EncryptDataWithSecretKey(ResponseStandardDTO, SecretKey); // } // else // { // ResponseStandardDTO = Comprssed(ResponseStandardDTO); // } // return ResponseStandardDTO; // } // catch (Exception Error) // { // throw Error; // } // finally // { // Common = null; // Connection = null; // } //} } }