static public bool LoadXmlFile <T>(Stream filestream, out T obj, Type[] extra = null) { try { var xmlSettings = new System.Xml.XmlReaderSettings() { CheckCharacters = false, }; XmlSerializer serializer = new XmlSerializer(typeof(T), extra); using (var streamReader = new StreamReader(filestream, Encoding.UTF8)) { using (var xmlReader = System.Xml.XmlReader.Create(streamReader, xmlSettings)) { obj = (T)serializer.Deserialize(xmlReader); } } } catch (Exception ex) { LogStatics.Debug(ex.ToString()); obj = default(T); return(false); } return(true); }
/// <summary> /// Get all nodes under the specified rootPath. /// </summary> /// <param name="rootPath">The rootPath must at least contains the drive and may include any number of subdirectories. Wildcards aren't supported.</param> public List <INode> GetNodes(string rootPath) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); List <INode> nodes = new List <INode>(); //TODO use Parallel.Net to process this when it becomes available UInt32 nodeCount = (UInt32)_nodes.Length; for (UInt32 i = 0; i < nodeCount; ++i) { if (_nodes[i].NameIndex != 0 && GetNodeFullNameCore(i).StartsWith(rootPath, StringComparison.InvariantCultureIgnoreCase)) { nodes.Add(new NodeWrapper(this, i, _nodes[i])); } } stopwatch.Stop(); LogStatics.Debug( string.Format( "{0} node{1} have been retrieved in {2} ms", nodes.Count, nodes.Count > 1 ? "s" : string.Empty, (float)stopwatch.ElapsedTicks / TimeSpan.TicksPerMillisecond ) ); return(nodes); }
private async void SearchAsync(string text) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Restart(); if (Finder.IsReady) { _cancellation?.Cancel(); _cancellation = new CancellationTokenSource(); _cancellation_token = _cancellation.Token; try { StatusText = "検索中..."; var SearchedList = await Finder.SearchFileAsync(text, SearchRange, SearchMax, _cancellation_token); _SearchResults = new ObservableCollection <FileFinderDisplayItemViewModel>(SearchedList.Select(x => new FileFinderDisplayItemViewModel(x))); RefreshDisplayItemVisibility(); StatusText = "検索完了"; } catch (OperationCanceledException) { } } stopwatch.Stop(); LogStatics.Debug(string.Format("call Search at {0:F3} s", (float)stopwatch.Elapsed.TotalSeconds)); }
private void WatermarkTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e) { TextBox textBox = (TextBox)sender; try { converter.ConvertFromString(e.Text.ToUpper()); textBox.Text = string.Empty; } catch (Exception ex) { LogStatics.Debug(ex.ToString()); e.Handled = false; textBox.Text = string.Empty; } }
static public bool SaveXmlFile <T>(Stream filestream, T obj, Type[] extra = null) { try { XmlSerializer serializer = new XmlSerializer(typeof(T), extra); using (var streamWriter = new StreamWriter(filestream, Encoding.UTF8)) { serializer.Serialize(streamWriter, obj); streamWriter.Flush(); } } catch (Exception ex) { LogStatics.Debug(ex.ToString()); return(false); } return(true); }
public void Execute(LauncherCommandInfo CommandInfo) { string[] Commands = ParseCommandList(CommandInfo); int CommnadCount = Commands.Count(); foreach (var Command in Commands.Select((command, index) => new { command, index })) { bool IsImmediately = Command.index != CommnadCount - 1 || (App.AppConfig.IsImmediately && CommandInfo.IsImmediately); try { if (App.AppConfig.IsCopyToClipboard || !IsImmediately) { System.Windows.Forms.Clipboard.Clear(); System.Threading.Thread.Sleep(100); System.Windows.Forms.Clipboard.SetText(Command.command); } } catch (Exception ex) { LogStatics.Debug(ex.ToString()); } switch (CommandInfo.Type) { case CommandExecuteType.None: break; case CommandExecuteType.Command: foreach (var CommandModule in App.PluginManagerInstance.CommandExecuteModules) { if (CommandModule.CanExecute(Command.command, IsImmediately)) { CommandModule.Execute(Command.command, IsImmediately); } } break; case CommandExecuteType.FileOpen: ExecuteFileOpen(Command.command); break; } } }
public void Info(string message, params object[] args) { LogStatics.Info(message, args); }
public void Info(string message) { LogStatics.Info(message); }
private static void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { LogStatics.Fatal(e.Exception, "App_DispatcherUnhandledException"); }
public void Warn(string message) { LogStatics.Warn(message); }
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { LogStatics.Fatal(e.ExceptionObject as Exception, "CurrentDomain_UnhandledException"); }
private static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e) { LogStatics.Fatal(e.Exception, "TaskScheduler_UnobservedTaskException"); }
public void Fatal(string message, params object[] args) { LogStatics.Fatal(message, args); }
public void Error(string message) { LogStatics.Error(message); }
public void Debug(string message) { LogStatics.Debug(message); }
public void Fatal(Exception exception, string message) { LogStatics.Fatal(exception, message); }
public void Error(Exception exception, string message, params object[] args) { LogStatics.Error(exception, message, args); }
public void Error(string message, params object[] args) { LogStatics.Error(message, args); }
public void Error(Exception exception, string message) { LogStatics.Error(exception, message); }
public void Debug(string message, params object[] args) { LogStatics.Debug(message, args); }
public void Fatal(Exception exception, string message, params object[] args) { LogStatics.Fatal(exception, message, args); }
public void Fatal(string message) { LogStatics.Fatal(message); }
public void Warn(string message, params object[] args) { LogStatics.Warn(message, args); }