public string SwapForFreshConnection(string name, Uri uri) { ServicePoint servicePoint = ServicePointManager.FindServicePoint(uri); servicePoint.CloseConnectionGroup(name); return(GetConnectionGroupName()); }
public string SwapForFreshConnection(string name, string url) { ServicePoint servicePoint = ServicePointManager.FindServicePoint(new Uri(url)); try { servicePoint.CloseConnectionGroup(name); } catch (NotImplementedException) { // Workaround for Mono } return(GetConnectionGroupName()); }
/// <summary> /// Sends an HTTPRequest to the website on 443 to determine if there is a valid certificate /// </summary> /// <param name="domainName">any valid domain name without "www."</param> /// <returns>SSLCert object with Issuer and Subject (type)</returns> public SSLCert GetSSLVerification(string domainName) { SSLCert myCert = new SSLCert { Issuer = "None", Subject = "None", DomainToCheck = domainName }; string groupName = Guid.NewGuid().ToString(); Uri u = new Uri(string.Format(@"https://www.{0}", domainName)); ServicePoint sp = ServicePointManager.FindServicePoint(u); if (string.IsNullOrEmpty(domainName)) { return(myCert); } HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(string.Format(@"https://www.{0}", domainName)); try { req.Timeout = 3000; req.Method = "HEAD"; req.ConnectionGroupName = groupName; using (WebResponse resp = req.GetResponse()) { } myCert = new SSLCert(sp.Certificate, domainName); } catch (WebException we) { if (!we.Message.Contains("timed out")) { try { req = (HttpWebRequest)HttpWebRequest.Create(string.Format(@"https://{0}", domainName)); using (WebResponse resp = req.GetResponse()) { } myCert = new SSLCert(sp.Certificate, domainName); } catch (Exception) { } } } catch (Exception) { } finally { sp.CloseConnectionGroup(groupName); } myCert.FixedName = GetCompanyFromRecordName(myCert.IssuerName, domainName, DigTypeEnum.SSL).TrimStart(new char[] { '"', '\\' }); return(myCert); }
private static string GetUrlSslPublicKey(string certifiedUrl) { Uri u = new Uri(certifiedUrl); ServicePoint sp = ServicePointManager.FindServicePoint(u); string groupName = Guid.NewGuid().ToString(); HttpWebRequest req = HttpWebRequest.Create(u) as HttpWebRequest; req.ConnectionGroupName = groupName; using (WebResponse resp = req.GetResponse()) { } sp.CloseConnectionGroup(groupName); return(sp.Certificate.GetPublicKeyString()); }
private void ResetConnections() { ServicePoint srvrPoint = ServicePointManager.FindServicePoint(new Uri("https://" + address + ":4504/")); srvrPoint.CloseConnectionGroup("WinmaxDataServices"); }
/// <summary> /// Initialization for a ftp remote file (i.e http://). Use HttpWebRequest for checking path. /// Then open a stream and get file size. Use Utility.Crc32 to calculate the CRC on the stream. /// All errors are catch and write in log manager. /// </summary> private void mInitHttpFile() { try { string connectionGroupName = Guid.NewGuid().ToString(); System.Net.HttpWebRequest lRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(_filePath); lRequest.ConnectionGroupName = connectionGroupName; ServicePoint servicePoint = lRequest.ServicePoint; try { lRequest.Method = System.Net.WebRequestMethods.Http.Head; using (System.Net.HttpWebResponse lResponse = (System.Net.HttpWebResponse)lRequest.GetResponse()) { _exists = true; _fileType = FileTypeEnum.HttpFile; //CalculCRC Utility.Crc32 lCrcCalculator = new PIS.Ground.Core.Utility.Crc32(); System.IO.Stream lFileStream; OpenReadHttpFile(out lFileStream, connectionGroupName); if (lFileStream != null) { using (lFileStream) { _size = lFileStream.Length; _crc = lCrcCalculator.CalculateChecksum(lFileStream); } } else { PIS.Ground.Core.LogMgmt.LogManager.WriteLog(PIS.Ground.Core.Data.TraceType.ERROR, "mInitHttpFile returned null file", "PIS.Ground.Core.Data.RemoteFileClass", null, EventIdEnum.GroundCore); } } } finally { if (lRequest != null) { try { lRequest.Abort(); } catch (NotImplementedException) { // Ignore the not implemented exception } } if (servicePoint != null) { servicePoint.CloseConnectionGroup(connectionGroupName); servicePoint = null; } } } catch (NotSupportedException lEx) { PIS.Ground.Core.LogMgmt.LogManager.WriteLog(TraceType.ERROR, "mInitHttpFile() NotSupportedException with FilePath : " + _filePath, "PIS.Ground.Core.Data.RemoteFileClass", lEx, EventIdEnum.GroundCore); } catch (System.Security.SecurityException lEx) { PIS.Ground.Core.LogMgmt.LogManager.WriteLog(TraceType.ERROR, "mInitHttpFile() SecurityException with FilePath : " + _filePath, "PIS.Ground.Core.Data.RemoteFileClass", lEx, EventIdEnum.GroundCore); } catch (UriFormatException lEx) { PIS.Ground.Core.LogMgmt.LogManager.WriteLog(TraceType.ERROR, "mInitHttpFile() UriFormatException with FilePath : " + _filePath, "PIS.Ground.Core.Data.RemoteFileClass", lEx, EventIdEnum.GroundCore); } catch (Exception lEx) { PIS.Ground.Core.LogMgmt.LogManager.WriteLog(TraceType.ERROR, "mInitHttpFile() UnsupportedException with FilePath : " + _filePath, "PIS.Ground.Core.Data.RemoteFileClass", lEx, EventIdEnum.GroundCore); } }
/// <summary> /// set the notification url /// </summary> /// <param name="sessionId">session id</param> /// <param name="notificationURL">notificaion url</param> /// <returns>true if success else false</returns> public bool SetNotificationInformation(Guid sessionId, string notificationURL) { ISessionManager objSessionMgr = new SessionManager(); try { string connectionGroupName = Guid.NewGuid().ToString(); System.Net.HttpWebRequest lRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(notificationURL); lRequest.ConnectionGroupName = connectionGroupName; ServicePoint servicePoint = lRequest.ServicePoint; try { lRequest.Method = System.Net.WebRequestMethods.Http.Get; using (System.Net.HttpWebResponse lResponse = (System.Net.HttpWebResponse)lRequest.GetResponse()) { if (lResponse.StatusCode == System.Net.HttpStatusCode.OK) { string error = objSessionMgr.SetNotificationURL(sessionId, notificationURL); if (error == string.Empty) { return(true); } else { LogManager.WriteLog(TraceType.ERROR, "Invalid Session Id", "PIS.Ground.Session.SessionService.SetNotificationInformation()", null, EventIdEnum.Session); return(false); } } else { LogManager.WriteLog(TraceType.ERROR, "Invalid Notification URL", "PIS.Ground.Session.SessionService.SetNotificationInformation()", null, EventIdEnum.Session); return(false); } } } finally { if (lRequest != null) { try { lRequest.Abort(); } catch (NotImplementedException) { // Ignore the not implemented exception } } if (servicePoint != null) { servicePoint.CloseConnectionGroup(connectionGroupName); servicePoint = null; } } } catch (Exception ex) { LogManager.WriteLog(TraceType.ERROR, ex.Message, "PIS.Ground.Session.SessionService.SetNotificationInformation()", ex, EventIdEnum.Session); return(false); } }