コード例 #1
0
ファイル: IPCast.cs プロジェクト: fflorat/IRAP
        //// 获取系统中所有终端的ID清单
        unsafe public static string GetAllTerms(string[] terms)
        {
            string termIds = "";
            // int OUT_put = 0;
            IntPtr pArray = Marshal.AllocHGlobal(0);
            int    count  = IPCast.GetTermList(pArray, 0);

            if (count > 0)
            {
                pArray = Marshal.ReAllocHGlobal(pArray, new IntPtr(count * 4));
                int ret = IPCast.GetTermList(pArray, count);        // 获取终端ID清单

                if (ret > 0)
                {
                    uint *pId = (uint *)pArray.ToPointer();
                    for (int i = 0; i < ret; i++)
                    {
                        uint tid = pId[i];
                        termIds += tid.ToString();
                        termIds += ",";
                        //获取终端状态
                        long   size          = Marshal.SizeOf(typeof(IPCast.TermAttrEx));
                        IntPtr pTermStatusEx = Marshal.AllocHGlobal((int)new IntPtr(size));

                        if (IPCast.GetTermStatusEx(tid, pTermStatusEx))
                        {
                            IPCast.TermAttrEx termAttrEx = (IPCast.TermAttrEx)Marshal.PtrToStructure(pTermStatusEx, typeof(IPCast.TermAttrEx));
                            Debug.WriteLine("termAttr.tid =" + termAttrEx.tid.ToString());
                            Debug.WriteLine("termAttr.status =" + termAttrEx.status.ToString());
                            Debug.WriteLine("termAttr.work_status =" + termAttrEx.work_status.ToString());
                            Debug.WriteLine("termAttr.call_status =" + termAttrEx.call_status.ToString());
                            Debug.WriteLine("termAttr.a_sid =" + termAttrEx.a_sid.ToString());
                            Debug.WriteLine("termAttr.vol =" + termAttrEx.vol.ToString());
                            Debug.WriteLine("termAttr.ipaddr =" + termAttrEx.ipaddr);
                            Debug.WriteLine("termAttr.fwdaddr =" + termAttrEx.fwdaddr);
                            Debug.WriteLine("termAttr.name =" + termAttrEx.name);
                            string tinfo = "tid:" + termAttrEx.tid.ToString() + " " + "name: " + termAttrEx.name + " " + "termIP: " + termAttrEx.ipaddr + " " + "vol:" + termAttrEx.vol.ToString() + "  " +
                                           "work_state:" + termAttrEx.work_status.ToString() + "Call_Status:" + termAttrEx.call_status.ToString() + " " + "a_sid:" + termAttrEx.a_sid.ToString() +
                                           "  " + "ServerIp: " + " " + termAttrEx.fwdaddr;
                            //MessageBox.Show(tinfo);

                            terms[i] = tinfo;
                        }

                        Marshal.FreeHGlobal(pTermStatusEx);
                    }
                }
                Marshal.FreeHGlobal(pArray);
            }
            termIds.Trim(',');
            return(termIds);
        }
コード例 #2
0
        private bool TermsIdle(int[] terms)
        {
            bool rlt   = false;
            bool cycle = true;

            while (cycle)
            {
                cycle = false;

                for (int i = 0; i < terms.Length; i++)
                {
                    Thread.Sleep(10);

                    long   size          = Marshal.SizeOf(typeof(IPCast.TermAttrEx));
                    IntPtr pTermStatusEx = Marshal.AllocHGlobal((int)new IntPtr(size));

                    try
                    {
                        if (IPCast.GetTermStatusEx((uint)terms[i], pTermStatusEx))
                        {
                            IPCast.TermAttrEx termAttrEx =
                                (IPCast.TermAttrEx)Marshal.PtrToStructure(
                                    pTermStatusEx,
                                    typeof(IPCast.TermAttrEx));
                            if (termAttrEx.status != 0)
                            {
                                rlt   = false;
                                cycle = true;

                                break;
                            }
                            else
                            {
                                rlt = true;
                            }
                        }
                        else
                        {
                            rlt = false;
                            break;
                        }
                    }
                    finally
                    {
                        Marshal.FreeHGlobal(pTermStatusEx);
                    }
                }
            }

            return(rlt);
        }
