public void RunProcess(IRepository repository, IFTP ftp, ILogger logger) { ////Get the ILH process from the DB ////Will be used to link to this specific run //var process = repository.GetFirst<Process>(x => x.Name == "ILH"); ////Create a new process run linked to the ILH Process type ////Set start to current time //var processStart = DateTime.Now; //var processRun = new ProcessRun { ProcessId = process.ProcessId, Start = processStart }; ////Create the process run in the DB ////Actions won't actually be executed in the DB until repository.Save() is called //repository.Create<ProcessRun>(processRun); //repository.Save(); ////Get settings for current process //var settings = repository.GetFirst<Setting>(x => x.ProcessId == process.ProcessId); //foreach(var fileInfo in new DirectoryInfo(settings.SourcePath).GetFiles()) //{ // //Create a new file in the DB // var file = new DataAccess.File { Path = settings.SourcePath, Name = fileInfo.Name, ProcessRunId = processRun.ProcessRunId }; // repository.Create<DataAccess.File>(file); // repository.Save(); // using (StreamReader reader = new StreamReader(fileInfo.FullName)) // { // string line; // while ((line = reader.ReadLine()) != null) // { // // Write FileLine to DB // var fileLine = new FileLine { FileId = file.FileId, Line = line }; // repository.Create<FileLine>(fileLine); // } // } // repository.Save(); //} }
public static IFTP Instrance(int ident) { IFTP ftp = null; FTPConfigInfo ftpConfig = FTPConfigs.GetFTP(ident); if (!string.IsNullOrEmpty(ftpConfig.AssemblyType)) { string[] filenames = ftpConfig.AssemblyType.Split(','); Assembly ass = Assembly.LoadFrom(System.Web.HttpRuntime.BinDirectory + filenames[1] + ".dll"); ftp = (IFTP)Activator.CreateInstance(ass.GetType(filenames[0], false, true), new object[] { (IConfigInfo)ftpConfig }); if (ftp == null) { throw ExceptionManager.MessageException("存储系统配置文件有误,请检查!"); } } else { if (ftpConfig.Timeout == 0) //不限时 { ftp = new FTPClient(ftpConfig.Serveraddress, ftpConfig.Serverport, ftpConfig.Username, ftpConfig.Password, ftpConfig.Mode); } else { ftp = new FTPClient(ftpConfig.Serveraddress, ftpConfig.Serverport, ftpConfig.Username, ftpConfig.Password, ftpConfig.Mode, ftpConfig.Timeout); } } ftp.FtpConfig = ftpConfig; //ftpDic.TryGetValue(ident, out ftp); //if (ftp == null) //{ // FTPConfigInfo ftpConfig = FTPConfigs.GetFTP(ident); // if (!string.IsNullOrEmpty(ftpConfig.AssemblyType)) // { // string[] filenames=ftpConfig.AssemblyType.Split(','); // Assembly ass = Assembly.LoadFrom(System.Web.HttpRuntime.BinDirectory + filenames[1] + ".dll"); // ftp = (IFTP)Activator.CreateInstance(ass.GetType(filenames[0], false, true), new object[] { (IConfigInfo)ftpConfig }); // if (ftp == null) // { // throw ExceptionManager.MessageException("存储系统配置文件有误,请检查!"); // } // } // else // { // if (ftpConfig.Timeout == 0)//不限时 // { // ftp = new FTPClient(ftpConfig.Serveraddress, ftpConfig.Serverport, ftpConfig.Username, ftpConfig.Password, ftpConfig.Mode); // } // else // { // ftp = new FTPClient(ftpConfig.Serveraddress, ftpConfig.Serverport, ftpConfig.Username, ftpConfig.Password, ftpConfig.Mode, ftpConfig.Timeout); // } // } // ftp.FtpConfig = ftpConfig; // ftpDic[ident] = ftp; //} return(ftp); }
public void RunProcess(IRepository repository, IFTP ftp, ILogger logger) { try { Boolean runStatus = false; String localWorkingPathSubDir = String.Format("{0:yyyyMMddHmmss}", DateTime.Now); var process = repository.GetFirst <Process>(x => x.Name == "I02U"); var processRun = new ProcessRun { ProcessId = process.ProcessId, Start = DateTime.Now }; repository.Create <ProcessRun>(processRun); repository.Save(); logger.Log(repository, processRun.ProcessRunId, "Update Order Replenishment Process Start"); logger.Log(repository, processRun.ProcessRunId, "Fetching FTP file(s)"); if (GetFTPFiles(repository, logger, ftp, processRun.ProcessRunId, localWorkingPathSubDir) == true) { logger.Log(repository, processRun.ProcessRunId, "Loading FTP file(s) into SQL Server"); if (LoadFTPFilesIntoDB(repository, logger, processRun.ProcessRunId, localWorkingPathSubDir) == true) { logger.Log(repository, processRun.ProcessRunId, "Creating consolidated file"); if (CreateConsolidatedI02UFile(repository, logger, processRun.ProcessRunId) == true) { logger.Log(repository, processRun.ProcessRunId, "Update Order Replenishment Process completed successfully"); runStatus = true; } } } processRun.End = DateTime.Now; processRun.RunStatus = runStatus; repository.Update <ProcessRun>(processRun); repository.Save(); } catch (Exception e) { logger.Log(repository, 0, "RunProcess() failed", 3, e.Message); } }
/// <summary> /// FTP连接测试 /// </summary> /// <param name="Serveraddress">FTP服务器地址</param> /// <param name="Serverport">FTP端口</param> /// <param name="Username">用户名</param> /// <param name="Password">密码</param> /// <param name="Timeout">超时时间(秒)</param> /// <param name="uploadpath">附件保存路径</param> /// <param name="message">返回信息</param> /// <returns>是否可用</returns> public static bool TestConnect(string uploadpath, ref string message) { IFTP ftpupload = CurrentFTP; bool isvalid = ftpupload.Connect(); if (!isvalid) { message = ftpupload.ErrorMessage; return(isvalid); } //切换到指定路径下,如果目录不存在,将创建 if (!ftpupload.ChangeDir(uploadpath)) { ftpupload.MakeDir(uploadpath); if (!ftpupload.ChangeDir(uploadpath)) { message += ftpupload.ErrorMessage; isvalid = false; } } return(isvalid); }
private Boolean GetFTPFiles(IRepository repository, ILogger logger, IFTP ftp, Int32 processRunId, String localWorkingPathSubDir) { Boolean filesExist = false; try { var dealerGroups = repository.Get <DealerGroup>(); var settings = repository.Get <Setting>(); var ftpHost = settings.First(x => x.Key == Constants.FtpHost).Value; var ftpUsername = settings.First(x => x.Key == Constants.FtpUsername).Value; var ftpPassword = settings.First(x => x.Key == Constants.FtpPassword).Value; var sourcePath = settings.First(x => x.Key == Constants.DMSourcePath).Value; var destinationPath = settings.First(x => x.Key == Constants.DMDestinationPath).Value; var sourceFilename = settings.First(x => x.Key == Constants.DMSourceFilename).Value; var destinationFilename = settings.First(x => x.Key == Constants.DMDestinationFilename).Value; var localWorkingPath = settings.First(x => x.Key == Constants.DMLocalWorkingPath).Value; foreach (var dealerGroup in dealerGroups) { foreach (var dealer in dealerGroup.Dealers) { String filename = String.Format("A{0}{1}", dealer.Code, sourceFilename); String remoteFile = String.Format("{0}/{1}/N{2}/{3}", sourcePath, dealerGroup.Code, dealer.Code, filename); String remoteFilePath = String.Format("{0}/{1}/N{2}", sourcePath, dealerGroup.Code, dealer.Code); String localFile = String.Format(@"{0}{1}\{2}", localWorkingPath, localWorkingPathSubDir, filename); System.IO.Directory.CreateDirectory(String.Format(@"{0}{1}", localWorkingPath, localWorkingPathSubDir)); if (ftp.Get(ftpHost, ftpUsername, ftpPassword, remoteFile, localFile) == true) { filesExist = true; logger.Log(repository, processRunId, "Fetching " + remoteFile); String remoteFileRename = String.Format("{0}.{1:yyyyMMdd}.{2:Hmmss}", filename, DateTime.Now, DateTime.Now); //ftp.Rename(ftpHost, ftpUsername, ftpPassword, remoteFile, remoteFileRename); var file = new DataAccess.FileSource { Path = remoteFilePath, Name = filename, ProcessRunId = processRunId }; repository.Create <DataAccess.FileSource>(file); repository.Save(); } } } } catch (Exception e) { logger.Log(repository, processRunId, "GetFTPFiles() failed", 3, e.Message); return(false); } if (filesExist == false) { logger.Log(repository, processRunId, "No FTP Files to Process"); } return(filesExist); }