public void OnLoad(string fileName) { Preconditions.CheckNotNullOrEmpty(fileName, "fileName"); _view.OnShowProgress(true); _root.Clear(); _vertices.Clear(); var loader = LoaderFactory.Create(LoaderFactory.Excel); if (!Preconditions.CheckNotNull(loader)) { _view.OnShowError("Ошибка при загрузке файла."); return; } var thread = new Thread(() => { _root = loader.Load(fileName); _root.Traverse(AddVertices); _view.OnGraphLoaded(_root, _vertices); _view.OnUpdateView(); _view.OnShowProgress(false); }) { IsBackground = true }; thread.Start(); }
static void RunResourceLoader() { Console.WriteLine("Please enter url"); var urlString = Console.ReadLine(); if (!string.IsNullOrWhiteSpace(urlString)) { Console.WriteLine("Please select type of loader:\nA - WebClientLoader\nB - HttpWebRequestLoader"); //pattern Fabric ILoader loader = LoaderFactory.Create(Console.ReadKey().Key); Console.WriteLine(" - will be used -> {0} ", loader.GetType().Name); string resultOfLoad = string.Empty; try { resultOfLoad = loader.Load(new Uri(urlString)); } catch (ResourseNotLoadedException ex) { Console.WriteLine(ex.ToString()); } if (!string.IsNullOrWhiteSpace(resultOfLoad)) { Console.WriteLine("Website as string:\n{0}", resultOfLoad); } else { Console.WriteLine("The webClientLoader returned an empty string"); } } else { Console.WriteLine("Url is not valid"); Console.ReadLine(); return; } }