Пример #1
0
 public JintScriptingContext(InputScript script)
     : this()
 {
     Script         = script;
     Script.Context = this;
     Expose();
 }
Пример #2
0
 public void AddOrUpdate(InputScript script, bool createContext = false)
 {
     lock (scripts)
     {
         var index = scripts.IndexOf(script);
         if (index > -1)
         {
             var ctx = GetContext(scripts[index]);
             if (ctx != null)
             {
                 RemoveContext(ctx);
                 ctx.Dispose();
             }
             
             scripts[index] = script;
             Create(script);
         }
         else
         {
             scripts.Add(script);
             if (createContext)
                 Create(script);
         }
     }
 }
Пример #3
0
 public JintScriptingContext(InputScript script)
     : this()
 {
     Script = script;
     Script.Context = this;
     Expose();
 }
Пример #4
0
        public void Setup()
        {
            scriptProviderMock = new Mock<IScriptProvider>();
            scriptProviderMock.Setup(s => s.Scripts).Returns(Scripts);
            scriptProvider = scriptProviderMock.Object;

            toMatch = TestFactory.CreateTestInputScript();
        }
Пример #5
0
 public IScriptContext Create(InputScript script)
 {
     lock (contexts)
     {
         var ctx = new JintScriptingContext(script);
         contexts.Add(ctx);
         return ctx;
     }
 }
Пример #6
0
 public void RemoveScript(InputScript script)
 {
     lock (scripts)
     {
         if (scripts.Contains(script))
             scripts.Remove(script);
     }
     var ctx = GetContext(script);
     if (ctx != null)
         RemoveContext(ctx);
 }
Пример #7
0
        protected string GetPathToSourceFile(InputScript s, string f)
        {
            if (!HasSourceFilesDirectory(s))
                return null;

            var pathToSourceFileDirectory = Path.Combine(AppConfigProvider.AppConfig.ScriptsFolder, s.Name);
            if (!FileSystemUtils.DirectoryExists(pathToSourceFileDirectory))
                return null;

            var fileName = Path.GetFileName(f);
            return fileName == null ? null : Path.Combine(pathToSourceFileDirectory, fileName);
        }
Пример #8
0
        public void Setup()
        {
            okScript = TestFactory.CreateTestInputScript();
            notOkScript = TestFactory.CreateTestInputScript();

            scriptProviderMock = new Mock<IScriptProvider>();
            scriptProviderMock.Setup(s => s.RemoveScript(It.Is<InputScript>(v => v.Equals(notOkScript))))
                .Throws<Exception>();
            scriptProvider = scriptProviderMock.Object;

            storageProviderMock = new Mock<IStorageProvider>();
            storageProvider = storageProviderMock.Object;
        }
Пример #9
0
        public void AddScript(InputScript script, bool createContext = false)
        {
            lock (scripts)
            {
                if (scripts.Contains(script))
                    return;

                scripts.Add(script);
            }
            
            if (createContext)
                Create(script);
        }
Пример #10
0
        public void Setup()
        {
            existingScript = TestFactory.CreateTestInputScript();
            nonExistingScript = TestFactory.CreateTestInputScript();
            nonExistingScript.FileName = "somethingelse";

            scriptProviderMock = new Mock<IScriptProvider>();
            scriptProviderMock.Setup(s => s.Scripts).Returns(Scripts);
            scriptProvider = scriptProviderMock.Object;

            storageProviderMock = new Mock<IStorageProvider>();
            storageProvider = storageProviderMock.Object;
        }
Пример #11
0
 public static InputScript Copy(InputScript s)
 {
     return new InputScript
     {
         Context = s.Context,
         FileName = s.FileName,
         Id = s.Id,
         Inputs = s.Inputs,
         IsValid = s.IsValid,
         Name = s.Name,
         SourceFileNames = s.SourceFileNames,
         SourceFiles = s.SourceFiles
     };
 }
Пример #12
0
        public void LoadAllSourceFiles(InputScript s)
        {
            s.SourceFiles.Clear();
            foreach (var sourceFile in s.SourceFileNames)
            {
                if (!SourceFileExists(s, sourceFile))
                    continue;
                var p = GetPathToSourceFile(s, sourceFile);
                if (p == null)
                    continue;

                s.SourceFiles.Add(LoadSourceFile(p));
            }
        }
Пример #13
0
 private void UpdateScriptFile(InputScript n, InputScript o)
 {
     var path = AppConfigProvider.AppConfig.ScriptsFolder;
     var oldScriptPath = Path.Combine(path, o.FileName);
     var newScriptPath = Path.Combine(path, n.FileName);
     if (!FileSystemUtils.FileExists(newScriptPath) && FileSystemUtils.FileExists(oldScriptPath))
         FileSystemUtils.MoveFile(oldScriptPath, newScriptPath);
     FileSystemUtils.SaveObjectToDisk(n, newScriptPath);
 }
