Esempio n. 1
0
        public void RegisterProvider_NotAvailable()
        {
            var resourceManager = new NativeResourceManager();
            var gotProvider     = resourceManager.TryGetProvider <INativeFileProvider>(out INativeFileProvider result);

            Assert.IsFalse(gotProvider);
        }
Esempio n. 2
0
        void PrepareTask(ApplicationJumpTaskWrap task)
        {
            IApplicationJumpTaskInfoInternal taskInternal = task.ApplicationJumpTask;

            if (taskInternal.IsInitialized)
            {
                return;
            }
            string iconResourceName;

            if (task.ApplicationJumpTask.Icon == null)
            {
                task.IconResourcePath  = task.ApplicationJumpTask.IconResourcePath;
                task.IconResourceIndex = task.ApplicationJumpTask.IconResourceIndex;
                iconResourceName       = string.Format("{0}_{1}", task.IconResourcePath, task.IconResourceIndex);
            }
            else
            {
                if (task.ApplicationJumpTask.IconResourcePath != null)
                {
                    throw new ApplicationJumpTaskBothIconAndIconResourcePathSpecifiedException();
                }
                string iconResourcePath;
                if (!IconStorage.TryStoreIconToFile(task.ApplicationJumpTask.Icon, NativeResourceManager.ExpandVariables(IconStorageFolder), out iconResourceName, out iconResourcePath))
                {
                    throw new ApplicationJumpTaskInvalidIconException();
                }
                task.IconResourcePath  = iconResourcePath;
                task.IconResourceIndex = 0;
            }
            if (task.ApplicationJumpTask.CommandId == null)
            {
                taskInternal.SetAutoGeneratedCommandId(string.Format("{0}${1}${2}", task.ApplicationJumpTask.CustomCategory, task.ApplicationJumpTask.Title, iconResourceName));
            }
        }
Esempio n. 3
0
        protected void runProgram(string program, Dictionary <string, object> variablesIn, int expectedIterations, out FrameContext context)
        {
            var inputStream = new AntlrInputStream(program);
            var lexer       = new CloacaLexer(inputStream);
            CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
            var errorListener = new ParseErrorListener();
            var parser        = new CloacaParser(commonTokenStream);

            parser.AddErrorListener(errorListener);

            var antlrVisitorContext = parser.file_input();

            Assert.That(errorListener.Errors.Count, Is.Zero, "There were parse errors:\n" + errorListener.Report());

            var visitor = new CloacaBytecodeVisitor(variablesIn);

            visitor.Visit(antlrVisitorContext);

            // We'll do a disassembly here but won't assert against it. We just want to make sure it doesn't crash.
            CodeObject compiledProgram = visitor.RootProgram.Build();

            Dis.dis(compiledProgram);

            // TODO: This dependency association is kind of gross. It's almost circular and is broken by assigning
            // the interpreter reference to the schedular after its initial constructor.
            var scheduler   = new Scheduler();
            var interpreter = new Interpreter(scheduler);

            // Create native resource manager which will handle builtins that provide access to 'native' resources such as files.
            var nativeResourceManager = new NativeResourceManager();

            nativeResourceManager.RegisterProvider <INativeFileProvider>(new DefaultFileProvider());
            nativeResourceManager.RegisterBuiltins(interpreter);

            interpreter.DumpState = true;
            scheduler.SetInterpreter(interpreter);

            var receipt = scheduler.Schedule(compiledProgram);

            context = receipt.Frame;
            foreach (string varName in variablesIn.Keys)
            {
                context.SetVariable(varName, variablesIn[varName]);
            }

            // Waiting on the task makes sure we get punched in the face by any exceptions it throws.
            // But they'll come rolling in as AggregateExceptions so we'll have to unpack them.
            var scheduler_task = scheduler.RunUntilDone();

            scheduler_task.Wait();
            Assert.That(receipt.Completed);
            if (receipt.EscapedExceptionInfo != null)
            {
                receipt.EscapedExceptionInfo.Throw();
            }

            Assert.That(scheduler.TickCount, Is.EqualTo(expectedIterations));
        }
Esempio n. 4
0
        public void RegisterProvider_Available()
        {
            var resourceManager = new NativeResourceManager();
            var provider        = new DefaultFileProvider();

            resourceManager.RegisterProvider <INativeFileProvider>(provider);

            var gotProvider = resourceManager.TryGetProvider <INativeFileProvider>(out INativeFileProvider result);

            Assert.IsTrue(gotProvider);
        }
