Esempio n. 1
0
        public VariableSpaceDispatcher()
        {
            EventHandlers["ocw:varSpace:create"] += new Action <string, dynamic>(async(space, dataMap) =>
            {
                VariableSpace varSpace;

                if (!ms_variableSpaces.TryGetValue(space, out varSpace))
                {
                    varSpace = new VariableSpace(space);
                    ms_variableSpaces[space] = varSpace;
                }

                var dictionary = dataMap as IDictionary <string, object>;

                Debug.WriteLine("variable space {0} created (map is {1}, dict is {2})", space, dataMap.GetType().Name, dictionary);

                if (dictionary != null)
                {
                    foreach (var kvp in dictionary)
                    {
                        Debug.WriteLine("setting {0} in space {1} to {2}", kvp.Key, space, kvp.Value);

                        await varSpace.SetValueNoSync(kvp.Key, kvp.Value);
                    }
                }
            });

            EventHandlers["ocw:varSpace:set"] += new Action <string, string, dynamic>((space, key, value) =>
            {
                // get the variable space requested
                VariableSpace varSpace;

                if (ms_variableSpaces.TryGetValue(space, out varSpace))
                {
                    Debug.WriteLine("setting {0} in space {1} to {2}", key, space, value);

                    varSpace.SetValueNoSync(key, value);
                }
            });

            EventHandlers["onClientResourceStart"] += new Action <string>(a =>
            {
                if (a == GetCurrentResourceName())
                {
                    TriggerServerEvent("ocw:varSpace:resync");
                }
            });

            Tick += VariableSpaceDispatcher_Tick;
        }
Esempio n. 2
0
        public static VariableSpace Create(string spaceId)
        {
            var space = VariableSpaceDispatcher.GetVariableSpace(spaceId);

            if (space == null)
            {
                space = new VariableSpace(spaceId);
                VariableSpaceDispatcher.AddVariableSpace(space);

                BaseScript.TriggerServerEvent("ss:makeVarSpace", spaceId);
            }

            return(space);
        }
Esempio n. 3
0
 internal static void AddVariableSpace(VariableSpace space)
 {
     ms_variableSpaces.Add(space.SpaceId, space);
 }