/// <summary> /// This function allows for a GET of VMS Servers from Connection via HTTP - typically there are only one defined /// on the server so there's no filter clauses or the like supported to keep it simple. /// </summary> /// <param name="pConnectionServer"> /// Reference to the ConnectionServer object that points to the home server where the servers are being fetched from. /// </param> /// <param name="pServers"> /// The list of VMSServers is returned via this out parameter /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult GetVmsServers(ConnectionServerRest pConnectionServer, out List <VmsServer> pServers) { WebCallResult res = new WebCallResult(); res.Success = false; pServers = null; if (pConnectionServer == null) { res.ErrorText = "Null Connection server object passed to GetVmsServers"; return(res); } string strUrl = ConnectionServerRest.AddClausesToUri(pConnectionServer.BaseUrl + "vmsservers"); //issue the command to the CUPI interface res = pConnectionServer.GetCupiResponse(strUrl, MethodType.GET, ""); if (res.Success == false) { return(res); } //if the call was successful the JSON dictionary should always be populated with something, but just in case do a check here. //if this is empty that's an error - a zero count is also not valid since there must always be one. if (string.IsNullOrEmpty(res.ResponseText) || res.TotalObjectCount == 0) { pServers = new List <VmsServer>(); res.Success = false; return(res); } pServers = pConnectionServer.GetObjectsFromJson <VmsServer>(res.ResponseText); if (pServers == null) { pServers = new List <VmsServer>(); res.ErrorText = "Could not parse JSON into VmsServers:" + res.ResponseText; res.Success = false; return(res); } //the ConnectionServer property is not filled in in the default class constructor used by the Json parser - //run through here and assign it for all instances. foreach (var oObject in pServers) { oObject.HomeServer = pConnectionServer; } return(res); }
/// <summary> /// Create a new routing rule condition in the Connection directory /// </summary> /// <param name="pConnectionServer"> /// Connection server being edited /// </param> /// <param name="pRoutingRuleObjectId"> /// Routing rule to add the condition for /// </param> /// <param name="pOperator"> /// operator (equals, lessThan etc...) /// </param> /// <param name="pParameter"> /// Parameter (calling number, called number etc...) /// </param> /// <param name="pOperandValue"> /// Value to evaluate the parameter against using the operator /// </param> /// <returns> /// Instance of the WebCallResult class. /// </returns> public static WebCallResult AddRoutingRuleCondition(ConnectionServerRest pConnectionServer, string pRoutingRuleObjectId, RoutingRuleConditionOperator pOperator, RoutingRuleConditionParameter pParameter, string pOperandValue) { WebCallResult res = new WebCallResult(); res.Success = false; if (pConnectionServer == null) { res.ErrorText = "Null ConnectionServer referenced passed to AddRoutingRuleCondition"; return(res); } if (string.IsNullOrEmpty(pRoutingRuleObjectId)) { res.ErrorText = "Empty RoutingRuleObjectID passed to AddRoutingRuleCondition"; return(res); } if (string.IsNullOrEmpty(pOperandValue)) { res.ErrorText = "Empty pOperandValue passed to AddRoutingRuleCondition"; return(res); } string strBody = "<RoutingRuleCondition>"; //strBody += string.Format("<{0}>{1}</{0}>", "RoutingRuleObjectId", pRoutingRuleObjectId); strBody += string.Format("<{0}>{1}</{0}>", "Parameter", (int)pParameter); strBody += string.Format("<{0}>{1}</{0}>", "Operator", (int)pOperator); strBody += string.Format("<{0}>{1}</{0}>", "OperandValue", pOperandValue); strBody += "</RoutingRuleCondition>"; res = pConnectionServer.GetCupiResponse(pConnectionServer.BaseUrl + "routingrules/" + pRoutingRuleObjectId + "/routingruleconditions", MethodType.POST, strBody, false); //if the call went through then the ObjectId will be returned in the URI form. if (res.Success) { if (res.ResponseText.Contains(@"/vmrest/routingrules/" + pRoutingRuleObjectId + "/routingruleconditions/")) { res.ReturnedObjectId = res.ResponseText.Replace(@"/vmrest/routingrules/" + pRoutingRuleObjectId + "/routingruleconditions/", "").Trim(); } } return(res); }
/// <summary> /// Gets the list of all routing rule conditions associated with a routing rule. /// </summary> /// <param name="pConnectionServer"> /// The Connection server object that references the server the routing rule should be pulled from /// </param> /// <param name="pRoutingRuleObjectId"> /// Routing rule to fetch conditions for /// </param> /// <param name="pRoutingRuleConditions"> /// Out parameter that is used to return the list of RoutingRuleCondition objects defined on Connection. This /// list can be empty, conditions are not required /// </param> /// <param name="pPageNumber"> /// Results page to fetch - defaults to 1 /// </param> /// <param name="pRowsPerPage"> /// Results to return per page, defaults to 20 /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult GetRoutingRuleConditions(ConnectionServerRest pConnectionServer, string pRoutingRuleObjectId, out List <RoutingRuleCondition> pRoutingRuleConditions, int pPageNumber = 1, int pRowsPerPage = 20) { pRoutingRuleConditions = null; WebCallResult res = new WebCallResult { Success = false }; if (pConnectionServer == null) { res.ErrorText = "Null ConnectionServer referenced passed to GetRoutingRuleConditions"; return(res); } if (string.IsNullOrEmpty(pRoutingRuleObjectId)) { res.ErrorText = "Empty RoutingRuleObjectId referenced passed to GetRoutingRuleConditions"; return(res); } string strUrl = ConnectionServerRest.AddClausesToUri(pConnectionServer.BaseUrl + "routingrules/" + pRoutingRuleObjectId + "/routingruleconditions", "pageNumber=" + pPageNumber, "rowsPerPage=" + pRowsPerPage); //issue the command to the CUPI interface res = pConnectionServer.GetCupiResponse(strUrl, MethodType.GET, ""); if (res.Success == false) { return(res); } //if the call was successful the JSON dictionary should always be populated with something, but just in case do a check here. //if this is empty that does not mean an error - routing rules don't need conditions if (string.IsNullOrEmpty(res.ResponseText) || (res.TotalObjectCount == 0)) { pRoutingRuleConditions = new List <RoutingRuleCondition>(); return(res); } pRoutingRuleConditions = pConnectionServer.GetObjectsFromJson <RoutingRuleCondition>(res.ResponseText); //the ConnectionServer property is not filled in in the default class constructor used by the Json parser - //run through here and assign it for all instances. foreach (var oObject in pRoutingRuleConditions) { oObject.HomeServer = pConnectionServer; } return(res); }
/// <summary> /// Create a new search space in the Connection directory /// </summary> /// <param name="pConnectionServer"> /// Connection server being edited /// </param> /// <param name="pName"> /// Name of the new search space - must be unique. /// </param> /// <param name="pDescription"> /// Optional description of new search space. /// </param> /// <param name="pLocationObjectId"> /// Optional location ObjectId to create the search space in - if not provided it will default to the primary location of the Connection server /// its being created in /// </param> /// <returns> /// Instance of the WebCallResult class. /// </returns> public static WebCallResult AddSearchSpace(ConnectionServerRest pConnectionServer, string pName, string pDescription = "", string pLocationObjectId = "") { WebCallResult res = new WebCallResult(); res.Success = false; if (pConnectionServer == null) { res.ErrorText = "Null ConnectionServer referenced passed to AddSearchSpace"; return(res); } //make sure that something is passed in for the 2 required params - the extension is optional. if (String.IsNullOrEmpty(pName)) { res.ErrorText = "Empty value passed for partition name in AddSearchSpace"; return(res); } string strBody = "<SearchSpace>"; strBody += string.Format("<{0}>{1}</{0}>", "Name", pName); if (!string.IsNullOrEmpty(pDescription)) { strBody += string.Format("<{0}>{1}</{0}>", "Description", pDescription); } if (!string.IsNullOrEmpty(pLocationObjectId)) { strBody += string.Format("<{0}>{1}</{0}>", "LocationObjectId", pLocationObjectId); } strBody += "</SearchSpace>"; res = pConnectionServer.GetCupiResponse(pConnectionServer.BaseUrl + "searchspaces", MethodType.POST, strBody, false); //if the call went through then the ObjectId will be returned in the URI form. if (res.Success) { if (res.ResponseText.Contains(@"/vmrest/searchspaces/")) { res.ReturnedObjectId = res.ResponseText.Replace(@"/vmrest/searchspaces/", "").Trim(); } } return(res); }
/// <summary> /// This method allows for a GET of configuration valies from Connection via HTTP - it allows for passing any number of additional clauses /// for filtering (query directives), sorting and paging of results. The format of the clauses should look like: /// filter: "query=(FullName startswith System)" /// sort: "sort=(fullname asc)" /// page: "pageNumber=0" /// : "rowsPerPage=8" /// Escaping of spaces is done automatically, no need to account for that. /// </summary> /// <param name="pConnectionServer"> /// Reference to the ConnectionServer object that points to the home server where the values are being fetched from. /// </param> /// <param name="pConfigurationValues"> /// The values found will be returned in this generic list of ConfigurationValues /// </param> /// <param name="pClauses"> /// Zero or more strings can be passed for clauses (filters, sorts, page directives). Only one query and one sort parameter at a time /// are currently supported by CUPI - in other words you can't have "query=(alias startswith ab)" and "query=(FirstName startswith a)" in /// the same call. Also if you have a sort and a query clause they must both reference the same column. /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult GetConfigurationValues(ConnectionServerRest pConnectionServer, out List <ConfigurationValue> pConfigurationValues, params string[] pClauses) { WebCallResult res = new WebCallResult(); res.Success = false; pConfigurationValues = null; if (pConnectionServer == null) { res.ErrorText = "Null Connection server object passed to GetConfigurationValues"; return(res); } string strUrl = ConnectionServerRest.AddClausesToUri(pConnectionServer.BaseUrl + "configurationvalues", pClauses); //issue the command to the CUPI interface res = pConnectionServer.GetCupiResponse(strUrl, MethodType.GET, ""); if (res.Success == false) { return(res); } //if the call was successful the JSON dictionary should always be populated with something, but just in case do a check here. //if this is empty that is not an error, just return the empty list if (string.IsNullOrEmpty(res.ResponseText)) { pConfigurationValues = new List <ConfigurationValue>(); res.Success = false; return(res); } //no error, just return empty list. if (res.TotalObjectCount == 0 | res.ResponseText.Length < 25) { pConfigurationValues = new List <ConfigurationValue>(); return(res); } pConfigurationValues = pConnectionServer.GetObjectsFromJson <ConfigurationValue>(res.ResponseText); foreach (var oObject in pConfigurationValues) { oObject.HomeServer = pConnectionServer; } return(res); }
/// <summary> /// Helper function for fetching all policies targeted at a particular user. /// </summary> /// <param name="pConnectionServer"> /// Reference to the ConnectionServer object that points to the home server where the policies are being fetched from. /// </param> /// <param name="pUserObjectId"> /// GUID of the user to fetch for. /// </param> /// <param name="pPolicies"> /// The list of policies returned from the CUPI call (if any) is returned as a generic list of Policy class instances via this out param. /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult GetPoliciesForUser(ConnectionServerRest pConnectionServer, string pUserObjectId, out List <Policy> pPolicies) { if (string.IsNullOrEmpty(pUserObjectId)) { pPolicies = new List <Policy>(); return(new WebCallResult { ErrorText = "Empty UserObjectId passed to GetPoliciesForUser" }); } string strClause = string.Format("query=(UserObjectId is {0})", pUserObjectId); return(GetPolicies(pConnectionServer, out pPolicies, strClause)); }
/// <summary> /// Create a new routing rule in the Connection directory /// </summary> /// <param name="pConnectionServer"> /// Connection server being edited /// </param> /// <param name="pDisplayName"> /// Display Name of the new routing rule - must be unique. /// </param> /// <param name="pPropList"> /// List ConnectionProperty pairs that identify a property name and a new value for that property to apply to the rule being created. /// This is passed in as a ConnectionPropertyList instance which contains 1 or more ConnectionProperty instances. Can be passed as null here. /// </param> /// <returns> /// Instance of the WebCallResult class. /// </returns> public static WebCallResult AddRoutingRule(ConnectionServerRest pConnectionServer, string pDisplayName, ConnectionPropertyList pPropList) { WebCallResult res = new WebCallResult(); res.Success = false; if (pConnectionServer == null) { res.ErrorText = "Null ConnectionServer referenced passed to AddRoutingRule"; return(res); } if (String.IsNullOrEmpty(pDisplayName)) { res.ErrorText = "Empty value passed for display name in AddRoutingRule"; return(res); } //create an empty property list if it's passed as null since we use it below if (pPropList == null) { pPropList = new ConnectionPropertyList(); } pPropList.Add("DisplayName", pDisplayName); string strBody = "<RoutingRule>"; foreach (var oPair in pPropList) { //tack on the property value pair with appropriate tags strBody += string.Format("<{0}>{1}</{0}>", oPair.PropertyName, oPair.PropertyValue); } strBody += "</RoutingRule>"; res = pConnectionServer.GetCupiResponse(pConnectionServer.BaseUrl + "routingrules", MethodType.POST, strBody, false); //fetch the objectId of the newly created object off the return if (res.Success) { if (res.ResponseText.Contains(@"/vmrest/routingrules/")) { res.ReturnedObjectId = res.ResponseText.Replace(@"/vmrest/routingrules/", "").Trim(); } } return(res); }
/// <summary> /// Constructor requeires ConnectionServer object to pull time zone details from. /// </summary> public TimeZones(ConnectionServerRest pConnectionServer) { if (pConnectionServer == null) { throw new ArgumentException("Null ConnectionServer referenced pasted to TimeZones construtor"); } WebCallResult res = LoadTimeZones(pConnectionServer); if (res.Success == false) { throw new UnityConnectionRestException(res, "Failed to fetch timezones in TimeZones constructor:" + res.ToString()); } }
/// <summary> /// Adds a new Meeting Place service account /// </summary> /// <param name="pConnectionServer"> /// The Connection server to add the service to /// </param> /// <param name="pDisplayName"> /// Name of the service to add. Display name should be unique among external services. /// </param> /// <param name="pServiceAlias"></param> /// <param name="pServicePassword"></param> /// <param name="pServerName"></param> /// <param name="pTransferExtensionDialString"></param> /// <param name="oNewSerive"></param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult AddMeetingPlaceExternalService(ConnectionServerRest pConnectionServer, string pDisplayName, string pServiceAlias, string pServicePassword, string pServerName, string pTransferExtensionDialString, out ExternalService oNewSerive) { oNewSerive = null; var res = AddMeetingPlaceExternalService(pConnectionServer, pDisplayName, pServiceAlias, pServicePassword, pServerName, pTransferExtensionDialString); if (res.Success) { return(GetExternalService(out oNewSerive, pConnectionServer, res.ReturnedObjectId)); } return(res); }
/// <summary> /// Adds a new Exchange service account /// </summary> /// <param name="pConnectionServer"> /// The Connection server to add the service to /// </param> /// <param name="pDisplayName"> /// Name of the service to add. Display name should be unique among external services. /// </param> /// <param name="pServiceAlias"></param> /// <param name="pServicePassword"></param> /// <param name="pServerName"></param> /// <param name="pAuthenticationMode"></param> /// <param name="pExchangeServerType"></param> /// <param name="pSecurityTransportType"></param> /// <param name="oNewSerive"></param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult AddExchangeExternalService(ConnectionServerRest pConnectionServer, string pDisplayName, string pServiceAlias, string pServicePassword, string pServerName, AuthenticationMode pAuthenticationMode, ExchServerType pExchangeServerType, SecurityTransportType pSecurityTransportType, out ExternalService oNewSerive) { oNewSerive = null; var res = AddExchangeExternalService(pConnectionServer, pDisplayName, pServiceAlias, pServicePassword, pServerName, pAuthenticationMode, pExchangeServerType, pSecurityTransportType); if (res.Success) { return(GetExternalService(out oNewSerive, pConnectionServer, res.ReturnedObjectId)); } return(res); }
/// <summary> /// Gets all the port groups defined for a particular media switch (if any) /// </summary> /// <param name="pConnectionServer"> /// Connection server the port groups are homedon /// </param> /// <param name="pPortGroups"> /// List of port groups associated with phone system (if any) are returned on this out parameter /// </param> /// <param name="pMediaSwitchObjectId"> /// Media switch (phone system) to fetch port groups for /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult GetPortGroups(ConnectionServerRest pConnectionServer, out List <PortGroup> pPortGroups, string pMediaSwitchObjectId) { if (string.IsNullOrEmpty(pMediaSwitchObjectId)) { pPortGroups = new List <PortGroup>(); return(new WebCallResult { ErrorText = "Empty MediaSwitchObjectId passed to GetPortGroups" }); } return(GetPortGroups(pConnectionServer, out pPortGroups, 1, 512, string.Format("query=(MediaSwitchObjectId is {0})", pMediaSwitchObjectId))); }
/// <summary> /// Adds a new phone system with the display name provided /// </summary> /// <param name="pConnectionServer"> /// The Connection server to add the phone system to /// </param> /// <param name="pDisplayName"> /// Name of the phone system to add. Display name should be unique among phone systems. /// </param> /// <param name="pPhoneSystem"> /// If the phone system is added, an instance of it is created and passed back on this out parameter. /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult AddPhoneSystem(ConnectionServerRest pConnectionServer, string pDisplayName, out PhoneSystem pPhoneSystem) { pPhoneSystem = null; WebCallResult res = AddPhoneSystem(pConnectionServer, pDisplayName); //if the create goes through, fetch the phone system as an object and return it. if (res.Success) { res = GetPhoneSystem(out pPhoneSystem, pConnectionServer, res.ReturnedObjectId); } return(res); }
/// <summary> /// Returns a list of CallHandlerOwner objects representing the owners (users or public distribution lists) for a particular /// system call handler. /// A call handler may have no owners in which case an empty list is returned. /// </summary> /// <param name="pConnectionServer"></param> /// <param name="pCallHandlerObjectId"> /// Call handler to fetch owner information for. /// </param> /// <param name="pCallHandlerOwners"> /// List of CallHandlerOwner objects. Can represent users or public distribution lists. /// </param> /// <param name="pClauses"> /// Optional search clauses such as "query=(name is testname)" /// </param> /// <returns> /// Instance of the WebCallResult object with details of the call and results. /// </returns> public static WebCallResult GetCallHandlerOwners(ConnectionServerRest pConnectionServer, string pCallHandlerObjectId, out List <CallHandlerOwner> pCallHandlerOwners, params string[] pClauses) { WebCallResult res = new WebCallResult(); res.Success = false; pCallHandlerOwners = new List <CallHandlerOwner>(); if (pConnectionServer == null) { res.ErrorText = "Null Connection server object passed to GetCallHandlerOwners"; return(res); } string strUrl = ConnectionServerRest.AddClausesToUri(pConnectionServer.BaseUrl + "handlers/callhandlers/" + pCallHandlerObjectId + "/callhandlerowners", pClauses); res = pConnectionServer.GetCupiResponse(strUrl, MethodType.GET, ""); if (res.Success == false) { return(res); } if (string.IsNullOrEmpty(res.ResponseText)) { res.Success = false; res.ErrorText = "Empty response recieved"; return(res); } //not a failure, just return an empty list if (res.TotalObjectCount == 0 | res.ResponseText.Length < 25) { return(res); } pCallHandlerOwners = pConnectionServer.GetObjectsFromJson <CallHandlerOwner>(res.ResponseText, "CallhandlerOwner"); if (pCallHandlerOwners == null) { pCallHandlerOwners = new List <CallHandlerOwner>(); res.ErrorText = "Could not parse JSON into call handler owner objects:" + res.ResponseText; res.Success = false; } return(res); }
/// <summary> /// Uploads a WAV file indicated as a voice name for the target distribution list referenced by the pObjectID value. /// </summary> /// <param name="pConnectionServer"> /// Reference to the ConnectionServer object that points to the home server where the list is homed. /// </param> /// <param name="pSourceLocalFilePath"> /// Full path on the local file system pointing to a WAV file to be uploaded as a voice name for the list referenced. /// </param> /// <param name="pObjectId"> /// ObjectId of the distribution list to upload the voice name WAV file for. /// </param> /// <param name="pUserObjectId"> /// User that owns the private list to set the voice name for. /// </param> /// <param name="pConvertToPcmFirst"> /// Converts the wav file into a format Connection can handle before uploading /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult SetPrivateListVoiceName(ConnectionServerRest pConnectionServer, string pSourceLocalFilePath, string pObjectId, string pUserObjectId, bool pConvertToPcmFirst = false) { WebCallResult res = new WebCallResult(); res.Success = false; if (pConnectionServer == null) { res.ErrorText = "Null ConnectionServer referenced passed to SetPrivateListVoiceName"; return(res); } if (string.IsNullOrEmpty(pUserObjectId) || string.IsNullOrEmpty(pObjectId)) { res.ErrorText = "Empty objectId or UserObjectId passed to SetPrivateListVoiceName"; return(res); } //check and make sure a legit folder is referenced in the target path if (String.IsNullOrEmpty(pSourceLocalFilePath) || (File.Exists(pSourceLocalFilePath) == false)) { res = new WebCallResult(); res.Success = false; res.ErrorText = "Invalid local file path passed to SetPrivateListVoiceName: " + pSourceLocalFilePath; return(res); } //if the user wants to try and rip the WAV file into PCM 16/8/1 first before uploading the file, do that conversion here if (pConvertToPcmFirst) { string strConvertedWavFilePath = pConnectionServer.ConvertWavFileToPcm(pSourceLocalFilePath); if (string.IsNullOrEmpty(strConvertedWavFilePath) || File.Exists(strConvertedWavFilePath) == false) { res.ErrorText = "Converted PCM WAV file path not found in SetPrivateListVoiceName: " + strConvertedWavFilePath; return(res); } //point the wav file we'll be uploading to the newly converted G711 WAV format file. pSourceLocalFilePath = strConvertedWavFilePath; } //use the 8.5 and later voice name formatting here which simplifies things a great deal. string strResourcePath = string.Format(@"{0}users/{1}/privatelists/{2}/voicename", pConnectionServer.BaseUrl, pUserObjectId, pObjectId); //upload the WAV file to the server. return(pConnectionServer.UploadWavFile(strResourcePath, pSourceLocalFilePath)); }
/// <summary> /// Gets the list of all notification templates and resturns them as a generic list of NotificationTemplate objects. This /// list can be used for providing drop down list selection for user creation purposes or the like. /// </summary> /// <param name="pConnectionServer"> /// The Connection server object that references the server the templates should be pulled from /// </param> /// <param name="pTemplates"> /// Out parameter that is used to return the list of NotificationTemplate objects defined on Connection - /// there must be at least one. /// </param> /// <param name="pPageNumber"> /// Results page to fetch - defaults to 1 /// </param> /// <param name="pRowsPerPage"> /// Results to return per page, defaults to 20 /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult GetNotificationTemplates(ConnectionServerRest pConnectionServer, out List <NotificationTemplate> pTemplates, int pPageNumber = 1, int pRowsPerPage = 20) { WebCallResult res; pTemplates = new List <NotificationTemplate>(); if (pConnectionServer == null) { res = new WebCallResult(); res.ErrorText = "Null ConnectionServer referenced passed to GetNotificationTemplates"; return(res); } string strUrl = ConnectionServerRest.AddClausesToUri(pConnectionServer.BaseUrl + "notificationtemplates", "pageNumber=" + pPageNumber, "rowsPerPage=" + pRowsPerPage); //issue the command to the CUPI interface res = pConnectionServer.GetCupiResponse(strUrl, MethodType.GET, ""); if (res.Success == false) { return(res); } if (string.IsNullOrEmpty(res.ResponseText)) { res.ErrorText = "Empty response received"; res.Success = false; return(res); } //not an error just return the empty list if (res.TotalObjectCount == 0 | res.ResponseText.Length < 25) { return(res); } pTemplates = pConnectionServer.GetObjectsFromJson <NotificationTemplate>(res.ResponseText); //the ConnectionServer property is not filled in in the default class constructor used by the Json parser - //run through here and assign it for all instances. foreach (var oObject in pTemplates) { oObject.HomeServer = pConnectionServer; } return(res); }
/// <summary> /// Adds a new port group server to a port group. /// </summary> /// <param name="pConnectionServer"> /// The Connection server to add the port group server to. /// </param> /// <param name="pPortGroupObjectId"> /// Port group to add the port group server to. /// </param> /// <param name="pMediaPortGroupServiceEnum"></param> /// <param name="pHostOrIpAddress"> /// Host address or IP address of the server to add. /// </param> /// <param name="pHostOrIpAddressV6"> /// IPV6 host or ip address /// </param> /// <param name="pPortGroupServer"> /// Instance of the new PortGroupServer is passed back on this out parameter /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult AddPortGroupServer(ConnectionServerRest pConnectionServer, string pPortGroupObjectId, int pMediaPortGroupServiceEnum, string pHostOrIpAddress, string pHostOrIpAddressV6, out PortGroupServer pPortGroupServer) { pPortGroupServer = null; WebCallResult res = AddPortGroupServer(pConnectionServer, pPortGroupObjectId, pMediaPortGroupServiceEnum, pHostOrIpAddress, pHostOrIpAddressV6); //if the create goes through, fetch the phone system as an object and return it. if (res.Success) { res = GetPortGroupServer(out pPortGroupServer, pConnectionServer, res.ReturnedObjectId, pPortGroupObjectId); } return(res); }
/// <summary> /// Create a new port group - port groups get ports assigned to them and are, in turn, assigned to phone systems. /// </summary> /// <param name="pConnectionServer"> /// Connection server to create the new port gorup on. /// </param> /// <param name="pDisplayName"> /// Display name of the new port gorup /// </param> /// <param name="pPhoneSystemObjectId"> /// Phone system to associate the port group to. /// </param> /// <param name="pHostOrIpAddress"> /// Host name or IP address of the phone system (i.e. the Call Manager server) /// </param> /// <param name="pPhoneIntegrationMethod"> /// SIP, SCCP or PIMG/TIMG /// </param> /// <param name="pSccpDevicePrefix"> /// When setting up a port group for SCCP you need to provide a device prefix such as "UnityUM1-VI". For other integration types this can /// be left blank /// </param> /// <param name="pPortGroup"> /// instance of the newly created PortGroup is passed back on this out parameter /// </param> /// <returns> /// Instance of the WebCallResult class with details of the method call and the results from the server. /// </returns> public static WebCallResult AddPortGroup(ConnectionServerRest pConnectionServer, string pDisplayName, string pPhoneSystemObjectId, string pHostOrIpAddress, TelephonyIntegrationMethodEnum pPhoneIntegrationMethod, string pSccpDevicePrefix, out PortGroup pPortGroup) { pPortGroup = null; WebCallResult res = AddPortGroup(pConnectionServer, pDisplayName, pPhoneSystemObjectId, pHostOrIpAddress, pPhoneIntegrationMethod, pSccpDevicePrefix); if (res.Success == false) { return(res); } return(GetPortGroup(out pPortGroup, pConnectionServer, res.ReturnedObjectId)); }
/// <summary> /// Import an LDAP user as a local Unity Connection user. /// </summary> /// <param name="pConnectionServer"> /// Connection server to import the user on. /// </param> /// <param name="pTemplateAlias"> /// Alias of the user template to use when importing the user, required. /// </param> /// <param name="pPkid"> /// Unique ID from the Call Manager database for the LDAP synchronized user. /// </param> /// <param name="pAlias"> /// Alias of the user in LDAP to import /// </param> /// <param name="pFirstName"> /// First name of the user to import /// </param> /// <param name="pLastName"> /// Last name of the user to import /// </param> /// <param name="pExtension"> /// Extension number to assign the user in Connection's diretory /// </param> /// <param name="pPropList"> /// Name value pair list of optional values to include in the import. /// </param> /// <param name="pUser"> /// Instance of the UserFull class is passed back filled in with the details of the newly import user if the /// import succeeds. Null if the import fails. /// </param> /// <returns> /// Instance of the WebCallResults class with details of the call and results from the server. /// </returns> public static WebCallResult ImportLdapUser(ConnectionServerRest pConnectionServer, string pTemplateAlias, string pPkid, string pAlias, string pFirstName, string pLastName, string pExtension, ConnectionPropertyList pPropList, out UserFull pUser) { pUser = null; var res = ImportLdapUser(pConnectionServer, pTemplateAlias, pPkid, pAlias, pFirstName, pLastName, pExtension, pPropList); if (res.Success) { return(UserFull.GetUser(pConnectionServer, res.ReturnedObjectId, out pUser)); } return(res); }
/// <summary> /// This function allows for a GET of policies from Connection via HTTP - it allows for passing any number of additional clauses /// for filtering (query directives), sorting and paging of results. The format of the clauses should look like: /// filter: "query=(UserObjectId is 0d84fee3-8680-4bd2-aa81-49e32921299b)" /// page: "pageNumber=0" /// : "rowsPerPage=8" /// Escaping of spaces is done automatically, no need to account for that. /// </summary> /// <param name="pConnectionServer"> /// Reference to the ConnectionServer object that points to the home server where the policies are being fetched from. /// </param> /// <param name="pPolicies"> /// The list of policies returned from the CUPI call (if any) is returned as a generic list of Policy class instances via this out param. /// </param> /// <param name="pClauses"> /// Zero or more strings can be passed for clauses (filters, sorts, page directives). Only one query and one sort parameter at a time /// are currently supported by CUPI - in other words you can't have "query=(alias startswith ab)" and /// "query=(UserObjectId is 0d84fee3-8680-4bd2-aa81-49e32921299b)" /// in the same call. Also if you have a sort and a query clause they must both reference the same column. /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult GetPolicies(ConnectionServerRest pConnectionServer, out List <Policy> pPolicies, params string[] pClauses) { WebCallResult res = new WebCallResult(); res.Success = false; pPolicies = new List <Policy>(); if (pConnectionServer == null) { res.ErrorText = "Null Connection server object passed to GetPolicies"; return(res); } string strUrl = ConnectionServerRest.AddClausesToUri(pConnectionServer.BaseUrl + "policies", pClauses); //issue the command to the CUPI interface res = pConnectionServer.GetCupiResponse(strUrl, MethodType.GET, ""); if (res.Success == false) { return(res); } if (string.IsNullOrEmpty(res.ResponseText)) { res.Success = false; res.ErrorText = "Empty response received"; return(res); } //not an error, return empty list if (res.TotalObjectCount == 0 | res.ResponseText.Length < 25) { return(res); } pPolicies = pConnectionServer.GetObjectsFromJson <Policy>(res.ResponseText); //the ConnectionServer property is not filled in in the default class constructor used by the Json parser - //run through here and assign it for all instances. foreach (var oObject in pPolicies) { oObject.HomeServer = pConnectionServer; } return(res); }
/// <summary> /// Adds a new Exchange service account /// </summary> /// <param name="pConnectionServer"> /// The Connection server to add the service to /// </param> /// <param name="pDisplayName"> /// Name of the service to add. Display name should be unique among external services. /// </param> /// <param name="pServiceAlias"></param> /// <param name="pServicePassword"></param> /// <param name="pServerName"></param> /// <param name="pAuthenticationMode"></param> /// <param name="pExchangeServerType"></param> /// <param name="pSecurityTransportType"></param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult AddExchangeExternalService(ConnectionServerRest pConnectionServer, string pDisplayName, string pServiceAlias, string pServicePassword, string pServerName, AuthenticationMode pAuthenticationMode, ExchServerType pExchangeServerType, SecurityTransportType pSecurityTransportType) { WebCallResult res = new WebCallResult { Success = false }; if (pConnectionServer == null) { res.ErrorText = "Null ConnectionServer referenced passed to AddExchangeExternalService"; return(res); } //make sure that something is passed in for the required param if (String.IsNullOrEmpty(pDisplayName)) { res.ErrorText = "Empty value passed for display name in AddExchangeExternalService"; return(res); } string strBody = "<ExternalService>"; strBody += string.Format("<{0}>{1}</{0}>", "DisplayName", pDisplayName.HtmlBodySafe()); strBody += string.Format("<{0}>{1}</{0}>", "ServiceAlias", pServiceAlias.HtmlBodySafe()); strBody += string.Format("<{0}>{1}</{0}>", "ServicePassword", pServicePassword.HtmlBodySafe()); strBody += string.Format("<{0}>{1}</{0}>", "ServerType", (int)ServerType.Exchange); strBody += string.Format("<{0}>{1}</{0}>", "Server", pServerName); strBody += string.Format("<{0}>{1}</{0}>", "AuthenticationMode", (int)pAuthenticationMode); strBody += string.Format("<{0}>{1}</{0}>", "ExchServerType", (int)pExchangeServerType); strBody += string.Format("<{0}>{1}</{0}>", "SecurityTransportType", (int)pSecurityTransportType); strBody += "</ExternalService>"; res = pConnectionServer.GetCupiResponse(string.Format("{0}externalservices", pConnectionServer.BaseUrl), MethodType.POST, strBody, false); //if the call went through then the ObjectId will be returned in the URI form. if (res.Success) { const string strPrefix = @"/vmrest/externalservices/"; if (res.ResponseText.Contains(strPrefix)) { res.ReturnedObjectId = res.ResponseText.Replace(strPrefix, "").Trim(); } } return(res); }
/// <summary> /// constructor takes a ConnectionServer as a parameter - passed as null when constructing lists internally /// </summary> /// <param name="pConnectionServer"></param> public InstalledLanguage(ConnectionServerRest pConnectionServer = null) { if (pConnectionServer == null) { return; } HomeServer = pConnectionServer; var res = GetInstalledLanguages(); if (res.Success == false) { throw new UnityConnectionRestException(res, "Failed to load installed languages:" + res); } }
/// <summary> /// Constructor requires ConnectionServer object where the role is defined. Optionally you can pass the enum of the role you want to /// populate the class instance with /// </summary> public Role(ConnectionServerRest pConnectionServer, RoleName pRoleName) { if (pConnectionServer == null) { throw new ArgumentException("Null ConnectionServer referenced pasted to Role construtor"); } HomeServer = pConnectionServer; WebCallResult res = GetRole(pRoleName); if (res.Success == false) { throw new UnityConnectionRestException(res, string.Format("Failed to fetch role by enum={0}", pRoleName)); } }
/// <summary> /// This function allows for a GET of Ldapusers from Connection via HTTP - it allows for passing any number of additional clauses /// for filtering (query directives), sorting and paging of results. The format of the clauses should look like: /// filter: "query=(firstname startswith ab)" /// sort: "sort=(alias asc)" /// Escaping of spaces is done automatically, no need to account for that. /// </summary> /// <remarks> /// While this method name does have the plural in it, you'll want to use it for fetching single users as well. If searching by /// pKid just construct a query in the form "query=(pkid is {pkid})". /// </remarks> /// <param name="pConnectionServer"> /// Reference to the ConnectionServer object that points to the home server where the users are being fetched from. /// </param> /// <param name="pUsers"> /// The list of users returned from the CUPI call (if any) is returned as a generic list of UserLdap class instances via this out param. /// If no users are found this is returned as en empty /// </param> /// <param name="pClauses"> /// Zero or more strings can be passed for clauses (filters, sorts, page directives). Only one query and one sort parameter at a time /// are currently supported by CUPI - in other words you can't have "query=(alias startswith ab)" and "query=(FirstName startswith a)" in /// the same call. Also if you have a sort and a query clause they must both reference the same column. /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult GetLdapUsers(ConnectionServerRest pConnectionServer, out List <UserLdap> pUsers, params string[] pClauses) { WebCallResult res = new WebCallResult(); res.Success = false; pUsers = new List <UserLdap>(); if (pConnectionServer == null) { res.ErrorText = "Null Connection server object passed to GetLdapUsers"; return(res); } string strUrl = ConnectionServerRest.AddClausesToUri(pConnectionServer.BaseUrl + "import/users/ldap", pClauses); res = pConnectionServer.GetCupiResponse(strUrl, MethodType.GET, ""); if (res.Success == false) { return(res); } if (string.IsNullOrEmpty(res.ResponseText)) { res.ErrorText = "Empty response received"; res.Success = false; return(res); } //not an error, just return empty list if (res.TotalObjectCount == 0 | res.ResponseText.Length < 25) { return(res); } pUsers = pConnectionServer.GetObjectsFromJson <UserLdap>(res.ResponseText, "ImportUser"); //the ConnectionServer property is not filled in in the default class constructor used by the Json parser - //run through here and assign it for all instances. foreach (var oUser in pUsers) { oUser.HomeServer = pConnectionServer; } return(res); }
/// <summary> /// Adds a schedule as a member of the schedule set /// </summary> /// <param name="pConnectionServer"> /// Connection server that's being edited /// </param> /// <param name="pScheduleSetObjectId"> /// Schedule set to add the member to /// </param> /// <param name="pScheduleObjectId"> /// Schedule to add as a member /// </param> /// <param name="pIsHoliday"> /// pass as true for Holiday schedules /// </param> /// <returns> /// Instance of the WebCallResult class /// </returns> public static WebCallResult AddScheduleSetMember(ConnectionServerRest pConnectionServer, string pScheduleSetObjectId, string pScheduleObjectId, bool pIsHoliday=false) { WebCallResult res = new WebCallResult(); res.Success = false; if (pConnectionServer == null) { res.ErrorText = "Null ConnectionServer referenced passed to AddScheduleSetMember"; return res; } if (string.IsNullOrEmpty(pScheduleSetObjectId) | string.IsNullOrEmpty(pScheduleObjectId)) { res.ErrorText = "Empty pScheduleSetObjectId or pScheduleObjectId passed to AddScheduleSetMember"; return res; } string strBody = "<ScheduleSetMember>"; strBody += string.Format("<{0}>{1}</{0}>", "ScheduleSetObjectId", pScheduleSetObjectId); strBody += string.Format("<{0}>{1}</{0}>", "ScheduleObjectId", pScheduleObjectId); if (pIsHoliday) { strBody += string.Format("<{0}>{1}</{0}>", "Exclude", "true"); } strBody += "</ScheduleSetMember>"; string strPath = string.Format("schedulesets/{0}/schedulesetmembers", pScheduleSetObjectId); res = pConnectionServer.GetCupiResponse(pConnectionServer.BaseUrl + strPath, MethodType.POST, strBody, false); //if the call went through then the ObjectId will be returned in the URI form. strPath += "/"; if (res.Success) { if (res.ResponseText.Contains(@"/vmrest/"+strPath)) { res.ReturnedObjectId = res.ResponseText.Replace(@"/vmrest/"+strPath, "").Trim(); } } return res; }
/// <summary> /// Sets the post greeting recording for a particular language. The WAV file is uploaded (after optionally being converted /// to a format Conneciton will accept). /// </summary> /// <param name="pConnectionServer"> /// The Connection server that houses the post greeting recording being edited. /// </param> /// <param name="pSourceLocalFilePath"> /// Full path on the local file system to the WAV file to be uploaded as the greeting. /// </param> /// <param name="pPostGreetingRecordingObjectId"> /// The GUID identifying the post greeting recording that owns the greeting being edited. /// </param> /// <param name="pLanguageId"> /// The language ID of the WAV file being uploaded (for US English this is 1033). The LanguageCodes enum defined in the ConnectionTypes /// class can be helpful here. /// </param> /// <param name="pConvertToPcmFirst"> /// Defaults to false, but if passed as true this has the target WAV file first converted PCM, 16 Khz, 8 bit mono before uploading. This /// helps ensure Connection will not complain about the media file format. /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult SetPostGreetingRecordingWavFile(ConnectionServerRest pConnectionServer, string pSourceLocalFilePath, string pPostGreetingRecordingObjectId, int pLanguageId, bool pConvertToPcmFirst = false) { WebCallResult res = new WebCallResult(); if (pConnectionServer == null) { res.ErrorText = "Null ConnectionServer referenced passed to SetPostGreetingRecordingWavFile"; return(res); } //check and make sure a legit folder is referenced in the target path if (String.IsNullOrEmpty(pSourceLocalFilePath) || (File.Exists(pSourceLocalFilePath) == false)) { res = new WebCallResult(); res.Success = false; res.ErrorText = "Invalid local file path passed to SetPostGreetingRecordingWavFile: " + pSourceLocalFilePath; return(res); } //if the user wants to try and rip the WAV file into G711 first before uploading the file, do that conversion here if (pConvertToPcmFirst) { string strConvertedWavFilePath = pConnectionServer.ConvertWavFileToPcm(pSourceLocalFilePath); if (string.IsNullOrEmpty(strConvertedWavFilePath) || File.Exists(strConvertedWavFilePath) == false) { res.ErrorText = "Converted G711 WAV file path not found in SetPostGreetingRecordingWavFile: " + strConvertedWavFilePath; return(res); } //point the wav file we'll be uploading to the newly converted G711 WAV format file. pSourceLocalFilePath = strConvertedWavFilePath; } //new construction - requires 8.5 or later and is done in one step to send the greeting to the server. string strGreetingStreamUriPath = string.Format("https://{0}:8443/vmrest/postgreetingrecordings/{1}/postgreetingrecordingstreamfiles/{2}/audio", pConnectionServer.ServerName, pPostGreetingRecordingObjectId, pLanguageId); return(pConnectionServer.UploadWavFile(strGreetingStreamUriPath, pSourceLocalFilePath)); }
/// <summary> /// Overloaded GetGreetingWAVFile function that takes the call handler ID, greeting type and language code which looks up the stream file name /// to fetch from the Connection server. /// </summary> /// <param name="pConnectionServer"> /// Connection server that houses the greeting being fetched. /// </param> /// <param name="pTargetLocalFilePath"> /// The fully qualified file path on the local OS to store the WAV file for this stream. /// </param> /// <param name="pCallHandlerObjectId"> /// The call handler that owns the greeting being fetched. /// </param> /// <param name="pGreetingType"> /// The type of greeting (Alternate, Off Hours, Standard) /// </param> /// <param name="pLanguageCode"> /// The language code (i.e. US English = 1033). /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult GetGreetingWavFile(ConnectionServerRest pConnectionServer, string pTargetLocalFilePath, string pCallHandlerObjectId, GreetingTypes pGreetingType, int pLanguageCode) { WebCallResult res = new WebCallResult(); res.Success = false; if (pConnectionServer == null) { res.ErrorText = "Null ConnectionServer referenced passed to GetWGreetingAVFile"; return(res); } //fetch the greeting stream file object for this greeting and language code. GreetingStreamFile oStreamFile; try { oStreamFile = new GreetingStreamFile(pConnectionServer, pCallHandlerObjectId, pGreetingType, pLanguageCode); } catch (UnityConnectionRestException ex) { return(ex.WebCallResult); } catch (Exception ex) { //this will be rather common - keep the wording here toned down. res.ErrorText = "No greeting stream file found for greeting in GetGreetingWAVFile: " + ex.Message; return(res); } //fetch the StreamFile name from the directory - this identifies the actual WAV file in the streams folder on the Connection //server. Normally if there's a greeting stream file record for a greeting there will be a stream file for it - but just //in case. if (String.IsNullOrEmpty(oStreamFile.StreamFile)) { res.ErrorText = "No recording found for stream file"; return(res); } //call the alternateive static definition that actually has the WAV file fetch logic in it. return(GetGreetingWavFile(pConnectionServer, pTargetLocalFilePath, oStreamFile.StreamFile)); }
/// <summary> /// Constructor for the Server class /// </summary> /// <param name="pConnectionServer"> /// ConnectionServer data is being fetched from. /// </param> public Cluster(ConnectionServerRest pConnectionServer) { if (pConnectionServer == null) { throw new ArgumentException("Null ConnectionServer referenced passed to Cluster construtor"); } HomeServer = pConnectionServer; //fetch the servers in the cluster (always 1 but can be 2) WebCallResult res = GetServers(HomeServer); if (res.Success == false) { throw new UnityConnectionRestException(res, string.Format("Cluster details not found in Cluster constructor\n\r{0}", res.ErrorText)); } }
/// <summary> /// Allows for the creation of a new COS on the Connection server directory. The name must be provided /// </summary> /// <remarks> /// This is an alternateive AddClassOfService that passes back a ClassOfService object with the newly created list filled /// out in it if the add goes through. /// </remarks> /// <param name="pConnectionServer"> /// Reference to the ConnectionServer object that points to the home server where the list is being added. /// </param> /// <param name="pDisplayName"> /// Display name to be used for the new cos. /// </param> /// <param name="pPropList"> /// List ConnectionProperty pairs that identify a list's property name and a new value for that property to apply to the list being created. /// This is passed in as a ConnectionPropertyList instance which contains 1 or more ConnectionProperty instances. Can be passed as null here. /// </param> /// <param name="oClassOfService"> /// Out parameter that instance of Class of Service class is returned on if a match is found - null if no match is found. /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult AddClassOfService(ConnectionServerRest pConnectionServer, string pDisplayName, ConnectionPropertyList pPropList, out ClassOfService oClassOfService) { oClassOfService = null; WebCallResult res = AddClassOfService(pConnectionServer, pDisplayName, pPropList); //if the create goes through, fetch the list as an object and return it all filled in. if (res.Success) { res = GetClassOfService(out oClassOfService, pConnectionServer, res.ReturnedObjectId); } return(res); }
/// <summary> /// Adds a new port group codec to a port group /// </summary> /// <param name="pConnectionServer"> /// The Connection server to add the port group codec to /// </param> /// <param name="pPortGroupObjectId"> /// Port group to add the codec to /// </param> /// <param name="pRtpCodecDefObjectId"> /// RtpCodec to add /// </param> /// <param name="pPreferredPacketSizeMs"> /// Packet size to use - 10, 20 or 30. /// </param> /// <param name="pPreference"> /// Lower values mean this codec is more preferred than higher values for other codecs - typically start with 0 then go to 1, then /// 2 etc... only has meaning if the port group is SIP. /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult AddPortGroupCodec(ConnectionServerRest pConnectionServer, string pPortGroupObjectId, string pRtpCodecDefObjectId, int pPreferredPacketSizeMs, int pPreference) { WebCallResult res = new WebCallResult(); res.Success = false; if (pConnectionServer == null) { res.ErrorText = "Null ConnectionServer referenced passed to AddPortGroupCodec"; return(res); } //make sure that something is passed in for the required param if (String.IsNullOrEmpty(pPortGroupObjectId) | string.IsNullOrEmpty(pRtpCodecDefObjectId)) { res.ErrorText = "Empty value passed for port group ObjectId or CodecDefObjectId in AddPortGroupCodec"; return(res); } string strBody = "<PortGroupCodec>"; //tack on the property value pair with appropriate tags strBody += string.Format("<MediaPortGroupObjectId>{0}</MediaPortGroupObjectId>", pPortGroupObjectId); strBody += string.Format("<PreferredPacketSizeMs>{0}</PreferredPacketSizeMs>", pPreferredPacketSizeMs); strBody += string.Format("<RtpCodecDefObjectId>{0}</RtpCodecDefObjectId>", pRtpCodecDefObjectId); strBody += string.Format("<Preference>{0}</Preference>", pPreference); strBody += "</PortGroupCodec>"; res = pConnectionServer.GetCupiResponse(string.Format("{0}portgroups/{1}/portgroupcodecs", pConnectionServer.BaseUrl, pPortGroupObjectId), MethodType.POST, strBody, false); //if the call went through then the ObjectId will be returned in the URI form. if (res.Success) { string strPrefix = string.Format("/vmrest/portgroups/{0}/portgroupcodecs/", pPortGroupObjectId); if (res.ResponseText.Contains(strPrefix)) { res.ReturnedObjectId = res.ResponseText.Replace(strPrefix, "").Trim(); } } return(res); }
/// <summary> /// Returns a list of role objects that are assigned to the user - an empty list is returned if the user has no roles /// </summary> /// <param name="pConnectionServer" type="Cisco.UnityConnection.RestFunctions.ConnectionServerRest"> /// ConnectionServer the user is hosted on /// </param> /// <param name="pUserObjectId" type="string"> /// Unique Id of the user to get the roles for /// </param> /// <param name="pRoles"> /// List of Role objects corresponding to the roles assigned to the user. Can return empty list. /// </param> /// <returns> /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface. /// </returns> public static WebCallResult GetRolesForUser(ConnectionServerRest pConnectionServer, string pUserObjectId, out List <Role> pRoles) { WebCallResult res; pRoles = new List <Role>(); if (pConnectionServer == null) { res = new WebCallResult { ErrorText = "Null ConnectionServer referenced passed to GetRolesForUser", Success = false }; return(res); } res = pConnectionServer.GetCupiResponse(string.Format("{0}users/{1}/userroles", pConnectionServer.BaseUrl, pUserObjectId), MethodType.GET, ""); if (res.Success == false) { return(res); } //if the call was successful the JSON dictionary should always be populated with something, but just in case do a check here. //if this is empty that means an error in this case - a 0 count list is ok, though if (string.IsNullOrEmpty(res.ResponseText)) { res.Success = false; return(res); } if (res.TotalObjectCount == 0) { res.Success = true; return(res); } pRoles = pConnectionServer.GetObjectsFromJson <Role>(res.ResponseText, "UserRole"); //the ConnectionServer property is not filled in in the default class constructor used by the Json parser - //run through here and assign it for all instances. foreach (var oObject in pRoles) { oObject.HomeServer = pConnectionServer; } return(res); }