public void LoadDirectory(string Path) { T item; if (!AssertParameterNotNull(Path, "Path")) { return; } Log(LogLevels.Information, $"Parsing directory {Path}"); try { foreach (string FileName in directoryEnumerator.EnumerateFiles(Path)) { Log(LogLevels.Information, $"Loading file {FileName}"); if (!Try(() => fileLoader.Load(FileName)).OrAlert(out item, "Failed to load file")) { continue; } Try(() => OnItemLoaded(item)).OrAlert("Failed to add item in library"); } } catch (Exception ex) { Log(ex); } }
private string CreateItemUrl(Item itemToCreate, string folderToImage) { if (String.IsNullOrEmpty(itemToCreate.ImageUrl) && itemToCreate.Image != null) { //TODO would be nice to have a not hardcoded int function string[] directories = folderToImage.Split(Path.DirectorySeparatorChar); //TODO check image format before loading to server string result = Path.DirectorySeparatorChar + Path.Combine(directories[directories.Length - 2], Path.Combine(directories[directories.Length - 1], _fileLoader.Load(folderToImage, itemToCreate.Image))); if (!IsImageUrlCorrect(result)) { throw new Exception("Incorrect image format"); } return(result); } else if ((!String.IsNullOrEmpty(itemToCreate.ImageUrl) && itemToCreate.Image == null) || (!String.IsNullOrEmpty(itemToCreate.ImageUrl) && itemToCreate.Image != null)) { if (!IsImageUrlCorrect(itemToCreate.ImageUrl)) { throw new Exception("Incorrect image format"); } return(itemToCreate.ImageUrl); } else { return(null); } }
public async Task SafeOpenFile(string filePath) { try { _appSettings.LastOpenedFile = filePath; var runnableRelay = new RunnableRelay <NxFile>((reporter, _) => { var loadingFilePleaseWait = LocalizationManager.Instance.Current.Keys.LoadingFile_PleaseWait; reporter.SetText(loadingFilePleaseWait); return(_fileLoader.Load(filePath)); }) { SupportProgress = false, SupportsCancellation = false }; var nxFile = await _backgroundTaskService.RunAsync(runnableRelay); _openedFileService.OpenedFile = nxFile; } catch (FileNotSupportedException ex) { _logger.LogError(ex, LocalizationManager.Instance.Current.Keys.FileNotSupported_Log.SafeFormat(filePath)); } catch (Exception ex) { _logger.LogError(ex, LocalizationManager.Instance.Current.Keys.LoadingError_Failed.SafeFormat(filePath, ex.Message), ex); } }
private void LoadSelected() { var file = (ImportingFile)ImportingFiles.CurrentItem; var parser = (ParserTypeItem)ParserTypes.CurrentItem; App.Current.Dispatcher.InvokeAsync(() => { loader.Load(new ImportFileInfo(file.FileInfo, parser.Parser, true)); }); }
private IEnumerable <Token> GetSourceTokensForInclude(Token token, string baseName) { string currentDirectory = token.Location.Directory; string fileName = _fileLoader.ExpandFileName(currentDirectory, baseName); string source = _fileLoader.Load(fileName); Lexer lexer = new Lexer(source, fileName); return(lexer.Tokens); }
private void LoadAsset(ChannelAssetAssociation channelAssetAssociation, IPlayer player) { PlaylistAsset playlistAsset = channelAssetAssociation.PlaylistAsset; AddPlayTimes(playlistAsset); _logger.WriteMessage("PlayerType: " + playlistAsset.PlayerType); if (player is IStreamLoader) { _logger.WriteMessage("Decrypting"); IStreamLoader streamLoader = (IStreamLoader)player; using ( MemoryStream stream = channelAssetAssociation.PlaylistAsset.DecryptAssetFile( _assetPath + channelAssetAssociation.PlaylistAsset.GetAssetFilenameGUIDSuffix() + "\\" + channelAssetAssociation.PlaylistAsset.AssetFilename, "password")) { //if (_count > 1) Thread.Sleep(5000); _logger.WriteMessage("Loading"); if (!_runScreenSaver) { _previousSlide.NewContentRequired(); return; } streamLoader.Load(stream); } } else if (player is IURLLoader) { IURLLoader urlLoader = (IURLLoader)player; urlLoader.Load(channelAssetAssociation.PlaylistAsset.AssetWebSite); } else if (player is IFileLoader) { _logger.WriteMessage("Decrypting"); // if (_count > 1) Thread.Sleep(15000); string decryptedFilePath = DecryptToTemp(channelAssetAssociation); _logger.WriteMessage("Decrypting Finished"); IFileLoader fileLoader = (IFileLoader)player; if (!_runScreenSaver) { File.Delete(decryptedFilePath); _previousSlide.NewContentRequired(); return; } fileLoader.Load(decryptedFilePath); _logger.WriteMessage("Finished loading"); } else if (player is INoAssetsLoader) { ((INoAssetsLoader)player).Load(((ContentPlaylistAsset)channelAssetAssociation.PlaylistAsset).Message); } }
protected void Load(string file, string key, string locale) { if (loaded.ContainsKey(locale + "." + file)) { return; } IFileMapping mapping = loader.Load(root, locale, file); loaded.Add(locale + "." + file, mapping); }
/// <summary> /// 加载数据 /// </summary> /// <param name="file">文件名</param> /// <param name="key">键</param> /// <param name="locale">当前语言</param> private void Load(string file, string key, string locale) { if (loaded.ContainsKey(locale + "." + file)) { return; } var mapping = loader.Load(root, locale, file); loaded.Add(locale + "." + file, mapping); }
public XElement GetProfileXml(string profileName) { var profilesXmlFileContent = _fileLoader.Load(); var profilesXml = XElement.Parse(profilesXmlFileContent); var profiles = profilesXml.Elements("Profile").Where(x => { var xAttribute = x.Attribute("name"); return(xAttribute != null && xAttribute.Value.ToLower() == profileName.ToLower()); }); return(profiles.FirstOrDefault()); }
public void Load(CanvasControl canvas) { _loader.Load(canvas); if (_loader.Loaded) { // Set the saver's file path so that subsequent saves will save to the file that was just loaded. _saver.SetActiveFilePath(_loader.LoadedFilePath); // Since we have loaded a file, we know that the current drawing now has a file. _currentDrawingHasFile = true; } }
private async Task Process(string[] files) { var monitor = new PerformanceMonitor(files.Length); using (Observable.Interval(TimeSpan.FromSeconds(30)).Subscribe(item => log.LogInformation(monitor.ToString()))) { var inputBlock = new BufferBlock <ProcessingChunk <string> >(new DataflowBlockOptions { BoundedCapacity = 1000000 }); var deserializeBlock = new TransformBlock <ProcessingChunk <string>, ProcessingChunk <TweetDTO> >( json => new ProcessingChunk <TweetDTO>(json.FileName, json.ChunkId, json.TotalChunks, jsonConvert.DeserializeObject <TweetDTO>(json.Data)), new ExecutionDataflowBlockOptions { BoundedCapacity = 2, MaxDegreeOfParallelism = Environment.ProcessorCount }); var outputBlock = new ActionBlock <ProcessingChunk <TweetDTO> >( Deserialized, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }); inputBlock.LinkTo(deserializeBlock, new DataflowLinkOptions { PropagateCompletion = true }); deserializeBlock.LinkTo(outputBlock, new DataflowLinkOptions { PropagateCompletion = true }); foreach (var file in files) { try { var data = fileLoader.Load(file); for (var i = 0; i < data.Length; i++) { await inputBlock.SendAsync(new ProcessingChunk <string>(file, i, data.Length, data[i])).ConfigureAwait(false); } monitor.Increment(); } catch (Exception ex) { log.LogError(ex, "Failed"); } } inputBlock.Complete(); await Task.WhenAll(inputBlock.Completion, outputBlock.Completion).ConfigureAwait(false); } }
public void Load(string file, IFileLoader loader) { if (loader is FileLoaders.LayeredSurface) { Reset(); surface = (SadConsole.Surfaces.LayeredSurface)loader.Load(file); surface.RenderArea = new Rectangle(0, 0, Math.Min(MainScreen.Instance.InnerEmptyBounds.Width, surface.RenderArea.Width), Math.Min(MainScreen.Instance.InnerEmptyBounds.Height, surface.RenderArea.Height)); layerManagementPanel.SetLayeredSurface(surface); Title = System.IO.Path.GetFileName(file); } }
public IEnumerable <Product> GetByFileName(string fileName) { var products = new List <Product>(); using (Stream input = loader.Load(fileName)) { var reader = XmlReader.Create(input); while (reader.Read()) { if (reader.Name != "product") { continue; } var product = mapper.Map(reader); products.Add(product); } } return(products); }
private IEnumerable <Token> GetSourceTokensForInclude(Token token, string baseName) { string currentDirectory = token.Location.Directory; string fileName = ""; foreach (string searchPath in CodeBaseOptions.Instance().SearchPaths.Split(';')) { currentDirectory = searchPath; fileName = _fileLoader.ExpandFileName(currentDirectory, baseName); if (File.Exists(fileName)) { break; } } string source = _fileLoader.Load(fileName); Lexer lexer = new Lexer(source, fileName); return(lexer.Tokens); }
public FileContentTool(string path) { loader = new TxtFileLoader(); Content = loader.Load(path); }
public bool Load(string path) { _currentFile = _fileLoader.Load(path); return(_currentFile != null); }
/// <summary> /// Loads the include text. /// </summary> /// <param name="requestFileName">Name of the request file.</param> /// <param name="content">The content.</param> /// <param name="location">The location.</param> /// <returns></returns> public bool LoadIncludeText(string requestFileName, out string content, out string location) { return(_fileLoader.Load(requestFileName, _transformer.Path, out content, out location)); }
public IEnumerable <T> Load(string filePath) { return(loader.Load(filePath)); }