public void It_Should_Load_Template_From_Cache_Second_Time()
 {
     var loader = new FileSystemLoader("./templates/");
     Assert.Equal("I'm the {{foo}} template.", loader.Load("Foo"));
     Assert.Equal(1, loader.TemplateCache.Count);
     Assert.Equal("I'm the {{foo}} template.", loader.Load("Foo"));
 }
Пример #2
0
        public void TestMethod1()
        {
            var loader = new FileSystemLoader("d:/test/shaders");

            string source = loader.Load("rootshader.frag", "").Content;

            Assert.AreNotEqual(string.Empty, source);
        }
Пример #3
0
        private IEnumerable <IContentType> LoadTypesFromOneExtensionPath(string extensionPath, IEntitiesSource entitiesSource)
        {
            var wrapLog  = Log.Call <IList <IContentType> >(extensionPath);
            var fsLoader = new FileSystemLoader(extensionPath, RepositoryTypes.Folder, true, entitiesSource, Log);
            var types    = fsLoader.ContentTypes();

            return(wrapLog("ok", types));
        }
        public void It_Should_Override_On_Cache_Collision()
        {
            var loader = new FileSystemLoader("./templates/");

            loader.AddToTemplateCache("Foo", "TemplateData!");
            loader.AddToTemplateCache("Foo", "NewTemplateData!");

            Assert.Equal(1, loader.TemplateCache.Count);
            Assert.Equal("NewTemplateData!", loader.TemplateCache["Foo"]);
        }
Пример #5
0
        public HttpResponseMessage Get()
        {
            HttpResponseMessage Response = new HttpResponseMessage(HttpStatusCode.OK);

            byte[]           arr    = Encoding.ASCII.GetBytes("Sreten");
            FileSystemLoader loader = new FileSystemLoader();

            arr = loader.GetMedia(66, 18);
            Response.Content = new ByteArrayContent(arr);
            Response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
            return(Response);
        }
Пример #6
0
        void Start()
        {
            // Initialise all local variables
            fileLoader        = gameObject.GetComponent <FileSystemLoader>();
            chunksToLoadQueue = new Queue <ChunkLoadData>();
            loadedChunkQueue  = new Queue <KinectFramesStore>();
            IsLoading         = false;
            IsPlaying         = false;

            // Subscribe event handlers to event
            FileInfoFinishedLoad += FileInfoLoadFinishedHandler;
            ChunkFinishedLoad    += LoadChunkFinishedHandler;
        }
Пример #7
0
        public void LoadTemplate()
        {
            // Arrange
            var loader = new FileSystemLoader(Environment.GetEnvironmentVariable("SCAFFOLD_TEMPLATES"), Environment.GetEnvironmentVariable("SCAFFOLD_PLUGINS"));

            // Act
            var pluginsName = new string[] { "docker", "kubernetes" };
            var template    = loader.Load("c#", "console", pluginsName);

            // Assert
            Assert.NotNull(template);
            Assert.Equal("c#", template.Language);
            Assert.Equal("console", template.Name);
            Assert.NotEmpty(template.Files);
            Assert.NotEmpty(template.Plugins);
        }
Пример #8
0
        public async System.Threading.Tasks.Task <HttpResponseMessage> PutAsync(HttpRequestMessage msg)
        {
            HttpResponseMessage response = new HttpResponseMessage();
            FileSystemLoader    loader   = new FileSystemLoader();

            if (msg.Content.Headers.ContentType.MediaType != "application/octet-stream")
            {
                response.StatusCode = HttpStatusCode.UnsupportedMediaType;
                return(response);
            }
            byte[] pic = await msg.Content.ReadAsByteArrayAsync();

            loader.SaveMedia(67, 18, pic);
            response.StatusCode = HttpStatusCode.OK;
            return(response);
        }
Пример #9
0
        // 删除文件或者目录
        // parameters:
        //      strCurrentDirectory 当前路径,注意这是物理路径
        // return:
        //      -1  出错
        //      其他  实际删除的文件和目录个数
        public static int DeleteFile(
            string strRootPath,
            string strCurrentDirectory,
            string strPattern,
            out string strError)
        {
            strError = "";

            try
            {
                FileSystemLoader loader = new FileSystemLoader(strCurrentDirectory, strPattern);
                loader.ListStyle = ListStyle.None;
                int count = 0;
                foreach (FileSystemInfo si in loader)
                {
                    // 检查文件或目录必须在根以下。防止漏洞
                    if (PathUtil.IsChildOrEqual(si.FullName, strRootPath) == false)
                    {
                        continue;
                    }

                    if (si is DirectoryInfo)
                    {
                        PathUtil.DeleteDirectory(si.FullName);
                    }

                    if (si is FileInfo)
                    {
                        File.Delete(si.FullName);
                    }

                    count++;
                }

                return(count);
            }
            catch (DirectoryNotFoundException)
            {
                return(0);
            }
            catch (Exception ex)
            {
                strError = ExceptionUtil.GetAutoText(ex);
                return(-1);
            }
        }
