public UserInfoModel GetUserInfo() { try { var accountName = @"" + (_user.Identity.Name != null ? _user.Identity.Name : WindowsIdentity.GetCurrent().Name); var employeeId = GetEmployeeId(); var binding = new BasicHttpBinding(); binding.Name = "UserInfoWebServiceSoap"; binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; var addressUri = dbService.GetConfigurationProperties("UserInfoServiceUrl"); if (addressUri.Contains("https")) { binding.Security.Mode = BasicHttpSecurityMode.Transport; } var endpoint = new EndpointAddress(addressUri); var client = new UserInfoServiceReference.UserInfoWebServiceSoapClient(binding, endpoint); Util.ApplyCredentials("", "", client.ClientCredentials); var element = client.getUserInfoByEmpIDAsync(employeeId).ConfigureAwait(true).GetAwaiter().GetResult(); userInfoXml = element.ToString(); var info = Util.ConvertXElementToXmlDocument(element); var userInfo = Util.ConvertXmlNodeToObject <UserInfoModel>(info); employeeId = 0; var locationId = 0; var jobCode = 0; var departmentCode = 0; int.TryParse(userInfo.empID, out employeeId); int.TryParse(userInfo.locationID, out locationId); int.TryParse(userInfo.jobCode, out jobCode); int.TryParse(userInfo.dept, out departmentCode); if (employeeId < 0) { employeeId = 0; } userInfo.empID = employeeId.ToString(); userInfo.locationID = locationId.ToString(); userInfo.jobCode = jobCode.ToString(); userInfo.dept = departmentCode.ToString(); return(userInfo); } catch (Exception ex) { CustomLogging.ErrorLog(ex); return(new UserInfoModel()); } }
public static string ConvertToBase64(string plainText) { try { var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText); return(System.Convert.ToBase64String(plainTextBytes)); }catch (Exception ex) { CustomLogging.ErrorLog(ex); return(""); } }
public static string GetEncodedSecurityCode(string securityCode) { try { string base64String = ConvertToBase64(securityCode); return(base64String.Replace("=", "%3D")); } catch (Exception ex) { CustomLogging.ErrorLog(ex); return(""); } }
public static string ConvertFromBase64(string encodedText) { try { byte[] data = System.Convert.FromBase64String(encodedText); return(System.Text.Encoding.UTF8.GetString(data)); } catch (Exception ex) { CustomLogging.ErrorLog(ex); return(""); } }
public static string DecodeSecurityCode(string encodedCode) { try { string tempString = encodedCode.Replace("%3D", "="); string securityCode = ConvertFromBase64(tempString); return(securityCode); } catch (Exception ex) { CustomLogging.ErrorLog(ex); return(""); } }
public static string GetSilverLightURL(string deviceName, string encodedSC, string baseURL, string urlParams) { try { var urlParamsArray = urlParams.Split(','); baseURL = baseURL + "?"; baseURL = baseURL + urlParamsArray[0] + "=" + deviceName + "&" + urlParamsArray[1] + "=" + encodedSC; return(baseURL); } catch (Exception ex) { CustomLogging.ErrorLog(ex); return(""); } }
public static string GetHTMLClocktURL(string deviceName, string encodedSC, string baseURL, string urlParams, string nsValue) { try { var urlParamsArray = urlParams.Split(','); baseURL = baseURL + "?"; // Replaced '%3D' with '=' in sc parameter as mentioned in SP-511 Go-Live Check List baseURL = baseURL + urlParamsArray[0] + "=" + nsValue + "&" + urlParamsArray[1] + "=" + deviceName + "&" + urlParamsArray[2] + "=" + encodedSC.Replace("%3D", "="); return(baseURL); } catch (Exception ex) { CustomLogging.ErrorLog(ex); return(""); } }
/// <summary> /// Generate clock on basis of locationID for user /// </summary> /// <param name="locationID"></param> /// <returns></returns> public ClockURL GetClockURLObject(string locationID) { try { // validating if location is registered in DB or not. return error in case of invalid location ID if (dbService.ValidateClock(locationID) == false) { ClockURL clockDTObject = new ClockURL(); clockDTObject.StatusCode = "101"; //Location is empty or not registered in DB clockDTObject.StatusMessage = "Invalid Location"; return(clockDTObject); } // getting device name and encoded security code form Database to generate URL's string clockName = dbService.GetClockNameFromLocationId(locationID); string encodedSecurityCode = dbService.GetEncodedSecurityCode(locationID); string locationType = dbService.GetLocationType(locationID); var securityCode = Util.DecodeSecurityCode(encodedSecurityCode); //generating SilverLight URL string baseURL = dbService.GetConfigurationProperties("SilverLightBaseURL"); string urlParams = dbService.GetConfigurationProperties("SilverLightURLParams"); string silverLightURL = Util.GetSilverLightURL(clockName, encodedSecurityCode, baseURL, urlParams); //generating HTMLClock URL string HTMLBaseURL = dbService.GetConfigurationProperties("HTMLBaseURL"); string urlParamsHTML = dbService.GetConfigurationProperties("HTMLURLParams"); string nsValue = dbService.GetConfigurationProperties("nsValue"); string HTMLClockURL = Util.GetHTMLClocktURL(clockName, encodedSecurityCode, HTMLBaseURL, urlParamsHTML, nsValue); //setting values to return in a single object ClockURL clockDTO = new ClockURL(clockName, securityCode); clockDTO.EncodedSecurityCode = encodedSecurityCode; clockDTO.SilverLighClockURL = silverLightURL; clockDTO.HTMLClockURL = HTMLClockURL; clockDTO.LocationType = locationType; return(clockDTO); }catch (Exception ex) { CustomLogging.ErrorLog(ex); return(new ClockURL()); } }
public string[] GetWebClockMembership() { try { var userName = _user.Identity.Name != null ? Util.GetUsernameWithoutDomain(_user.Identity.Name) : Util.GetUsernameWithoutDomain(System.Security.Principal.WindowsIdentity.GetCurrent().Name); var userDomain = _user.Identity.Name != null ? Util.GetDomainNameFromUsername(_user.Identity.Name) : Util.GetDomainNameFromUsername(System.Security.Principal.WindowsIdentity.GetCurrent().Name); var accountName = @"" + (_user.Identity.Name != null ? _user.Identity.Name : WindowsIdentity.GetCurrent().Name); CustomLogging.InfoLog("Loggedin User = "******"UserInfoWebServiceSoap"; binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; var addressUri = dbService.GetConfigurationProperties("UserInfoServiceUrl"); if (addressUri.Contains("https")) { binding.Security.Mode = BasicHttpSecurityMode.Transport; } var endpoint = new EndpointAddress(addressUri); var client = new UserInfoServiceReference.UserInfoWebServiceSoapClient(binding, endpoint); Util.ApplyCredentials("", "", client.ClientCredentials); var webClockGroups = client.getMembershipBySAMAccountNameAsync(accountName).ConfigureAwait(true).GetAwaiter().GetResult(); return(webClockGroups); } catch (Exception ex) { CustomLogging.ErrorLog(ex); return(null); } }
/// <summary> /// Generate clock on basis of ID passed from dropdown for normal user /// </summary> /// <param name="locationID"></param> /// <returns></returns> public ClockURL GenerateClock(string locationID) { try { string clockName = "", securityCode = "", encodedSecurityCode = "", locationType = ""; //getting clockName and Encoded sercuirty code from Database clockName = dbService.GetClockNameFromLocationId(locationID); encodedSecurityCode = dbService.GetEncodedSecurityCode(locationID); locationType = dbService.GetLocationType(locationID); encodedSecurityCode = String.IsNullOrEmpty(encodedSecurityCode) ? Util.GetEncodedSecurityCode(clockName) : encodedSecurityCode; securityCode = Util.DecodeSecurityCode(encodedSecurityCode); //getting SilverLight URL string baseURL = dbService.GetConfigurationProperties("SilverLightBaseURL"); string urlParams = dbService.GetConfigurationProperties("SilverLightURLParams"); string silverLightURL = Util.GetSilverLightURL(clockName, encodedSecurityCode, baseURL, urlParams); //getting HTMLClock URL string HTMLBaseURL = dbService.GetConfigurationProperties("HTMLBaseURL"); string urlParamsHTML = dbService.GetConfigurationProperties("HTMLURLParams"); string nsValue = dbService.GetConfigurationProperties("nsValue"); string HTMLClockURL = Util.GetHTMLClocktURL(clockName, encodedSecurityCode, HTMLBaseURL, urlParamsHTML, nsValue); // returning object ClockURL clockDTO = new ClockURL(clockName, securityCode); clockDTO.EncodedSecurityCode = encodedSecurityCode; clockDTO.SilverLighClockURL = silverLightURL; clockDTO.HTMLClockURL = HTMLClockURL; clockDTO.LocationType = locationType; return(clockDTO); } catch (Exception ex) { CustomLogging.ErrorLog(ex); return(new ClockURL()); } }
public static string GetClockPrefix(string clockName) { try { clockName = clockName.ToUpper(); if (clockName[0] == 'T') { return(clockName.Substring(0, 2)); } else if (clockName[0] == 'M') { return(clockName.Substring(0, 3)); } else { return(clockName); } }catch (Exception ex) { CustomLogging.ErrorLog(ex); return(""); } }
public int GetEmployeeId() { var employeeId = 0; try { var accountName = @"" + (_user.Identity.Name != null ? _user.Identity.Name : WindowsIdentity.GetCurrent().Name); var binding = new BasicHttpBinding(); binding.Name = "UserInfoWebServiceSoap"; binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; var addressUri = dbService.GetConfigurationProperties("UserInfoServiceUrl"); if (addressUri.Contains("https")) { binding.Security.Mode = BasicHttpSecurityMode.Transport; } var endpoint = new EndpointAddress(addressUri); var client = new UserInfoServiceReference.UserInfoWebServiceSoapClient(binding, endpoint); Util.ApplyCredentials("", "", client.ClientCredentials); var empId = client.getMyEmpIDByAccountNameAsync(accountName).ConfigureAwait(true).GetAwaiter().GetResult(); int.TryParse(empId, out employeeId); if (employeeId < 0) { employeeId = 0; } } catch (Exception ex) { CustomLogging.ErrorLog(ex); } return(employeeId); }
public dynamic GetAllStatesFromStoreInfo(string isPhysical) { try { ADLocationsModel locations = new ADLocationsModel(); var binding = new BasicHttpBinding(); binding.Name = "StoreInfoWebServiceSoap"; binding.MaxReceivedMessageSize = 6553600; binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; var addressUri = dbService.GetConfigurationProperties("StoreInfoServiceUrl"); if (addressUri.Contains("https")) { binding.Security.Mode = BasicHttpSecurityMode.Transport; } var endpoint = new EndpointAddress(addressUri); var client = new StoreServiceReference.RetrieveNameSoapClient(binding, endpoint); Util.ApplyCredentials("", "", client.ClientCredentials); var element = client.getAllLocationsAsync(isPhysical.ToString()).ConfigureAwait(true).GetAwaiter().GetResult(); if (element != null) { var xmlDocument = Util.ConvertXElementToXmlDocument(element.Nodes[1]); var info = xmlDocument.FirstChild.FirstChild; locations = Util.ConvertXmlNodeToObject <ADLocationsModel>(info); } return(locations); } catch (Exception ex) { CustomLogging.ErrorLog(ex); return(new ADLocationsModel()); } }