static void RunOperation(StringDictionary keyValues) { using (var fs = new FileStream("trace.log", FileMode.Append)) { TextWriterTraceListener listener = new TextWriterTraceListener(fs); Trace.Listeners.Clear(); Trace.Listeners.Add(listener); Trace.IndentSize = 3; Trace.AutoFlush = true; ISPOperation operation = null; try { operation = GetOpertion(keyValues["o"]); operation.InitParameters(keyValues); operation.Validate(keyValues); operation.Run(keyValues); } catch (Exception ex) { if (ex.Message.Length > 0) { Console.Error.WriteLine(ex.Message); } if (operation != null) { PrintUsage(operation.HelpMessage); } WriteTrace(ex.ToString()); } } }
static ISPOperation GetOpertion(string name) { ISPOperation operation = null; switch (name.ToLowerInvariant()) { case "export": operation = new SPExportPersonalView(); break; case "import": operation = new SPImportPersonalView(); break; default: throw new SPSyntaxException("Invalid operation."); } return operation; }