/// <summary> /// The main method of the program. /// </summary> private static void Main() { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; StorageNodeSettings settings; if (File.Exists("config.xml")) { settings = new StorageNodeSettings(File.ReadAllText("config.xml")); } else { Logger.Log("\"config.xml\" not found, creating with the defaults.", LogLevel.Warning); settings = new StorageNodeSettings(); File.WriteAllText("config.xml", settings.ToString()); } Logger.Init(string.Empty, "Storage", settings.LogLevel, true); _node = new StorageNode(settings); _node.Run(); Logger.Shutdown(); }
/// <summary> /// Connects to the specified controller. /// </summary> /// <param name="def">The controller to connect to.</param> /// <returns>True if the connection failed or return a JoinSuccess, false if it returned a JoinFailure.</returns> private bool ConnectToController(NodeDefinition def) { Message message = new Message(def, new JoinAttempt(NodeType.Storage, _settings.NodeName, _settings.Port, _settings.ToString()), true) { SendWithoutConfirmation = true }; SendMessage(message); message.BlockUntilDone(); if (message.Success) { if (message.Response.Data is JoinFailure) { Logger.Log("Failed to join controllers: " + ((JoinFailure)message.Response.Data).Reason, LogLevel.Error); AfterStop(); _database.Shutdown(); return(false); } // success JoinSuccess successData = (JoinSuccess)message.Response.Data; Connections[def].ConnectionEstablished(def, NodeType.Controller); if (successData.Data["PrimaryController"].ValueAsBoolean) { Logger.Log("Setting the primary controller to " + message.Address.ConnectionName, LogLevel.Info); Primary = message.Address; } _database.SetMaxChunkItemCount(successData.Data["MaxChunkItemCount"].ValueAsInteger); SendMessage(new Message(message.Response, new Acknowledgement(), false)); } return(true); }