/// <summary> /// Removes a manage URLs. /// </summary> /// <param name="type">The manage type.</param> /// <param name="url">The service url to remove.</param> /// <param name="context">The communication data.</param> /// <returns>True if the url have been removed; else false.</returns> public static bool RemoveManageURL(string type, string url, Nequeo.Xml.Authorisation.Communication.Data.context context) { // Validate. if (String.IsNullOrEmpty(type)) { throw new ArgumentNullException("type"); } if (String.IsNullOrEmpty(url)) { throw new ArgumentNullException("url"); } try { // Find all manage with service name and application name. Communication.Data.contextManage manage = null; try { // Get all urls of the type. manage = context.manageURLs.First(u => u.type.ToLower() == type.ToLower()); } catch { } // If manage exists. if (manage != null) { // Find the index of the manage to remove. manage.url = manage.url.Remove(u => u.service.ToLower().Equals(url.ToLower())); // Save the new data. SaveCommunicationDataAsync(context); return(true); } else { return(false); } } catch (Exception) { throw; } }
/// <summary> /// Get the host manage URLs for a type. /// </summary> /// <param name="type">The host type.</param> /// <param name="context">The communication data.</param> /// <returns>The manage URLs; else null.</returns> /// <exception cref="System.Exception"></exception> /// <exception cref="System.ArgumentNullException"></exception> public static string[] GetManageURLs(string type, Nequeo.Xml.Authorisation.Communication.Data.context context) { // Validate. if (String.IsNullOrEmpty(type)) { throw new ArgumentNullException("type"); } try { // Find all host unique identifier. Communication.Data.contextManage manage = null; List <string> urls = new List <string>(); try { // Get all urls of the type. manage = context.manageURLs.First(u => u.type.ToLower() == type.ToLower()); } catch { } // If host exists. if (manage != null) { // For each host add the url. foreach (Communication.Data.contextManageUrl item in manage.url) { urls.Add(item.service); } // Return the manage URLs request for the unique identifier. return(urls.Count > 0 ? urls.ToArray() : null); } else { return(null); } } catch (Exception) { throw; } }
/// <summary> /// Adds new manage URLs. /// </summary> /// <param name="type">The manage type.</param> /// <param name="urls">The list of service urls.</param> /// <param name="context">The communication data.</param> /// <returns>True if the urls have been added; else false.</returns> public static bool AddManageURL(string type, string[] urls, Nequeo.Xml.Authorisation.Communication.Data.context context) { // Validate. if (String.IsNullOrEmpty(type)) { throw new ArgumentNullException("type"); } if (urls == null) { return(false); } try { // Find all manage with service name and application name. Communication.Data.contextManage manage = null; try { // Get all urls of the type. manage = context.manageURLs.First(u => u.type.ToLower() == type.ToLower()); } catch { } // If manage exists. if (manage != null) { // Get the type list. Communication.Data.contextManageUrl[] manageURLs = manage.url.AddIfNotExists <Communication.Data.contextManageUrl, string> ( urls, (m, u) => m.service.ToLower() == u.ToLower(), a => { var manageURL = new Communication.Data.contextManageUrl(); manageURL.service = a; return(manageURL); } ); // Assign the manage URL details. manage.url = manageURLs; // Save the new data. SaveCommunicationDataAsync(context); return(true); } else { // Get the type list. Communication.Data.contextManageUrl[] manageURLs = new Communication.Data.contextManageUrl[urls.Length]; // Assign each port detail. for (int i = 0; i < urls.Length; i++) { manageURLs[i].service = urls[i]; } // Load all the mangers into a temp list. List <Communication.Data.contextManage> tempManagers = new List <Communication.Data.contextManage>(context.manageURLs); Communication.Data.contextManage manageData = new Communication.Data.contextManage() { url = manageURLs, type = type }; // Add the host from the list. tempManagers.Add(manageData); // Assign the new host list to the // new context data. context.manageURLs = tempManagers.ToArray(); // Save the new data. SaveCommunicationDataAsync(context); return(true); } } catch (Exception) { throw; } }