/// <summary> /// Получаем список ФТП настроек Input /// </summary> /// <returns></returns> public static List <FTPSetting> GetFtpInputSettings() { using (var db = new FCCPortalEntities2()) { try { List <FTPSetting> settings = new List <FTPSetting>(); db.FTPSettings.Where(x => x.FtpServiceType == 1).ToList().ForEach(x => { settings.Add(new FTPSetting(x.Id, x.UserId, x.UserName, x.Host, x.Port ?? 0, x.Password, x.Path, x.UseSSL, (bool)x.DeleteFile, x.Enabled, x.FtpServiceType)); }); return(settings); } catch (Exception exception) { string innerException = exception.InnerException == null ? "" : exception.InnerException.Message; string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; LogHelper.AddLog("Error in method: " + methodName + "; Exception: " + exception.Message + " Innner Exception: " + innerException); return(null); } } }
public static FTPConversionSettingModel GetFtpConersionSettings(int userId) { using (var db = new FCCPortalEntities2()) { try { var dbSetting = db.FTPConversionSettings.SingleOrDefault(x => x.UserId == userId); return(new FTPConversionSettingModel(dbSetting.Id, dbSetting.AddProcessed, dbSetting.ReturnResults, dbSetting.MirrorInput, dbSetting.MoveProcessed, dbSetting.UserId)); } catch (Exception exception) { string innerException = exception.InnerException == null ? "" : exception.InnerException.Message; string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; LogHelper.AddLog("Error in method: " + methodName + "; Exception: " + exception.Message + " Innner Exception: " + innerException); return(null); } } }
public static List <Tuple <string, string> > ExtractFiles(FtpWebResponse response, FTPSetting ftpSettings) { FlexiCapture.Cloud.ServiceAssist.DB.FTPConversionSettings ftpConvSettings; using (var db = new FCCPortalEntities2()) { if (AcceptableTypes == null) { AcceptableTypes = db.DocumentTypes .Select(x => x).ToList(); } ftpConvSettings = db.FTPConversionSettings .SingleOrDefault(x => x.UserId == ftpSettings.UserId); } Stream responseStream = response.GetResponseStream(); StreamReader reader = new StreamReader(responseStream); List <Tuple <string, string> > fileNameExtensionTuples = new List <Tuple <string, string> >(); List <Tuple <string, string> > newFileNameExtensionTuples = new List <Tuple <string, string> >(); string line = reader.ReadLine(); while (!string.IsNullOrEmpty(line)) { var fileName = line;//.Split(' ').LastOrDefault(); foreach (var type in AcceptableTypes) { foreach (var splittedType in type.Extension.Split(';')) { if (fileName.Contains(splittedType)) { fileNameExtensionTuples .Add(Tuple.Create(fileName, splittedType)); break; } } } line = reader.ReadLine(); } reader.Close(); response.Close(); fileNameExtensionTuples.ForEach(x => { string storedFilename = DownloadFile(ftpSettings.Host, ftpSettings.Path, x.Item1, x.Item2, ftpSettings.UserName, ftpSettings.Password, ftpConvSettings, ftpSettings); newFileNameExtensionTuples.Add(Tuple.Create(storedFilename, x.Item2)); }); return(newFileNameExtensionTuples); }
/// <summary> /// Проверка на наличие доступа пользователя к сервису FTP /// </summary> /// <param name="userId"></param> /// <returns></returns> private static bool IsPrivilegedEnough(int userId) { try { bool isPrivelegedEnough = false; if (userId <= 0) { throw new ArgumentOutOfRangeException(); } UserServiceSubscribes query; using (var db = new FCCPortalEntities2()) { query = (from ss in db.UserServiceSubscribes where ss.UserId.Equals(userId) && ss.ServiceId == FtpProfileId && ss.SubscribeStateId == FtpSProfileActiveState select ss).FirstOrDefault(); } if (query == null) { return(false); } return(true); } catch (Exception e) { string innerException = e.InnerException == null ? "" : e.InnerException.Message; string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name; LogHelper.AddLog("Error in method: " + methodName + "; Exception: " + e.Message + " Innner Exception: " + innerException); return(false); } }