Пример #1
0
        /// <summary>
        /// 加载需求
        /// </summary>
        public void LoadRequirement()
        {
            var physicalRequirementPath = SwiftConfiguration.GetJobTaskRequirementPath(CurrentTaskPath);

            if (!File.Exists(physicalRequirementPath))
            {
                throw new Exception(string.Format("任务需求文件不存在:{0}", physicalRequirementPath));
            }

            var taskRequirementJson = string.Empty;

            try
            {
                taskRequirementJson = File.ReadAllText(physicalRequirementPath, Encoding.UTF8);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("读取任务需求文件异常:{0}", ex.Message));
            }

            if (string.IsNullOrWhiteSpace(taskRequirementJson))
            {
                throw new Exception(string.Format("任务需求文件为空:{0}", physicalRequirementPath));
            }

            Requirement = taskRequirementJson;
        }
Пример #2
0
        /// <summary>
        /// 处理下载请求
        /// </summary>
        private byte[] ProcessDownloadRequest(string requestUrl, byte[] inputData, NameValueCollection paras)
        {
            string filePath = string.Empty;

            // 如果指定了文件名,则使用文件名
            string fileName = paras["fileName"];

            if (!string.IsNullOrWhiteSpace(fileName))
            {
                fileName = HttpUtility.UrlDecode(fileName);
                filePath = Path.Combine(SwiftConfiguration.BaseDirectory, fileName.Replace('/', Path.DirectorySeparatorChar));
            }

            // 如果未指定文件名,则根据业务参数计算
            if (string.IsNullOrWhiteSpace(filePath))
            {
                if (requestUrl == "/download/task/requirement")
                {
                    var jobName = paras["jobName"];
                    var jobId   = paras["jobId"];
                    var taskId  = paras["taskId"];
                    filePath = SwiftConfiguration.GetJobTaskRequirementPath(jobName, jobId, int.Parse(taskId));
                }

                if (requestUrl == "/download/job/package")
                {
                    var jobName    = paras["jobName"];
                    var jobVersion = paras["jobVersion"];
                    filePath = SwiftConfiguration.GetJobPackagePath(jobName, jobVersion);
                }

                if (requestUrl == "/download/task/result")
                {
                    var jobName = paras["jobName"];
                    var jobId   = paras["jobId"];
                    var taskId  = paras["taskId"];
                    filePath = SwiftConfiguration.GetJobTaskResultPath(jobName, jobId, int.Parse(taskId));
                }

                if (requestUrl == "/download/job/result")
                {
                    var jobName = paras["jobName"];
                    var jobId   = paras["jobId"];
                    filePath = SwiftConfiguration.GetJobResultPackagePath(jobName, jobId);
                }
            }

            LogWriter.Write(string.Format("处理下载请求:{0}", filePath));

            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException("文件不存在:" + filePath);
            }

            return(File.ReadAllBytes(filePath));
        }
Пример #3
0
        /// <summary>
        /// 将任务需求写到文件
        /// </summary>
        public void WriteRequirement()
        {
            var taskPath = CurrentTaskPath;

            if (!Directory.Exists(taskPath))
            {
                Directory.CreateDirectory(taskPath);
            }

            string taskRequirementPath = SwiftConfiguration.GetJobTaskRequirementPath(taskPath);

            File.WriteAllText(taskRequirementPath, Requirement, Encoding.UTF8);
        }
Пример #4
0
        /// <summary>
        /// 下载数据处理
        /// </summary>
        /// <param name="msgType"></param>
        /// <param name="paras"></param>
        /// <param name="data"></param>
        private void ProcessResponse(string msgType, Dictionary <string, string> paras, byte[] data, CancellationToken cancellationToken = default(CancellationToken))
        {
            string filePath = string.Empty;

            paras.TryGetValue("fileName", out string fileName);
            if (!string.IsNullOrWhiteSpace(fileName))
            {
                filePath = Path.Combine(SwiftConfiguration.BaseDirectory, fileName.Replace('/', Path.DirectorySeparatorChar));
            }

            if (string.IsNullOrWhiteSpace(filePath))
            {
                if (msgType == "download/job/package")
                {
                    var jobName    = paras["jobName"];
                    var jobVersion = paras["jobVersion"];
                    filePath = SwiftConfiguration.GetJobPackagePath(jobName, jobVersion);
                }

                if (msgType == "download/task/requirement")
                {
                    var jobName = paras["jobName"];
                    var jobId   = paras["jobId"];
                    var taskId  = int.Parse(paras["taskId"]);
                    filePath = SwiftConfiguration.GetJobTaskRequirementPath(jobName, jobId, taskId);
                }

                if (msgType == "download/task/result")
                {
                    var jobName = paras["jobName"];
                    var jobId   = paras["jobId"];
                    var taskId  = int.Parse(paras["taskId"]);
                    filePath = SwiftConfiguration.GetJobTaskResultPath(jobName, jobId, taskId);
                }
            }

            LogWriter.Write(string.Format("收到下载数据:{0},{1}", msgType, filePath));

            SaveDownloadFile(filePath, data, cancellationToken);
        }