private void Init() { var userName = Env.GetComputerName(); var password = Env.GetComputerName(); var identity = _db.GetItem <Identity>(Store.IdentityKey); var job = _db.GetItem <Job>(Store.JobKey); if (identity.Uuid == null) { Console.WriteLine("Registering for new identity"); identity = _api.Register(userName, password); _db.ReplaceItem(Store.IdentityKey, identity); job = UpdateCurrentJob(identity); } else { Console.WriteLine("App is logging in"); identity = _api.GetIdentity(userName, password); _db.ReplaceItem(Store.IdentityKey, identity); job = UpdateCurrentJob(identity); } _socket = MacMonWebSocket.InitSocket(identity.Jwt, _url); InitSocketMonitor(_socket); _channel = _socket.MakeChannel($"MACHINE:{identity.Uuid}"); JoinChannel(_channel, identity); Commands.Executor.Init(_channel).Start(); _jobExecutor = Executor.Init(_channel, _db); _jobExecutor.Start(job); }
public void Start() { Console.WriteLine("app started"); Identity machineIdentity = _db.GetItem <Identity>(Store.IdentityKey); Job currentJob = _db.GetItem <Job>(Store.JobKey); Console.WriteLine("app started -> Identity {0}", machineIdentity.Uuid == null); Console.WriteLine("app started -> Current Job {0}", currentJob == null); Profile profile = _db.GetItem <Profile>(Store.ProfileKey); if (machineIdentity.Uuid == null) { Console.WriteLine("Registering for new identity"); // Machine needs to register for a new IDENTITY machineIdentity = _api.Register(profile.Name, profile.Password); _db.ReplaceItem(Store.IdentityKey, machineIdentity); // Now we need ask for JOB to perform currentJob = UpdateCurrentJob(machineIdentity); } else { Console.WriteLine("App is logging in"); machineIdentity = _api.GetIdentity(profile.Name, profile.Password); _db.ReplaceItem(Store.IdentityKey, machineIdentity); currentJob = UpdateCurrentJob(machineIdentity); } _socket = MacMonWebSocket.InitSocket(machineIdentity.Jwt); InitSocketMonitor(_socket); _channel = _socket.MakeChannel($"MACHINE:{machineIdentity.Uuid}"); var channelParam = new Dictionary <string, object> { { "token", machineIdentity.Jwt.Token } }; InitChannelMonitor(_channel); _channel.Join(channelParam) .Receive(Reply.Status.Ok, r => Console.WriteLine("Joined channel successfully -> {0}", r)) .Receive(Reply.Status.Error, r => Console.WriteLine("Joined channel failed -> {0}", r)); Commands.Executor.Init(_channel, profile).Start(); Jobs.Executor.Init(_channel, _db, machineIdentity).Start(currentJob); }