Ejemplo n.º 1
0
        public void ReceiveS2F37(PrimaryMessageWrapper e, ref byte[] ERACK)
        {
            //Structure: L,2
            //    1. < CEED > enable / disable
            //    2.L,n #CEIDs
            //        1. < CEID1 >
            //        .
            //        .
            //        n. < CEIDn >

            ERACK[0] = SanwaACK.ERACK_ACK;

            Item CEEDItem      = e.Message.SecsItem.Items[0];
            Item EventListItem = e.Message.SecsItem.Items[1];

            //確認所有CEID是否正確
            for (int i = 0; i < EventListItem.Count; i++)
            {
                Item EventItem = EventListItem.Items[i];
                if (!CheckFomart3x5x20(EventItem))
                {
                    ERACK[0] = SanwaACK.ERACK_CEID_NOT_EXIS;
                    return;
                }

                SetItemToStringType(EventItem, out string EventID);

                _eventIDList.TryGetValue(EventID, out SanwaEvent eventObj);

                if (eventObj == null)
                {
                    ERACK[0] = SanwaACK.ERACK_CEID_NOT_EXIS;
                    return;
                }
            }

            bool enabled = CEEDItem.GetValue <bool>();

            if (EventListItem.Count == 0)   //Event 全部設定
            {
                foreach (var keyValuePair in _eventList)
                {
                    SanwaEvent eventObj = keyValuePair.Value;
                    eventObj._enabled = enabled;
                }
            }
            else
            {
                for (int i = 0; i < EventListItem.Count; i++)
                {
                    Item EventItem = EventListItem.Items[i];
                    SetItemToStringType(EventItem, out string EventID);
                    _eventIDList.TryGetValue(EventID, out SanwaEvent eventObj);
                    eventObj._enabled = enabled;
                }
            }
        }
