Ejemplo n.º 1
0
        /// <summary>
        /// Builds an instance of an AlternateExtension object, filling it with the details of an alternate extension idenitified by the
        /// UserObjectID and the ObjectId of the alternate extension owned by that user.
        /// This AlternateExtension has already been created - you can use this to "re fill" an existing alternate extension with possibly
        /// updated information or if you created an "empty" AlternateExtension object and now want to populate it.
        /// </summary>
        /// <param name="pObjectId">
        /// The GUID identifying the alternate extension to fetch
        /// </param>
        /// <returns>
        /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface.
        /// </returns>
        private WebCallResult GetAlternateExtension(string pObjectId)
        {
            string strUrl = string.Format("{0}users/{1}/alternateextensions/{2}", HomeServer.BaseUrl, UserObjectId, pObjectId);

            //issue the command to the CUPI interface
            WebCallResult res = HomeServer.GetCupiResponse(strUrl, MethodType.GET, "");

            if (res.Success == false)
            {
                return(res);
            }

            try
            {
                JsonConvert.PopulateObject(ConnectionServerRest.StripJsonOfObjectWrapper(res.ResponseText, "AlternateExtension"), this,
                                           RestTransportFunctions.JsonSerializerSettings);
            }
            catch (Exception ex)
            {
                res.ErrorText = "Failure populating class instance form JSON response:" + ex;
                res.Success   = false;
            }

            //all the updates above will flip pending changes into the queue - clear that here.
            this.ClearPendingChanges();

            return(res);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Fetch the ObjectId of a template by it's name.  Empty string returned if not match is found.
        /// </summary>
        /// <param name="pName">
        /// Name of the template to find
        /// </param>
        /// <param name="pCount">
        /// Total number of templates found
        /// </param>
        /// <returns>
        /// ObjectId of template if found or empty string if not.
        /// </returns>
        private string GetObjectIdFromName(string pName, out int pCount)
        {
            pCount = 0;
            string strUrl = string.Format("{0}callhandlertemplates/?query=(DisplayName is {1})", HomeServer.BaseUrl, pName.UriSafe());

            //issue the command to the CUPI interface
            WebCallResult res = HomeServer.GetCupiResponse(strUrl, MethodType.GET, "");

            if (res.Success == false || res.TotalObjectCount != 1)
            {
                pCount = res.TotalObjectCount;
                return("");
            }

            List <CallHandlerTemplate> oTemplates = HomeServer.GetObjectsFromJson <CallHandlerTemplate>(res.ResponseText);

            foreach (var oTemplate in oTemplates)
            {
                if (oTemplate.DisplayName.Equals(pName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(oTemplate.ObjectId);
                }
            }

            return("");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Fetch a COSes ObjectId by it's name - fetching a COS needs to happen via ObjectId so we get all the properties - searching by name returns only the display
        /// name and ObjectId but not all the rest of the properties.
        /// </summary>
        /// <param name="pCosName">
        /// Display name of the COS to search for
        /// </param>
        /// <returns>
        /// ObjectId of the COS with the name if found, or blank string if not.
        /// </returns>
        private string GetObjectIdByCosName(string pCosName)
        {
            string strUrl = string.Format("{0}coses/?query=(DisplayName is {1})", HomeServer.BaseUrl, pCosName.UriSafe());

            //issue the command to the CUPI interface
            WebCallResult res = HomeServer.GetCupiResponse(strUrl, MethodType.GET, "");

            if (res.Success == false)
            {
                return("");
            }

            List <ClassOfService> oCoses = HomeServer.GetObjectsFromJson <ClassOfService>(res.ResponseText, "Cos");

            if (oCoses == null)
            {
                return("");
            }

            foreach (var oCos in oCoses)
            {
                if (oCos.DisplayName.Equals(pCosName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(oCos.ObjectId);
                }
            }

            return("");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns the message count for a specific folder type (inbox, sent, deleted)
        /// </summary>
        /// <param name="pFolder">
        /// Mailbox folder to fetch count for
        /// </param>
        /// <param name="pCount">
        /// Message count for the folder type
        /// </param>
        /// <returns>
        /// Instance of the WebCallResult class with details of the fetch and results from the server
        /// </returns>
        public WebCallResult GetFolderCount(FolderTypes pFolder, out int pCount)
        {
            pCount = 0;
            string strUrl = string.Format("{0}mailbox/folders/{1}?userobjectid={2}", HomeServer.BaseUrl, pFolder.ToString(), UserObjectId);

            //issue the command to the CUPI interface
            WebCallResult res = HomeServer.GetCupiResponse(strUrl, MethodType.GET, "");

            if (res.Success == false)
            {
                return res;
            }

            Folder oFolder= HomeServer.GetObjectFromJson<Folder>(res.ResponseText, "Folder");

            if (oFolder==null)
            {
                res.ErrorText = "Failure parsing JSON response into MailboxInfo class:" + res.ResponseText;
                res.Success = false;
                return res;
            }

            pCount = oFolder.MessageCount;
            return res;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Fill the current instance of a PrivateList in with properties fetched from the server.  When getting a list of
        /// lists or searching by alias you get a "short" list of properties - unfortunatley this is short by 4 or 5 properties which
        /// is not worth a nested "FullList" and "BaseList" approach used with users (which have a much larger delta in properties). Further
        /// two of those properties missing are the extension and voice name path which are so commonly needed items that it's worth the
        /// extra fetch to get them here.
        /// </summary>
        /// <param name="pObjectId">
        /// GUID identifier of the list to be fetched.  Either this or the Alias needs to be provided.
        /// </param>
        /// <param name="pNumericId">
        /// </param>
        /// <returns>
        /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface.
        /// </returns>
        private WebCallResult GetPrivateList(string pObjectId, int pNumericId)
        {
            WebCallResult res;

            if (string.IsNullOrEmpty(pObjectId))
            {
                //get the list by ID - you can't do this via URL construction so just fetch the entire list of private lists and find the one
                //with the ID you want and copy it into the current instance
                List <PrivateList> oLists;
                res = GetPrivateLists(HomeServer, _userOwnerObjectId, out oLists);
                if (res.Success == false)
                {
                    return(res);
                }

                foreach (PrivateList oList in oLists)
                {
                    if (oList.NumericId == pNumericId)
                    {
                        //cheesy object copy
                        this.DisplayName = oList.DisplayName;
                        this.NumericId   = oList.NumericId;
                        this.ObjectId    = oList.ObjectId;
                    }
                }
            }
            else
            {
                //go fetch the private list by ObjectId
                string strUrl = string.Format("{0}users/{1}/privatelists/{2}", HomeServer.BaseUrl, _userOwnerObjectId, pObjectId);

                //issue the command to the CUPI interface
                res = HomeServer.GetCupiResponse(strUrl, MethodType.GET, "");

                if (res.Success == false)
                {
                    return(res);
                }

                try
                {
                    JsonConvert.PopulateObject(res.ResponseText, this, RestTransportFunctions.JsonSerializerSettings);
                }
                catch (Exception ex)
                {
                    res.ErrorText = "Failure populating class instance form JSON response:" + ex;
                    res.Success   = false;
                }
            }

            //all the updates above will flip pending changes into the queue - clear that here.
            this.ClearPendingChanges();

            if (string.IsNullOrEmpty(this.ObjectId))
            {
                res.Success = false;
            }

            return(res);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Fills the current instance of InterviewHandlerQuestion in with properties fetched from the server.
        /// </summary>
        /// <param name="pInterviewHandlerObjectId">
        /// Unique GUID of the interview handler this question is associatded with
        /// </param>
        /// <param name="pQuestionNumber">
        /// 1-20
        /// </param>
        /// <returns>
        /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface.
        /// </returns>
        private WebCallResult GetInterviewQuestion(string pInterviewHandlerObjectId, int pQuestionNumber)
        {
            if (string.IsNullOrEmpty(pInterviewHandlerObjectId))
            {
                return(new WebCallResult
                {
                    Success = false,
                    ErrorText = "No value for ObjectId or display name passed to GetInterviewHandler."
                });
            }

            string strUrl = string.Format("{0}handlers/interviewhandlers/{1}/interviewquestions/{2}", HomeServer.BaseUrl, pInterviewHandlerObjectId, pQuestionNumber);

            //issue the command to the CUPI interface
            WebCallResult res = HomeServer.GetCupiResponse(strUrl, MethodType.GET, "");

            if (res.Success == false)
            {
                return(res);
            }

            try
            {
                JsonConvert.PopulateObject(ConnectionServerRest.StripJsonOfObjectWrapper(res.ResponseText, "InterviewQuestion"), this,
                                           RestTransportFunctions.JsonSerializerSettings);
            }
            catch (Exception ex)
            {
                res.ErrorText = "Failure populating class instance form JSON response:" + ex;
                res.Success   = false;
            }

            return(res);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Fills current instance of class with details of post greeting recording for objectId passed in if found.
        /// </summary>
        /// <param name="pObjectId">
        /// Unique Id for post greeting recording to load
        /// </param>
        /// <param name="pDisplayName">
        /// Optional name of post greeting recording to find
        /// </param>
        /// <returns>
        /// Instance of WebCallResult class
        /// </returns>
        private WebCallResult GetPostGreetingRecording(string pObjectId, string pDisplayName)
        {
            WebCallResult res = new WebCallResult();

            res.Success = false;

            string strObjectId = pObjectId;

            if (string.IsNullOrEmpty(pObjectId))
            {
                strObjectId = GetObjectIdFromName(pDisplayName);
                if (string.IsNullOrEmpty(strObjectId))
                {
                    res.ErrorText = "Could not find post greeting recording by name=" + pDisplayName;
                    return(res);
                }
            }

            string strUrl = HomeServer.BaseUrl + "postgreetingrecordings/" + strObjectId;

            //issue the command to the CUPI interface
            res = HomeServer.GetCupiResponse(strUrl, MethodType.GET, "");

            if (res.Success == false)
            {
                return(res);
            }

            try
            {
                JsonConvert.PopulateObject(res.ResponseText, this, RestTransportFunctions.JsonSerializerSettings);
            }
            catch (Exception ex)
            {
                res.ErrorText = "Failure populating class instance form JSON response:" + ex;
                res.Success   = false;
            }


            return(res);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Fetch an external service ObjectId by it's name -
        /// </summary>
        /// <param name="pServiceName">
        /// Display name of the service to search for
        /// </param>
        /// <returns>
        /// ObjectId of the external service with the name if found, or blank string if not.
        /// </returns>
        private string GetObjectIdByServiceName(string pServiceName)
        {
            string strUrl = string.Format("{0}externalservices/?query=(DisplayName is {1})", HomeServer.BaseUrl, pServiceName.UriSafe());

            WebCallResult res = HomeServer.GetCupiResponse(strUrl, MethodType.GET, "");

            if (res.Success == false || res.TotalObjectCount == 0)
            {
                return("");
            }

            List <ExternalService> oServices = HomeServer.GetObjectsFromJson <ExternalService>(res.ResponseText);

            foreach (var oService in oServices)
            {
                if (oService.DisplayName.Equals(pServiceName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(oService.ObjectId);
                }
            }

            return("");
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the list of all installed languages and resturns them as a generic list of InstalledLangauge objects.
        /// </summary>
        /// <returns>
        /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface.
        /// </returns>
        private WebCallResult GetInstalledLanguages()
        {
            string strUrl = HomeServer.BaseUrl + "installedlanguages";

            //issue the command to the CUPI interface
            WebCallResult res = HomeServer.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 means an error in this case - should always be at least one template
            if (string.IsNullOrEmpty(res.ResponseText) || res.TotalObjectCount == 0)
            {
                InstalledLanguages = new List <InstalledLanguage>();
                res.Success        = false;
                return(res);
            }

            InstalledLanguages = HomeServer.GetObjectsFromJson <InstalledLanguage>(res.ResponseText);

            if (InstalledLanguages == null || InstalledLanguages.Count == 0)
            {
                res.Success   = false;
                res.ErrorText = "Failed to fetch installed languages on server";
                return(res);
            }

            foreach (var oLanguage in InstalledLanguages)
            {
                oLanguage.HomeServer = HomeServer;
            }

            return(res);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Fetches a message handler object filled with all the properties for a specific entry identified with the ObjectId
        /// of the user that owns it
        /// CUPI returns it as a list even though it's a single entry so we have to treat it as though we're fetching a list of
        /// objects.
        /// </summary>
        /// <returns>
        /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface.
        /// </returns>
        public WebCallResult GetMessageHandler()
        {
            string strUrl = string.Format("{0}users/{1}/messagehandlers", HomeServer.BaseUrl, SubscriberObjectId);
            List <MessageHandler> oTemp = new List <MessageHandler>();
            var res = HomeServer.GetCupiResponse(strUrl, MethodType.GET, null);

            if (!res.Success)
            {
                return(res);
            }
            if (res.TotalObjectCount != 1)
            {
                res.Success   = false;
                res.ErrorText = "Object count returned from messageHandler fetch not equal to 1";
                return(res);
            }
            oTemp = HomeServer.GetObjectsFromJson <MessageHandler>(res.ResponseText);
            if (oTemp.Count != 1)
            {
                res.Success   = false;
                res.ErrorText = "Objects returned from JSON parse of messageHandler fetch not equal to 1";
                return(res);
            }

            var oItem = oTemp.First();

            this.DeliveryReceiptAction = oItem.DeliveryReceiptAction;
            this.EmailAction           = oItem.EmailAction;
            this.FaxAction             = oItem.FaxAction;
            this.ObjectId        = oItem.ObjectId;
            this.RelayAddress    = oItem.RelayAddress;
            this.VoicemailAction = oItem.VoicemailAction;


            ClearPendingChanges();
            return(res);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Fetch the ObjectId of a global user by it's alias.  Empty string returned if not match is found.
        /// </summary>
        /// <param name="pAlias">
        /// Alias of the global user to find
        /// </param>
        /// <returns>
        /// ObjectId of global user if found or empty string if not.
        /// </returns>
        private string GetObjectIdFromAlias(string pAlias)
        {
            string strUrl = string.Format("{0}globalusers?query=(Alias is {1})", HomeServer.BaseUrl, pAlias.UriSafe());

            //issue the command to the CUPI interface
            WebCallResult res = HomeServer.GetCupiResponse(strUrl, MethodType.GET, "");

            if (res.Success == false || res.TotalObjectCount == 0)
            {
                return("");
            }

            List <GlobalUser> oTemplates = HomeServer.GetObjectsFromJson <GlobalUser>(res.ResponseText);

            foreach (var oTemplate in oTemplates)
            {
                if (oTemplate.Alias.Equals(pAlias, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(oTemplate.ObjectId);
                }
            }

            return("");
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Fetch the ObjectId of a schedule set by it's name.  Empty string returned if not match is found.
        /// </summary>
        /// <param name="pName">
        /// Name of the schedule set to find
        /// </param>
        /// <returns>
        /// ObjectId of schedule set if found or empty string if not.
        /// </returns>
        private string GetObjectIdFromName(string pName)
        {
            string strUrl = HomeServer.BaseUrl + string.Format("schedulesets/?query=(DisplayName is {0})", pName.UriSafe());

            //issue the command to the CUPI interface
            WebCallResult res = HomeServer.GetCupiResponse(strUrl, MethodType.GET, "");

            if (res.Success == false || res.TotalObjectCount == 0)
            {
                return "";
            }

            List<ScheduleSet> oTemplates = HomeServer.GetObjectsFromJson<ScheduleSet>(res.ResponseText);

            foreach (var oTemplate in oTemplates)
            {
                if (oTemplate.DisplayName.Equals(pName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return oTemplate.ObjectId;
                }
            }

            return "";
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Fetch a port group ObjectId by it's name -
        /// </summary>
        /// <param name="pPhoneSystemName">
        /// Display name of the port group to search for
        /// </param>
        /// <returns>
        /// ObjectId of the port group with the name if found, or blank string if not.
        /// </returns>
        private string GetObjectIdByPortGroupName(string pPhoneSystemName)
        {
            string strUrl = string.Format("{0}portgroups/?query=(DisplayName is {1})", HomeServer.BaseUrl, pPhoneSystemName.UriSafe());

            //issue the command to the CUPI interface
            WebCallResult res = HomeServer.GetCupiResponse(strUrl, MethodType.GET, "");

            if (res.Success == false || res.TotalObjectCount == 0)
            {
                return("");
            }

            List <PortGroup> oPortGroups = HomeServer.GetObjectsFromJson <PortGroup>(res.ResponseText);

            foreach (var oPortGroup in oPortGroups)
            {
                if (oPortGroup.DisplayName.Equals(pPhoneSystemName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(oPortGroup.ObjectId);
                }
            }

            return("");
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Fetch the ObjectId of a search space by it's name.  Empty string returned if not match is found.
        /// </summary>
        /// <param name="pName">
        /// Name of the search space to find
        /// </param>
        /// <returns>
        /// ObjectId of search space if found or empty string if not.
        /// </returns>
        private string GetObjectIdFromName(string pName)
        {
            string strUrl = HomeServer.BaseUrl + string.Format("searchspaces/?query=(Name is {0})", pName.UriSafe());

            //issue the command to the CUPI interface
            WebCallResult res = HomeServer.GetCupiResponse(strUrl, MethodType.GET, "");

            if (res.Success == false || res.TotalObjectCount == 0)
            {
                return("");
            }

            List <SearchSpace> oSearchSpaces = HomeServer.GetObjectsFromJson <SearchSpace>(res.ResponseText);

            foreach (var oSpace in oSearchSpaces)
            {
                if (oSpace.Name.Equals(pName, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(oSpace.ObjectId);
                }
            }

            return("");
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Builds an instance of an MenuEntry object, filling it with the details of a menu entry idenitified by the
        /// CallHandlerObjectID and the key name of the menu entry.
        /// This MenuEntry has already been created - you can use this to "re fill" an existing menu entry with possibly
        /// updated information or if you created an "empty" MenuEntry object and now want to populate it.
        /// </summary>
        /// <param name="pKey">
        /// name of the menu entry to be fetched - can be 0-9, # or *
        /// </param>
        /// <returns>
        /// Instance of the WebCallResults class containing details of the items sent and recieved from the CUPI interface.
        /// </returns>
        public WebCallResult GetMenuEntry(string pKey)
        {
            WebCallResult res;

            if (string.IsNullOrEmpty(pKey))
            {
                res           = new WebCallResult();
                res.ErrorText = "Empty menu entry key parameter passed to GetMenuEntry";
                return(res);
            }

            string strUrl = string.Format("{0}handlers/callhandlers/{1}/menuentries/{2}", HomeServer.BaseUrl, CallHandlerObjectId, pKey);

            //issue the command to the CUPI interface
            res = HomeServer.GetCupiResponse(strUrl, MethodType.GET, "");

            if (res.Success == false)
            {
                return(res);
            }

            try
            {
                JsonConvert.PopulateObject(ConnectionServerRest.StripJsonOfObjectWrapper(res.ResponseText, "MenuEntry"), this,
                                           RestTransportFunctions.JsonSerializerSettings);
            }
            catch (Exception ex)
            {
                res.ErrorText = "Failure populating class instance form JSON response:" + ex;
                res.Success   = false;
            }

            //all the updates above will flip pending changes into the queue - clear that here.
            this.ClearPendingChanges();
            return(res);
        }