public void TestGenerateAllFiles_Static_File()
        {
            IFile        file         = mocks.DynamicMock <IFile>();
            ProviderInfo providerMock = mocks.DynamicMock <ProviderInfo>();

            using (mocks.Record())
            {
                SetupFolder(folder, new IFolder[0], new IScript[0], new[] { file }, "");
                SetupProject();
                SetupLoader();
                SetupStaticFile(file);
                SetupProvider(providerMock);
                SetupController();
                Expect.Call(() => projectInfo.AddGeneratedFile(new GeneratedFile(
                                                                   "file.jpg", "C:\\Temp\\file.jpg", "file.jpg", "", "Iterator")));
            }

            GenerationHelper helper = new GenerationHelper(progressHelper, loader, projectInfo, fileController);
            ProjectFileTree  tree   = new ProjectFileTree();

            helper.GenerateAllFiles("", folder, tree, scriptObject, "C:\\Temp");

            Assert.That(tree.AllNodes.Count, Is.EqualTo(1));
            Assert.That(tree.AllNodes[0].Status, Is.EqualTo(ProjectFileStatusEnum.UnAnalysedFile));
            Assert.That(tree.AllNodes[0].Text, Is.EqualTo("file.jpg"));
            Assert.That(tree.ChildNodes[0].AssociatedFile.RelativeFilePath, Is.EqualTo("file.jpg"));
            BinaryFileInformation bfi = (BinaryFileInformation)tree.ChildNodes[0].AssociatedFile;

            Assert.That(bfi.NewGenFile.FilePath,
                        Is.EqualTo(Path.Combine(controller.GetTempFilePathForComponent(ComponentKey.Workbench_FileGenerator), tree.ChildNodes[0].AssociatedFile.RelativeFilePath)),
                        "New Gen file was not assigned to");
            mocks.VerifyAll();
        }
示例#2
0
        /// <summary>
        /// Creates the static files and writes them to the Workbench_FileGenerator component directory.
        /// </summary>
        /// <param name="folderName">The relative path of the folder this file will be placed in.</param>
        /// <param name="file"></param>
        /// <param name="parentNode"></param>
        /// <returns>The number of files created.</returns>
        private int CreateStaticFile(string folderName, IFile file, ProjectFileTreeNode parentNode)
        {
            int fileCount = 0;

            if (string.IsNullOrEmpty(file.IteratorName))
            {
                fileCount++;
                string fileName         = UpdateScriptName(null, file);
                string relativeFilePath = Path.Combine(folderName, fileName);
                string fullPath         = Path.Combine(absoluteBasePath, relativeFilePath);

                if (GetSkipCurrentFile(file, Path.Combine(_Project.ProjectSettings.OutputPath, relativeFilePath)))
                {
                    return(fileCount);
                }

                _FileController.WriteResourceToFile(_Loader.CurrentAssembly, file.StaticFileName, fullPath);

                _Project.AddGeneratedFile(new GeneratedFile(file.Name, fullPath, relativeFilePath, "", file.IteratorName));

                if (addToProjectFileTree)
                {
                    BinaryFile            outFile     = new BinaryFile(fullPath, false);
                    BinaryFileInformation binFileInfo = new BinaryFileInformation();
                    binFileInfo.NewGenFile       = outFile;
                    binFileInfo.RelativeFilePath = relativeFilePath;
                    parentNode.AddChildNode(binFileInfo, fileName);
                }
                AddFileCountToPreviousEventAndRefire(_ProgressHelper, 1);

                return(fileCount);
            }
            ProviderInfo provider;
            Type         iteratorType = _Project.GetIteratorTypeFromProviders(file.IteratorName, out provider);

            IScriptBaseObject[] iteratorObjects = GetIteratorObjects(iteratorType, provider);

            if (iteratorObjects != null)
            {
                if (iteratorType.IsArray)
                {
                    throw new NotImplementedException("Array iterator types not handled for static files yet. Please inform [email protected] about this error.");
                }

                foreach (IScriptBaseObject iteratorObject in iteratorObjects)
                {
                    string fileName         = UpdateScriptName(iteratorObject, file);
                    string relativeFilePath = Path.Combine(folderName, fileName);
                    string fullPath         = Path.Combine(absoluteBasePath, relativeFilePath);

                    if (GetSkipCurrentFile(file, Path.Combine(_Project.ProjectSettings.OutputPath, relativeFilePath)))
                    {
                        // Skip the file.
                        continue;
                    }

                    _FileController.WriteResourceToFile(_Loader.CurrentAssembly, file.StaticFileName, fullPath);

                    _Project.AddGeneratedFile(new GeneratedFile(file.Name, fullPath, relativeFilePath, "", file.IteratorName));

                    if (addToProjectFileTree)
                    {
                        BinaryFile            outFile     = new BinaryFile(fullPath, false);
                        BinaryFileInformation binFileInfo = new BinaryFileInformation();
                        binFileInfo.RelativeFilePath = relativeFilePath;
                        binFileInfo.NewGenFile       = outFile;


                        parentNode.AddChildNode(binFileInfo, fileName);
                    }
                    fileCount++;
                    AddFileCountToPreviousEventAndRefire(_ProgressHelper, 1);
                }
            }

            return(fileCount);
        }