Exemplo n.º 1
0
        /// <summary>
        /// 创建聊天窗体
        /// </summary>
        /// <param name="native">方法库</param>
        /// <param name="indicator">指标</param>
        public ParametersWindow(INativeBase native, CIndicator indicator)
        {
            m_indicator = indicator;
            m_native    = native;
            String xmlPath = DataCenter.GetAppPath() + "\\config\\ParametersWindow.xml";

            Native = m_native;
            LoadFile(xmlPath, null);
            m_window = FindControl("windowParameters") as WindowEx;
            GetParameters();
            //注册点击事件
            RegisterEvents(m_window);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 添加方法
        /// </summary>
        /// <param name="indicator">方法库</param>
        /// <returns>指标</returns>
        public static void AddFunctions(CIndicator indicator)
        {
            string[] functions     = FUNCTIONS.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            int      functionsSize = functions.Length;

            for (int i = 0; i < functionsSize; i++)
            {
                indicator.AddFunction(new CFunctionAjax(indicator, STARTINDEX + i, PREFIX + functions[i]));
            }
            if (m_requests == null)
            {
                m_requests = new List <AjaxRequest>();
                Thread thread = new Thread(new ThreadStart(AjaxHandle));
                thread.Start();
            }
        }
Exemplo n.º 3
0
        // 保存指标与合约之间的关系
        public bool SaveIndicator(CIndicator indictor, String instrument)
        {
            List <CIndicator> lstIndicators;

            if (mapIndictors.TryGetValue(instrument, out lstIndicators))
            {
                lstIndicators.Add(indictor);
            }
            else
            {
                lstIndicators = new List <CIndicator>();
                lstIndicators.Add(indictor);
                mapIndictors[instrument] = lstIndicators;
            }
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 启动监听
        /// </summary>
        public void Start()
        {
            m_useScript = CFileA.IsFileExist(m_fileName);
            if (m_useScript)
            {
                m_native = NativeHandler.CreateNative();
                CFileA.Read(m_fileName, ref m_script);
                m_indicator = CFunctionEx.CreateIndicator(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(" + CStr.ConvertIntToStr(maxThreadNum) + "," + CStr.ConvertIntToStr(minThreadNum) + ");");
            }
            while (DataCenter.IsAppAlive)
            {
                Socket socket = m_listener.Accept();
                ThreadPool.QueueUserWorkItem(new WaitCallback(ReadData), socket);
            }
            m_listener.Close();
        }
Exemplo n.º 5
0
        /// <summary>
        /// 运行指标
        /// </summary>
        public void Run()
        {
            if (m_chart == null)
            {
                m_chart        = new ChartA();
                m_chart.Native = m_native;
                m_dataSource   = SecurityDataHelper.CreateDataSource(m_chart);
            }
            if (m_indicator != null)
            {
                m_indicator.Dispose();
            }
            String indicator = m_template.m_indicator;

            if (m_template.m_filter != null && m_template.m_filter.Length > 0)
            {
                indicator += "FILTER:=" + m_template.m_filter;
            }
            else
            {
                indicator += "FILTER:=1";
            }
            m_indicator = SecurityDataHelper.CreateIndicator(m_chart, m_dataSource, indicator, m_template.m_parameters);
            m_indicator.OnCalculate(0);
            m_infos.Clear();
            List <Security> securities = new List <Security>();

            DataCenter.SecurityService.GetSecuritiesByCodes(m_template.m_codes, securities);
            int securitiesSize = securities.Count;

            for (int i = 0; i < securitiesSize; i++)
            {
                Security           security = securities[i];
                SecurityFilterInfo info     = new SecurityFilterInfo();
                info.DataSource          = m_dataSource;
                info.Security            = security;
                m_infos[security.m_code] = info;
            }
            LatestDataInfo dataInfo = new LatestDataInfo();

            dataInfo.m_codes      = m_template.m_codes;
            dataInfo.m_formatType = 1;
            m_quoteService.PushLatestDatas(m_qtRequestID, dataInfo);
            m_securityFilterService.StartFilter(m_sfRequestID, m_template);
            m_runningState = 0;
            m_matchCount   = 0;
        }
Exemplo n.º 6
0
        /// <summary>
        /// 添加指标
        /// </summary>
        /// <param name="chart">股票控件</param>
        /// <param name="dataSource">数据源</param>
        /// <param name="text">文本</param>
        /// <param name="parameters">参数</param>
        public static CIndicator CreateIndicator(ChartA chart, CTable dataSource, String text, String parameters)
        {
            CIndicator indicator = chart.Native.CreateIndicator();

            indicator.DataSource = dataSource;
            indicator.Name       = "";
            //indicator.FullName = "";
            if (dataSource != null)
            {
                indicator.SetSourceField(KeyFields.CLOSE, KeyFields.CLOSE_INDEX);
                indicator.SetSourceField(KeyFields.HIGH, KeyFields.HIGH_INDEX);
                indicator.SetSourceField(KeyFields.LOW, KeyFields.LOW_INDEX);
                indicator.SetSourceField(KeyFields.OPEN, KeyFields.OPEN_INDEX);
                indicator.SetSourceField(KeyFields.VOL, KeyFields.VOL_INDEX);
                indicator.SetSourceField(KeyFields.AMOUNT, KeyFields.AMOUNT_INDEX);
                indicator.SetSourceField(KeyFields.CLOSE.Substring(0, 1), KeyFields.CLOSE_INDEX);
                indicator.SetSourceField(KeyFields.HIGH.Substring(0, 1), KeyFields.HIGH_INDEX);
                indicator.SetSourceField(KeyFields.LOW.Substring(0, 1), KeyFields.LOW_INDEX);
                indicator.SetSourceField(KeyFields.OPEN.Substring(0, 1), KeyFields.OPEN_INDEX);
                indicator.SetSourceField(KeyFields.VOL.Substring(0, 1), KeyFields.VOL_INDEX);
                indicator.SetSourceField(KeyFields.AMOUNT.Substring(0, 1), KeyFields.AMOUNT_INDEX);
            }
            IndicatorData indicatorData = new IndicatorData();

            indicatorData.m_parameters = parameters;
            indicatorData.m_script     = text;
            indicator.Tag = indicatorData;
            String constValue = "";

            if (parameters != null && parameters.Length > 0)
            {
                String[] strs     = parameters.Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                int      strsSize = strs.Length;
                for (int i = 0; i < strsSize; i++)
                {
                    String   str   = strs[i];
                    String[] strs2 = str.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    constValue += "const " + strs2[0] + ":" + strs2[3] + ";";
                }
            }
            if (text != null && text.Length > 0)
            {
                indicator.Script = constValue + text;
            }
            return(indicator);
        }
    static public void DoTween_Indicator_Color(this CIndicator pIndicator, Color pColorStart, Color pColorDest, float fDuration)
    {
        pIndicator.DoSetColor(pColorStart);
        switch (pIndicator.p_eType)
        {
        case CIndicator.EIndicatorType.UGUI:
            pIndicator.p_pUIText.DOBlendableColor(pColorDest, fDuration);
            break;

#if TMPro
        case CIndicator.EIndicatorType.TextMeshPro:
            pIndicator.p_pUIText_TMPro.DOBlendableColor(pColorDest, fDuration);
            break;
#endif
        default:
            Debug.Log("Error");
            break;
        }
    }
Exemplo n.º 8
0
        /// <summary>
        /// 计算指标
        /// </summary>
        /// <param name="id">指标ID</param>
        /// <param name="code">代码</param>
        /// <returns>返回数据</returns>
        public static Dictionary <String, double> CalculateIndicatorExtern(int id, String code)
        {
            Dictionary <String, double> list = new Dictionary <String, double>();

            if (m_indicators.ContainsKey(id) &&
                SecurityService.m_historyDatas.ContainsKey(code) &&
                SecurityService.m_latestDatas.ContainsKey(code))
            {
                CIndicator        indicator  = m_indicators[id];
                List <CIndicator> indicators = new List <CIndicator>();
                indicators.Add(indicator);
                List <SecurityData> datas            = new List <SecurityData>();
                List <SecurityData> oldSecurityDatas = SecurityService.m_historyDatas[code];
                int oldSecurityDatasSize             = oldSecurityDatas.Count;
                for (int i = 0; i < oldSecurityDatasSize; i++)
                {
                    datas.Add(oldSecurityDatas[i]);
                }
                SecurityLatestData latestData = SecurityService.m_latestDatas[code];
                SecurityData       newData    = new SecurityData();
                StockService.GetSecurityData(latestData, latestData.m_lastClose, 1440, 1, ref newData);
                datas.Add(newData);
                CTable dataSource = indicator.DataSource;
                int[]  fields     = new int[] { KeyFields.CLOSE_INDEX, KeyFields.HIGH_INDEX, KeyFields.LOW_INDEX, KeyFields.OPEN_INDEX, KeyFields.VOL_INDEX, KeyFields.AMOUNT_INDEX };
                SecurityDataHelper.BindHistoryDatas(m_chart, dataSource, indicators, fields, datas);
                datas.Clear();
                int rowsCount     = dataSource.RowsCount;
                int variablesSize = indicator.MainVariables.Count;
                if (rowsCount > 0)
                {
                    foreach (String name in indicator.MainVariables.Keys)
                    {
                        int    field = indicator.MainVariables[name];
                        double value = dataSource.Get2(rowsCount - 1, field);
                        list[name] = value;
                    }
                }
                dataSource.Clear();
            }
            return(list);
        }
Exemplo n.º 9
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.º 10
0
        /// <summary>
        /// 创建指标
        /// </summary>
        /// <param name="native">方法库</param>
        /// <param name="script">脚本</param>
        /// <param name="xml">XML</param>
        /// <returns>指标</returns>
        public static CIndicator CreateIndicator(String script, INativeBase native)
        {
            CIndicator indicator = native.CreateIndicator();
            CTable     table     = native.CreateTable();

            indicator.DataSource = table;
            CFunctionBase.AddFunctions(indicator);
            CFunctionHttp.AddFunctions(indicator);
            int index = STARTINDEX;

            string[] functions     = FUNCTIONS.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            int      functionsSize = functions.Length;

            for (int i = 0; i < functionsSize; i++)
            {
                indicator.AddFunction(new CFunctionEx(indicator, index + i, functions[i], native));
            }
            indicator.Script = script;
            table.AddColumn(0);
            table.Set(0, 0, 0);
            indicator.OnCalculate(0);
            return(indicator);
        }
Exemplo n.º 11
0
    /* public - [Event] Function
     * 프랜드 객체가 호출(For Friend class call)*/

    // ========================================================================== //

    #region Protected

    /* protected - [abstract & virtual]         */

    /* protected - [Event] Function
     * 자식 객체가 호출(For Child class call)		*/

    /* protected - Override & Unity API         */

    #endregion Protected

    // ========================================================================== //

    #region Private

    /* private - [Proc] Function
     * 로직을 처리(Process Local logic)           */

    static private void OnPopIndciator(CIndicator pIndicator)
    {
        CManagerPooling <EUIObject, CIndicator> .instance.DoPush(pIndicator);
    }
Exemplo n.º 12
0
 /// <summary>
 /// 设置脚本
 /// </summary>
 /// <param name="text">脚本</param>
 public void SetText(String text)
 {
     m_text = text;
     m_gaia = CFunctionEx.CreateIndicator("", text, m_xml);
 }
 static public void DoTween_Indicator_Pos(this CIndicator pIndicator, Vector3 vecPosStart, Vector3 vecOffsetDest, float fDuration)
 {
     pIndicator.transform.position = vecPosStart;
     pIndicator.transform.DOMove(vecPosStart + vecOffsetDest, fDuration).SetEase(Ease.Linear);
 }
Exemplo n.º 14
0
 /// <summary>
 /// 创建方法
 /// </summary>
 /// <param name="indicator">指标</param>
 /// <param name="id">ID</param>
 /// <param name="name">名称</param>
 public CFunctionAjax(CIndicator indicator, int id, String name)
 {
     m_indicator = indicator;
     m_ID        = id;
     m_name      = name;
 }
Exemplo n.º 15
0
        /// <summary>
        /// 接受请求
        /// </summary>
        /// <param name="param">参数</param>
        private static void ReadData(object param)
        {
            Socket      socket      = (Socket)param;
            NodeService nodeService = DataCenter.NodeService;
            int         newSocketID = (int)socket.Handle;

            try
            {
                byte[]       buffer       = new byte[102400];
                int          len          = socket.Receive(buffer);
                MemoryStream memoryStream = new MemoryStream(buffer);
                StreamReader reader       = new StreamReader(memoryStream);
                HttpData     data         = new HttpData();
                data.m_remoteIP   = ((IPEndPoint)socket.RemoteEndPoint).Address.ToString();
                data.m_remotePort = ((IPEndPoint)socket.RemoteEndPoint).Port;
                String requestHeader;
                int    contentLength = 0;
                string parameters    = "";
                while ((requestHeader = reader.ReadLine()) != null && !String.IsNullOrEmpty(requestHeader))
                {
                    String lowerHeader = requestHeader.ToLower();
                    if (lowerHeader.IndexOf("get") == 0)
                    {
                        int end = lowerHeader.IndexOf("http/");
                        data.m_method = "GET";
                        parameters    = requestHeader.Substring(5, end - 6);
                    }
                    else if (lowerHeader.IndexOf("post") == 0)
                    {
                        int end = lowerHeader.IndexOf("http/");
                        data.m_method = "POST";
                        parameters    = requestHeader.Substring(5, end - 6);
                    }
                    else if (lowerHeader.IndexOf("accept: ") == 0)
                    {
                        try
                        {
                            data.m_contentType = requestHeader.Substring(8, requestHeader.IndexOf(',') - 8);
                        }
                        catch { }
                    }
                    else if (lowerHeader.IndexOf("content-type:") == 0)
                    {
                        data.m_contentType = requestHeader.Substring(14);
                    }
                    else if (lowerHeader.IndexOf("host:") == 0)
                    {
                        data.m_url = requestHeader.Substring(requestHeader.IndexOf(':') + 2);
                    }
                    else if (lowerHeader.IndexOf("content-length") == 0)
                    {
                        int    begin = lowerHeader.IndexOf("content-length:") + "content-length:".Length;
                        String postParamterLength = requestHeader.Substring(begin).Trim();
                        contentLength = Convert.ToInt32(postParamterLength);
                    }
                }
                if (contentLength > 0)
                {
                    if (data.m_contentType != null && data.m_contentType == "application/octet-stream(test)")
                    {
                        HttpFileData fileHttpData = new HttpFileData();
                        int          recvLength   = 0;
                        while (recvLength < contentLength)
                        {
                            byte[] bytes = new byte[10240];
                            recvLength += socket.Receive(bytes);
                            fileHttpData.m_recvLength  = recvLength;
                            fileHttpData.m_totalLength = contentLength;
                            fileHttpData.m_buffer      = bytes;
                            FileTransferService.OnReceive(data, fileHttpData);
                        }
                    }
                    else
                    {
                        int idx = 0, ide = 0;
                        data.m_body = new byte[contentLength];
                        while (idx < contentLength)
                        {
                            int recvData = reader.Read();
                            if (recvData != -1)
                            {
                                if (recvData != 0)
                                {
                                    ide++;
                                }
                                idx++;
                            }
                            else
                            {
                                break;
                            }
                        }
                        reader.Close();
                        memoryStream.Dispose();
                        if (ide == 0)
                        {
                            socket.Receive(data.m_body);
                        }
                        else
                        {
                            for (int i = 0; i < contentLength; i++)
                            {
                                data.m_body[i] = buffer[len - contentLength + i];
                            }
                        }
                    }
                    data.m_contentLength = contentLength;
                }
                else
                {
                    reader.Close();
                    memoryStream.Dispose();
                }
                if (data.m_method.Length == 0)
                {
                    return;
                }
                int cindex = parameters.IndexOf('?');
                if (cindex != -1)
                {
                    data.m_url = data.m_url + "/" + parameters;
                    parameters = parameters.Substring(cindex + 1);
                    String[] strs     = parameters.Split(new string[] { "&" }, StringSplitOptions.RemoveEmptyEntries);
                    int      strsSize = strs.Length;
                    for (int i = 0; i < strsSize; i++)
                    {
                        String[] subStrs = strs[i].Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
                        data.m_parameters[subStrs[0].ToLower()] = subStrs[1];
                    }
                }
                else
                {
                    data.m_url += "/" + parameters;
                }
                CIndicator indicator = null;
                if (nodeService.UseScript)
                {
                    try
                    {
                        lock (nodeService.m_indicators)
                        {
                            indicator = nodeService.m_indicators.Pop();
                        }
                    }
                    catch
                    {
                        indicator = CFunctionEx.CreateIndicator(nodeService.Script, nodeService.Native);
                    }
                    List <CFunction> functions = indicator.GetFunctions();
                    int functionsSize          = functions.Count;
                    for (int i = 0; i < functionsSize; i++)
                    {
                        CFunctionHttp function = functions[i] as CFunctionHttp;
                        if (function != null)
                        {
                            function.m_data = data;
                        }
                    }
                }
                data.m_socketID = newSocketID;
                lock (nodeService.m_httpDatas)
                {
                    nodeService.m_httpDatas[newSocketID] = data;
                }
                if (indicator != null)
                {
                    indicator.CallFunction("ONHTTPREQUEST();");
                }
                if (data.m_close)
                {
                    return;
                }
                int resContentLength = 0;
                if (data.m_resBytes != null)
                {
                    resContentLength = data.m_resBytes.Length;
                }
                else
                {
                    if (data.m_resStr != null)
                    {
                        resContentLength = Encoding.Default.GetBytes(data.m_resStr).Length;
                    }
                }
                StringBuilder bld = new StringBuilder();
                bld.Append("HTTP/1.0 " + data.m_statusCode.ToString() + " OK\r\n");
                bld.Append(String.Format("Content-Length: {0}\r\n", resContentLength));
                bld.Append("Connection: close\r\n\r\n");
                if (data.m_resBytes != null)
                {
                    socket.Send(Encoding.Default.GetBytes(bld.ToString()));
                    socket.Send(data.m_resBytes);
                }
                else
                {
                    bld.Append(data.m_resStr);
                    socket.Send(Encoding.Default.GetBytes(bld.ToString()));
                }
                if (indicator != null)
                {
                    lock (nodeService.m_indicators)
                    {
                        nodeService.m_indicators.Push(indicator);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace);
            }
            finally
            {
                lock (nodeService.m_httpDatas)
                {
                    nodeService.m_httpDatas.Remove(newSocketID);
                }
                socket.Close();
            }
        }
Exemplo n.º 16
0
 private static void Instance_p_EVENT_OnMakeResource(EUIObject arg1, CIndicator arg2)
 {
     arg2.p_Event_OnDisable.AddListener(OnPopIndciator);
 }
Exemplo n.º 17
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.º 18
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.º 19
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.º 20
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();
                    }
                }
            }
        }
Exemplo n.º 21
0
 /// <summary>
 /// 创建方法
 /// </summary>
 /// <param name="indicator">指标</param>
 /// <param name="id">ID</param>
 /// <param name="name">名称</param>
 /// <param name="withParameters">是否有参数</param>
 public CFunctionDataSource(CIndicator indicator, int id, String name)
 {
     m_indicator = indicator;
     m_ID        = id;
     m_name      = name;
 }