Exemplo n.º 1
0
 /// <summary>
 /// 销毁对象方法
 /// </summary>
 public virtual void Dispose()
 {
     if (!m_isDisposed)
     {
         if (m_chart != null)
         {
             m_chart.Dispose();
             m_chart = null;
         }
         if (m_dataSource != null)
         {
             m_dataSource.Dispose();
             m_dataSource = null;
         }
         if (m_latestDataCallBack != null)
         {
             m_quoteService.UnRegisterListener(m_qtRequestID, m_latestDataCallBack);
             m_latestDataCallBack = null;
         }
         if (m_securityFilterDataCallBack != null)
         {
             Stop();
             m_securityFilterService.UnRegisterListener(m_sfRequestID, m_securityFilterDataCallBack);
             m_securityFilterDataCallBack = null;
         }
         if (m_indicator != null)
         {
             m_indicator.Dispose();
             m_indicator = null;
         }
         m_isDisposed = true;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 检查脚本
        /// </summary>
        public void CheckScript()
        {
            String newScript = "";

            CFileA.Read(m_fileName, ref newScript);
            if (m_script != newScript)
            {
                Console.WriteLine("检测到脚本被修改...");
                m_script = newScript;
                lock (m_indicators)
                {
                    while (true)
                    {
                        try
                        {
                            CIndicator indicator = m_indicators.Pop();
                            indicator.Dispose();
                        }
                        catch
                        {
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 启动线程
        /// </summary>
        /// <param name="param">参数</param>
        private void CreateThread(object param)
        {
            CIndicator indicator = CreateIndicator(DataCenter.NodeService.Script, m_native);

            indicator.CallFunction(param.ToString());
            indicator.Dispose();
        }
Exemplo n.º 4
0
 /// <summary>
 /// 销毁方法
 /// </summary>
 public virtual void Dispose()
 {
     if (!m_isDisposed)
     {
         if (m_gaia != null)
         {
             m_gaia.Dispose();
         }
         m_isDisposed = true;
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// 删除指标
 /// </summary>
 /// <param name="id">指标ID</param>
 public static void DeleteIndicatorExtern(int id)
 {
     if (m_indicators.ContainsKey(id))
     {
         CIndicator indicator = m_indicators[id];
         m_indicators.Remove(id);
         indicator.Clear();
         indicator.DataSource.Dispose();
         indicator.DataSource = null;
         indicator.Dispose();
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// 异步运行计划
        /// </summary>
        /// <param name="parameter">参数</param>
        public void Run(object parameter)
        {
            //获取参数
            object[] parameters    = parameter as object[];
            String   id            = parameters[0].ToString();
            String   commandString = parameters[1].ToString();

            SetLastResult(id, "正在执行");
            try
            {
                UIXml uiXml = new UIXml();
                uiXml.CreateNative();
                CIndicator indicator = CFunctionEx.CreateIndicator(id, commandString, uiXml);
                indicator.Dispose();
                uiXml.Dispose();
            }
            catch (Exception ex)
            {
                SetLastResult(id, "失败:" + ex.Message + "\r\n" + ex.StackTrace);
                return;
            }
            SetLastResult(id, "成功");
        }
Exemplo n.º 7
0
 /// <summary>
 /// 宏运行中
 /// </summary>
 /// <param name="macro">宏</param>
 /// <returns>状态</returns>
 public virtual int OnMacroRunning(Macro macro)
 {
     if (OnMacroStart(macro) == 0)
     {
         return(0);
     }
     if (macro.m_script.Length > 0)
     {
         int        endIndex      = m_chart.Index;
         ChartA     ct            = m_chart.Chart;
         CTable     dataSource    = ct.DataSource;
         CTable     newDataSource = SecurityDataHelper.CreateDataSource(ct);
         int        interval      = macro.m_interval;
         CIndicator indicator     = SecurityDataHelper.CreateIndicator(ct, newDataSource, "", "");
         //indicator.AddFunction(new CFunctionEx(indicator, 1000, "ALERT", m_mainFrame-));
         //indicator.AddFunction(new CFunctionEx(indicator, 1001, "SETCYCLE", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1002, "SETLAYOUT", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1003, "SETCODE", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1004, "SHOWWINDOW", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1005, "SLEEP", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1006, "SCROLLLEFT", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1007, "SCROLLRIGHT", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1008, "ZOOMIN", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1009, "ZOOMOUT", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1010, "WIN_MOUSEEVENT", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1011, "WIN_SETTEXT", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1012, "WIN_EXECUTE", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1013, "WIN_SENDKEY", m_chart));
         //indicator.AddFunction(new CFunctionEx(indicator, 1014, "WIN_GETVALUE", m_chart));
         indicator.Script = macro.m_script;
         int[] fields     = new int[] { KeyFields.CLOSE_INDEX, KeyFields.HIGH_INDEX, KeyFields.LOW_INDEX, KeyFields.OPEN_INDEX, KeyFields.VOL_INDEX, KeyFields.AMOUNT_INDEX };
         int   fieldsSize = fields.Length;
         int   startIndex = endIndex - (interval - 1);
         if (startIndex < 0)
         {
             startIndex = 0;
         }
         if (startIndex > endIndex)
         {
             startIndex = endIndex;
         }
         if (macro.m_type == 0 || macro.m_type == 2 || endIndex == -1)
         {
             double date = 0;
             newDataSource.Set(date, KeyFields.VOL_INDEX, 0);
             int index = newDataSource.GetRowIndex(date);
             for (int j = 0; j < fieldsSize; j++)
             {
                 if (fields[j] != KeyFields.VOL_INDEX)
                 {
                     newDataSource.Set2(index, fields[j], 0);
                 }
             }
         }
         else
         {
             for (int i = startIndex; i <= endIndex; i++)
             {
                 double date = dataSource.GetXValue(i);
                 newDataSource.Set(date, KeyFields.VOL_INDEX, dataSource.Get2(i, KeyFields.VOL_INDEX));
                 int index = newDataSource.GetRowIndex(date);
                 for (int j = 0; j < fieldsSize; j++)
                 {
                     if (fields[j] != KeyFields.VOL_INDEX)
                     {
                         newDataSource.Set2(index, fields[j], dataSource.Get2(i, fields[j]));
                     }
                 }
             }
         }
         if (macro.m_type == 1 || macro.m_type == 3)
         {
             indicator.OnCalculate(0);
         }
         else
         {
             for (int i = 0; i < interval; i++)
             {
                 indicator.OnCalculate(0);
             }
         }
         indicator.Clear();
         indicator.Dispose();
         newDataSource.Dispose();
     }
     OnMacroEnd(macro);
     return(1);
 }
Exemplo n.º 8
0
        /// <summary>
        /// 发送全体消息
        /// </summary>
        private void SendAll()
        {
            byte[]       fileBytes   = null;
            RadioButtonA rbBarrage   = GetRadioButton("rbBarrage");
            RadioButtonA rbText      = GetRadioButton("rbText");
            RadioButtonA rbFile      = GetRadioButton("rbFile");
            RadioButtonA rbAttention = GetRadioButton("rbAttention");
            String       text        = GetTextBox("txtSend").Text;
            String       sayText     = text;

            if (rbFile.Checked)
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    text      = "sendfile('" + new FileInfo(openFileDialog.FileName).Name + "');";
                    fileBytes = File.ReadAllBytes(openFileDialog.FileName);
                    sayText   = text;
                }
                else
                {
                    return;
                }
            }
            else
            {
                if (text == null || text.Trim().Length == 0)
                {
                    MessageBox.Show("请输入你想说的内容!", "提示");
                }
            }
            if (rbBarrage.Checked)
            {
                text = "addbarrage('" + text + "');";
            }
            else if (rbText.Checked)
            {
                text = "addtext('" + text + "');";
            }
            else if (rbAttention.Checked)
            {
                text = "how('" + GetTextBox("txtUserName").Text + "喊:" + text + "');";
            }
            ChatData chatData = new ChatData();

            chatData.m_content = text;
            if (fileBytes != null)
            {
                chatData.m_body       = fileBytes;
                chatData.m_bodyLength = fileBytes.Length;
            }
            chatData.m_from = DataCenter.UserName;
            DataCenter.SendAll(chatData);
            if (rbBarrage.Checked)
            {
                CIndicator indicator = CFunctionEx.CreateIndicator("", text, this);
                indicator.Clear();
                indicator.Dispose();
            }
            TextBoxA txtReceive = GetTextBox("txtReceive");

            txtReceive.Text += "我说:\r\n" + sayText + "\r\n";
            txtReceive.Invalidate();
            if (txtReceive.VScrollBar != null && txtReceive.VScrollBar.Visible)
            {
                txtReceive.VScrollBar.ScrollToEnd();
                txtReceive.Update();
                txtReceive.Invalidate();
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 发送消息
        /// </summary>
        private void Send(List <GridRow> rows)
        {
            byte[]       fileBytes   = null;
            String       text        = GetTextBox("txtSend").Text;
            RadioButtonA rbBarrage   = GetRadioButton("rbBarrage");
            RadioButtonA rbText      = GetRadioButton("rbText");
            RadioButtonA rbFile      = GetRadioButton("rbFile");
            RadioButtonA rbAttention = GetRadioButton("rbAttention");
            String       sayText     = text;

            if (rbFile.Checked)
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    text      = "sendfile('" + new FileInfo(openFileDialog.FileName).Name + "');";
                    fileBytes = File.ReadAllBytes(openFileDialog.FileName);
                    sayText   = text;
                }
                else
                {
                    return;
                }
            }
            else
            {
                if (text == null || text.Trim().Length == 0)
                {
                    MessageBox.Show("请输入你想说的内容!", "提示");
                }
            }
            if (rbBarrage.Checked)
            {
                text = "addbarrage('" + text + "');";
            }
            else if (rbText.Checked)
            {
                text = "addtext('" + text + "');";
            }
            else if (rbAttention.Checked)
            {
                text = "how('" + GetTextBox("txtUserName").Text + "喊:" + text + "');";
            }
            int  rowsSize = rows.Count;
            bool sendAll  = false;

            if (rowsSize > 0)
            {
                for (int i = 0; i < rowsSize; i++)
                {
                    GridRow     thisRow     = rows[i];
                    String      ip          = thisRow.GetCell("colP1").GetString();
                    int         port        = thisRow.GetCell("colP2").GetInt();
                    String      userID      = thisRow.GetCell("colP3").GetString();
                    ChatService chatService = null;
                    String      key         = ip + ":" + CStr.ConvertIntToStr(port);
                    chatService = DataCenter.GetClientChatService(key);
                    if (chatService != null)
                    {
                        if (!chatService.Connected)
                        {
                            int socketID = OwLib.BaseService.Connect(ip, port);
                            if (socketID != -1)
                            {
                                chatService.Connected = true;
                                chatService.SocketID  = socketID;
                                chatService.Enter();
                            }
                            else
                            {
                                sendAll = true;
                            }
                        }
                    }
                    else
                    {
                        int type = thisRow.GetCell("colP5").GetInt();
                        if (type == 1)
                        {
                            continue;
                        }
                        else
                        {
                            int socketID = OwLib.BaseService.Connect(ip, port);
                            if (socketID != -1)
                            {
                                chatService            = new ChatService();
                                chatService.SocketID   = socketID;
                                chatService.ServerIP   = ip;
                                chatService.ServerPort = port;
                                chatService.ToServer   = false;
                                DataCenter.AddClientChatService(key, chatService);
                                BaseService.AddService(chatService);
                            }
                            else
                            {
                                sendAll = true;
                            }
                        }
                    }
                    ChatData chatData = new ChatData();
                    chatData.m_content = text;
                    if (fileBytes != null)
                    {
                        chatData.m_body       = fileBytes;
                        chatData.m_bodyLength = fileBytes.Length;
                    }
                    chatData.m_from = DataCenter.UserName;
                    if (sendAll)
                    {
                        chatData.m_to = userID;
                        DataCenter.SendAll(chatData);
                    }
                    else
                    {
                        chatService.Send(chatData);
                    }
                    if (rbBarrage.Checked)
                    {
                        CIndicator indicator = CFunctionEx.CreateIndicator("", text, this);
                        indicator.Clear();
                        indicator.Dispose();
                    }
                    TextBoxA txtReceive = GetTextBox("txtReceive");
                    txtReceive.Text += "我说:\r\n" + sayText + "\r\n";
                    txtReceive.Invalidate();
                    if (txtReceive.VScrollBar != null && txtReceive.VScrollBar.Visible)
                    {
                        txtReceive.VScrollBar.ScrollToEnd();
                        txtReceive.Update();
                        txtReceive.Invalidate();
                    }
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 调用主线程返方法
        /// </summary>
        /// <param name="sender">调用者</param>
        /// <param name="args">参数</param>
        public void Invoke(object sender, object args)
        {
            CMessage message = args as CMessage;

            if (message != null)
            {
                if (message.m_serviceID == ChatService.SERVICEID_CHAT)
                {
                    if (message.m_functionID == ChatService.FUNCTIONID_SENDALL)
                    {
                        ChatData chatData = new ChatData();
                        ChatService.GetChatData(chatData, message.m_body, message.m_bodyLength);
                        CIndicator indicator = CFunctionEx.CreateIndicator2("", chatData, this);
                        indicator.Clear();
                        indicator.Dispose();
                    }
                    else if (message.m_functionID == ChatService.FUNCTIONID_GETHOSTS)
                    {
                        List <ChatHostInfo> datas = new List <ChatHostInfo>();
                        int type = 0;
                        ChatService.GetHostInfos(datas, ref type, message.m_body, message.m_bodyLength);
                        if (type != 2)
                        {
                            int datasSize = datas.Count;
                            for (int i = 0; i < datasSize; i++)
                            {
                                ChatHostInfo   hostInfo    = datas[i];
                                List <GridRow> rows        = m_gridHosts.m_rows;
                                int            rowsSize    = rows.Count;
                                bool           containsRow = false;
                                for (int j = 0; j < rowsSize; j++)
                                {
                                    GridRow oldRow = rows[j];
                                    if (oldRow.GetCell("colP1").GetString() == hostInfo.m_ip && oldRow.GetCell("colP2").GetInt() == hostInfo.m_serverPort)
                                    {
                                        containsRow = true;
                                    }
                                }
                                if (!containsRow)
                                {
                                    if (hostInfo.m_type == 1)
                                    {
                                        String      key = hostInfo.m_ip + ":" + hostInfo.m_serverPort;
                                        ChatService newServerService = DataCenter.GetClientChatService(key);
                                        if (newServerService == null)
                                        {
                                            newServerService            = new ChatService();
                                            newServerService.ServerIP   = hostInfo.m_ip;
                                            newServerService.ServerPort = hostInfo.m_serverPort;
                                            newServerService.ToServer   = true;
                                            BaseService.AddService(newServerService);
                                            DataCenter.AddClientChatService(key, newServerService);
                                        }
                                    }
                                    else
                                    {
                                        GridRow row = new GridRow();
                                        m_gridHosts.AddRow(row);
                                        row.AddCell("colP1", new GridStringCell(hostInfo.m_ip));
                                        row.AddCell("colP2", new GridIntCell(hostInfo.m_serverPort));
                                        if (hostInfo.m_type == 1)
                                        {
                                            row.AddCell("colP3", new GridStringCell("--"));
                                            row.AddCell("colP4", new GridStringCell("--"));
                                        }
                                        else
                                        {
                                            row.AddCell("colP3", new GridStringCell(hostInfo.m_userID));
                                            row.AddCell("colP4", new GridStringCell(hostInfo.m_userName));
                                        }
                                        row.AddCell("colP5", new GridStringCell(hostInfo.m_type == 1 ? "服务器" : "客户端"));
                                    }
                                }
                            }
                        }
                        else
                        {
                            Dictionary <String, String> removeHosts = new Dictionary <String, String>();
                            foreach (ChatHostInfo hostInfo in datas)
                            {
                                removeHosts[hostInfo.ToString()] = "";
                            }
                            List <GridRow> rows     = m_gridHosts.m_rows;
                            int            rowsSize = rows.Count;
                            if (rowsSize > 0)
                            {
                                for (int i = 0; i < rowsSize; i++)
                                {
                                    GridRow row = rows[i];
                                    String  key = row.GetCell("colP1").GetString() + ":" + row.GetCell("colP2").GetString();
                                    if (removeHosts.ContainsKey(key))
                                    {
                                        m_gridHosts.RemoveRow(row);
                                        i--;
                                        rowsSize--;
                                    }
                                }
                            }
                        }
                        SetHostGridRowVisible();
                    }
                    else if (message.m_functionID == ChatService.FUNCTIONID_SEND)
                    {
                        ChatData chatData = new ChatData();
                        ChatService.GetChatData(chatData, message.m_body, message.m_bodyLength);
                        CIndicator indicator = CFunctionEx.CreateIndicator2("", chatData, this);
                        indicator.Clear();
                        indicator.Dispose();
                    }
                }
            }
            String newStr = args as String;

            if (newStr != null)
            {
                if (newStr == "showchat")
                {
                    FlashWindow(m_mainForm.Handle, true);
                    SetForegroundWindow(m_mainForm.Handle);
                }
                else if (newStr == "shake")
                {
                    m_mainForm.Play();
                }
                else if (newStr.StartsWith("how:"))
                {
                    String  text    = newStr.Substring(4);
                    Barrage barrage = new Barrage();
                    barrage.Text = text;
                    barrage.Mode = 1;
                    m_barrageForm.BarrageDiv.AddBarrage(barrage);
                }
                else
                {
                    TextBoxA txtReceive = GetTextBox("txtReceive");
                    txtReceive.Text += newStr;
                    txtReceive.Invalidate();
                    if (txtReceive.VScrollBar != null && txtReceive.VScrollBar.Visible)
                    {
                        txtReceive.VScrollBar.ScrollToEnd();
                        txtReceive.Update();
                        txtReceive.Invalidate();
                    }
                }
            }
        }