/// <summary> /// 取得即時報價服務 /// </summary> /// <param name="quoteServiceInformation">報價服務資訊</param> /// <returns>返回值: AbstractQuoteService 報價服務抽象類別</returns> public AbstractQuoteService GetQuoteService(QuoteServiceInformation quoteServiceInformation) { AbstractQuoteService cQuoteService = null; string sDataSource = quoteServiceInformation.DataSource; if (sDataSource == null) { Assembly cAssembly = Assembly.LoadFile(Path.GetFullPath(quoteServiceInformation.Location)); Type cType = cAssembly.GetType(quoteServiceInformation.Name); cQuoteService = Activator.CreateInstance(cType) as AbstractQuoteService; cQuoteService.Load(); //讀取資訊 } else { cQuoteService = GetQuoteService(sDataSource); } return cQuoteService; }
/// <summary> /// 停止報價元件服務 /// </summary> /// <param name="quoteServiceInformation">報價服務資訊</param> public void StopQuoteService(QuoteServiceInformation quoteServiceInformation) { if (quoteServiceInformation.Enabled) { string sDataSource = quoteServiceInformation.DataSource; RemoveQuoteService(sDataSource); //移除報價服務 quoteServiceInformation.Enabled = false; quoteServiceInformation.DataSource = null; } }
/// <summary> /// 更新報件元件資訊 /// </summary> /// <param name="quoteDirectory">報價元件資料夾</param> public void Refresh(string quoteDirectory) { string[] sDllFiles = Directory.GetFiles(quoteDirectory, "*.dll"); int iLength = sDllFiles.Length; for (int i = 0; i < iLength; i++) { string sDllFile = sDllFiles[i]; string sAssembly = Path.GetFileNameWithoutExtension(sDllFile); FileVersionInfo cFileInfo = FileVersionInfo.GetVersionInfo(sDllFile); QuoteServiceInformation cQuoteInfo = null; lock (__cQuoteServiceInfos) { if (!__cQuoteServiceInfos.TryGetValue(sAssembly, out cQuoteInfo)) { cQuoteInfo = new QuoteServiceInformation(); __cQuoteServiceInfos.Add(sAssembly, cQuoteInfo); } } //更新報價元件 if (!cQuoteInfo.Enabled) { //沒有被啟動的才可以更新 cQuoteInfo.Company = cFileInfo.CompanyName; cQuoteInfo.Description = cFileInfo.Comments; cQuoteInfo.FileVersion = cFileInfo.FileVersion; cQuoteInfo.Name = sAssembly; cQuoteInfo.Location = sDllFile; cQuoteInfo.ProductVersion = cFileInfo.ProductVersion; } } }
/// <summary> /// 啟動報價元件服務 /// </summary> /// <param name="quoteServiceInformation">報價服務資訊</param> /// <param name="userId">使用者ID</param> /// <param name="password">使用者密碼</param> /// <returns>返回值:true=登入成功, false=登入失敗</returns> public bool StartQuoteService(QuoteServiceInformation quoteServiceInformation, string userId = null, string password = null) { bool bRet = quoteServiceInformation.Enabled; if (!bRet) { AbstractQuoteService cQuoteService = GetQuoteService(quoteServiceInformation); if (userId != null && password != null) { cQuoteService.UserId = userId; cQuoteService.Password = password; } bool bLogin = cQuoteService.Login(); //登入報價伺服器 if (bLogin) { quoteServiceInformation.Enabled = bLogin; quoteServiceInformation.DataSource = cQuoteService.DataSource; AddQuoteService(cQuoteService); bRet = bLogin; } } return bRet; }
/// <summary> /// 取得所有報價元件資訊 /// </summary> /// <returns>返回值:QuoteServiceInformation類別的陣列</returns> public QuoteServiceInformation[] GetQuoteServiceInformations() { QuoteServiceInformation[] cQuoteServiceInfos = null; lock (__cQuoteServiceInfos) { int iCount = __cQuoteServiceInfos.Count; cQuoteServiceInfos = new QuoteServiceInformation[iCount]; __cQuoteServiceInfos.Values.CopyTo(cQuoteServiceInfos, 0); } return cQuoteServiceInfos; }