Esempio n. 1
0
        /// <summary>
        /// 接收消息方法
        /// </summary>
        /// <param name="message">消息</param>
        public override void OnReceive(CMessage message)
        {
            if (message.m_functionID != FUNCTIONID_MACRO_GETMACROS)
            {
                message.m_requestID = m_operatorRequestID;
            }
            List <Macro> macros = new List <Macro>();

            GetMacros(macros, message.m_body, message.m_bodyLength);
            int macrosSize = macros.Count;

            switch (message.m_functionID)
            {
            case FUNCTIONID_MACRO_GETMACROS:
            {
                m_macros = macros;
                m_loaded = true;
                break;
            }

            case FUNCTIONID_MACRO_ADDMACROS:
            {
                bool add = false;
                for (int i = 0; i < macrosSize; i++)
                {
                    Macro macro = null;
                    if (!GetMacroByID(macros[i].m_macroID, ref macro))
                    {
                        m_macros.Add(macros[i]);
                        add = true;
                    }
                }
                if (!add)
                {
                    return;
                }
                break;
            }

            case FUNCTIONID_MACRO_DELETEMACROS:
            {
                for (int i = 0; i < macrosSize; i++)
                {
                    Macro macro = null;
                    if (GetMacroByID(macros[i].m_macroID, ref macro))
                    {
                        m_macros.Remove(macro);
                    }
                }
                break;
            }

            case FUNCTIONID_MACRO_EXECUTEMACROS:
            {
                for (int i = 0; i < macrosSize; i++)
                {
                    Macro macro = null;
                    if (GetMacroByID(macros[i].m_macroID, ref macro))
                    {
                        m_chart.Chart.BeginInvoke(macro);
                    }
                    else
                    {
                        m_chart.Chart.BeginInvoke(macros[i]);
                    }
                }
                break;
            }

            case FUNCTIONID_MACRO_UPDATEMACROS:
            {
                for (int i = 0; i < macrosSize; i++)
                {
                    Macro updateMacro   = macros[i];
                    int   curMacrosSize = m_macros.Count;
                    for (int j = 0; j < curMacrosSize; j++)
                    {
                        Macro macro = m_macros[j];
                        if (macro.m_macroID == updateMacro.m_macroID)
                        {
                            m_macros[j] = updateMacro;
                            break;
                        }
                    }
                }
                break;
            }
            }
            base.OnReceive(message);
        }
Esempio n. 2
0
        /// <summary>
        /// 运行宏
        /// </summary>
        /// <param name="args">参数</param>
        private void RunMacro(object args)
        {
            Macro macro = args as Macro;

            OnMacroRunning(macro);
        }
Esempio n. 3
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);
 }