Пример #14
0
 private void UpdateScriptDirectory(InputScript n, InputScript o)
 {
     var path = AppConfigProvider.AppConfig.ScriptsFolder;
     var oldFolderPath = Path.Combine(path, o.Name);
     var newFolderPath = Path.Combine(path, n.Name);
     if (!FileSystemUtils.DirectoryExists(newFolderPath) && FileSystemUtils.DirectoryExists(oldFolderPath))
         FileSystemUtils.MoveDirectory(oldFolderPath, newFolderPath);
 }
Пример #15
0
 private void CreatePlaceholderSourceFiles(InputScript s)
 {
     foreach (var sourceName in s.SourceFileNames)
     {
         var path = Path.Combine(AppConfigProvider.AppConfig.ScriptsFolder, s.Name, sourceName);
         if (!FileSystemUtils.FileExists(path))
             FileSystemUtils.SaveStringToDisk("// Code away!!", path);
     }
 }
Пример #16
0
 public abstract void UpdateScript(InputScript n, InputScript o);
Пример #17
0
 public void UpdateScript(InputScript n, InputScript o)
 {
     UpdateScriptDirectory(n, o);
     UpdateScriptFile(n, o);
 }
Пример #18
0
 public void SaveScriptSource(InputScript script, string fileName, string source)
 {
     var scriptsPath = AppConfigProvider.AppConfig.ScriptsFolder;
     var sourcePath = Path.Combine(scriptsPath, script.Name, fileName);
     FileSystemUtils.SaveStringToDisk(source, sourcePath);
 }
Пример #19
0
 public void SaveScript(InputScript s)
 {
     var path = AppConfigProvider.AppConfig.ScriptsFolder;
     if (!FileSystemUtils.DirectoryExists(path))
         throw new Exception("Directory does not exist");
     FileSystemUtils.SaveObjectToDisk(s, Path.Combine(path, s.FileName));
     CreateSourceFilesDirectoryIfNotExists(s);
     CreatePlaceholderSourceFiles(s);
 }
Пример #20
0
 public void RemoveScript(InputScript s)
 {
     var path = AppConfigProvider.AppConfig.ScriptsFolder;
     if (!FileSystemUtils.DirectoryExists(path))
         throw new Exception("Directory does not exist");
     FileSystemUtils.RemoveFile(Path.Combine(path, s.FileName));
 }
Пример #21
0
 public IScriptContext GetContext(InputScript script)
 {
     lock (contexts)
     {
         return contexts.FirstOrDefault(s => s.Script.Equals(script));
     }
 }
Пример #22
0
 public async Task<ApiResult<Object>> Save(InputScript configuration)
 {
     var cmd = new SaveInputScript(storageProvider, scriptProvider, configuration);
     await cmd.Execute();
     return cmd.Result;
 }
Пример #23
0
 public abstract void SaveScript(InputScript s);
Пример #24
0
 public ApiResult<Object> Validate(InputScript configuration)
 {
     var cmd = new ValidateInputScript(scriptProvider, configuration);
     cmd.Execute();
     return cmd.Result;
 }
Пример #25
0
 protected void CreateSourceFilesDirectory(InputScript s)
 {
     var path = Path.Combine(AppConfigProvider.AppConfig.ScriptsFolder, s.Name);
     FileSystemUtils.CreateDirectory(path);
 }
Пример #26
0
 public abstract void SaveScriptSource(InputScript script, string fileName, string source);
Пример #27
0
 public ApiResult<Object> Remove(InputScript configuration)
 {
     var cmd = new RemoveInputScript(scriptProvider, storageProvider, configuration);
     cmd.Execute();
     return cmd.Result;
 }
Пример #28
0
 protected void CreateSourceFilesDirectoryIfNotExists(InputScript s)
 {
     if (!HasSourceFilesDirectory(s))
         CreateSourceFilesDirectory(s);
 }
Пример #29
0
 public void SaveScript_ThrowsIfScriptsFolderDoesNotExist()
 {
     var s = new InputScript();
     fileSystemUtilsMock.Setup(f => f.DirectoryExists(It.IsAny<string>())).Returns(false);
     provider.SaveScript(s);
 }
Пример #30
0
 protected bool HasSourceFilesDirectory(InputScript s)
 {
     var path = Path.Combine(AppConfigProvider.AppConfig.ScriptsFolder, s.Name);
     return FileSystemUtils.DirectoryExists(path);
 }
Пример #31
0
 protected bool SourceFileExists(InputScript s, string f)
 {
     var pathToFile = GetPathToSourceFile(s, f);
     return pathToFile != null && FileSystemUtils.FileExists(pathToFile);
 }
Пример #32
0
 protected bool Equals(InputScript other)
 {
     return(Id.Equals(other.Id));
 }