コード例 #3
0
        private void ConnectToITCSM2000Serv()
        {
            try
            {
                bool vaStatus =
                    IPCast.Connect(
                        SysParams.Instance.VAParams.Address,
                        SysParams.Instance.VAParams.UserID,
                        SysParams.Instance.VAParams.UserPWD);
                ipCallback = new IPCast.SetCallBack(SetCallBackHandler);

                if (vaStatus)
                {
                    IPCast.IPCAST_SetCallBack(ipCallback);
                }
            }
            catch (Exception error)
            {
                WriteLogInThread(error.Message);
            }
        }
コード例 #4
0
ファイル: IPCast.cs プロジェクト: fflorat/IRAP
        unsafe public static string GetAllSessions(string[] sessions)
        {
            string SessionSids = "SessionSids:0";
            IntPtr pArray      = Marshal.AllocHGlobal(0);
            int    count       = IPCast.GetSessionList(pArray, 0);

            if (count > 0)
            {
                pArray = Marshal.ReAllocHGlobal(pArray, new IntPtr(count * 4));
                int ret = IPCast.GetSessionList(pArray, count);  //获取会话列表

                if (ret > 0)
                {
                    uint *pSid = (uint *)pArray.ToPointer();
                    for (int i = 0; i < ret; i++)
                    {
                        uint sid = pSid[i];
                        SessionSids += sid.ToString();
                        SessionSids += ",";
                        long   size      = Marshal.SizeOf(typeof(IPCast.SessionAttr));
                        IntPtr pSessions = Marshal.AllocHGlobal((int)new IntPtr(size));
                        if (IPCast.GetSessionStatus(sid, pSessions))
                        {
                            IPCast.SessionAttr sessionAttr = (IPCast.SessionAttr)Marshal.PtrToStructure(pSessions, typeof(IPCast.SessionAttr));
                            string             sinfo       = "sid: " + sessionAttr.sid.ToString() + "   name: " + sessionAttr.name + " status: " + sessionAttr.status.ToString() + " type: " + sessionAttr.type.ToString() +
                                                             " Grade: " + sessionAttr.grade.ToString() + " t_play: " + sessionAttr.t_play.ToString() + " t_total: " + sessionAttr.t_total.ToString() + " iFile: " + sessionAttr.iFile.ToString();
                            sessions[i] = sinfo;
                        }
                        Marshal.FreeHGlobal(pSessions);
                    }
                    Marshal.FreeHGlobal(pArray);
                }
            }

            SessionSids.Trim(',');
            return(SessionSids);
        }
