/// <summary> /// Open a new Session for working with /// </summary> /// <param name="username">Username to login with on a new session</param> /// <param name="password">Passowrd to login with on a new session</param> public void NewSession(string username, string password) { var callUrl = String.Format("{0}/NMS/Platform/AuthenticationSvc/v1/", m_HostUri); var factory = new ChannelFactory <NMS.Platform.Services.IAuthentication>(new WebHttpBinding(WebHttpSecurityMode.Transport), new EndpointAddress(new Uri(callUrl))); factory.Endpoint.EndpointBehaviors.Add(new WebHttpBehavior()); var channel = factory.CreateChannel(); using (new OperationContextScope((IContextChannel)channel)) { WebOperationContext.Current.OutgoingRequest.Headers.Add("Authorization", String.Format("Basic {0}", Convert.ToBase64String( System.Text.ASCIIEncoding.ASCII.GetBytes( String.Format("nms//{0}:{1}", username, password))))); m_SessInfo = channel.ValidateCredentials(null, NmsProductGUID); } ValidateLicenseOnSession(); var appData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Nuance"); if (!Directory.Exists(appData)) { Directory.CreateDirectory(appData); } var sessFile = Path.Combine(appData, "Icd.Sess"); var encryptor = new SessionDataEncryptor(); File.WriteAllText(sessFile, encryptor.Encrypt(m_SessInfo.SessionToken)); }
/// <summary> /// Try an existing session, including validating for Search ICD license type /// </summary> /// <param name="startSession">Session token to try--if not null, will only try this token; otherwise, will try The "%AppData%/Nuance/Icd.Sess" file if it exists</param> /// <returns>True if session is valid for use with Search ICD; false otherwise</returns> public bool TryExistingSession(string startSession = null) { string sessionStr = startSession; if (sessionStr == null) { var sessFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Nuance", "Icd.Sess"); if (File.Exists(sessFile)) { var encryptor = new SessionDataEncryptor(); sessionStr = encryptor.Decrypt(File.ReadAllText(sessFile)); } } if (sessionStr != null) { var callGetSessions = String.Format("{0}/NMS/Platform/SessionSvc/v1/", m_HostUri); m_SessInfo = new NMS.Platform.Objects.SessionInfo(); m_SessInfo.SessionToken = sessionStr; NMS.Platform.Objects.SessionInfo session = null; try { session = CallSessionedREST <NMS.Platform.Objects.SessionInfo, NMS.Platform.ISessionSvc>(callGetSessions, (proxy) => { return(proxy.RefreshSession()); }); } finally { m_SessInfo = null; } if (session != null) { if (session.SessionTokenExpirationTime >= DateTime.Now.AddHours(-2)) { m_SessInfo = session; ValidateLicenseOnSession(); return(true); } } } return(false); }
/// <summary> /// Initialize a new NMS Application Service Data Provider with a given NMS Host URI /// </summary> /// <param name="hostUri">NMS Host URI to utilize in following calls</param> public AppNmsSvcDataProvider(string hostUri) { m_HostUri = hostUri; m_SessInfo = null; }