コード例 #1
0
 public Classes.action Run(Classes.action formattedAction, int uid, int evRef)
 {
     _uidAndEvRef = $"{uid.ToString()}_{evRef.ToString()}_";;
     //_uid = uid;
     //_evRef = evRef;
     formattedAction = ChangeIncorrectEvRef(formattedAction);
     return(formattedAction);
 }
コード例 #2
0
        private void LogAllKeysAndValues(Classes.action formattedAction)
        {
            if (formattedAction == null || formattedAction.Keys.Count == 0)
            {
                return;
            }

            foreach (var formattedActionKey in formattedAction.Keys)
            {
                _logging.Log($"Key: {formattedActionKey}", LogLevel.DebugToFile);
            }
        }
コード例 #3
0
        private Classes.action ChangeIncorrectEvRef(Classes.action formattedAction)
        {
            //Remove duplicate keys. Only keep the one that might be the latest

            _logging.LogIfLogToFileEnabled($"formattedAction has {formattedAction.Keys.Count} keys before reformatting");
            LogAllKeysAndValues(formattedAction);
            formattedAction = RemoveDuplicateKeys(formattedAction);
            formattedAction = RemoveUidEvRefAndAllOtherGarbage(formattedAction);

            _logging.LogIfLogToFileEnabled($"formattedAction has {formattedAction.Keys.Count} keys after reformatting");
            LogAllKeysAndValues(formattedAction);
            return(formattedAction);
        }
コード例 #4
0
        private void CreateTriggerAndAddToCollection(Classes.action settings, IPlugInAPI.strTrigActInfo trigActInfo)
        {
            var triggerType = (string)settings[TriggerTypeKey];

            object[] argObjects   = new object[] { _logging, this, _callback };
            var      triggerToAdd = TriggerFactory.Get(_hs, triggerType, _logging, this, _callback, _collectionFactory, _homeSeerHandler);

            if (triggerToAdd != null)
            {
                triggerToAdd.AddSettingsFromTrigActionInfo(trigActInfo);
                AddOrUpdatedToRunningTriggers(triggerToAdd);
                AddDeviceId(triggerToAdd.DeviceId);
            }
        }
コード例 #5
0
        public IPlugInAPI.strMultiReturn TriggerProcessPostUi(NameValueCollection postData,
                                                              IPlugInAPI.strTrigActInfo trigActInfo)
        {
            var returnData = new IPlugInAPI.strMultiReturn();

            returnData.DataOut     = trigActInfo.DataIn;
            returnData.TrigActInfo = trigActInfo;
            returnData.sResult     = string.Empty;

            if (postData == null || postData.Count < 1)
            {
                return(returnData);
            }

            object action          = new Classes.action();
            var    formattedAction = _collectionFactory.GetActionsIfPossible(trigActInfo);

            formattedAction = _reformatCopiedAction.Run(formattedAction, trigActInfo.UID, trigActInfo.evRef);

            postData.Add(Constants.TriggerTypeKey,
                         this.ToString());        //this.GetType().Name);// typeof(this).Name;//this.ToString());

            postData.Add(Constants.IsConditionKey, _isCondition.ToString());

            //postData.Add(Constants.Uid, trigActInfo.UID.ToString());
            //postData.Add(Constants.EvRef, trigActInfo.evRef.ToString());

            foreach (string dataKey in postData)
            {
                if (string.IsNullOrEmpty(dataKey))
                {
                    continue;
                }

                var strippedKey = StripKeyOfUidStuff(dataKey);

                formattedAction.AddObject(strippedKey, (object)postData[dataKey]);
            }

            object objAction = (object)formattedAction;

            Utility.SerializeObject(ref objAction, ref returnData.DataOut);
            returnData.sResult = string.Empty;

            return(returnData);
        }
コード例 #6
0
        private Classes.action RemoveDuplicateKeys(Classes.action formattedAction)
        {
            var keysToCheck         = formattedAction.Keys.ToList();
            var duplicateKeysToKeep = ReturnDuplicateKeysToKeep(keysToCheck);

            foreach (var duplicateKeyToKeep in duplicateKeysToKeep)
            {
                if (duplicateKeyToKeep.KeysToRemove != null)
                {
                    foreach (var keyToRemove in duplicateKeyToKeep.KeysToRemove)
                    {
                        formattedAction.Remove(keyToRemove);
                    }
                }
            }

            return(formattedAction);
        }
コード例 #7
0
        private Classes.action RemoveUidEvRefAndAllOtherGarbage(Classes.action formattedAction)
        {
            var allKeys        = formattedAction.Keys.ToList();
            var keyInfoList    = new List <KeyToReplaceAndReplacement>();
            var uidKeyToLocate = @"\d{1,5}_\d{1,5}_[A-Z]";
            var regex          = new Regex(uidKeyToLocate);

            foreach (var currentKey in allKeys)
            {
                //exit if we dont find any "crap"
                if (!regex.IsMatch(currentKey))
                {
                    continue;
                }

                var indexOfUnderScore = currentKey.IndexOf('_', 2);
                if (indexOfUnderScore > 0)
                {
                    var maxLength = GetLengthToUse(currentKey, indexOfUnderScore);
                    //remap a
                    var keyInfo = new KeyToReplaceAndReplacement();
                    keyInfo.OriginalKey = currentKey;
                    keyInfo.NewKey      = currentKey.Substring(0, maxLength);
                    keyInfoList.Add(keyInfo);
                }
            }

            foreach (var keyToHandle in keyInfoList)
            {
                //replace garbage keys
                var valueToKeep = formattedAction[keyToHandle.OriginalKey];
                if (!formattedAction.ContainsKey(keyToHandle.NewKey))
                {
                    formattedAction.Add(keyToHandle.NewKey, valueToKeep);
                }
                formattedAction.Remove(keyToHandle.OriginalKey);
            }

            return(formattedAction);
        }