private DownloadInfo DoDownloadIfNeed(IndexShopContext context, XmlFileInfo xmlInfo) { var filePath = FilePathHelper.GetFilePath(_settings.DirectoryPath, xmlInfo); if (context.DownloadFresh || File.Exists(filePath) == false) { var downloadContext = new BackgroundBaseContext($"Download:{xmlInfo.Name}", "download"); downloadContext.Prepare(); downloadContext.Start(); context.Contexts.Add(downloadContext); var downloader = new FeedsDownloader(_settings.AttemptsToDownload, Db, downloadContext); var file = downloader.Download(_settings.DirectoryPath, xmlInfo); downloadContext.Content = "Все скачали"; downloadContext.Finish(); return(file); } return(new DownloadInfo(xmlInfo.ShopId, xmlInfo.NameLatin, xmlInfo.Weight) { ShopName = xmlInfo.NameLatin, FilePath = filePath }); }
public void AnalyzeAndStoreSingle(XmlFileInfo xmlFile) { var xmlFileResult = XmlFileAnalyzer.ParseSingleFile(xmlFile); XmlQueries.AddMultipleWithoutKey(xmlFileResult); OnStoreChangeHandler(ChangedFileTypeFlag.Xml); }
public void Run(IIntegrationResult result) { foreach (FilePair Pair in this.FilePairs) { string XmlFilePath = Pair.XmlFile; if (!Path.IsPathRooted(XmlFilePath)) { XmlFilePath = Path.Combine(result.WorkingDirectory, XmlFilePath); } string XslFilePath = Pair.XslFile; if (!Path.IsPathRooted(XslFilePath)) { XslFilePath = Path.Combine(result.WorkingDirectory, XslFilePath); } string XslFileName = Path.GetFileName(XslFilePath); if (!File.Exists(XslFilePath)) { Log.Warning("File not Found: " + XslFileName); } WildCardPath Pattern = new WildCardPath(XmlFilePath); FileInfo[] Files = Pattern.GetFiles(); foreach (FileInfo XmlFileInfo in Files) { Log.Info(String.Format("Merging file {0} through {1}", XmlFileInfo, XslFileName)); if (XmlFileInfo.Exists) { string Data; String Contents; using (TextReader Reader = XmlFileInfo.OpenText()) { Contents = Reader.ReadToEnd(); } XslTransformer Transformer = new XslTransformer(); Dictionary <string, string> XslParms = new Dictionary <string, string>(); XslParms.Add("CCNetServer", this.DashboardServerName); XslParms.Add("CCNetBuild", new LogFile(result).Filename); XslParms.Add("CCNetProject", result.ProjectName); XslParms.Add("XmlSourceName", Path.GetFileName(XmlFilePath)); XslParms.Add("XmlSourcePath", XmlFileInfo.FullName); Data = Transformer.Transform(Contents, XslFilePath, XslParms); result.AddTaskResult((new XslMergerTaskResult(Data))); } else { Log.Warning("File not Found: " + XmlFileInfo); } } } }
public List <Statement> ParseSingleFile(XmlFileInfo xmlDocument) { BatisXmlMapParser parser = new BatisXmlMapParser().WithFileInfo(xmlDocument.FilePath, xmlDocument.ProjectName).Load(); bool isBatisQueryXmlFile = parser.XmlNamespace == XmlMapConstants.XmlNamespace; if (isBatisQueryXmlFile) { return(parser.GetMapFileStatments()); } return(new List <Statement>()); }
public SqlMapConfig ParseSingleConfigFile(XmlFileInfo xmlDocument) { BatisXmlConfigParser parser = new BatisXmlConfigParser().WithFileInfo(xmlDocument.FilePath, xmlDocument.ProjectName).Load(); if (parser.BatisXmlFileType == BatisXmlFileTypeEnum.SqlMapConfig) { return(parser.Result); } return(new SqlMapConfig { ParsedSuccessfully = false }); }
private DownloadInfo DownloadFile( XmlFileInfo fileInfo, string directoryPath) { FileWork(directoryPath, fileInfo); var downloadInfo = new DownloadInfo(fileInfo.ShopId, fileInfo.NameLatin, fileInfo.Weight) { StartTime = DateTime.Now, ShopName = fileInfo.Name, Url = fileInfo.XmlFeed, FilePath = FilePathHelper.GetFilePath(directoryPath, fileInfo) }; return(DoDownloadFile(downloadInfo)); }
public void Run(IIntegrationResult result) { foreach (FilePair Pair in this.FilePairs) { string XmlFilePath = Pair.XmlFile; if (!Path.IsPathRooted(XmlFilePath)) { XmlFilePath = Path.Combine(result.WorkingDirectory, XmlFilePath); } string XslFilePath = Pair.XslFile; if (!Path.IsPathRooted(XslFilePath)) { XslFilePath = Path.Combine(result.WorkingDirectory, XslFilePath); } string XslFileName = Path.GetFileName(XslFilePath); if (!File.Exists(XslFilePath)) { Log.Warning("File not Found: " + XslFileName); } WildCardPath Pattern = new WildCardPath(XmlFilePath); FileInfo[] Files = Pattern.GetFiles(); foreach (FileInfo XmlFileInfo in Files) { Log.Info(String.Format("Merging file {0} through {1}", XmlFileInfo, XslFileName)); if (XmlFileInfo.Exists) { string Data; String Contents; using (TextReader Reader = XmlFileInfo.OpenText()) { Contents = Reader.ReadToEnd(); } XslTransformer Transformer = new XslTransformer(); Data = Transformer.Transform(Contents, XslFilePath); result.AddTaskResult((new XslMergerTaskResult(Data))); } else { Log.Warning("File not Found: " + XmlFileInfo); } } } }
public bool TryStreamData <TContext>(XmlFileInfo xfi, FA mode, Action <KSoft.IO.XmlElementStream, FA, TContext> streamProc, TContext ctxt, string ext = null) { Contract.Requires(xfi != null); Contract.Requires(streamProc != null); System.IO.FileInfo file; bool result = Directories.TryGetFile(xfi.Location, xfi.Directory, xfi.FileName, out file, ext); if (mode == FA.Read) { if (!result) { return(false); } using (var s = new KSoft.IO.XmlElementStream(file.FullName, mode, this)) { SetupStream(s); streamProc(s, mode, ctxt); } } else if (mode == FA.Write) { if (xfi.Writable) { using (var s = KSoft.IO.XmlElementStream.CreateForWrite(xfi.RootName, this)) { SetupStream(s); streamProc(s, mode, ctxt); s.Document.Save(file.FullName); } } } return(true); }
private static void FileWork(string directoryPath, XmlFileInfo fileInfo) { var filePath = FilePathHelper.GetFilePath(directoryPath, fileInfo); var oldDirectoryPath = FilePathHelper.CombinePath(directoryPath, "old/"); if (File.Exists(filePath) == false) { return; } if (Directory.Exists(oldDirectoryPath) == false) { Directory.CreateDirectory(oldDirectoryPath); } var oldFilePath = FilePathHelper.GetFilePath(oldDirectoryPath, fileInfo); if (File.Exists(oldFilePath)) { File.Delete(oldFilePath); } File.Move(filePath, oldFilePath); }
public DownloadInfo Download(string filePath, XmlFileInfo info) { return(DoDownload(new() { info }, filePath).First()); }
public static string GetFilePath( string directoryPath, XmlFileInfo fileInfo) => $"{directoryPath}{fileInfo.NameLatin}.xml".Replace("//", "/");