本文整理汇总了C#中ICore.Start方法的典型用法代码示例。如果您正苦于以下问题:C# ICore.Start方法的具体用法?C# ICore.Start怎么用?C# ICore.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICore
的用法示例。
在下文中一共展示了ICore.Start方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static int Main(string[] args)
{
if (_pipeProxy != null)
{
Log.WriteSystemEventLog("MCEBuddy engine app already running, cannot start another instance.", EventLogEntryType.Error);
return -1; // We can't start engine's
}
if (!AppProcess.HaveAdministrativeRights())
{
Log.WriteSystemEventLog("Start MCEBuddy engine app with Administrative rights.", EventLogEntryType.Information);
AppProcess.StartAppWithAdministrativeRights(Application.ExecutablePath); // Engine needs Admin rights for firewall and binding
return -2; // Exit, the process will restart with admin rights
}
// Capture the Window close event if the user manually closes it
_controlHandler = new HandlerRoutine(ConsoleCloseCheck); // Setup a static object otherwise on some systems it crashes with null pointer exception due to garbage collection
SetConsoleCtrlHandler(_controlHandler, true);
// Now that we are running, first Stop the the Windows Service otherwise we don't be able to start (stop before starting the GUI to prevent closure)
Log.WriteSystemEventLog("Trying to stop MCEBuddy engine service.", EventLogEntryType.Information);
WindowsService.StopService(GlobalDefs.MCEBUDDY_SERVICE_NAME, 10000);
//Start MCEBuddy GUI with Normal user rights (just incase this is running admin rights
try
{
if (AppProcess.HaveAdministrativeRights())
{
AppProcess.StartAppWithMediumPrivilegeFromUISession(Path.Combine(GlobalDefs.AppPath, "MCEBuddy.GUI.exe"), "", false);
}
else // Normal user
{
Process Proc = new Process();
Proc.StartInfo.FileName = Path.Combine(GlobalDefs.AppPath, "MCEBuddy.GUI.exe");
Proc.StartInfo.CreateNoWindow = false;
Proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
Proc.Start();
}
}
catch (Exception e)
{
// Sometimes the DLL does not work or is missing or running on wrong windows version, catch it and log it
Log.WriteSystemEventLog("MCEBuddy engine app: Unable to start MCEBuddy GUI. Error ->\r\n" + e.ToString(), EventLogEntryType.Warning);
}
Log.WriteSystemEventLog("Starting MCEBuddy engine app.", EventLogEntryType.Information);
MCEBuddyConf.GlobalMCEConfig = new MCEBuddyConf(GlobalDefs.ConfigFile); // Read the settings for global objects
MCEBuddyConf.CheckDefaultJobPaths(); // Update paths before we start the engine to it is read
_host = new ServiceHost(typeof(Core));
TimeSpan timeoutPeriod = GlobalDefs.PIPE_TIMEOUT;
// Create a binding for network SOAP WEB SERVICES
string serverString = GlobalDefs.MCEBUDDY_WEB_SOAP_PIPE;
serverString = serverString.Replace(GlobalDefs.MCEBUDDY_SERVER_PORT, MCEBuddyConf.GlobalMCEConfig.GeneralOptions.localServerPort.ToString(System.Globalization.CultureInfo.InvariantCulture)); // Update the Server Port with that from the config file
BasicHttpBinding ntb = new BasicHttpBinding(GlobalDefs.MCEBUDDY_PIPE_SECURITY);
ntb.OpenTimeout = ntb.CloseTimeout = ntb.SendTimeout = ntb.ReceiveTimeout = timeoutPeriod;
ntb.TransferMode = TransferMode.Buffered;
ntb.MaxReceivedMessageSize = ntb.MaxBufferPoolSize = ntb.MaxBufferSize = Int32.MaxValue;
ntb.ReaderQuotas = XmlDictionaryReaderQuotas.Max;
ServiceEndpoint soapEndpoint = _host.AddServiceEndpoint(typeof(ICore), ntb, serverString);
// Increase the max objects allowed in serialization channel otherwise we lose the connection when there more than 5K objects in the queue
foreach (OperationDescription operation in soapEndpoint.Contract.Operations)
{
DataContractSerializerOperationBehavior dataContractBehavior = operation.Behaviors[typeof(DataContractSerializerOperationBehavior)] as DataContractSerializerOperationBehavior;
if (dataContractBehavior != null)
dataContractBehavior.MaxItemsInObjectGraph = Int32.MaxValue;
}
// Create a binding for local NAMED PIPES
NetNamedPipeBinding npb = new NetNamedPipeBinding();
npb.OpenTimeout = npb.CloseTimeout = npb.SendTimeout = npb.ReceiveTimeout = timeoutPeriod;
npb.TransferMode = TransferMode.Buffered;
npb.MaxReceivedMessageSize = npb.MaxBufferPoolSize = npb.MaxBufferSize = Int32.MaxValue;
npb.ReaderQuotas = XmlDictionaryReaderQuotas.Max;
ServiceEndpoint namedPipeEndpoint = _host.AddServiceEndpoint(typeof(ICore), npb, GlobalDefs.MCEBUDDY_LOCAL_NAMED_PIPE);
// Increase the max objects allowed in serialization channel otherwise we lose the connection when there more than 5K objects in the queue
foreach (OperationDescription operation in namedPipeEndpoint.Contract.Operations)
{
DataContractSerializerOperationBehavior dataContractBehavior = operation.Behaviors[typeof(DataContractSerializerOperationBehavior)] as DataContractSerializerOperationBehavior;
if (dataContractBehavior != null)
dataContractBehavior.MaxItemsInObjectGraph = Int32.MaxValue;
}
_host.CloseTimeout = GlobalDefs.PIPE_TIMEOUT;
_host.Open();
_pipeFactory = new ChannelFactory<ICore>(npb, new EndpointAddress(GlobalDefs.MCEBUDDY_LOCAL_NAMED_PIPE));
_pipeProxy = _pipeFactory.CreateChannel();
if (MCEBuddyConf.GlobalMCEConfig.GeneralOptions.engineRunning)
_pipeProxy.Start();
// Now that we are up and running
SystemEvents.PowerModeChanged += OnPowerChange; // Register for power event changes
ConsoleKeyInfo cki;
Console.Title = "MCEBuddy 2.x Service Started, Press ESC to stop";
//.........这里部分代码省略.........
示例2: OnStart
protected override void OnStart(string[] args)
{
Log.WriteSystemEventLog("MCEBuddy service OnStart called", EventLogEntryType.Information);
try
{
RequestAdditionalTime(10000); // Ask for 10 second to complete initial operations and not mark service as unresponsive
MCEBuddyConf.GlobalMCEConfig = new MCEBuddyConf(GlobalDefs.ConfigFile); // Read the settings for global objects
MCEBuddyConf.CheckDefaultJobPaths(); // Update paths before we start the engine to it is read
_host = new ServiceHost(typeof(Core));
TimeSpan timeoutPeriod = GlobalDefs.PIPE_TIMEOUT;
// Create a binding for network SOAP WEB SERVICES
string serverString = GlobalDefs.MCEBUDDY_WEB_SOAP_PIPE;
serverString = serverString.Replace(GlobalDefs.MCEBUDDY_SERVER_PORT, MCEBuddyConf.GlobalMCEConfig.GeneralOptions.localServerPort.ToString(System.Globalization.CultureInfo.InvariantCulture)); // Update the Server Port with that from the config file
BasicHttpBinding ntb = new BasicHttpBinding(GlobalDefs.MCEBUDDY_PIPE_SECURITY);
ntb.OpenTimeout = ntb.CloseTimeout = ntb.SendTimeout = ntb.ReceiveTimeout = timeoutPeriod;
ntb.TransferMode = TransferMode.Buffered;
ntb.MaxReceivedMessageSize = ntb.MaxBufferPoolSize = ntb.MaxBufferSize = Int32.MaxValue;
ntb.ReaderQuotas = XmlDictionaryReaderQuotas.Max;
ServiceEndpoint soapEndpoint = _host.AddServiceEndpoint(typeof(ICore), ntb, serverString);
// Increase the max objects allowed in serialization channel otherwise we lose the connection when there more than 5K objects in the queue
foreach (OperationDescription operation in soapEndpoint.Contract.Operations)
{
DataContractSerializerOperationBehavior dataContractBehavior = operation.Behaviors[typeof(DataContractSerializerOperationBehavior)] as DataContractSerializerOperationBehavior;
if (dataContractBehavior != null)
dataContractBehavior.MaxItemsInObjectGraph = Int32.MaxValue;
}
// Create a binding for local NAMED PIPES
NetNamedPipeBinding npb = new NetNamedPipeBinding();
npb.OpenTimeout = npb.CloseTimeout = npb.SendTimeout = npb.ReceiveTimeout = timeoutPeriod;
npb.TransferMode = TransferMode.Buffered;
npb.MaxReceivedMessageSize = npb.MaxBufferPoolSize = npb.MaxBufferSize = Int32.MaxValue;
npb.ReaderQuotas = XmlDictionaryReaderQuotas.Max;
ServiceEndpoint namedPipeEndpoint = _host.AddServiceEndpoint(typeof(ICore), npb, GlobalDefs.MCEBUDDY_LOCAL_NAMED_PIPE);
// Increase the max objects allowed in serialization channel otherwise we lose the connection when there more than 5K objects in the queue
foreach (OperationDescription operation in namedPipeEndpoint.Contract.Operations)
{
DataContractSerializerOperationBehavior dataContractBehavior = operation.Behaviors[typeof(DataContractSerializerOperationBehavior)] as DataContractSerializerOperationBehavior;
if (dataContractBehavior != null)
dataContractBehavior.MaxItemsInObjectGraph = Int32.MaxValue;
}
_host.CloseTimeout = GlobalDefs.PIPE_TIMEOUT;
_host.Open();
Log.WriteSystemEventLog("MCEBuddy service started on port " + MCEBuddyConf.GlobalMCEConfig.GeneralOptions.localServerPort.ToString(System.Globalization.CultureInfo.InvariantCulture), EventLogEntryType.Information);
_pipeFactory = new ChannelFactory<ICore>(npb, new EndpointAddress(GlobalDefs.MCEBUDDY_LOCAL_NAMED_PIPE));
_pipeProxy = _pipeFactory.CreateChannel();
if (MCEBuddyConf.GlobalMCEConfig.GeneralOptions.engineRunning) // Check for last saved state by user
{
_pipeProxy.Start();
Log.WriteSystemEventLog(Localise.GetPhrase("Last user saved state: MCEBuddy engine started"), EventLogEntryType.Information);
}
else
Log.WriteSystemEventLog(Localise.GetPhrase("Last user saved state: MCEBuddy engine NOT started"), EventLogEntryType.Information);
}
catch (Exception e)
{
Log.WriteSystemEventLog(Localise.GetPhrase("MCEBuddy service failed to start. Error:") + e.ToString(), EventLogEntryType.Error);
}
}