public void LoadFile(string fileName, System.IO.Stream stream, bool editMode, Format format = null) { format = format ?? DocumentInfos.FindFormat(fileName) ?? DocumentInfos.DefaultFormat; if (format == null) { throw new ArgumentOutOfRangeException("fileName", "Could not find format of the file"); } var doc = format.Info.Create(); doc.FileName = fileName; doc.Load(stream, format, null); doc.EditMode = editMode; SetDocument(doc); }
public override bool Process(ProcessCommandLineArgs args) { var command = args.Command; if (command.GetBool("server", "s") != true) { return(false); } EnableBackups = command.GetBool("backup") ?? true; var password = command.GetValue("password", "pw"); var operatorPassword = command.GetValue("op", "oppassword", "oppw"); var port = command.GetInt("port") ?? 14400; var nat = command.GetBool("nat") ?? false; var userLevel = command.GetEnum <UserLevel>("userlevel", "ul") ?? UserLevel.Viewer; var fileName = command.GetValue("file", "generic:0"); if (!string.IsNullOrEmpty(fileName)) { if (File.Exists(fileName)) { using (var stream = File.OpenRead(fileName)) { LoadFile(fileName, stream, true); } } else { var format = DocumentInfos.FindFormat(fileName); if (format == null) { throw new InvalidOperationException(string.Format("Unrecognized format for file name '{0}'", fileName)); } var doc = format.Info.Create(); doc.FileName = fileName; doc.EditMode = true; SetDocument(doc); } } var autosaveInterval = command.GetInt("autosave") ?? 0; if (autosaveInterval > 0) { // turn on autosaving } var backup = command.GetBool("backup") ?? false; if (backup) { // turn on backups } args.Writer.WriteLine("Starting PabloDraw server on port {0}...", port); StartServer(port, password, operatorPassword, nat, userLevel, args.Writer); args.Writer.WriteLine("Started!"); ConsoleHelper.Run(args); args.Writer.WriteLine("Stopping..."); StopServer(); return(true); }
public override bool Process(ProcessCommandLineArgs args) { var command = args.Command; if (command.GetBool("server", "s") != true) { return(false); } EnableBackups = command.GetBool("backup") ?? true; var password = command.GetValue("password", "pw"); var operatorPassword = command.GetValue("op", "oppassword", "oppw"); _port = command.GetInt("port") ?? 14400; var nat = command.GetBool("nat") ?? false; var userLevel = command.GetEnum <UserLevel>("userlevel", "ul") ?? UserLevel.Viewer; var fileName = command.GetValue("file", "generic:0"); if (!string.IsNullOrEmpty(fileName)) { if (File.Exists(fileName)) { using (var stream = File.OpenRead(fileName)) { LoadFile(fileName, stream, true); } } else { var format = DocumentInfos.FindFormat(fileName); if (format == null) { throw new InvalidOperationException(string.Format("Unrecognized format for file name '{0}'", fileName)); } var doc = format.Info.Create(); doc.FileName = fileName; doc.EditMode = true; SetDocument(doc); } } _autosaveInterval = command.GetInt("autosave") ?? 0; if (_autosaveInterval > 0) { if (!Directory.Exists(_port.ToString())) { Directory.CreateDirectory(_port.ToString( )); // Store AutoSave in its port number folder so that multiple instances don't overwrite each other. } _autosaveInterval *= 1000; // Convert to seconds. _autoSaveTimer = new Timer(TimerCallback, null, _autosaveInterval, Timeout.Infinite); } _backup = command.GetBool("backup") ?? false; args.Writer.WriteLine("Starting PabloDraw server on port {0}...", _port); StartServer(_port, password, operatorPassword, nat, userLevel, args.Writer); args.Writer.WriteLine("Started! Press any key to stop"); System.Console.Read(); args.Writer.WriteLine("Stopping..."); StopServer(); return(true); }