private void treePermissions_MouseDown(object sender, MouseEventArgs e) { TreeNode clickedPermNode = treePermissions.GetNodeAt(e.X, e.Y); if (clickedPermNode == null) { return; } if (gridMain.SelectedIndices.Length < 1) { return; } APIKey apiKey = (APIKey)gridMain.Rows[gridMain.SelectedIndices[0]].Tag; if (clickedPermNode.ImageIndex == 1) //unchecked, so need to add a permission { _listApiKeysLocal[gridMain.SelectedIndices[0]].ListPermissions.Add((APIPermission)clickedPermNode.Tag); clickedPermNode.ImageIndex = 2; } else if (clickedPermNode.ImageIndex == 2) //checked, so need to delete the perm { _listApiKeysLocal[gridMain.SelectedIndices[0]].ListPermissions.Remove((APIPermission)clickedPermNode.Tag); clickedPermNode.ImageIndex = 1; } }
public APIKey Copy() { APIKey apiKey = (APIKey)MemberwiseClone(); apiKey.ListPermissions = ListPermissions.ToList(); return(apiKey); }
private APIKey GenerateNewKey() { APIKey apiKey = new APIKey(); //prepare the xml document to send-------------------------------------------------------------------------------------- XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = (" "); StringBuilder strbuild = new StringBuilder(); //Send the message and get the result------------------------------------------------------------------------------------- string result = ""; try { string officeData = WebServiceMainHQProxy.CreateWebServiceHQPayload(strbuild.ToString(), eServiceCode.FHIR); result = WebServiceMainHQProxy.GetWebServiceMainHQInstance().GenerateFHIRAPIKey(officeData); } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } XmlDocument doc = new XmlDocument(); doc.LoadXml(result); //Process errors------------------------------------------------------------------------------------------------------------ XmlNode node = doc.SelectSingleNode("//Error"); if (node != null) { MessageBox.Show(node.InnerText); return(null); } //Process a valid return value------------------------------------------------------------------------------------------------ node = doc.SelectSingleNode("//APIKey"); if (node != null) { apiKey.Key = node.InnerText; } node = doc.SelectSingleNode("//FHIRAPIKeyNum"); if (node != null) { apiKey.FHIRAPIKeyNum = PIn.Long(node.InnerText); } node = doc.SelectSingleNode("//KeyStatus"); if (node != null) { APIKeyStatus status; if (Enum.TryParse(node.InnerText, out status)) { apiKey.KeyStatus = status; } else { apiKey.KeyStatus = APIKeyStatus.ReadEnabled; } } return(apiKey); }
///<summary>Displays the permissions that are assigned for the selected API key.</summary> private void SetPermissions() { if (gridMain.SelectedIndices.Length < 1) { return; } APIKey apiKey = (APIKey)gridMain.ListGridRows[gridMain.SelectedIndices[0]].Tag; listPermissions.SetItems(apiKey.ListPermissions); }
private void butSetAll_Click(object sender, EventArgs e) { if (gridMain.SelectedIndices.Length < 1) { return; } APIKey apiKey = (APIKey)gridMain.Rows[gridMain.SelectedIndices[0]].Tag; foreach (TreeNode node in treePermissions.Nodes) { node.ImageIndex = 2; if (!apiKey.ListPermissions.Contains((APIPermission)node.Tag)) //The selected key does have the permission for this node. { _listApiKeysLocal[gridMain.SelectedIndices[0]].ListPermissions.Add((APIPermission)node.Tag); } } }
///<summary>Displays the permissions that are assigned for the selected API key.</summary> private void SetPermissions() { if (gridMain.SelectedIndices.Length < 1) { return; } treePermissions.Enabled = true; APIKey apiKey = (APIKey)gridMain.Rows[gridMain.SelectedIndices[0]].Tag; foreach (TreeNode node in treePermissions.Nodes) { node.ImageIndex = 1; if (apiKey.ListPermissions.Contains((APIPermission)node.Tag)) //The selected key does have the permission for this node. { node.ImageIndex = 2; } } }
private void butGenerateKey_Click(object sender, EventArgs e) { APIKey apiKey = GenerateNewKey(); if (apiKey == null) { return; //We already showed them an error message. } _listApiKeysHQ.Add(apiKey); //Since this came from HQ, we want it in that list. FormFHIRAPIKeyEdit FormFAKE = new FormFHIRAPIKeyEdit(); FormFAKE.APIKeyCur = apiKey.Copy(); DialogResult res = FormFAKE.ShowDialog(); if (res == DialogResult.OK) { _listApiKeysLocal.Add(FormFAKE.APIKeyCur); FillGrid(); } }
///<summary>Makes web call to WebServicesMainHQ with the update list of API keys. Returns true if the update was successful.</summary> private bool UpdateKeysForOffice(List <APIKey> _listApiKeysLocal) { APIKey apiKey = new APIKey(); //prepare the xml document to send-------------------------------------------------------------------------------------- XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = (" "); StringBuilder strbuild = new StringBuilder(); using (XmlWriter writer = XmlWriter.Create(strbuild, WebServiceMainHQProxy.CreateXmlWriterSettings(true))) { writer.WriteStartElement("Payload"); writer.WriteStartElement("ListAPIKeysUpdated"); WriteListAPIKeys(writer, _listApiKeysLocal); writer.WriteEndElement(); writer.WriteEndElement(); //Payload } //Send the message and get the result------------------------------------------------------------------------------------- string result = ""; try { string officeData = WebServiceMainHQProxy.CreateWebServiceHQPayload(strbuild.ToString(), eServiceCode.FHIR); result = WebServiceMainHQProxy.GetWebServiceMainHQInstance().UpdateFHIRAPIKeys(officeData); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } XmlDocument doc = new XmlDocument(); doc.LoadXml(result); //Process errors------------------------------------------------------------------------------------------------------------ XmlNode node = doc.SelectSingleNode("//Error"); if (node != null) { MessageBox.Show(node.InnerText); return(false); } return(true); }
private void butClose_Click(object sender, EventArgs e) { if (textSubInterval.errorProvider1.GetError(textSubInterval) != "") { MsgBox.Show(this, "Please fix data entry errors first."); return; } bool changed = false; foreach (APIKey apiKeyHQ in _listApiKeysHQ) { APIKey apiKeyLocal = _listApiKeysLocal.FirstOrDefault(x => x.Key == apiKeyHQ.Key); if (apiKeyLocal == null || //A new key was generated but then Cancel was clicked on FormFHIRAPIKeyEdit. apiKeyLocal.DeveloperName != apiKeyHQ.DeveloperName || apiKeyLocal.DeveloperEmail != apiKeyHQ.DeveloperEmail || apiKeyLocal.DeveloperPhone != apiKeyHQ.DeveloperPhone || apiKeyLocal.ListPermissions.Any(x => !apiKeyHQ.ListPermissions.Contains(x)) || apiKeyHQ.ListPermissions.Any(x => !apiKeyLocal.ListPermissions.Contains(x))) { changed = true; break; } } if (changed && !UpdateKeysForOffice(_listApiKeysLocal)) { return; } Program prog = Programs.GetCur(ProgramName.FHIR); prog.Enabled = checkEnabled.Checked; Programs.Update(prog); ProgramProperty progProp = ProgramProperties.GetPropByDesc("SubscriptionProcessingFrequency", ProgramProperties.GetForProgram(prog.ProgramNum)); ProgramProperties.UpdateProgramPropertyWithValue(progProp, textSubInterval.Text); DataValid.SetInvalid(InvalidType.Programs); Close(); }
private List <APIKey> GetApiKeys() { List <APIKey> listApiKeys = new List <APIKey>(); //prepare the xml document to send-------------------------------------------------------------------------------------- XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = (" "); StringBuilder strbuild = new StringBuilder(); //Send the message and get the result------------------------------------------------------------------------------------- string result = ""; try { string officeData = WebServiceMainHQProxy.CreateWebServiceHQPayload(strbuild.ToString(), eServiceCode.FHIR); result = WebServiceMainHQProxy.GetWebServiceMainHQInstance().GetFHIRAPIKeysForOffice(officeData); } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } XmlDocument doc = new XmlDocument(); doc.LoadXml(result); XPathNavigator nav = doc.CreateNavigator(); //Process errors------------------------------------------------------------------------------------------------------------ XPathNavigator node = nav.SelectSingleNode("//Error"); if (node != null) { MessageBox.Show(node.Value); return(null); } //Process a valid return value------------------------------------------------------------------------------------------------{ node = nav.SelectSingleNode("//ListAPIKeys"); if (node != null && node.MoveToFirstChild()) { do { APIKey apiKey = new APIKey(); apiKey.Key = node.SelectSingleNode("APIKeyValue").Value; apiKey.FHIRAPIKeyNum = PIn.Long(node.SelectSingleNode("FHIRAPIKeyNum").Value); apiKey.DateDisabled = DateTime.Parse(node.SelectSingleNode("DateDisabled").Value); APIKeyStatus status; if (Enum.TryParse(node.SelectSingleNode("KeyStatus").Value, out status)) { apiKey.KeyStatus = status; } else { apiKey.KeyStatus = APIKeyStatus.ReadEnabled; } apiKey.DeveloperName = node.SelectSingleNode("DeveloperName").Value; apiKey.DeveloperEmail = node.SelectSingleNode("DeveloperEmail").Value; apiKey.DeveloperPhone = node.SelectSingleNode("DeveloperPhone").Value; apiKey.FHIRDeveloperNum = PIn.Long(node.SelectSingleNode("FHIRDeveloperNum").Value); XPathNavigator nodePerms = node.SelectSingleNode("ListAPIPermissions"); if (nodePerms != null && nodePerms.MoveToFirstChild()) { do { APIPermission perm; if (Enum.TryParse(nodePerms.Value, out perm)) { apiKey.ListPermissions.Add(perm); } } while(nodePerms.MoveToNext()); } listApiKeys.Add(apiKey); } while(node.MoveToNext()); } return(listApiKeys); }
public FormFHIRAPIKeyEdit(APIKey apiKey) { InitializeComponent(); Lan.F(this); _apiKeyCur = apiKey; }