Ejemplo n.º 2
0
        public void ReceiveS2F35(PrimaryMessageWrapper e, ref byte[] LRACK)
        {
            //Structure: L,2
            //            1. < DATAID >
            //            2.L,a # event
            //                1.L,2 #event 1
            //                    1. < CEID1>
            //                    2. L,b
            //                        1. <RPTID1>
            //                        .
            //                        .
            //                        b. <RPTIDb>

            //                a.L,2 #event a
            //                    1. < CEIDa >
            //                    2.L,c
            //                        1.<RPTID1>
            //                        .
            //                        .
            //                        c. <RPTIDc>
            LRACK[0] = SanwaACK.LRACK_ACK;

            Item EventListItem = e.Message.SecsItem.Items[1];

            //不符合資料格式 start ++
            if (EventListItem.Format != SecsFormat.List)
            {
                LRACK[0] = SanwaACK.LRACK_INVALID_FORMAT;
                return;
            }

            for (int i = 0; i < EventListItem.Count; i++)
            {
                Item CEIDItem      = EventListItem.Items[i].Items[0];
                Item RPTIDListItem = EventListItem.Items[i].Items[1];

                if (!CheckFomart3x5x20(CEIDItem))
                {
                    LRACK[0] = SanwaACK.LRACK_INVALID_FORMAT;
                    return;
                }

                if (RPTIDListItem.Count > 0)
                {
                    SetItemToStringType(CEIDItem, out string ceid);

                    bool       FindEventObj = false;
                    SanwaEvent eventObj     = null;
                    foreach (SanwaEvent EvntObj in _eventList.Values)
                    {
                        if (EvntObj._id == ceid)
                        {
                            eventObj     = EvntObj;
                            FindEventObj = true;
                            break;
                        }
                    }

                    if (!FindEventObj)
                    {
                        LRACK[0] = SanwaACK.LRACK_INVALID_FORMAT;
                        return;
                    }

                    //RPID List 清單已經滿了
                    if (eventObj._rptidList.Count > 0)
                    {
                        LRACK[0] = SanwaACK.LRACK_CEID_DEFINED;
                        return;
                    }

                    for (int j = 0; j < RPTIDListItem.Count; j++)
                    {
                        Item RPTIDItem = RPTIDListItem.Items[j];

                        if (!CheckFomart3x5x20(RPTIDItem))
                        {
                            LRACK[0] = SanwaACK.LRACK_INVALID_FORMAT;
                            return;
                        }

                        SetItemToStringType(RPTIDItem, out string rptid);

                        _reportList.TryGetValue(rptid, out SanwaRPTID sanwaRPTID);

                        if (sanwaRPTID == null)
                        {
                            LRACK[0] = SanwaACK.LRACK_RPTID_NOT_EXIST;
                            return;
                        }
                    }
                }
            }
            //不符合資料格式 End ++

            if (EventListItem.Count == 0)
            {
                foreach (var eventObj in _eventList)
                {
                    SanwaEvent eventList = eventObj.Value;
                    eventList.ClearRPTIDList();
                }
            }

            for (int i = 0; i < EventListItem.Count; i++)
            {
                Item CEIDItem      = EventListItem.Items[i].Items[0];
                Item RPTIDListItem = EventListItem.Items[i].Items[1];

                SetItemToStringType(CEIDItem, out string ceid);

                //_eventList.TryGetValue(ceid, out SanwaEvent eventObj);


                bool       FindEventObj = false;
                SanwaEvent eventObj     = null;
                foreach (SanwaEvent EvntObj in _eventList.Values)
                {
                    if (EvntObj._id == ceid)
                    {
                        eventObj     = EvntObj;
                        FindEventObj = true;
                        break;
                    }
                }

                if (FindEventObj)
                {
                    if (RPTIDListItem.Count == 0)
                    {
                        eventObj.ClearRPTIDList();
                    }
                    else
                    {
                        for (int j = 0; j < RPTIDListItem.Count; j++)
                        {
                            Item RPTIDItem = RPTIDListItem.Items[j];
                            SetItemToStringType(RPTIDItem, out string rptid);
                            eventObj.AddRPTID(rptid);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void ReceiveS2F33(PrimaryMessageWrapper e, ref byte[] DRACK)
        {
            //Structure: L,2
            //        1. < DATAID >
            //        2.L,a # reports
            //            1.L,2 report 1
            //                1. < RPTID1 >
            //                2.L,b #VIDs this report
            //                    1. < VID1 >
            //                    .
            //                    .
            //                    b.< VIDb >
            //            a.L,2 report a
            //                1. < RPTIDa >
            //                2.L,c #VIDs this report
            //                    1. < VID1 >
            //                    .
            //                    .
            //                    c. < VIDc >
            DRACK[0] = SanwaACK.DRACK_ACK;

            Item ReportListItem = e.Message.SecsItem.Items[1];

            //不符合資料格式 start ++
            if (ReportListItem.Format != SecsFormat.List)
            {
                DRACK[0] = SanwaACK.DRACK_INVALID_FORMAT;
                return;
            }

            for (int i = 0; i < ReportListItem.Count; i++)
            {
                Item RPTIDItem   = ReportListItem.Items[i].Items[0];
                Item VIDListItem = ReportListItem.Items[i].Items[1];

                if (!CheckFomart3x5x20(RPTIDItem))
                {
                    DRACK[0] = SanwaACK.DRACK_INVALID_FORMAT;
                    return;
                }

                if (VIDListItem.Count > 0)
                {
                    SetItemToStringType(RPTIDItem, out string rptid);
                    foreach (var reportObj in _reportList)
                    {
                        SanwaRPTID sanwaRPTID = reportObj.Value;

                        //RPTID 已經被定義
                        if (sanwaRPTID._id == rptid)
                        {
                            DRACK[0] = SanwaACK.DRACK_RPTID_DEFINED;
                            return;
                        }
                    }

                    for (int j = 0; j < VIDListItem.Count; j++)
                    {
                        Item VIDItem = VIDListItem.Items[j];

                        if (!CheckFomart3x5x20(VIDItem))
                        {
                            DRACK[0] = SanwaACK.DRACK_INVALID_FORMAT;
                            return;
                        }

                        SetItemToStringType(VIDItem, out string vid);

                        _svIDList.TryGetValue(vid, out SanwaSV svObj);
                        if (svObj != null)
                        {
                            continue;
                        }

                        _ecIDList.TryGetValue(vid, out SanwaEC ecObj);
                        if (ecObj != null)
                        {
                            continue;
                        }

                        _dvIDList.TryGetValue(vid, out SanwaDV dvObj);
                        if (ecObj != null)
                        {
                            continue;
                        }

                        DRACK[0] = SanwaACK.DRACK_VID_NOT_EXIST;
                        return;
                    }
                }
            }
            //不符合資料格式 End ++
            //是否停止移除所有Host定義的PRID
            if (ReportListItem.Count == 0)
            {
                foreach (var reportObj in _reportList)
                {
                    SanwaRPTID sanwaRPTID = reportObj.Value;
                    sanwaRPTID.Clear();
                }

                foreach (var eventObj in _eventList)
                {
                    SanwaEvent eventList = eventObj.Value;
                    eventList.ClearRPTIDList();
                }

                _reportList.Clear();
            }
            //寫入_reportList中
            for (int i = 0; i < ReportListItem.Count; i++)
            {
                Item RPTIDItem   = ReportListItem.Items[i].Items[0];
                Item VIDListItem = ReportListItem.Items[i].Items[1];

                SetItemToStringType(RPTIDItem, out string rptid);

                if (VIDListItem.Count != 0)
                {
                    SanwaRPTID rptObj = new SanwaRPTID
                    {
                        _id     = rptid,
                        _format = RPTIDItem.Format
                    };

                    for (int j = 0; j < VIDListItem.Count; j++)
                    {
                        Item VIDItem = VIDListItem.Items[j];
                        SetItemToStringType(VIDItem, out string vid);

                        SanwaVID vidObj = new SanwaVID();
                        vidObj._id     = vid;
                        vidObj._format = VIDItem.Format;

                        rptObj.Add(vidObj);
                    }

                    _reportList.Add(rptid, rptObj);
                }
                else//VIDListItem.Count
                {
                    bool RemoveRPTID = false;
                    foreach (var reportObj in _reportList)
                    {
                        SanwaRPTID sanwaRPTID = reportObj.Value;
                        if (sanwaRPTID._id == rptid)
                        {
                            sanwaRPTID.Clear();
                            RemoveRPTID = true;
                            break;
                        }
                    }

                    if (RemoveRPTID)
                    {
                        //移除_reportList中的實體物件
                        _reportList.Remove(rptid);
                        //移除eventList中的註冊
                        foreach (var sanwaEventObj in _eventList)
                        {
                            SanwaEvent sanwaEvent = sanwaEventObj.Value;
                            if (sanwaEvent._rptidList.Count > 0)
                            {
                                sanwaEvent._rptidList.RemoveAll(id => id == rptid);
                            }
                        }
                    }
                }
            }
        }