Ejemplo n.º 1
0
        public void UnregisterScriptFormatter()
        {
            IScriptFormatter scriptFormatter = this.RegisterScriptFormatterInManager("scriptFormatter");

            this.scriptsManager.UnregisterScriptFormatter(scriptFormatter.Id);
            Assert.Throws <KeyNotFoundException>(() => this.scriptsManager.GetScriptFormatter(scriptFormatter.Id));
        }
Ejemplo n.º 2
0
        public void FormatStringNot()
        {
            IScriptFormatter scriptFormatter = this.RegisterScriptFormatterInManager("scriptFormatter");
            string           stringToFormat  = "123%notAScriptFormatter%456";

            Assert.AreEqual(stringToFormat, this.scriptsManager.FormatString(stringToFormat));
        }
Ejemplo n.º 3
0
        public void RegisterScriptFormatterOverwrite()
        {
            this.RegisterScriptFormatterInManager("scriptFormatter");
            IScriptFormatter scriptFormatter = this.RegisterScriptFormatterInManager("scriptFormatter");

            Assert.AreSame(scriptFormatter, this.scriptsManager.GetScriptFormatter(scriptFormatter.Id));
        }
Ejemplo n.º 4
0
        public void RegisterScriptFormatter()
        {
            IScriptFormatter scriptFormatter = this.RegisterScriptFormatterInManager("scriptFormatter");

            CollectionAssert.Contains(this.scriptsManager.GetListOfScriptFormatters(), scriptFormatter, "Contains");
            Assert.AreSame(scriptFormatter, this.scriptsManager.GetScriptFormatter(scriptFormatter.Id), "Equality");
            Assert.AreSame(this.scriptsManager, scriptFormatter.ScriptsManager, "ScriptsManager");
        }
Ejemplo n.º 5
0
        protected virtual IScriptFormatter RegisterScriptFormatterInManager(string id)
        {
            IScriptFormatter scriptFormatter = Substitute.For <IScriptFormatter>();

            scriptFormatter.Id.Returns(id);
            this.scriptsManager.RegisterScriptFormatter(scriptFormatter);
            return(scriptFormatter);
        }
Ejemplo n.º 6
0
        public void GetCachedFormatterResult()
        {
            IScriptFormatter scriptFormatter = this.RegisterScriptFormatterInManager("scriptFormatter");
            DynValue         expected        = DynValue.NewString("Ho ho ho!!");

            scriptFormatter.CachedVariable.Returns(expected);
            Assert.AreEqual(expected, this.scriptsManager.GetCachedResult("%" + scriptFormatter.Id + "%"));
        }
Ejemplo n.º 7
0
 public Scripter(IServer server, IScriptFileManager scriptFileManager, ILogger logger, IScriptFormatter formatter = null)
 {
     _server = server;
     _scriptFileManager = scriptFileManager;
     _includeTheseDatabases = new List<string>();
     _excludeTheseDatabases = new List<string>();
     _sources = new List<ScriptingSource>();
     _formatter = formatter ?? new ScriptFormatter();
     _logger = logger;
 }
Ejemplo n.º 8
0
        public void FormatStringNull()
        {
            IScriptFormatter scriptFormatter = this.RegisterScriptFormatterInManager("scriptFormatter");
            string           toReturn        = null;

            scriptFormatter.CachedVariable.Returns(DynValue.NewString(toReturn));
            string stringToFormat = "123%scriptFormatter%456";
            string expected       = "123456";

            Assert.AreEqual(expected, this.scriptsManager.FormatString(stringToFormat));
        }
Ejemplo n.º 9
0
        public void GetCachedFormatterResult_RunFirstUpdateNoChange()
        {
            IScriptFormatter scriptFormatter = this.RegisterScriptFormatterInManager("scriptFormatter");

            scriptFormatter.HasCachedVariable.Returns(false);
            scriptFormatter.UpdateCachedVariable().Returns(false);
            IScriptFormatter scriptFormatterHooked = this.RegisterScriptFormatterInManager("scriptFormatterHooked");

            scriptFormatterHooked.Hooks.Returns(new HashSet <string>()
            {
                "%scriptFormatter%"
            });

            this.scriptsManager.GetCachedResult("%" + scriptFormatter.Id + "%");
            scriptFormatter.Received(1).UpdateCachedVariable();
            scriptFormatterHooked.Received(0).UpdateCachedVariable();
        }
Ejemplo n.º 10
0
        public void CachedVariableChangedNotifySubscribersToUpdate_ScriptFormatter()
        {
            IScriptVariable scriptVariable = this.RegisterScriptVariableInManager("scriptVariable");

            scriptVariable.Hooks.Returns(new HashSet <string>()
            {
                "%scriptFormatterHook%"
            });
            IScriptFormatter scriptFormatter = this.RegisterScriptFormatterInManager("scriptFormatter");

            scriptFormatter.Hooks.Returns(new HashSet <string>()
            {
                "%scriptFormatterHook%"
            });
            IScriptFormatter scriptFormatterHook = this.RegisterScriptFormatterInManager("scriptFormatterHook");

            scriptFormatterHook.CachedVariableChanged += Raise.Event <EventHandler <CachedVariableChangedEventArgs> >(
                scriptFormatterHook, new CachedVariableChangedEventArgs(1, 2));
            scriptVariable.Received(0).UpdateCachedVariable(); // Variable does not have access to the cached variable of a formatter
            scriptFormatter.Received(1).UpdateCachedVariable();
        }
