示例#1
0
        private Dictionary <string, string> GetPathVariables(PatchObject patch, PatchListener listener)
        {
            var result = new Dictionary <string, string> ();

            // skip if rules count differ from patch
            if (patch.path.Length != listener.rules.Length)
            {
                return(null);
            }

            for (var i = 0; i < listener.rules.Length; i++)
            {
                var matches = listener.rules[i].Matches(patch.path[i]);
                if (matches.Count == 0 || matches.Count > 2)
                {
                    return(null);
                }
                else if (listener.rawRules[i][0] == ':')
                {
                    result.Add(listener.rawRules[i].Substring(1), matches[0].ToString());
                }
            }

            return(result);
        }
示例#2
0
        private string[] CheckPatch(PatchObject patch, PatchListener listener)
        {
            // skip if rules count differ from patch
            if (patch.path.Length != listener.rules.Length)
            {
                return(new string[] { });
            }

            List <string> pathVars = new List <string>();

            for (var i = 0; i < listener.rules.Length; i++)
            {
                var matches = listener.rules[i].Matches(patch.path[i]);
                if (matches.Count == 0 || matches.Count > 2)
                {
                    return(new string[] { });
                }
                else if (matches[0].Groups.Count > 1)
                {
                    pathVars.Add(matches[0].ToString());
                    // pathVars = pathVars.concat(matches.slice(1));
                }
            }

            return(pathVars.ToArray());
        }
示例#3
0
 public void RemoveListener(PatchListener listener)
 {
     for (var i = this.listeners.Count - 1; i >= 0; i--)
     {
         if (this.listeners[i].Equals(listener))
         {
             this.listeners.RemoveAt(i);
         }
     }
 }
示例#4
0
        public PatchListener Listen(string segments, string operation, Action <string[], MessagePackObject> callback)
        {
            var regexpRules = this.ParseRegexRules(segments.Split('/'));

            PatchListener listener = new PatchListener {
                callback  = callback,
                operation = operation,
                rules     = regexpRules
            };

            this.listeners[operation].Add(listener);

            return(listener);
        }
示例#5
0
        public PatchListener Listen(string segments, Action <DataChange> callback)
        {
            var rawRules    = segments.Split('/');
            var regexpRules = this.ParseRegexRules(rawRules);

            PatchListener listener = new PatchListener {
                callback = callback,
                rules    = regexpRules,
                rawRules = rawRules
            };

            this.listeners.Add(listener);

            return(listener);
        }
示例#6
0
        public PatchListener Listen(string segments, Action <DataChange> callback, bool immediate = false)
        {
            var rawRules    = segments.Split('/');
            var regexpRules = this.ParseRegexRules(rawRules);

            PatchListener listener = new PatchListener {
                callback = callback,
                rules    = regexpRules,
                rawRules = rawRules
            };

            this.listeners.Add(listener);

            if (immediate)
            {
                List <PatchListener> onlyListener = new List <PatchListener>();
                onlyListener.Add(listener);
                this.CheckPatches(Compare.GetPatchList(new IndexedDictionary <string, object>(), this.state), onlyListener);
            }

            return(listener);
        }