Пример #10
0
        // 转入新的目录
        // parameters:
        //      strRoot 根目录,物理路径
        //      strCurrentDirectory 当前路径,物理
        //      strPath 匹配模式
        //      strResultDirectory  返回的结果路径,注意这是物理路径
        // return:
        //      -1  出错
        //      0   要转去的物理目录不存在
        //      1   成功
        public static int ChangeDirectory(
            string strRoot,
            string strCurrentDirectory,
            string strPattern,
            out string strResultDirectory,
            out string strError)
        {
            strError = "";

            strResultDirectory = "";

            string strLogicResult = "";

            try
            {
                // 用逻辑路径来进行调用。这样的用意是避免越过根
                FileSystemLoader.ChangeDirectory(strCurrentDirectory.Substring(strRoot.Length),
                                                 strPattern,
                                                 out strLogicResult);
            }
            catch (Exception ex)
            {
                strError = ExceptionUtil.GetAutoText(ex);
                return(-1);
            }

            // 检测物理目录是否存在
            strResultDirectory = Path.Combine(strRoot, PathUtil.RemoveRootSlash(strLogicResult));

            // 检查文件或目录必须在根以下。防止漏洞
            if (PathUtil.IsChildOrEqual(strResultDirectory, strRoot) == false)
            {
                strError = "目录 '" + strLogicResult + "' 不存在";
                return(0);
            }

            if (Directory.Exists(strResultDirectory) == false)
            {
                strError = "目录 '" + strLogicResult + "' 不存在";
                return(0);
            }

            return(1);
        }
        public void GenerateProject()
        {
            // Arrange
            var loader      = new FileSystemLoader(Environment.GetEnvironmentVariable("SCAFFOLD_TEMPLATES"), Environment.GetEnvironmentVariable("SCAFFOLD_PLUGINS"));
            var pluginsName = new string[] { "docker", "kubernetes" };
            var tl          = loader.Load("c#", "console", pluginsName);
            var generator   = new LocalGenerator();

            var di = new DirectoryInfo($"{Environment.CurrentDirectory}/testProject");

            if (di.Exists)
            {
                di.Delete(true);
            }

            // Act
            var project = generator.Generate($"{Environment.CurrentDirectory}/testProject", tl);

            // Assert
            Assert.NotEmpty(project.CreatedFiles);
        }
Пример #12
0
        public void SubstituteTemplates()
        {
            // Arrange
            var loader = new FileSystemLoader(Environment.GetEnvironmentVariable("SCAFFOLD_TEMPLATES"), Environment.GetEnvironmentVariable("SCAFFOLD_PLUGINS"));

            var pluginsName = new string[] { "docker", "kubernetes" };
            var tl          = loader.Load("c#", "console", pluginsName);
            var generator   = new LocalGenerator();

            var di = new DirectoryInfo($"{Environment.CurrentDirectory}/testProject");

            if (di.Exists)
            {
                di.Delete(true);
            }

            var project = generator.Generate($"{Environment.CurrentDirectory}/testProject", tl);

            var templater = new RegexTemplater();

            // Act
            var templatedProject = templater.Substitute(new Context {
                ProjectName = "testProject",
                Description = "test c# project",
                Version     = "net5.0",
            }, project);

            // Assert
            Assert.NotEmpty(templatedProject.ProcessedFiles);
            //Assert.True(project.Compiles());

            foreach (var file in templatedProject.ProcessedFiles)
            {
                Assert.False(file.ContainsTemplates());
            }
        }
 public void It_Should_Take_Path_As_Argument()
 {
     var loader  = new FileSystemLoader("./templates");
     Assert.Equal("./templates", loader.Path);
 }
Пример #14
0
        private IPortfolioDefinitionDeserialiser GetFileDeserialiser(string filePath)
        {
            var loader = new FileSystemLoader(filePath);

            return(new PortfolioDefinitionJsonDeserialiser(loader));
        }
