BTool.AttrDataUtils.UpdateTmpAttrDict C# (CSharp) Method

UpdateTmpAttrDict() public method

public UpdateTmpAttrDict ( DataAttr>.Dictionary &tmpAttrDict, DataAttr dataAttr, bool dataChanged, string key ) : bool
tmpAttrDict DataAttr>.Dictionary
dataAttr DataAttr
dataChanged bool
key string
return bool
        public bool UpdateTmpAttrDict(ref Dictionary<string, DataAttr> tmpAttrDict, DataAttr dataAttr, bool dataChanged, string key)
        {
            bool success = true;
            try
            {
                if (dataChanged)
                {
                    dataAttr.DataUpdate = true;
                    tmpAttrDict.Add(key, dataAttr);
                }
                else if (m_deviceForm.attrData.attrDict.Count >= 1500)
                {
                    m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Warning, string.Format("Attribute Dictionary At Maximum {0} Elements\nData Lost\nAttrDataUtils\n", 1500));
                    success = false;
                }
                else
                {
                    m_deviceForm.attrData.attrDictAccess.WaitOne();
                    dataAttr.DataUpdate = true;
                    m_deviceForm.attrData.attrDict.Add(key, dataAttr);
                    m_deviceForm.attrData.attrDictAccess.ReleaseMutex();
                }
            }
            catch (Exception ex)
            {
                m_msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, "Attribute Dictionary Access Error\nUpdateTmpAttrDict()\n" + ex.Message + "\nAttrDataUtils\n");
                success = false;
            }
            return success;
        }

Usage Example

        public bool GetATT_HandleValueNotification(HCIReplies hciReplies, ref bool dataFound)
        {
            dataFound = false;
            bool success;

            if (success = rspHdlrsUtils.CheckValidResponse(hciReplies))
            {
                HCIReplies.HCI_LE_ExtEvent hciLeExtEvent = hciReplies.HciLeExtEvent;
                HCIReplies.HCI_LE_ExtEvent.ATT_HandleValueNotification valueNotification = hciLeExtEvent.AttHandleValueNotification;
                HCIReplies.LE_ExtEventHeader leExtEventHeader = hciLeExtEvent.Header;
                if (valueNotification != null)
                {
                    dataFound = true;
                    switch (leExtEventHeader.EventStatus)
                    {
                    case (byte)0:
                        if (valueNotification.Value != null)
                        {
                            Dictionary <string, DataAttr> tmpAttrDict = new Dictionary <string, DataAttr>();
                            string   attrKey     = attrUuidUtils.GetAttrKey(valueNotification.AttMsgHdr.ConnHandle, valueNotification.Handle);
                            DataAttr dataAttr    = new DataAttr();
                            bool     dataChanged = false;
                            if (!attrDataUtils.GetDataAttr(ref dataAttr, ref dataChanged, attrKey, "AttHandleValueNotification"))
                            {
                                success = false;
                                break;
                            }
                            else
                            {
                                dataAttr.Key        = attrKey;
                                dataAttr.ConnHandle = valueNotification.AttMsgHdr.ConnHandle;
                                dataAttr.Handle     = valueNotification.Handle;
                                dataAttr.Value      = valueNotification.Value;
                                if (!attrDataUtils.UpdateTmpAttrDict(ref tmpAttrDict, dataAttr, dataChanged, attrKey))
                                {
                                    success = false;
                                    break;
                                }
                                else if (!attrDataUtils.UpdateAttrDict(tmpAttrDict))
                                {
                                    success = false;
                                    break;
                                }
                                else
                                {
                                    SendRspCallback(hciReplies, true);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            break;
                        }

                    default:
                        success = rspHdlrsUtils.UnexpectedRspEventStatus(hciReplies, "AttHandleValueNotification");
                        break;
                    }
                }
            }
            if (!success && dataFound)
            {
                SendRspCallback(hciReplies, false);
            }
            return(success);
        }
All Usage Examples Of BTool.AttrDataUtils::UpdateTmpAttrDict