Beispiel #1
0
        /// <returns>
        ///     0 - successfully
        ///     -1 - failed
        /// </returns>
        public int AddJob(GalaxyJob job)
        {
            if (m_jobDictRefByJobName.ContainsKey(job.JobName))
            {
                return(-1);
            }
            m_jobDictRefByJobName.Add(job.JobName, job);

            return(0);
        }
Beispiel #2
0
        /// <returns>
        ///     null - failed
        /// </returns>
        public GalaxyJob GetJob(string strJobName)
        {
            GalaxyJob job = null;

            if (m_jobDictRefByJobName.ContainsKey(strJobName))
            {
                job = m_jobDictRefByJobName[strJobName];
            }

            return(job);
        }
Beispiel #3
0
        /// <returns>
        ///     null - failed
        /// </returns>
        public GalaxyJob GetJob(Guid jobId)
        {
            GalaxyJob retJob = null;

            foreach (GalaxyJob job in m_jobDictRefByJobName.Values)
            {
                if (job.JobId == jobId)
                {
                    retJob = job;
                    break;
                }
            }

            return(retJob);
        }
Beispiel #4
0
        /// <returns>
        ///     0 - successfully
        ///     -1 - failed
        /// </returns>
        public int LoadFromFile(string strJobFileName)
        {
            int iRet = 0;

            try
            {
                XmlDocument jobDoc = new XmlDocument();
                jobDoc.Load(strJobFileName);
                XmlElement  root        = jobDoc.DocumentElement;
                XmlNodeList jobNodeList = root.SelectNodes("GalaxyJob");
                foreach (XmlNode jobNode in jobNodeList)
                {
                    XmlNode         jobNameNode         = jobNode.SelectSingleNode("JobName");
                    string          strJobName          = jobNameNode.InnerText.Trim();
                    XmlNode         jobInstanceNameNode = jobNode.SelectSingleNode("PNInstanceName");
                    string          strPNInstanceName   = jobInstanceNameNode.InnerText.Trim();
                    XmlNode         jobIdNode           = jobNode.SelectSingleNode("JobId");
                    Guid            jobId                 = new Guid(jobIdNode.InnerText.Trim());
                    XmlNode         jobStatusNode         = jobNode.SelectSingleNode("JobStatus");
                    GalaxyJobStatus jobStatus             = GalaxyJob.String2JobStatus(jobStatusNode.InnerText.Trim());
                    XmlNode         exeNameNode           = jobNode.SelectSingleNode("ExeFileName");
                    string          strExeFileName        = exeNameNode.InnerText.Trim();
                    XmlNode         relPathNode           = jobNode.SelectSingleNode("RelativePath");
                    string          strRelativePath       = relPathNode.InnerText.Trim();
                    XmlNode         argsNode              = jobNode.SelectSingleNode("Arguments");
                    string          strArgs               = argsNode.InnerText.Trim();
                    XmlNode         dataRootDirNode       = jobNode.SelectSingleNode("DataRootDir");
                    string          strProjectDataRootDir = dataRootDirNode.InnerText.Trim();
                    XmlNode         userNameNode          = jobNode.SelectSingleNode("UserName");
                    string          strUserName           = userNameNode.InnerText.Trim();
                    XmlNode         autoReportStatusNode  = jobNode.SelectSingleNode("AutoReportStatus");
                    bool            fAutoReportStatus     = bool.Parse(autoReportStatusNode.InnerText.Trim());
                    XmlNode         allowLongIdleTimeNode = jobNode.SelectSingleNode("AllowLongIdleTime");
                    bool            fAllowLongIdleTime    = bool.Parse(allowLongIdleTimeNode.InnerText.Trim());
                    XmlNode         outputDirNode         = jobNode.SelectSingleNode("OutputBaseDir");
                    string          strOutputBaseDir      = outputDirNode.InnerText.Trim();
                    // Get resource file list
                    XmlNode                 resourceFilesNode    = jobNode.SelectSingleNode("ResourceFiles");
                    XmlNodeList             resourceFileNodeList = resourceFilesNode.SelectNodes("ResourceFile");
                    List <ResourceFilePair> resourceFileList     = new List <ResourceFilePair>();
                    foreach (XmlNode resourceFileNode in resourceFileNodeList)
                    {
                        XmlNode          srcFileNode    = resourceFileNode.SelectSingleNode("SrcFileName");
                        XmlNode          dstRelFileNode = resourceFileNode.SelectSingleNode("DstRelativeFileName");
                        ResourceFilePair resourceFile   = new ResourceFilePair(srcFileNode.InnerText.Trim(), dstRelFileNode.InnerText.Trim());
                        resourceFileList.Add(resourceFile);
                    }
                    // Get dependent jobs
                    XmlNode       dependentJobsNode    = jobNode.SelectSingleNode("DependentJobs");
                    XmlNodeList   dependentJobNodeList = dependentJobsNode.SelectNodes("DependentJob");
                    List <string> dependentJobs        = new List <string>();
                    foreach (XmlNode dependentJobNode in dependentJobNodeList)
                    {
                        string strDependentJobName = dependentJobNode.InnerText.Trim();
                        dependentJobs.Add(strDependentJobName);
                    }
                    if (m_jobDictRefByJobName.ContainsKey(strJobName))
                    {
                        return(-1);
                    }
                    else
                    {
                        GalaxyJob job = new GalaxyJob();
                        job.AllowLongIdleTime  = fAllowLongIdleTime;
                        job.Arguments          = strArgs;
                        job.AutoReportStatus   = fAutoReportStatus;
                        job.DependentJobs      = dependentJobs;
                        job.ExeFileName        = strExeFileName;
                        job.JobId              = jobId;
                        job.JobStatus          = jobStatus;
                        job.OutputBaseDir      = strOutputBaseDir;
                        job.PNInstanceName     = strPNInstanceName;
                        job.RelativePath       = strRelativePath;
                        job.ResourceFileList   = resourceFileList;
                        job.JobName            = strJobName;
                        job.UserName           = strUserName;
                        job.ProjectDataRootDir = strProjectDataRootDir;
                        AddJob(job);
                    }
                }
            }
            catch (Exception)
            {
                iRet = -1;
            }

            return(iRet);
        }
