/// <summary> /// 开始播放声音 /// </summary> /// <param name="args">参数</param> private static void startPlay(object args) { String fileName = Application.StartupPath + "\\config\\" + args.ToString(); if (FCFile.isFileExist(fileName)) { try { int error = mciSendString("open " + fileName, null, 0, new IntPtr(0)); if (error == 0) { mciSendString("play " + fileName, null, 0, new IntPtr(0)); Thread.Sleep(3000); mciSendString("stop " + fileName, null, 0, new IntPtr(0)); mciSendString("close " + fileName, null, 0, new IntPtr(0)); } } catch (Exception ex) { Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace); } } lock (m_plays) { if (m_plays.ContainsKey(args.ToString())) { m_plays.Remove(args.ToString()); } } }
/// <summary> /// 获取通达信的历史数据的字符串 /// </summary> /// <param name="code">股票代码</param> /// <param name="path">本地文件路径</param> /// <returns>数据字符串</returns> public static String getTdxHistoryDatasStrByCode(String code, String path) { String fileName = FCStrEx.convertDBCodeToFileName(code); String result = ""; String filePath = path + fileName; if (FCFile.isFileExist(filePath)) { FCFile.read(filePath, ref result); } return(result); }
/// <summary> /// 文件放下方法 /// </summary> /// <param name="e">参数</param> protected override void OnDragDrop(DragEventArgs e) { base.OnDragDrop(e); StringBuilder filesName = new StringBuilder(""); Array files = (System.Array)e.Data.GetData(DataFormats.FileDrop);//将拖来的数据转化为数组存储 foreach (object i in files) { String str = i.ToString(); if (FCFile.isFileExist(str)) { m_designer.openFile(str); } } }
/// <summary> /// 创建用户状态服务 /// </summary> public UserCookieService() { String dataDir = DataCenter.GetUserPath() + "\\data"; if (!FCFile.isDirectoryExist(dataDir)) { FCFile.createDirectory(dataDir); } String dataBasePath = DataCenter.GetUserPath() + "\\data\\usercookies.db"; m_connectStr = "Data Source = " + dataBasePath; if (!FCFile.isFileExist(dataBasePath)) { CreateTable(); } }
/// <summary> /// 启动监听 /// </summary> public void start() { m_useScript = FCFile.isFileExist(m_fileName); if (m_useScript) { m_native = new FCNative(); FCFile.read(m_fileName, ref m_script); m_indicator = CFunctionEx.CreateScript(m_script, m_native); Console.WriteLine(m_script); } try { //string host = "127.0.0.1"; //IPAddress ip = IPAddress.Parse(host); if (m_indicator != null) { m_indicator.callFunction("ONHTTPSERVERSTARTING('" + m_fileName + "');"); } IPEndPoint ipe = new IPEndPoint(IPAddress.Any, m_port); m_listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); m_listener.Bind(ipe); m_listener.Listen(0); } catch (Exception ex) { if (m_indicator != null) { m_indicator.callFunction("ONHTTPSERVERSTARTFAIL('" + ex.Message + "\r\n" + ex.StackTrace + "');"); } return; } int minThreadNum = 0, portThreadNum = 0, maxThreadNum = 0; ThreadPool.GetMaxThreads(out maxThreadNum, out portThreadNum); ThreadPool.GetMinThreads(out minThreadNum, out portThreadNum); if (m_indicator != null) { m_indicator.callFunction("ONHTTPSERVERSTART(" + FCStr.convertIntToStr(maxThreadNum) + "," + FCStr.convertIntToStr(minThreadNum) + ");"); } while (true) { Socket socket = m_listener.Accept(); ThreadPool.QueueUserWorkItem(new WaitCallback(readData), socket); } m_listener.Close(); }
/// <summary> /// 获取分时数据 /// </summary> public static void getMinuteDatas() { if (m_minuteDatas.Count > 0) { return; } String appPath = DataCenter.getAppPath(); foreach (String code in m_codedMap.Keys) { String fileName = m_newFileDir + FCStrEx.convertDBCodeToFileName(code); if (!FCFile.isFileExist(fileName)) { fileName = m_newFileDir + FCStrEx.convertDBCodeToSinaCode(code).ToUpper() + ".txt"; } if (FCFile.isFileExist(fileName)) { String text = ""; FCFile.read(fileName, ref text); List <SecurityData> datas = new List <SecurityData>(); StockService.getHistoryDatasByMinuteStr(text, datas); if (datas.Count > 0) { int rindex = 0; int dataSize = datas.Count; while (rindex < dataSize) { SecurityData d = datas[rindex]; if (rindex == 0) { d.m_avgPrice = d.m_close; } else { SecurityData ld = datas[rindex - 1]; d.m_avgPrice = (ld.m_avgPrice * rindex + d.m_close) / (rindex + 1); } rindex++; } m_minuteDatas[code] = datas; } } } }
/// <summary> /// 获取或设置是否需要创建表 /// </summary> public void CreateTable() { String dataBasePath = DataCenter.GetUserPath() + "\\data\\" + DATABASENAME; if (!FCFile.isFileExist(dataBasePath)) { //创建数据库文件 SQLiteConnection.CreateFile(dataBasePath); } //创建表 SQLiteConnection conn = new SQLiteConnection(m_connectStr); conn.Open(); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = CREATETABLESQL; cmd.ExecuteNonQuery(); conn.Close(); }
/// <summary> /// 加载界面方法 /// </summary> protected override void OnLoad(EventArgs e) { base.OnLoad(e); String filePath = Application.StartupPath + "\\LoginInfo.txt"; if (FCFile.isFileExist(filePath)) { String content = ""; FCFile.read(filePath, ref content); if (content.Length > 0) { String[] strs = content.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); txtMDServer.Text = strs[0]; txtTDServer.Text = strs[1]; txtBrokerID.Text = strs[2]; txtInvestorID.Text = strs[3]; txtPassword.Text = strs[4]; } } }
/// <summary> /// 工作中 /// </summary> /// <param name="dataInfo">信息</param> /// <returns>状态</returns> public override int onWorking(WorkDataInfo dataInfo) { Console.WriteLine(dataInfo.m_id.ToString()); SecurityDataInfo securityDataInfo = dataInfo as SecurityDataInfo; String url = String.Format(m_listUrl, FCStrEx.ConvertDBCodeToSinaCode(securityDataInfo.m_security.m_code)); Log = String.Format("下载:{0}", securityDataInfo.m_security.m_code); String html = DataCenter.getHttpWebRequest(url, "GB2312"); if (html != null && html.Length > 0) { NewsInfo newsInfo = new NewsInfo("sinanews"); newsInfo.m_code = securityDataInfo.m_security.m_code; String dir = newsInfo.getDirectory(); if (!FCFile.isDirectoryExist(dir)) { FCFile.createDirectory(dir); } String identifier = "<div class=\"datelist\">"; int pos = html.IndexOf(identifier); if (pos != -1) { html = html.Substring(pos + identifier.Length); html = html.Substring(0, html.IndexOf("</ul>")); html = html.Replace("<ul>\r\n\t\t\t", "").Replace(" ", " "); String[] strs = html.Split(new String[] { "<br>" }, StringSplitOptions.RemoveEmptyEntries); int strsSize = strs.Length; for (int i = 0; i < strsSize; i++) { try { newsInfo.m_content = ""; String str = strs[i]; String[] subStrs = str.Split(new String[] { "<a target='_blank' href='" }, StringSplitOptions.RemoveEmptyEntries); if (subStrs.Length >= 2) { newsInfo.m_time = subStrs[0].Trim(); String[] sunStrs = subStrs[1].Split(new String[] { "'>" }, StringSplitOptions.RemoveEmptyEntries); newsInfo.m_url = sunStrs[0]; newsInfo.m_title = sunStrs[1].Replace("</a>", ""); String fileName = newsInfo.getFileName(); if (!FCFile.isFileExist(fileName)) { Log = String.Format("下载:{0}", securityDataInfo.m_security.m_code); String contentHtml = DataCenter.getHttpWebRequest(newsInfo.m_url, "UTF-8"); String sIdentifier = "<!-- 原始正文start -->", eIdentifier = "<!-- 原始正文end -->"; int sPos = contentHtml.IndexOf(sIdentifier); if (sPos != -1) { String content = contentHtml.Substring(sPos + sIdentifier.Length); int ePos = content.IndexOf(eIdentifier); newsInfo.m_content = content.Substring(0, ePos); FCFile.write(fileName, newsInfo.ToString()); } } } } catch (Exception ex) { } } } } return(1); }
/** * 输出日志 */ public override void log(int logType, String message) { if (checkOut(logType)) { String type = null; if (logType == 1) { type = "Debug"; } else if (logType == 2) { type = "Info"; } else if (logType == 3) { type = "Warn"; } else if (logType == 4) { type = "Error"; } else if (logType == 5) { type = "Fatal"; } //yyyyMMdd String dateTime = getNowDate(m_fileAppenderConfig.m_datePattern); message = String.Format("{0} {1} {2}\r\n", dateTime, type, message); String logFile = m_fileAppenderConfig.m_logFile; if (logFile.Length == 0) { return; } String separator = LogService.FILESEPARATOR; String date = getNowDate("yyyyMMdd"); int np = logFile.LastIndexOf(date); if (np < 0) { String logDir = LogService.getAppPath() + "\\log\\" + date; FCFile.createDirectory(logDir); int pos = logFile.LastIndexOf(separator); String logFileName = logFile.Substring(pos, logFile.Length - pos + 1); String newLogFile = logDir + separator + logFileName; m_fileAppenderConfig.m_logFile = newLogFile; logFile = newLogFile; } if (FCFile.isFileExist(logFile)) { FileInfo file = new FileInfo(logFile); long len = file.Length; if (len >= m_maxFileSize) { String logDir = LogService.getAppPath() + "\\log\\" + date; ArrayList <String> files = new ArrayList <String>(); FCFile.getFiles(logDir, files); int count = files.size(); files.clear(); int pos = logFile.LastIndexOf(separator); int pos2 = logFile.LastIndexOf("."); String logFileName = logFile.Substring(pos, pos2 - 1 - pos + 1); String newFileName = String.Format("{0}\\{1}.{2}.log", logDir, logFileName, count); FileInfo oldFile = new FileInfo(logFile); FileInfo newFile = new FileInfo(newFileName); oldFile.MoveTo(newFile.FullName); } } FCFile.append(logFile, message); } }