Example #1
0
        public bool Load()
        {
            var path = paths.GetDataPath(filename);

            if(!File.Exists(path))
            {
                Settings = new Settings();
            }
            else
            {
                var serializer = new DataContractSerializer(typeof(Settings));
                using(var stream = new FileStream(path, FileMode.Open))
                {
                    try
                    {

                        Settings = serializer.ReadObject(stream) as Settings;
                    }
                    catch
                    {
                        Settings = new Settings();
                        return false;
                    }
                }
            }

            FixBackwardCompatibility();
            return true;
        }
Example #2
0
        public void Load()
        {
            var path = Utils.GetAbsolutePath(filename);

            if (!File.Exists(path))
            {
                Settings = new Settings();
            }
            else
            {
                var serializer = new DataContractSerializer(typeof (Settings));
                using (var stream = new FileStream(path, FileMode.Open))
                {

                    Settings = serializer.ReadObject(stream) as Settings;
                }
            }
        }
Example #3
0
        public void Context()
        {
            Action<string> callback = s => actualCallbackValue = s;
            var plugin = new Plugin(callback);
            var plugins = new List<IPlugin> {plugin};

            var points = new List<Point> {new Point(0, 0), new Point(1, 2), new Point(2, 2.5), new Point(3, 4)};
            var settings = new Settings
            {
                Curves = new List<Curve> { new Curve { Name="testCurve", Points = points} },
            };

            var globalDummy = new GlobalDummy((key, value) =>
            {
                dummyCallbacks[key] = value;
            });

            Stub<ISettingsManager>().Expect(x => x.Settings).Return(settings);
            Stub<IEventAggregator>();
            WhenCalling<IPluginInvoker>(x => x.InvokeAndConfigurePlugins(Arg<IEnumerable<Type>>.Is.Anything)).Return(plugins);
            WhenCalling<IPluginInvoker>(x => x.ListAllPluginTypes()).Return(plugins.Select(p => p.GetType()));
            WhenCalling<IPluginInvoker>(x => x.ListAllGlobalEnumTypes()).Return(new List<Type> { typeof(TestPluginEnum)});
            Register<IGlobalProvider>(Get<ScriptHelpersGlobalProvider>());
            Register<IGlobalProvider>(Get<CurveGlobalProvider>());
            Register<IScriptParser>(Get<LuaScriptParser>());
            WhenCallingNewInstance<IGlobalProvider>(x => x.ListGlobals()).Return(new List<object> {globalDummy});

            var engine = Get<LuaEngine>();
            engine.Error += (s, e) => Assert.Fail(e.Exception.Message);
            const string simpleScript = @"
            if(starting) then
            x = 0.1;
            end

            y = testCurve:getY(x)
            x = y
            diagnostics:debug(y)
            z = 1
            filters:simple(z, 0.5)
            z = 0.5
            z = filters:simple(z, 0.5)
            if(starting) then
            globalDummy:callback(""testIndexParser"", z)
            globalDummy:callback(""enumTest"", TestPluginEnum.One)
            globalDummy:callback(""enumTestParser"", TestPluginEnum.La)
            end
            filters:simple(testCurve:getY(x), 0.5) --Test more complex parsing for NeedIndex algorithm
            --This needs to be last to test the other two
            testPlugin:dummy(""ping"")
            ";

            engine.Start(simpleScript);

            //Wait for the script to run atleast once
            Thread.Sleep(50);

            engine.Stop();
        }