public VisualStudioInstance(Process hostProcess, EnvDTE.DTE dte) { _hostProcess = hostProcess; _dte = dte; StartRemoteIntegrationService(dte); _integrationServiceChannel = new IpcClientChannel($"IPC channel client for {_hostProcess.Id}", sinkProvider: null); ChannelServices.RegisterChannel(_integrationServiceChannel, ensureSecurity: true); // Connect to a 'well defined, shouldn't conflict' IPC channel _integrationService = IntegrationService.GetInstanceFromHostProcess(hostProcess); // Create marshal-by-ref object that runs in host-process. _inProc = ExecuteInHostProcess <VisualStudio_InProc>( type: typeof(VisualStudio_InProc), methodName: nameof(VisualStudio_InProc.Create)); // There is a lot of VS initialization code that goes on, so we want to wait for that to 'settle' before // we start executing any actual code. _inProc.WaitForSystemIdle(); this.CSharpInteractiveWindow = new CSharpInteractiveWindow_OutOfProc(this); this.Editor = new Editor_OutOfProc(this); this.SolutionExplorer = new SolutionExplorer_OutOfProc(this); this.VisualStudioWorkspace = new VisualStudioWorkspace_OutOfProc(this); this.SendKeys = new SendKeys(this); // Ensure we are in a known 'good' state by cleaning up anything changed by the previous instance CleanUp(); }
public static void GetInstance(string uniqueName = "OpenRPAService") { if (RemoteInstance != null) { try { RemoteInstance.Ping(); return; } catch (Exception) { } } //if (secondInstanceChannel == null) //{ // secondInstanceChannel = new IpcClientChannel(); // ChannelServices.RegisterChannel(secondInstanceChannel, true); //} try { IpcClientChannel secondInstanceChannel = new IpcClientChannel(); ChannelServices.RegisterChannel(secondInstanceChannel, true); } catch (Exception ex) { Log.Debug(ex.ToString()); } string applicationIdentifier = uniqueName + Environment.UserName; string channelName = String.Concat(applicationIdentifier, Delimiter, ChannelNameSuffix); string remotingServiceUrl = IpcProtocol + channelName + "/" + RemoteServiceName; // Obtain a reference to the remoting service exposed by the server i.e the first instance of the application RemoteInstance = (OpenRPAService)RemotingServices.Connect(typeof(OpenRPAService), remotingServiceUrl); RemoteInstance.Ping(); }
/// <summary> /// ipcクライアントとして接続。サーバが起動されてない場合はfalseを返す。 /// </summary> /// <returns>サーバが起動してるか</returns> public bool startClient(string status = "") { CltChannel = new IpcClientChannel(); ChannelServices.RegisterChannel(CltChannel, true); try { shareData = (IpcDataClass)Activator.GetObject(typeof(IpcDataClass), address); if (status != "") { shareData.status = status; //shareData.callEvent(); } //shareData.changeValue += recieve; } catch (ArgumentException) { return(false); } //書き込めない->サーバが存在しない catch (RemotingException) { return(false); } catch (InvalidOperationException) { return(true); } return(true); }
public MonitorVdmClient() { // Set up communication with the virtual desktop monitoring server. _channel = new IpcClientChannel(); ChannelServices.RegisterChannel(_channel, false); _monitorVdm = (IMonitorVdmService)Activator.GetObject(typeof(IMonitorVdmService), "ipc://VirtualDesktopManagerAPI/MonitorVdmService"); }
public TRemoteService Service <TRemoteService>() { if (proxies.TryGetValue(typeof(TRemoteService), out object ipcProxy)) { return((TRemoteService)ipcProxy); } if (ipcClientChannel == null) { ipcClientChannel = new IpcClientChannel(); ChannelServices.RegisterChannel(ipcClientChannel, true); } string ipcServiceName = ApiIpcCommon.GetServiceName <TRemoteService>(serverId); string ipcUrl = $"ipc://{serverId}/{ipcServiceName}"; Log.Debug($"Calling: {ipcUrl}"); // Get proxy instance of rpc service instance published by server in PublishService() ipcProxy = RemotingServices.Connect(typeof(TRemoteService), ipcUrl); proxies[typeof(TRemoteService)] = ipcProxy; if (ipcProxy == null) { throw new Exception($"Failed to create IPC proxy for {typeof(TRemoteService).FullName}"); } return((TRemoteService)ipcProxy); }
public static void End() { if (Message != null) { Message.End(); Message = null; if (channel != null) { ChannelServices.UnregisterChannel(channel); channel = null; } } if (ServerProcess != null) { if (!ServerProcess.HasExited) { ServerProcess.Kill(); } ServerProcess.Dispose(); ServerProcess = null; } }
/// <summary> /// Creates a client channel and obtains a reference to the remoting service exposed by the server - /// in this case, the remoting service exposed by the first instance. Calls a function of the remoting service /// class to pass on command line arguments from the second instance to the first and cause it to activate itself. /// </summary> /// <param name="channelName">Application's IPC channel name.</param> /// <param name="args"> /// Command line arguments for the second instance, passed to the first instance to take appropriate action. /// </param> private static void SignalFirstInstance(string channelName, IList <string> args) { IpcClientChannel secondInstanceChannel = new IpcClientChannel(); ChannelServices.RegisterChannel(secondInstanceChannel, true); string remotingServiceUrl = IpcProtocol + channelName + "/" + RemoteServiceName; // Obtain a reference to the remoting service exposed by the server i.e the first instance of the application IPCRemoteService firstInstanceRemoteServiceReference = (IPCRemoteService)RemotingServices.Connect(typeof(IPCRemoteService), remotingServiceUrl); // Check that the remote service exists, in some cases the first instance may not yet have created one, in which case // the second instance should just exit if (firstInstanceRemoteServiceReference != null) { // Invoke a method of the remote service exposed by the first instance passing on the command line // arguments and causing the first instance to activate itself try { firstInstanceRemoteServiceReference.InvokeFirstInstance(args); } catch (Exception) { // ignored } } }
/// <summary> /// Gets an instance of a <see cref="Messager"/> to use to talk to the running instance of the client. /// </summary> /// <param name="p_eifEnvironmentInfo">The application's envrionment info.</param> /// <param name="p_gmdGameModeInfo">The descriptor of the game mode for which mods are being managed.</param> /// <returns>An instance of a <see cref="Messager"/> to use to talk to the running instance of the client, /// or <c>null</c> if no valid <see cref="Messager"/> could be created.</returns> public static IMessager GetMessager(EnvironmentInfo p_eifEnvironmentInfo, IGameModeDescriptor p_gmdGameModeInfo) { if (m_cchMessagerChannel == null) { System.Collections.IDictionary properties = new System.Collections.Hashtable(); properties["exclusiveAddressUse"] = false; m_cchMessagerChannel = new IpcClientChannel(); ChannelServices.RegisterChannel(m_cchMessagerChannel, true); } else { throw new InvalidOperationException("The IPC Channel has already been created as a CLIENT."); } string strMessagerUri = String.Format("ipc://{0}-{1}IpcServer/{1}Listener", CommonData.ModManagerName, p_gmdGameModeInfo.ModeId); IMessager msgMessager = null; try { Trace.TraceInformation(String.Format("Getting listener on: {0}", strMessagerUri)); msgMessager = (IMessager)Activator.GetObject(typeof(IMessager), strMessagerUri); //Just because a messager has been returned, dosn't mean it exists. //All you've really done at this point is create an object wrapper of type "Messager" which has the same methods, properties etc... //You wont know if you've got a real object, until you invoke something, hence the post (Power on self test) method. msgMessager.Post(); } catch (RemotingException e) { Trace.TraceError("Could not get Messager: {0}", strMessagerUri); TraceUtil.TraceException(e); return(null); } return(new MessagerClient(msgMessager)); }
/// <summary> /// Register the ipc client proxy /// </summary> internal void RegisterProxy() { try { string uri = "ipc://NetOffice.SampleChannel/NetOffice.WebTranslationService.DataService"; //Create an IPC client channel. _channel = new IpcClientChannel(); //Register the channel with ChannelServices. ChannelServices.RegisterChannel(_channel, true); //Register the client type. WellKnownClientTypeEntry[] entries = RemotingConfiguration.GetRegisteredWellKnownClientTypes(); if (null == GetEntry(entries, uri)) { RemotingConfiguration.RegisterWellKnownClientType( typeof(WebTranslationService), uri); } DataService = new WebTranslationService(); // try to do some action to see the server is alive string[] dumy = DataService.AvailableTranslations; } catch (RemotingException exception) { // rethrow the exception with a friendly message throw new RemotingException("Unable to connect the local translation service.", exception); } catch (Exception) { throw; } }
public T GetServerObject <T>(string url, bool WriteLog = false) where T : MarshalByRefObject { string FullName = typeof(T).Name; string ClassName = FullName.Split('\'')[0]; T ret = default(T); try { //string ChannleName = string.Format("ipc://IPC_{0}/{1}", specName, ClassName); string ChannleName = url; ToLog("IPC客户端日志", "指定客户端通道URL", ChannleName); string cname = string.Format("{0}", ClassName); IpcClientChannel icc = null;// new IpcClientChannel(cname,null); //ChannelServices.RegisterChannel(icc, false); //if (ChannelServices.GetChannel(icc.ChannelName) == null) if (!iccs.ContainsKey(cname)) { icc = new IpcClientChannel(); ToLog("IPC客户端日志", "注册客户端通道", icc.ChannelName); ChannelServices.RegisterChannel(icc, false); ////WellKnownClientTypeEntry remotEntry = new WellKnownClientTypeEntry(typeof(T), ChannleName); RemotingConfiguration.RegisterWellKnownClientType(typeof(T), ChannleName); iccs.Add(cname, icc); } else { ToLog("IPC客户端日志", "存在客户端通道", cname); //iccs[cname]; icc = iccs[cname]; } //string[] allstr = ChannelServices.GetUrlsForObject(ret); //if (allstr != null) ToLog("IPC客户端日志", "所有可通道", getAllChannelsInfo()); object obj; //Log("IPC客户端日志", "检查是否管理员", IsRoot().ToString()); //Log("IPC客户端日志","访问通道", ChannleName); obj = Activator.GetObject(typeof(T), ChannleName); //obj = remotEntry; //ret = (T)obj;// (T)Convert.ChangeType(remotEntry, typeof(T)); ret = (T)obj; (ret as RemoteServerClass).Success = true; //if (WriteLog) // Log("IPC客户端日志", "访问通道成功", ChannleName); } catch (Exception e) { ToLog("IPC客户端日志", "访问通道失败", string.Format("{0}:{1}", e.Message, e.StackTrace)); if (ret is RemoteServerClass) { (ret as RemoteServerClass).Success = false; (ret as RemoteServerClass).Message = string.Format("{0}:{1}", e.Message, e.StackTrace); } return(ret); } return(ret); //返回一个空内容的壳,需要调用GetRemoteData实际调取数据 }
public VisualStudioInstance(Process process, DTE dte) { _hostProcess = process; _dte = dte; dte.ExecuteCommandAsync(VisualStudioCommandNames.VsStartServiceCommand).GetAwaiter().GetResult(); _integrationServiceChannel = new IpcClientChannel($"IPC channel client for {_hostProcess.Id}", sinkProvider: null); ChannelServices.RegisterChannel(_integrationServiceChannel, ensureSecurity: true); // Connect to a 'well defined, shouldn't conflict' IPC channel var serviceUri = string.Format($"ipc://{IntegrationService.PortNameFormatString}", _hostProcess.Id); _integrationService = (IntegrationService)(Activator.GetObject(typeof(IntegrationService), $"{serviceUri}/{typeof(IntegrationService).FullName}")); _integrationService.Uri = serviceUri; // There is a lot of VS initialization code that goes on, so we want to wait for that to 'settle' before // we start executing any actual code. _integrationService.Execute(typeof(RemotingHelper), nameof(RemotingHelper.WaitForSystemIdle)); _csharpInteractiveWindow = new Lazy <CSharpInteractiveWindow>(() => new CSharpInteractiveWindow(this)); _editorWindow = new Lazy <EditorWindow>(() => new EditorWindow(this)); _solutionExplorer = new Lazy <SolutionExplorer>(() => new SolutionExplorer(this)); _workspace = new Lazy <Workspace>(() => new Workspace(this)); // Ensure we are in a known 'good' state by cleaning up anything changed by the previous instance Cleanup(); }
private static void RunAsController(string[] arguments) { if (arguments == null || arguments.Length < 2) { Console.WriteLine("Invalid arguments!"); return; } var config = ConfigurationManager.GetSection("NRack") as IConfigSource; if (config == null) { Console.WriteLine("NRack configuration is required!"); return; } var clientChannel = new IpcClientChannel(); ChannelServices.RegisterChannel(clientChannel, false); IBootstrap bootstrap = null; try { var remoteBootstrapUri = string.Format("ipc://NRack.Bootstrap[{0}]/Bootstrap.rem", Math.Abs(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar).GetHashCode())); bootstrap = (IBootstrap)Activator.GetObject(typeof(IBootstrap), remoteBootstrapUri); } catch (RemotingException) { if (config.Isolation != IsolationMode.Process) { Console.WriteLine("Error: the NRack.Server has not been started!"); return; } } RegisterCommands(); var cmdName = arguments[1]; ControlCommand cmd; if (!m_CommandHandlers.TryGetValue(cmdName, out cmd)) { Console.WriteLine("Unknown command"); return; } try { if (cmd.Handler(bootstrap, arguments.Skip(1).ToArray())) { Console.WriteLine("Ok"); } } catch (Exception e) { Console.WriteLine("Failed. " + e.Message); } }
public LiaToolBox(String path) { try { clientChannel = new IpcClientChannel(); ChannelServices.RegisterChannel(clientChannel, false); RemotingConfiguration.RegisterWellKnownClientType(typeof(IPCRemoteObject), "ipc://LiaVM/lia"); obj = new IPCRemoteObject(); } catch (Exception e) { if (e != null) { MessageBox.Show("VM이 종료되어 있습니다."); Environment.Exit(2); } } String programWithExt = Path.GetFileName(path); if (Path.GetExtension(programWithExt) == "li") { MessageBox.Show("정상적인 파일이 아닙니다."); Environment.Exit(2); } this.programName = Path.GetFileNameWithoutExtension(programWithExt); setName(); readCode(path); LiaConsoleWriteLine("Applicatino is Launch"); }
void ConnectToFirstInstance() { RemotingChannel = new IpcClientChannel(); ChannelServices.RegisterChannel(RemotingChannel, false); try { f_FirstInstance = (T)Activator.GetObject(typeof(T), "ipc://" + Identifier + "/" + RemotingObjectName); // HACK: we have to make a method call so we actually can tell // if the connection works or not var isAlive = f_FirstInstance.IsAlive; } catch (RemotingException ex) { #if MONO_UNIX if (FirstInstanceFileInfo == null) { // no idea what happened throw; } else { throw new RemotingException( "Remoting communication error with existing " + "application instance. Stalled file lock? (" + FirstInstanceFileInfo.FullName + ")", ex ); } #endif } }
public VisualStudioInstance(Process hostProcess, DTE dte, Version version, ImmutableHashSet <string> supportedPackageIds, string installationPath) { HostProcess = hostProcess; Dte = dte; Version = version; SupportedPackageIds = supportedPackageIds; InstallationPath = installationPath; StartRemoteIntegrationService(dte); _integrationServiceChannel = new IpcClientChannel($"IPC channel client for {HostProcess.Id}", sinkProvider: null); ChannelServices.RegisterChannel(_integrationServiceChannel, ensureSecurity: true); // Connect to a 'well defined, shouldn't conflict' IPC channel _integrationService = IntegrationService.GetInstanceFromHostProcess(hostProcess); // Create marshal-by-ref object that runs in host-process. _inProc = ExecuteInHostProcess <VisualStudio_InProc>( type: typeof(VisualStudio_InProc), methodName: nameof(VisualStudio_InProc.Create)); // There is a lot of VS initialization code that goes on, so we want to wait for that to 'settle' before // we start executing any actual code. _inProc.WaitForSystemIdle(); SendKeys = new SendKeys(this); Editor = new Editor_OutOfProc(this); // Ensure we are in a known 'good' state by cleaning up anything changed by the previous instance CleanUp(); }
static void Main(string[] args) { try { System.Console.WriteLine("Configuring channel..."); IpcClientChannel clientChannel = new IpcClientChannel(); ChannelServices.RegisterChannel(clientChannel); System.Console.WriteLine("Configuring remote object..."); IRemotedType TheObject = (IRemotedType)Activator.GetObject( typeof(RemotedType.IRemotedType), "ipc://MyIpcChannel/MyObject.rem"); System.Console.WriteLine("Please enter data, 'exit' quits the program!"); string input = string.Empty; do { System.Console.Write(">> Enter text: "); input = System.Console.ReadLine(); if (string.Compare(input, "exit", true) != 0) { System.Console.Write(">> Enter number: "); int c = Int32.Parse(System.Console.ReadLine()); TheObject.DoCall(input, 2); } } while (string.Compare(input, "exit", true) != 0); } catch (Exception ex) { System.Console.WriteLine("Exception while processing contents: " + ex.Message); System.Console.ReadLine(); } }
public static int Main(string[] args) { // this entrypoint is only for use when inter-process remoting to get an elevated host. if (args.Length != 3 || !AdminPrivilege.IsElevated) { return(1); } var pms = new PackageManager().Instance; var rpc = args[0]; var provider = args[1]; var payload = args[2]; var clientChannel = new IpcClientChannel(); ChannelServices.RegisterChannel(clientChannel, true); var remoteRequest = (IHostApi)RemotingServices.Connect(typeof(IHostApi), rpc, null); var localRequest = new RemotableHostApi(remoteRequest); pms.Initialize(localRequest); var pro = pms.SelectProviders(provider, localRequest).FirstOrDefault(); pro.ExecuteElevatedAction(payload.FromBase64(), localRequest); return(0); }
/// <summary> /// Sends the stored command line arguments over to the first instance. /// </summary> /// <param name="uri">The name used to identify the application.</param> private static void UpdateRemoteObject(string uri) { Logger.LogDebug("Workbench", 2, "Sending our command line arguments to the first instance\n"); // Open an inter-process-communication channel to the target application. var clientChannel = new IpcClientChannel(); ChannelServices.RegisterChannel(clientChannel, true); // Get shared object from other process. var proxy = Activator.GetObject(typeof(InstanceProxy), String.Format("ipc://{0}.{1}.{2}/{2}", Environment.MachineName, Environment.UserName, uri)) as InstanceProxy; // If we got a proxy object then pass the current command line arguments on. if (proxy != null) { try { proxy.SetCommandLineArgs(InstanceProxy.IsFirstInstance, InstanceProxy.CommandLineArgs); } catch { Logger.LogError("Workbench", "Sending command line parameters to existing instance failed.\n"); MessageBox.Show("MySQL Workbench encountered a problem when trying to pass on command line parameters" + " to the already running Workbench instance. Maybe there's a hanging Workbench process that is" + " pretending to be the current instance.\n\nPlease kill the hanging process and try again.", "MySQL Workbench Execution Problem", MessageBoxButtons.OK, MessageBoxIcon.Error); } } // Finally clean up. We are done. ChannelServices.UnregisterChannel(clientChannel); }
/// <summary> /// Registeres client side Ipc channel and Device as remote type. /// </summary> public static void RegisterClient() { IpcClientChannel channel = new IpcClientChannel(); ChannelServices.RegisterChannel(channel, true); RemotingConfiguration.RegisterWellKnownClientType(typeof(HE853.Device), "ipc://" + ChannelName + "/" + InterfaceName); }
private static void RunAsController(string[] arguments) { if (arguments == null || arguments.Length < 2) { Console.WriteLine("无效的参数!"); return; } var config = ConfigurationManager.GetSection("superSocket") as IConfigurationSource; if (config == null) { Console.WriteLine("superSocket不存在于Section节点"); return; } var clientChannel = new IpcClientChannel(); ChannelServices.RegisterChannel(clientChannel, false); IBootstrap bootstrap = null; try { var remoteBootstrapUri = string.Format("ipc://SuperSocket.Bootstrap[{0}]/Bootstrap.rem", Math.Abs(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar).GetHashCode())); bootstrap = (IBootstrap)Activator.GetObject(typeof(IBootstrap), remoteBootstrapUri); } catch (RemotingException) { if (config.Isolation != IsolationMode.Process) { Console.WriteLine("错误:该SuperSocket引擎尚未启动!"); return; } } RegisterCommands(); var cmdName = arguments[1]; ControlCommand cmd; if (!m_CommandHandlers.TryGetValue(cmdName, out cmd)) { Console.WriteLine("未知命令"); return; } try { if (cmd.Handler(bootstrap, arguments.Skip(1).ToArray())) { Console.WriteLine("Ok"); } } catch (Exception e) { Console.WriteLine("错误. " + e.Message); } }
public void Bug81653() { IpcClientChannel c = new IpcClientChannel(); ChannelDataStore cd = new ChannelDataStore(new string[] { "foo" }); string objectUri; c.CreateMessageSink(null, cd, out objectUri); }
/// <summary> /// オブジェクト開放。(Dispose Finalizeパターン実装) /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { if (ClientChannel != null) { ChannelServices.UnregisterChannel(ClientChannel); ClientChannel = null; } }
public void UnregisterChannel() { if (this.clientChannel != null) { ChannelServices.UnregisterChannel(this.clientChannel); this.clientChannel = null; } }
public void Dispose() { if (null != _channel) { ChannelServices.UnregisterChannel(_channel); _channel = null; } }
static ServiceManager() { BinaryClientFormatterSinkProvider sbs = new BinaryClientFormatterSinkProvider(); IpcClientChannel client = new IpcClientChannel("IronScheme", sbs); ChannelServices.RegisterChannel(client, false); }
void EndChannel() { if (this.channel != null) { ChannelServices.UnregisterChannel(this.channel); this.channel = null; } }
public void Srv_CreateChannel() { // クライアントサイドのチャンネルを生成 IpcClientChannel channel = new IpcClientChannel(); // チャンネルを登録 ChannelServices.RegisterChannel(channel, true); }
/// <summary> /// オブジェクト開放。 /// </summary> public void Dispose() { if (ClientChannel != null) { ChannelServices.UnregisterChannel(ClientChannel); ClientChannel = null; } }
public void Dispose() { if (channel != null) { ChannelServices.UnregisterChannel(channel); channel = null; } }
static RemoteObject ConnectServer() { IpcClientChannel clientChannel = new IpcClientChannel(); ChannelServices.RegisterChannel(clientChannel, false); return((RemoteObject)Activator.GetObject(typeof(RemoteObject), "ipc://serverChannel/ipcTest")); }
public IpcClient() { // Create the channel. IpcClientChannel channel = new IpcClientChannel(); // Register the channel. ChannelServices.RegisterChannel(channel, true); // Get an instance of the remote object. RemoteObject = Activator.GetObject(typeof(IpcRemoteObject), "ipc://ipcSample/test") as IpcRemoteObject; Console.WriteLine(RemoteObject.URL); return; }
private static int Main(string[] args) { // Enabling Windows XP visual effects before any controls are created Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Sort out the command line arguments CommandLineArgs clargs = new CommandLineArgs(args); // see if we're already running bool createdNew = false; System.Threading.Mutex mutex = new System.Threading.Mutex(true, "TVRenameMutex", out createdNew); if (!createdNew) { // we're already running // tell the already running copy to come to the foreground IpcClientChannel clientChannel = new IpcClientChannel(); ChannelServices.RegisterChannel(clientChannel, true); RemotingConfiguration.RegisterWellKnownClientType(typeof (IPCMethods), "ipc://TVRenameChannel/IPCMethods"); IPCMethods ipc = new IPCMethods(); // if we were already running, and no command line arguments, then bring application to the foreground // and we're done. if (args.Length == 0) { ipc.BringToForeground(); return 0; } // Send command-line arguments to already running TVRename via IPC CommandLineArgs.MissingFolderBehaviour before = ipc.MissingBehaviour; bool renameBefore = ipc.RenameBehaviour; if (clargs.RenameCheck == false) { // Temporarily override behaviour for missing folders ipc.RenameBehaviour = false; } if (clargs.MissingFolder != CommandLineArgs.MissingFolderBehaviour.Ask) { // Temporarily override behaviour for missing folders ipc.MissingBehaviour = clargs.MissingFolder; } // TODO: Unify command line handling between here and in UI.cs (ProcessArgs). Just send in clargs via IPC? if (clargs.Scan || clargs.DoAll) // doall implies scan ipc.Scan(); if (clargs.DoAll) ipc.DoAll(); if (clargs.Quit) { ipc.Quit(); return 0; } ipc.RenameBehaviour = renameBefore; ipc.MissingBehaviour = before; return 0; } #if !DEBUG try { #endif // Starting TVRename... // Check arguments for forced recover bool ok = true; string recoverText = ""; if (clargs.ForceRecover) { ok = false; // force recover dialog recoverText = "Recover manually requested."; } // Load settings files TVDoc doc = null; try { if (!string.IsNullOrEmpty(clargs.UserFilePath)) PathManager.SetUserDefinedBasePath(clargs.UserFilePath); } catch (System.Exception ex) { MessageBox.Show("Error while setting the User-Defined File Path:" + Environment.NewLine + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } FileInfo tvdbFile = PathManager.TVDBFile; FileInfo settingsFile = PathManager.TVDocSettingsFile; do // loop until no problems loading settings & tvdb cache files { if (!ok) // something went wrong last time around, ask the user what to do { RecoverXML rec = new RecoverXML(recoverText); if (rec.ShowDialog() == DialogResult.OK) { tvdbFile = rec.DBFile; settingsFile = rec.SettingsFile; } else return 1; } // try loading using current settings files, and set up the main // classes TheTVDB.Instance.setup(tvdbFile, PathManager.TVDBFile, clargs); doc = new TVDoc(settingsFile, clargs); if (!ok) doc.SetDirty(); ok = doc.LoadOK; if (!ok) { recoverText = ""; if (!doc.LoadOK && !String.IsNullOrEmpty(doc.LoadErr)) recoverText += doc.LoadErr; if (!TheTVDB.Instance.LoadOK && !String.IsNullOrEmpty(TheTVDB.Instance.LoadErr)) recoverText += "\r\n" + TheTVDB.Instance.LoadErr; } } while (!ok); // Show user interface UI theUI = new UI(doc); Application.Run(theUI); GC.KeepAlive(mutex); #if !DEBUG } catch (Exception e) { ShowException se = new ShowException(e); se.ShowDialog(); } #endif return 0; }