/// <summary> /// Выполняет подключение к текущему серверу /// </summary> /// <param name="host">Хост для подключения</param> /// <param name="port"></param> public void Connect(string host, int port) { try { if (Service == null) { Service = new NetScheduler(); } Service.Connect(host, port); Service.OnConnect += Service_OnConnect; Service.OnDataReceived += Service_OnDataReceived; Service.OnDisconnect += Service_OnDisconnect; OnConnected?.Invoke(); } catch (SocketException) { OnDisconnected?.Invoke(DisconnectedReasons.TimeOut); } catch (Exception ex) { Components.Logger.Instance.WriteLine(ex.ToString(), Components.LogLevel.Error); OnDisconnected?.Invoke(DisconnectedReasons.Unnamed); } }
public static void Initialize() { // Initialize logs instance GCLatencyMode oldMode = GCSettings.LatencyMode; RuntimeHelpers.PrepareConstrainedRegions(); GCSettings.LatencyMode = GCLatencyMode.Batch; ServicePointManager.DefaultConnectionLimit = int.MaxValue; Scheduler = new NetScheduler(Settings.Instance.Model.ThreadCount); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); }
public static bool Initialize() { if (Initialized) { Logs.Instance.Push("App provider already initialized!"); return(true); } // Initialize logs instance Logs.Instance.Push("App provider initializing..."); // Check program crashed. if (ProgramLock.ProgramCrashed) { Logs.Instance.Push("Program is terminated abnormally."); } #if DEBUG // Check exists instances. if (Instance.Count > 1) { throw new Exception("You must wait for app-provider initialization procedure before using instance-lazy!\n" + "For more informations, see the development documents."); } #endif // GC Setting GCLatencyMode oldMode = GCSettings.LatencyMode; RuntimeHelpers.PrepareConstrainedRegions(); GCSettings.LatencyMode = GCLatencyMode.Batch; // Extends Connteion Limit ServicePointManager.DefaultConnectionLimit = int.MaxValue; // Initialize Scheduler Scheduler = new NetScheduler(Settings.Instance.Model.ThreadCount); // Initialize Postprocessor Scheduler PPScheduler = new PostprocessorScheduler(Settings.Instance.Model.PostprocessorThreadCount); Logs.Instance.Push("App provider starts."); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); Initialized = true; return(true); }
static void Main(string[] args) { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); GCLatencyMode oldMode = GCSettings.LatencyMode; RuntimeHelpers.PrepareConstrainedRegions(); GCSettings.LatencyMode = GCLatencyMode.Batch; ServicePointManager.DefaultConnectionLimit = int.MaxValue; Scheduler = new NetScheduler(Settings.Instance.Model.ThreadCount); PPScheduler = new PostprocessorScheduler(Settings.Instance.Model.PostprocessorThreadCount); GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced); #if DEBUG ChatBot.BotManager.Instance.StartBots(); while (true) { System.Threading.Tasks.Task.Run(async() => await Loop.LoopInternal()); Thread.Sleep(1000 * 60 * 10); } #endif try { Command.Start(args); } catch (Exception e) { Console.WriteLine("An error occured! " + e.Message); Console.WriteLine(e.StackTrace); Console.WriteLine("Please, check log.txt file."); } Environment.Exit(0); }
private void Service_OnConnect(object sender, NetScheduler connection) { throw new NotImplementedException(); }
private void Service_OnDataReceived(object sender, NetScheduler connection, SpiderNetwork e, string key) { throw new NotImplementedException(); }