Ejemplo n.º 11
0
        public void NotifySubscribersToUpdate_ScriptFormatter()
        {
            IScriptVariable scriptVariable = this.RegisterScriptVariableInManager("scriptVariable");

            scriptVariable.Hooks.Returns(new HashSet <string>()
            {
                "%scriptFormatterHook%"
            });
            IScriptFormatter scriptFormatter = this.RegisterScriptFormatterInManager("scriptFormatter");

            scriptFormatter.Hooks.Returns(new HashSet <string>()
            {
                "%scriptFormatterHook%"
            });
            IScriptFormatter scriptFormatterHook = Substitute.For <IScriptFormatter>();

            scriptFormatterHook.Id.Returns("scriptFormatterHook");

            this.scriptsManager.NotifySubscribersToUpdate(scriptFormatterHook);
            scriptVariable.Received(0).UpdateCachedVariable(); // Variable does not have access to the cached variable of a formatter
            scriptFormatter.Received(1).UpdateCachedVariable();
        }
Ejemplo n.º 12
0
        public void NotifySubscribersToUpdate_ScriptVariable()
        {
            IScriptVariable scriptVariable = this.RegisterScriptVariableInManager("scriptVariable");

            scriptVariable.Hooks.Returns(new HashSet <string>()
            {
                "scriptVariableHook"
            });
            IScriptFormatter scriptFormatter = this.RegisterScriptFormatterInManager("scriptFormatter");

            scriptFormatter.Hooks.Returns(new HashSet <string>()
            {
                "scriptVariableHook"
            });
            IScriptVariable scriptVariableHook = Substitute.For <IScriptVariable>();

            scriptVariableHook.Id.Returns("scriptVariableHook");

            this.scriptsManager.NotifySubscribersToUpdate(scriptVariableHook);
            scriptVariable.Received(1).UpdateCachedVariable();
            scriptFormatter.Received(1).UpdateCachedVariable();
        }
Ejemplo n.º 13
0
        public virtual object GetCachedResult(string id)
        {
            if (!id.StartsWith("%") || !id.EndsWith("%"))
            {
                switch (id)
                {
                case "UIVersion": return(this.MumbleLinkFile.UIVersion);

                case "UITick": return(this.MumbleLinkFile.UITick);

                case "Name": return(this.MumbleLinkFile.Name);

                case "AvatarPosition": return(this.MumbleLinkFile.AvatarPosition.ToDictionary());

                case "AvatarFront": return(this.MumbleLinkFile.AvatarFront.ToDictionary());

                case "AvatarTop": return(this.MumbleLinkFile.AvatarTop.ToDictionary());

                case "CameraPosition": return(this.MumbleLinkFile.CameraPosition.ToDictionary());

                case "CameraFront": return(this.MumbleLinkFile.CameraFront.ToDictionary());

                case "CameraTop": return(this.MumbleLinkFile.CameraTop.ToDictionary());

                case "Description": return(this.MumbleLinkFile.Description);
                }

                if (this.MumbleLinkFile is Gw2MumbleLinkFile)
                {
                    Gw2MumbleLinkFile gw2MumbleLinkFile = (Gw2MumbleLinkFile)this.MumbleLinkFile;
                    switch (id)
                    {
                    case "CharacterName": return(gw2MumbleLinkFile.CharacterName);

                    case "ProfessionId": return(gw2MumbleLinkFile.ProfessionId);

                    case "MapId": return(gw2MumbleLinkFile.MapId);

                    case "WorldId": return(gw2MumbleLinkFile.WorldId);

                    case "TeamColorId": return(gw2MumbleLinkFile.TeamColorId);

                    case "IsCommander": return(gw2MumbleLinkFile.IsCommander);

                    case "ServerAddress": return(gw2MumbleLinkFile.ServerAddress.GetAddressBytes());

                    case "MapType": return(gw2MumbleLinkFile.MapType);

                    case "ShardId": return(gw2MumbleLinkFile.ShardId);

                    case "Instance": return(gw2MumbleLinkFile.Instance);

                    case "BuildId": return(gw2MumbleLinkFile.BuildId);
                    }
                }

                if (this.scriptVariables.ContainsKey(id))
                {
                    IScriptVariable script = this.scriptVariables[id];
                    if (!script.HasCachedVariable)
                    {
                        script.UpdateCachedVariable();
                    }
                    return(script.CachedVariable);
                }
            }
            else
            {
                id = id.Substring(1, id.Length - 2);
                if (this.scriptFormatters.ContainsKey(id))
                {
                    IScriptFormatter script = this.scriptFormatters[id];
                    if (!script.HasCachedVariable)
                    {
                        script.UpdateCachedVariable();
                    }
                    return(script.CachedVariable);
                }
            }

            return(null);
        }
Ejemplo n.º 14
0
 public virtual void RegisterScriptFormatter(IScriptFormatter scriptFormatter)
 {
     this.scriptFormatters[scriptFormatter.Id] = scriptFormatter;
     scriptFormatter.ScriptsManager            = this;
     scriptFormatter.CachedVariableChanged    += scriptFormatter_CachedVariableChanged;
 }
Ejemplo n.º 15
0
 public virtual void NotifySubscribersToUpdate(IScriptFormatter sourceScript)
 {
     this.NotifyFormatterSubscribersToUpdate("%" + sourceScript.Id + "%");
 }
Ejemplo n.º 16
0
 public Scripter(IServer server, IScriptFileManager scriptFileManager, ILogger logger, IScriptFormatter formatter = null)
 {
     _server                = server;
     _scriptFileManager     = scriptFileManager;
     _includeTheseDatabases = new List <string>();
     _excludeTheseDatabases = new List <string>();
     _sources               = new List <ScriptingSource>();
     _formatter             = formatter ?? new ScriptFormatter();
     _logger                = logger;
 }