Пример #15
0
        // 删除文件或者目录
        // parameters:
        //      root_paths  可用的根目录列表。只要在其中之一以下,就允许删除。否则不允许删除
        //      strCurrentDirectory 当前路径,注意这是物理路径
        // return:
        //      -1  出错
        //      其他  实际删除的文件和目录个数
        public int DeleteFile(
            // string strRootPath,
            List <string> root_paths,
            string strCurrentDirectory,
            string strPattern,
            out string strError)
        {
            strError = "";

            List <string> errors = new List <string>();

            try
            {
                FileSystemLoader loader = new FileSystemLoader(strCurrentDirectory, strPattern);
                loader.ListStyle = ListStyle.None;
                int count = 0;
                foreach (FileSystemInfo si in loader)
                {
                    // 检查文件或目录必须在根以下。防止漏洞
                    //if (PathUtil.IsChildOrEqual(si.FullName, strRootPath) == false)
                    //    continue;
                    if (IsChildOrEqual(si.FullName, root_paths) == false)
                    {
                        errors.Add("文件 " + si.Name + " 越过了限制目录,删除操作被拒绝");
                        continue;
                    }

                    if (si is DirectoryInfo)
                    {
                        _physicalFileCache.ClearAll();
                        PathUtil.DeleteDirectory(si.FullName);
                    }

                    if (si is FileInfo)
                    {
                        // File.Delete(si.FullName);
                        _physicalFileCache.FileDelete(si.FullName);

                        // 2017/9/24
                        // 顺带删除同名的 .~state 文件
                        string strTempFileName = si.FullName + ".~state";
                        if (File.Exists(strTempFileName))
                        {
                            File.Delete(strTempFileName);
                            count++;
                        }
                    }

                    count++;
                }

                if (errors.Count > 0)
                {
                    strError = StringUtil.MakePathList(errors, "; ");
                }

                return(count);
            }
            catch (DirectoryNotFoundException)
            {
                return(0);
            }
            catch (Exception ex)
            {
                strError = ExceptionUtil.GetAutoText(ex);
                return(-1);
            }
        }
Пример #16
0
        // 返回的 FileItemInfo.Name 中是逻辑全路径
        // parameters:
        //      strCurrentDirectory 当前路径。物理路径
        // return:
        //      -1  出错
        //      其他  列出的事项总数。注意,不是 lLength 所指出的本次返回数
        public static int ListFile(
            string strRootPath,
            string strCurrentDirectory,
            string strPattern,
            long lStart,
            long lLength,
            out List <FileItemInfo> infos,
            out string strError)
        {
            strError = "";
            infos    = new List <FileItemInfo>();

            int MAX_ITEMS = 100;    // 一次 API 最多返回的事项数量

            try
            {
                FileSystemLoader loader = new FileSystemLoader(strCurrentDirectory, strPattern);

                int i     = 0;
                int count = 0;
                foreach (FileSystemInfo si in loader)
                {
                    // 检查文件或目录必须在根以下。防止漏洞
                    if (PathUtil.IsChildOrEqual(si.FullName, strRootPath) == false)
                    {
                        continue;
                    }

                    if (i < lStart)
                    {
                        goto CONTINUE;
                    }
                    if (lLength != -1 && count > lLength)
                    {
                        goto CONTINUE;
                    }

                    if (count >= MAX_ITEMS)
                    {
                        goto CONTINUE;
                    }

                    FileItemInfo info = new FileItemInfo();
                    infos.Add(info);
                    info.Name       = si.FullName.Substring(strRootPath.Length);
                    info.CreateTime = si.CreationTimeUtc.ToString("u");
                    // 2017/4/8
                    info.LastWriteTime  = si.LastWriteTimeUtc.ToString("u");
                    info.LastAccessTime = si.LastAccessTimeUtc.ToString("u");

                    if (si is DirectoryInfo)
                    {
                        info.Size = -1; // 表示这是目录
                    }

                    if (si is FileInfo)
                    {
                        FileInfo fi = si as FileInfo;
                        info.Size = fi.Length;
                    }

                    count++;

CONTINUE:
                    i++;
                }

                return(i);
            }
            catch (DirectoryNotFoundException)
            {
                return(0);
            }
            catch (Exception ex)
            {
                strError = ExceptionUtil.GetAutoText(ex);
                return(-1);
            }
        }
 public void It_Should_Strip_Possible_Ending_Slash_On_Path()
 {
     var loader = new FileSystemLoader("./templates/");
     Assert.Equal("./templates", loader.Path);
 }
 public void It_Should_Should_Handle_BackSlashes()
 {
     var loader = new FileSystemLoader(@".\templates\");
     Assert.Equal(@".\templates", loader.Path);
 }
 public void It_Should_Skip_If_First_Level_Doesnt_Exist()
 {
     var loader = new FileSystemLoader("./templates/");
     Assert.Null(loader.Load("level2:Foobar"));
 }
 public void It_Should_Load_Template_From_FileSystem_With_Default_Extension()
 {
     var loader = new FileSystemLoader("./templates/");
     Assert.Equal("I'm the {{foo}} template.", loader.Load("Foo"));
 }
 public void It_Should_Load_Template_Nested_Paths_Using_Set_Delimiter()
 {
     var loader = new FileSystemLoader("./templates/", '|');
     Assert.Equal("I'm the {{foo}} template.", loader.Load("level1|Foo2"));
 }
 public void It_Should_Load_Template_From_FileSystem_With_Given_Extension()
 {
     var loader = new FileSystemLoader("./templates/", "must");
     Assert.Equal("I'm the {{bar}} template.", loader.Load("Bar"));
 }