コード例 #5
0
        private void Do()
        {
            try
            {
                #region 打开数据库连接
                Connect();
                if (dbConnection.State != ConnectionState.Open)
                {
                    WriteLogInThread(
                        string.Format(
                            "无法连接[{0}]数据库!",
                            SysParams.Instance.DBParams.DBAddress));
                    isThreadStarted = false;
                    return;
                }
                #endregion

                #region 建立 ITC MS2000 广播服务器连接
                //vaStatus =
                //    IPCast.Connect(
                //        SysParams.Instance.VAParams.Address,
                //        SysParams.Instance.VAParams.UserID,
                //        SysParams.Instance.VAParams.UserPWD);
                #endregion

                while (true)
                {
                    if (!isThreadStarted)
                    {
                        break;
                    }

                    DeleteExpireMP3Files();

                    try
                    {
                        #region 获取需要广播的消息
                        string rightNow = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                        string sqlCmd   =
                            string.Format(
                                "SELECT TOP 5 * FROM IRAPDWforMES..utb_Log_CRPlaying " +
                                "WHERE Conclusion=0 AND StationID='{0}' " +
                                //"AND ScheduledPlayTime <= '{1}' " +
                                // "AND ScheduledExpireTime >= '{1}' " + 暂时忽略过期广播消息的设置
                                "ORDER BY CreatedTime ASC",
                                SysParams.Instance.StationID,
                                rightNow);
                        DataSet ds =
                            ExecuteReturnDataSet(
                                CommandType.Text,
                                sqlCmd);
                        DataTable dt = ds.Tables[0];
                        #endregion

                        foreach (DataRow dr in dt.Rows)
                        {
                            if (!isThreadStarted)
                            {
                                break;
                            }

                            int      logID = (int)dr["LogID"];
                            DateTime timeScheduledPlaying = Convert.ToDateTime(dr["ScheduledPlayTime"].ToString());
                            DateTime timeScheduledExpire  = Convert.ToDateTime(dr["ScheduledExpireTime"].ToString());
                            string   cmdPlay        = dr["PlayCommand"].ToString();
                            int      valueCHControl = Convert.ToInt32(dr["CHCtrlValue"].ToString());
                            int      numOfPlaying   = Convert.ToInt32(dr["TimesPlayed"].ToString());

                            if (numOfPlaying <= 0)
                            {
                                numOfPlaying = 1;
                            }

                            WriteLogInThread(cmdPlay);

                            #region 生成目标终端集
                            int[] terms = GenerateTermIDs(valueCHControl);
                            #endregion

                            if (terms.Length == 0)
                            {
                                #region 没有设置广播播放的通道,忽略该条消息,将数据库中消息记录状态更新为已广播
                                SqlCommand cmd =
                                    new SqlCommand(
                                        string.Format(
                                            "UPDATE IRAPDWforMES..utb_Log_CRPlaying " +
                                            "SET Conclusion=1 WHERE LogID={0}",
                                            logID),
                                        dbConnection)
                                {
                                    CommandType = CommandType.Text,
                                };
                                try
                                {
                                    cmd.ExecuteNonQuery();
                                }
                                catch (Exception error)
                                {
                                    WriteLogInThread(error.Message);
                                }
                                #endregion
                            }
                            else
                            {
                                #region 生成待广播的声音文件集(mp3格式)
                                IPCast.PlayFile[] files;
                                int fileCount = GenerateVoices(cmdPlay, out files);
                                #endregion

                                #region 发送消息广播
                                if (!IPCast.IPCAST_ServerStatus())
                                {
                                    ConnectToITCSM2000Serv();
                                }
                                if (!IPCast.IPCAST_ServerStatus())
                                {
                                    WriteLogInThread(
                                        string.Format(
                                            "无法连接广播服务器[{0}],不能播放广播",
                                            SysParams.Instance.VAParams.Address));
                                    continue;
                                }

                                if (TermsIdle(terms))
                                {
                                    try
                                    {
                                        IPCast.FilePlayStart(
                                            ref files,
                                            fileCount,
                                            terms,
                                            terms.Length,
                                            500,
                                            3,
                                            0,
                                            0);
                                    }
                                    catch (Exception error)
                                    {
                                        WriteLogInThread(
                                            string.Format(
                                                "播放消息广播时发生错误:[{0}]。\r\n" +
                                                "可能没有找到需要播放的 MP3 文件。",
                                                error.Message));
                                    }
                                    #endregion

                                    #region 将数据库中消息记录状态更新为已广播
                                    SqlCommand cmd =
                                        new SqlCommand(
                                            string.Format(
                                                "UPDATE IRAPDWforMES..utb_Log_CRPlaying " +
                                                "SET Conclusion=1 WHERE LogID={0}",
                                                logID),
                                            dbConnection)
                                    {
                                        CommandType = CommandType.Text,
                                    };
                                    try
                                    {
                                        cmd.ExecuteNonQuery();
                                    }
                                    catch (Exception error)
                                    {
                                        WriteLogInThread(error.Message);
                                    }
                                    #endregion
                                }
                            }

                            Thread.Sleep(10);
                        }
                    }
                    catch (Exception error)
                    {
                        WriteLogInThread(error.Message);
                    }

                    Thread.Sleep(SysParams.Instance.RefreshTimeSpan);
                }
            }
            finally
            {
                #region 关闭 ITC MS2000 广播服务器连接
                IPCast.DisConnect();
                #endregion

                if (dbConnection.State != ConnectionState.Closed)
                {
                    Disconnect();
                }
                WriteLogInThread("停止监控......");
            }
        }