Exemple #1
0
        /// <summary>
        /// Adds the files in folderName to list.
        /// </summary>
        /// <param name="list">The list.</param>
        /// <param name="folderName">Name of the folder.</param>
        /// <param name="subFolderToAddToFileName">Name of the sub folder to add to file.</param>
        private static void AddFilesToList(List <EmbeddedFileDependency> list, string folderName, string subFolderToAddToFileName)
        {
            foreach (string filePath in Directory.GetFiles(folderName))
            {
                EmbeddedFileDependency fileDep =
                    new EmbeddedFileDependency(
                        Path.Combine(subFolderToAddToFileName, Path.GetFileName(filePath)),
                        filePath);

                list.Add(fileDep);
            }

            foreach (string folderPath in Directory.GetDirectories(folderName))
            {
                AddFilesToList(
                    list,
                    folderPath,
                    Path.Combine(subFolderToAddToFileName, Path.GetFileName(folderPath)));
            }
        }
Exemple #2
0
 //-----------------------------------------------------------------------------------------------
 private void AddStandardFile(StreamReader reader, string name)
 {
     EmbeddedFileDependency fileDep = new EmbeddedFileDependency(name);
     UTF8Encoding encoding = new UTF8Encoding();
     fileDep.Base64EncodedContents = Convert.ToBase64String(
         encoding.GetBytes(reader.ReadToEnd())
         );
     _OutputFiles.Add(fileDep);
     logger.Debug("Added/packed output file: " + name);
 }
        //Gets the GJob object from the given xml
        private static GJob JobFromXml(int jobId, string jobXml)
        {
            // TODO: validate against schema
            GJob job = new GJob();

            job.SetId(jobId);

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(jobXml);

            logger.Debug("Getting JobFromXML...");
            foreach (XmlNode inputFile in doc.SelectNodes("job/input/embedded_file"))
            {
                EmbeddedFileDependency dep = new EmbeddedFileDependency(inputFile.Attributes["name"].Value);
                dep.Base64EncodedContents = inputFile.InnerText;
                job.InputFiles.Add(dep);
                logger.Debug("adding input filedep:" + dep.FileName);
            }

            job.RunCommand = doc.SelectSingleNode("job/work").Attributes["run_command"].Value;

            logger.Debug("Job run command=" + job.RunCommand);

            foreach (XmlNode outputFile in doc.SelectNodes("job/output/embedded_file"))
            {
                EmbeddedFileDependency dep = new EmbeddedFileDependency(outputFile.Attributes["name"].Value);
                job.OutputFiles.Add(dep);
                logger.Debug("adding output filedep:" + dep.FileName);
            }

            return job;
        }
        /// <summary>
        /// Creates a task on the Manager from the provided XML task representation and returns its Id. 
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="sc">Security Credentials</param>
        /// <param name="taskXml"></param>
        /// <returns>application id</returns>
        public static string CreateTask(IManager manager, SecurityCredentials sc, string taskXml)
        {
            // TODO: validate against schema
            string taskId = manager.Owner_CreateApplication(sc);

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(taskXml);

            FileDependencyCollection manifest = new FileDependencyCollection();
            foreach (XmlNode manifestFile in doc.SelectNodes("task/manifest/embedded_file"))
            {
                EmbeddedFileDependency dep = new EmbeddedFileDependency(manifestFile.Attributes["name"].Value);
                dep.Base64EncodedContents = manifestFile.InnerText;
                manifest.Add(dep);
                logger.Debug("Added dependency to manifest: " + dep.FileName);
            }
            manager.Owner_SetApplicationManifest(sc, taskId, manifest);

            foreach (XmlNode jobXml in doc.SelectNodes("task/job"))
            {
                int jobId = int.Parse(jobXml.Attributes["id"].Value);
                jobXml.Attributes.Remove(jobXml.Attributes["id"]);

                // TODO: allow setting of priority in xml file
                AddJob(manager, sc, taskId, jobId, 0, jobXml.OuterXml);
                logger.Debug("Added job to manager: " + jobId);
            }

            return taskId;
        }
        public void UnPackToFolderTestFolders()
        {
            string fileName1 = @"test1.txt";
            string fileName2 = @"somefolder\And another with spaces\test1.txt";

            // create the file
            string fileLocation1 = CreateDummyFileUnderRootFolder(fileName1);
            string fileLocation2 = CreateDummyFileUnderRootFolder(fileName2);

            FileDependency fd1 = new EmbeddedFileDependency(fileName1, fileLocation1);
            FileDependency fd2 = new EmbeddedFileDependency(fileName2, fileLocation2);

            fd1.UnPackToFolder(_rootFolderNameToExtractTo);
            fd2.UnPackToFolder(_rootFolderNameToExtractTo);

            // just make sure the files are there
            Assert.IsTrue(File.Exists(Path.Combine(_rootFolderNameToExtractTo, fileName1)));
            Assert.IsTrue(File.Exists(Path.Combine(_rootFolderNameToExtractTo, fileName2)));
        }
        public void UnPackToFolderTestNoFolders()
        {
            string fileName = @"test1.txt";

            // create the file
            string fileLocation = CreateDummyFileUnderRootFolder(fileName);

            FileDependency fd = new EmbeddedFileDependency(fileName, fileLocation);

            fd.UnPackToFolder(_rootFolderNameToExtractTo);

            // just make sure the file is there
            Assert.IsTrue(File.Exists(Path.Combine(_rootFolderNameToExtractTo, fileName)));
        }
        private static void AddFilesToList(ArrayList list, string folderName, string subFolderToAddToFileName)
        {
            foreach (string filePath in Directory.GetFiles(folderName))
            {
                EmbeddedFileDependency fileDep =
                    new EmbeddedFileDependency(
                        Path.Combine(subFolderToAddToFileName, Path.GetFileName(filePath)),
                        filePath);

                list.Add(fileDep);
            }

            foreach (string folderPath in Directory.GetDirectories(folderName))
            {
                AddFilesToList(
                    list,
                    folderPath,
                    Path.Combine(subFolderToAddToFileName, Path.GetFileName(folderPath)));
            }
        }