private void btnRegister_Click(object sender, EventArgs e) { // this should take the token ID, friendly name, and the current username (with domain) and send it to the service int res = ServiceCommunication.SendNetworkMessage(ref client, JsonConvert.SerializeObject(new NetworkMessage(MessageType.RegisterToken) { Token = txtToken.Text, TokenFriendlyName = txtFriendlyName.Text, Username = ClientCommon.GetCurrentUsername() })); if (res > 0) { this.Close(); // we might have registered a token now? } }
private void LoadConfig() { startAgain: ServiceCommunication.SendNetworkMessage(ref client, JsonConvert.SerializeObject(new NetworkMessage(MessageType.GetState) { Username = ClientCommon.GetCurrentUsername() })); var task = Task <string> .Factory.StartNew(() => { return(ServiceCommunication.ReadNetworkMessage(ref client)); }); if (task.Result == "") { if (MessageBox.Show("Unable to connect to service. Please make sure its running", "NFC Ring Service Registration App", MessageBoxButtons.RetryCancel) == DialogResult.Cancel) { Application.Exit(); } // RETRY ISNT GOING TO DO ANYTHING YET goto startAgain; } else { tvwConfig.Nodes.Clear(); uss = JsonConvert.DeserializeObject <UserServerState>(task.Result); TreeNode user = tvwConfig.Nodes.Add(uss.UserConfiguration.Username); TreeNode tokens = user.Nodes.Add("Tokens"); if (uss.UserConfiguration.Tokens != null) { foreach (KeyValuePair <string, string> tok in uss.UserConfiguration.Tokens) { TreeNode tokenNode = tokens.Nodes.Add(tok.Value + " - " + tok.Key); tokenNode.Tag = "Token"; } } TreeNode plugins = user.Nodes.Add("Plugins"); if (uss.Plugins != null) { foreach (PluginInfo p in uss.Plugins) { TreeNode aPlugin = plugins.Nodes.Add(p.Name); aPlugin.Tag = "Plugin"; } } TreeNode events = user.Nodes.Add("Events"); if (uss.UserConfiguration.Events != null) { foreach (Event ev in uss.UserConfiguration.Events) { TreeNode eventNode = events.Nodes.Add(ev.PluginName + " - " + ev.Token); eventNode.Tag = "Event"; foreach (KeyValuePair <string, object> param in ev.Parameters) { if (param.Value != null) { TreeNode e = eventNode.Nodes.Add(param.Key + " = " + param.Value.ToString()); //e.Tag = "Event"; } } } } if ((uss.UserConfiguration.Tokens != null && uss.UserConfiguration.Tokens.Count > 0) && (uss.Plugins != null && uss.Plugins.Count > 0)) { btnAddEvent.Enabled = true; } tvwConfig.ExpandAll(); } }