Beispiel #5
0
        /// <returns>
        ///     0 - successfully
        ///     -1 - failed
        /// </returns>
        public int FlushToDisk(string strJobFileName)
        {
            int iRet = 0;

            lock (m_writeFileLock)
            {
                try
                {
                    XmlDocument    jobDoc         = new XmlDocument();
                    XmlDeclaration docDeclaration = jobDoc.CreateXmlDeclaration("1.0", "utf-8", null);
                    jobDoc.AppendChild(docDeclaration);
                    XmlElement root = jobDoc.CreateElement("GalaxyJobs");
                    jobDoc.AppendChild(root);
                    // Flush each jobs
                    foreach (GalaxyJob job in m_jobDictRefByJobName.Values)
                    {
                        XmlElement jobElement = jobDoc.CreateElement("GalaxyJob");

                        XmlElement      jobNameElement = jobDoc.CreateElement("JobName");
                        XmlCDataSection jobNameData    = jobDoc.CreateCDataSection(job.JobName);
                        jobNameElement.AppendChild(jobNameData);
                        jobElement.AppendChild(jobNameElement);

                        XmlElement pnInstanceNameElement = jobDoc.CreateElement("PNInstanceName");
                        pnInstanceNameElement.InnerText = job.PNInstanceName;
                        jobElement.AppendChild(pnInstanceNameElement);

                        XmlElement jobIdElement = jobDoc.CreateElement("JobId");
                        jobIdElement.InnerText = job.JobId.ToString();
                        jobElement.AppendChild(jobIdElement);

                        XmlElement jobStatusElement = jobDoc.CreateElement("JobStatus");
                        jobStatusElement.InnerText = GalaxyJob.JobStatus2String(job.JobStatus);
                        jobElement.AppendChild(jobStatusElement);

                        XmlElement exeNameElement = jobDoc.CreateElement("ExeFileName");
                        exeNameElement.InnerText = job.ExeFileName;
                        jobElement.AppendChild(exeNameElement);

                        XmlElement      relPathElement = jobDoc.CreateElement("RelativePath");
                        XmlCDataSection relPathData    = jobDoc.CreateCDataSection(job.RelativePath);
                        relPathElement.AppendChild(relPathData);
                        jobElement.AppendChild(relPathElement);

                        XmlElement userNameElement = jobDoc.CreateElement("UserName");
                        userNameElement.InnerText = job.UserName;
                        jobElement.AppendChild(userNameElement);

                        XmlElement      argsElement = jobDoc.CreateElement("Arguments");
                        XmlCDataSection argsData    = jobDoc.CreateCDataSection(job.Arguments);
                        argsElement.AppendChild(argsData);
                        jobElement.AppendChild(argsElement);

                        XmlElement autoReportStatusElement = jobDoc.CreateElement("AutoReportStatus");
                        autoReportStatusElement.InnerText = job.AutoReportStatus.ToString();
                        jobElement.AppendChild(autoReportStatusElement);

                        XmlElement allowLongIdleTimeElement = jobDoc.CreateElement("AllowLongIdleTime");
                        allowLongIdleTimeElement.InnerText = job.AllowLongIdleTime.ToString();
                        jobElement.AppendChild(allowLongIdleTimeElement);

                        XmlElement      outputDirElement = jobDoc.CreateElement("OutputBaseDir");
                        XmlCDataSection outputDirData    = jobDoc.CreateCDataSection(job.OutputBaseDir);
                        outputDirElement.AppendChild(outputDirData);
                        jobElement.AppendChild(outputDirElement);

                        XmlElement      dataRootDirElement = jobDoc.CreateElement("DataRootDir");
                        XmlCDataSection dataRootDirData    = jobDoc.CreateCDataSection(job.ProjectDataRootDir);
                        dataRootDirElement.AppendChild(dataRootDirData);
                        jobElement.AppendChild(dataRootDirElement);

                        // Add resource files
                        XmlElement resourceFilesElement = jobDoc.CreateElement("ResourceFiles");
                        foreach (ResourceFilePair resourceFile in job.ResourceFileList)
                        {
                            XmlElement resourceFileElement = jobDoc.CreateElement("ResourceFile");
                            // source file name
                            XmlElement      srcFileElement = jobDoc.CreateElement("SrcFileName");
                            XmlCDataSection srcFileData    = jobDoc.CreateCDataSection(resourceFile.SrcFileName);
                            srcFileElement.AppendChild(srcFileData);
                            resourceFileElement.AppendChild(srcFileElement);
                            // destination relative file name
                            XmlElement      dstRelFileElement = jobDoc.CreateElement("DstRelativeFileName");
                            XmlCDataSection dstRelFileData    = jobDoc.CreateCDataSection(resourceFile.DstRelativeFileName);
                            dstRelFileElement.AppendChild(dstRelFileData);
                            resourceFileElement.AppendChild(dstRelFileElement);
                            resourceFilesElement.AppendChild(resourceFileElement);
                        }
                        jobElement.AppendChild(resourceFilesElement);

                        // Add dependent jobs
                        XmlElement dependentJobsElement = jobDoc.CreateElement("DependentJobs");
                        foreach (string strDependentJobName in job.DependentJobs)
                        {
                            XmlElement      dependentJobElement  = jobDoc.CreateElement("DependentJob");
                            XmlCDataSection dependentJobNameData = jobDoc.CreateCDataSection(strDependentJobName);
                            dependentJobElement.AppendChild(dependentJobNameData);
                            dependentJobsElement.AppendChild(dependentJobElement);
                        }
                        jobElement.AppendChild(dependentJobsElement);

                        root.AppendChild(jobElement);
                    }
                    jobDoc.Save(strJobFileName);
                }
                catch (Exception)
                {
                    iRet = -1;
                }
            }

            return(iRet);
        }