Esempio n. 5
0
 public ProgramExecutor(InputOutputStream stdout)
 {
     _stdout                = stdout;
     _scheduler             = new Scheduler();
     _interpreter           = new Interpreter(_scheduler);
     _nativeResourceManager = new NativeResourceManager();
     _nativeResourceManager.RegisterProvider <INativeFileProvider>(new DefaultFileProvider());
     _nativeResourceManager.RegisterProvider <INativeStdioProvider>(new DefaultNativeStdioProvider(null, stdout));
     _nativeResourceManager.RegisterBuiltins(_interpreter);
     _scheduler.SetInterpreter(_interpreter);
 }
        protected override void TearDownCore()
        {
            string resourcesFolder = NativeResourceManager.ExpandVariables(NativeResourceManager.ResourcesFolder);

            if (Directory.Exists(resourcesFolder))
            {
                Directory.Delete(resourcesFolder, true);
            }
            NativeResourceManager.ProductNameOverride = null;
            NativeResourceManager.CompanyNameOverride = null;
            NativeResourceManager.VersionOverride     = null;
            base.TearDownCore();
        }
Esempio n. 7
0
        public void RegisterSameProvider_Exception()
        {
            var resourceManager = new NativeResourceManager();
            var provider        = new DefaultFileProvider();

            resourceManager.RegisterProvider <INativeFileProvider>(provider);

            Assert.Catch(
                typeof(Exception),
                () =>
            {
                resourceManager.RegisterProvider <INativeFileProvider>(provider);
            });
        }
Esempio n. 8
0
        public void ExpandVariablesTest()
        {
            Dictionary <string, Func <string> > variables = new Dictionary <string, Func <string> >();

            variables.Add("%ABC%", () => "_ABC_");
            variables.Add("%DEF%", () => "_DEF_");
            Assert.AreEqual("_ABC__DEF_", NativeResourceManager.ExpandVariablesCore("%ABC%%DEF%", variables));
            Assert.AreEqual("x_ABC_y_DEF_z", NativeResourceManager.ExpandVariablesCore("x%ABC%y%DEF%z", variables));
            Assert.AreEqual("x%%_ABC_y_DEF_", NativeResourceManager.ExpandVariablesCore("x%%%ABC%y%DEF%", variables));
            Assert.AreEqual("x%%_ABC_y%DEF", NativeResourceManager.ExpandVariablesCore("x%%%ABC%y%DEF", variables));
            Assert.AreEqual("%NONE%_ABC_", NativeResourceManager.ExpandVariablesCore("%NONE%%ABC%", variables));
            Assert.AreEqual("_ABC_", NativeResourceManager.ExpandVariablesCore("%Abc%", variables));
            Assert.AreEqual("_DEF_ABC%XYZ%", NativeResourceManager.ExpandVariablesCore("%DEF%ABC%XYZ%", variables));
        }
Esempio n. 9
0
 public bool TryStoreIconToFile(ImageSource icon, string storageFolder, out string iconID, out string iconPath)
 {
     Guard.ArgumentNotNull(icon, "icon");
     byte[] iconBytes = null;
     try {
         iconBytes = ImageLoader2.ImageToByteArray(icon, baseUri);
     } catch (Exception) {
         iconID   = null;
         iconPath = null;
         return(false);
     }
     iconID   = NativeResourceManager.CreateFileName(GetImageHash(iconBytes)) + ".ico";
     iconPath = UnpackIcon(Path.Combine(storageFolder, iconID), iconBytes);
     return(iconPath != null);
 }
Esempio n. 10
0
        protected virtual string GetLauncherPath()
        {
            if (!string.IsNullOrEmpty(CustomLauncherPath))
            {
                return(NativeResourceManager.ExpandVariables(CustomLauncherPath));
            }
            string filePath = Path.Combine(NativeResourceManager.ExpandVariables(DefaultLauncherStorageFolder), "DevExpress.Mvvm.UI.ApplicationJumpTaskLauncher" + AssemblyInfo.VSuffix + ".exe");

            if (File.Exists(filePath) && NativeResourceManager.GetFileTime(filePath) > NativeResourceManager.GetApplicationCreateTime())
            {
                return(filePath);
            }
            Directory.CreateDirectory(Path.GetDirectoryName(filePath));
            Stream stream = AssemblyHelper.GetEmbeddedResourceStream(typeof(JumpActionsManager).Assembly, "DevExpress.Mvvm.UI.ApplicationJumpTaskLauncher.exe", true);

            try {
                File.WriteAllBytes(filePath, StreamHelper.CopyAllBytes(stream));
            } catch (IOException) { } catch (UnauthorizedAccessException) { }
            return(filePath);
        }