Beispiel #1
2
 protected void addInclude(List<Asterisks> asteriskList)
 {
     updateExtensionsConfig = new UpdateConfigAction(EXTENSIONS_CONFIG, EXTENSIONS_CONFIG);
     foreach (Asterisks asterisk in asteriskList)
     {
         updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, "trunksFromWebApp", "include", asterisk.name_Asterisk);
     }
     managerResponse = managerConnection.SendAction(updateExtensionsConfig);
     if (!managerResponse.IsSuccess() && !rollbackState)
     {
         throw new ManagerException(managerResponse.Message);
     }
 }
Beispiel #2
1
    protected void createInitialContexts(List<Asterisks> asteriskList)
    {
        managerResponse = managerConnection.SendAction(new GetConfigAction(EXTENSIONS_CONFIG));
        updateExtensionsConfig = new UpdateConfigAction(EXTENSIONS_CONFIG, EXTENSIONS_CONFIG);
        if (managerResponse.IsSuccess())
        {
            GetConfigResponse responseConfig = (GetConfigResponse)managerResponse;
            string createdPrefix = Utils.createPrefix(asteriskList.Last().prefix_Asterisk);
            updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_NEWCAT, "trunksFromWebApp");
            updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, "trunksFromWebApp", "exten", "_" + createdPrefix + ",1,NoOp()");
            updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, "trunksFromWebApp", "exten", "_" + createdPrefix + ",n,Dial(SIP/${EXTEN})");
            updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, "trunksFromWebApp", "exten", "_" + createdPrefix + ",n,HangUp()");
            asteriskList.RemoveAt(asteriskList.Count-1);
            foreach (int key in responseConfig.Categories.Keys)
            {
                string extensionsCategory = responseConfig.Categories[key];

                if (!asteriskList.Contains(asteriskList.Find(asterisk => asterisk.name_Asterisk.Equals(extensionsCategory))) && ! extensionsCategory.Equals("globals") && !extensionsCategory.Equals("general"))
                {
                    updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, extensionsCategory, "include", "trunksFromWebApp");
                }
            }
            foreach(Asterisks asterisk in asteriskList)
            {
                updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, "trunksFromWebApp", "include", asterisk.name_Asterisk);
            }
            managerResponse = managerConnection.SendAction(updateExtensionsConfig);
            if (!managerResponse.IsSuccess() && !rollbackState)
            {
                throw new ManagerException(managerResponse.Message);
            }
        }
        else
        {
            throw new ManagerException(managerResponse.Message);
        }
    }
        public void HandleResponse(ManagerResponse response)
        {
            events.Response = response;
            if (response is ManagerError)
                events.Complete = true;

            if (events.Complete && autoEvent != null)
                autoEvent.Set();
        }
Beispiel #4
0
 protected void addInclude(string trunkName)
 {
     updateExtensionsConfig = new UpdateConfigAction(EXTENSIONS_CONFIG, EXTENSIONS_CONFIG);
     updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, "trunksFromWebApp", "include", trunkName);
     managerResponse = managerConnection.SendAction(updateExtensionsConfig);
     if (!managerResponse.IsSuccess() && !rollbackState)
     {
         throw new ManagerException(managerResponse.Message);
     }
 }
Beispiel #5
0
 protected void addContext(string contextName, string prefix)
 {
     string createdPrefix = Utils.createPrefix(prefix);
     updateExtensionsConfig = new UpdateConfigAction(EXTENSIONS_CONFIG, EXTENSIONS_CONFIG);
     updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_NEWCAT, contextName);
     updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, contextName, "exten", "_" + createdPrefix + ",1,NoOp()");
     updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, contextName, "exten", "_" + createdPrefix + ",n,Dial(SIP/${EXTEN}@" + contextName + ")");
     updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, contextName, "exten", "_" + createdPrefix + ",n,HangUp()");
     managerResponse = managerConnection.SendAction(updateExtensionsConfig);
     if (!managerResponse.IsSuccess() && !rollbackState)
     {
         throw new ManagerException(managerResponse.Message);
     }
 }
Beispiel #6
0
 protected void addContext(List<Asterisks> asteriskList)
 {
     updateExtensionsConfig = new UpdateConfigAction(EXTENSIONS_CONFIG, EXTENSIONS_CONFIG);
     foreach (Asterisks asterisk in asteriskList)
     {
         string createdPrefix = Utils.createPrefix(asterisk.prefix_Asterisk);
         updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_NEWCAT, asterisk.name_Asterisk);
         updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, asterisk.name_Asterisk, "exten", "_" + createdPrefix + ",1,NoOp()");
         updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, asterisk.name_Asterisk, "exten", "_" + createdPrefix + ",n,Dial(SIP/${EXTEN}@" + asterisk.name_Asterisk + ")");
         updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, asterisk.name_Asterisk, "exten", "_" + createdPrefix + ",n,HangUp()");
     }
     managerResponse = managerConnection.SendAction(updateExtensionsConfig);
     if (!managerResponse.IsSuccess() && !rollbackState)
     {
         throw new ManagerException(managerResponse.Message);
     }
 }
Beispiel #7
0
 protected void updateTrunk(string oldTrunkName, string newTrunkName, string newHostIP, string oldHostIP)
 {
     updateSipConfig = new UpdateConfigAction(SIP_CONFIG, SIP_CONFIG);
     updateSipConfig.AddCommand(UpdateConfigAction.ACTION_RENAMECAT, oldTrunkName, null, newTrunkName);
     updateSipConfig.AddCommand(UpdateConfigAction.ACTION_UPDATE, newTrunkName, "host", newHostIP, oldHostIP);
     managerResponse = managerConnection.SendAction(updateSipConfig);
     if (!managerResponse.IsSuccess() && !rollbackState)
     {
         throw new ManagerException(managerResponse.Message);
     }
 }
Beispiel #8
0
 protected void reloadModules()
 {
     updateSipConfig = new UpdateConfigAction(SIP_CONFIG, SIP_CONFIG, true);
     updateExtensionsConfig = new UpdateConfigAction(EXTENSIONS_CONFIG, EXTENSIONS_CONFIG, true);
     managerResponse = managerConnection.SendAction(updateSipConfig);
     managerResponse = managerConnection.SendAction(updateExtensionsConfig);
 }
Beispiel #9
0
 protected void deleteContext(string deletedContext)
 {
     updateExtensionsConfig = new UpdateConfigAction(EXTENSIONS_CONFIG, EXTENSIONS_CONFIG);
     updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_DELCAT, deletedContext);
     updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_DELETE, "trunksFromWebApp", "include", deletedContext, deletedContext);
     managerResponse = managerConnection.SendAction(updateExtensionsConfig);
     if (!managerResponse.IsSuccess() && !rollbackState)
     {
         throw new ManagerException(managerResponse.Message);
     }
 }
Beispiel #10
0
 protected void updateTLS(Asterisks currentAsterisk, Asterisks updatedAsterisk, Asterisks originalAsterisk)
 {
     updateSipConfig = new UpdateConfigAction(SIP_CONFIG, SIP_CONFIG);
     if (currentAsterisk.tls_enabled == 1 && updatedAsterisk.tls_enabled == 0 && originalAsterisk.tls_enabled == 1)
     {
         updateSipConfig.AddCommand(UpdateConfigAction.ACTION_DELETE, updatedAsterisk.name_Asterisk, "transport", "tls", "tls");
     }
     else if (currentAsterisk.tls_enabled == 1 && updatedAsterisk.tls_enabled == 1 && originalAsterisk.tls_enabled == 0)
     {
         updateSipConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, updatedAsterisk.name_Asterisk, "transport", "tls", "tls");
     }
     managerResponse = managerConnection.SendAction(updateSipConfig);
     if (!managerResponse.IsSuccess() && !rollbackState)
     {
         throw new ManagerException(managerResponse.Message);
     }
 }
Beispiel #11
0
 protected void checkContexts(List<Asterisks> asteriskList)
 {
     managerResponse = managerConnection.SendAction(new GetConfigAction(EXTENSIONS_CONFIG));
     updateExtensionsConfig = new UpdateConfigAction(EXTENSIONS_CONFIG, EXTENSIONS_CONFIG);
     if (managerResponse.IsSuccess())
     {
         GetConfigResponse responseConfig = (GetConfigResponse)managerResponse;
         int remoteIndex = responseConfig.Categories.Values.ToList().IndexOf("trunksFromWebApp");
         foreach (int key in responseConfig.Categories.Keys)
         {
             string extensionsCategory = responseConfig.Categories[key];
             if (!extensionsCategory.Equals("trunksFromWebApp"))
             {
                 if (!asteriskList.Contains(asteriskList.Find(asterisk => asterisk.name_Asterisk.Equals(extensionsCategory))))
                 {
                     if (!responseConfig.Lines(key).ContainsValue("include=trunksFromWebApp") && !extensionsCategory.Equals("globals") && !extensionsCategory.Equals("general"))
                     {
                         updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, extensionsCategory, "include", "trunksFromWebApp");
                     }
                 }
             }
         }
         managerResponse = managerConnection.SendAction(updateExtensionsConfig);
         if (!managerResponse.IsSuccess() && !rollbackState)
         {
             throw new ManagerException(managerResponse.Message);
         }
     }
     else
     {
         throw new ManagerException(managerResponse.Message);
     }
 }
Beispiel #12
0
 protected void updateTLS(int newTLSstatus, string newCertDestination, string oldCertDestination, int oldTLSstatus, List<Asterisks> asteriskList)
 {
     updateSipConfig = new UpdateConfigAction(SIP_CONFIG, SIP_CONFIG);
     if (newTLSstatus == 1 && oldTLSstatus == 0)
     {
         updateSipConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, "globals", "tlsenable", "tls");
         updateSipConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, "globals", "tlscertfile", oldCertDestination);
         foreach (Asterisks asterisk in asteriskList)
         {
             if (asterisk.tls_enabled == 1)
                 updateSipConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, asterisk.name_Asterisk, "transport", "tls");
         }
     }
     else if (oldTLSstatus == 1 && newTLSstatus == 0)
     {
         updateSipConfig.AddCommand(UpdateConfigAction.ACTION_DELETE, "globals", "tlsenable", "tls", "tls");
         updateSipConfig.AddCommand(UpdateConfigAction.ACTION_DELETE, "globals", "tlscertfile", oldCertDestination, oldCertDestination);
         foreach (Asterisks asterisk in asteriskList)
         {
             if (asterisk.tls_enabled == 1)
                 updateSipConfig.AddCommand(UpdateConfigAction.ACTION_DELETE, asterisk.name_Asterisk, "transport", "tls", "tls");
         }
     }
     else if (oldTLSstatus == 1 && newTLSstatus == 1)
     {
         updateSipConfig.AddCommand(UpdateConfigAction.ACTION_UPDATE, "globals", "tlscertfile", newCertDestination, oldCertDestination);
     }
     managerResponse = managerConnection.SendAction(updateSipConfig);
     if (!managerResponse.IsSuccess() && !rollbackState)
     {
         throw new ManagerException(managerResponse.Message);
     }
 }
Beispiel #13
0
 protected void deleteInitialContexts(List<Asterisks> asteriskList)
 {
     updateExtensionsConfig = new UpdateConfigAction(EXTENSIONS_CONFIG, EXTENSIONS_CONFIG);
     updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_DELCAT, "trunksFromWebApp");
     managerResponse = managerConnection.SendAction(new GetConfigAction(EXTENSIONS_CONFIG));
     if (managerResponse.IsSuccess())
     {
         GetConfigResponse responseConfig = (GetConfigResponse)managerResponse;
         foreach (int key in responseConfig.Categories.Keys)
         {
             string extensionsCategory = responseConfig.Categories[key];
             if (extensionsCategory.Equals("trunksFromWebApp") || extensionsCategory.Equals("globals") || extensionsCategory.Equals("general"))
                 continue;
             if (asteriskList.Contains(asteriskList.Find(asterisk => asterisk.name_Asterisk.Equals(extensionsCategory))))
             {
                 updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_DELCAT, extensionsCategory);
             }
             else
             {
                 updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_DELETE, extensionsCategory, "include", "trunksFromWebApp", "trunksFromWebApp");
             }
         }
         managerResponse = managerConnection.SendAction(updateExtensionsConfig);
         if (!managerResponse.IsSuccess() && !rollbackState)
         {
             throw new ManagerException(managerResponse.Message);
         }
     }
     else
     {
         throw new ManagerException(managerResponse.Message);
     }
 }
Beispiel #14
0
		internal void DispatchResponse(Dictionary<string, string> buffer, ManagerResponse response)
		{
			string responseActionId = string.Empty;
			string actionId = string.Empty;
			IResponseHandler responseHandler = null;

			if (buffer != null)
			{
				if (buffer["response"].ToLower(Helper.CultureInfo) == "error")
					response = new ManagerError(buffer);
				else if (buffer.ContainsKey("actionid"))
					actionId = buffer["actionid"];
			}

			if (response != null)
				actionId = response.ActionId;

			if (!string.IsNullOrEmpty(actionId))
			{
				int hash = Helper.GetInternalActionId(actionId).GetHashCode();
				responseActionId = Helper.StripInternalActionId(actionId);
				responseHandler = GetRemoveResponseHandler(hash);

				if (response != null)
					response.ActionId = responseActionId;
				if (responseHandler != null)
				{
					if (response == null)
					{
						ManagerActionResponse action = responseHandler.Action as ManagerActionResponse;
						if (action == null || (response = action.ActionCompleteResponseClass() as ManagerResponse) == null)
							response = Helper.BuildResponse(buffer);
						else
							Helper.SetAttributes(response, buffer);
						response.ActionId = responseActionId;
					}

					try
					{
						responseHandler.HandleResponse(response);
					}
					catch (Exception ex)
					{
#if LOGGER
						logger.Error("Unexpected exception in responseHandler {0}\n{1}", response, ex);
#else
						throw new ManagerException("Unexpected exception in responseHandler " + responseHandler.GetType().FullName, ex);
#endif
					}
				}
			}
			
			if (response == null && buffer.ContainsKey("ping") && buffer["ping"] == "Pong")
			{
				response = Helper.BuildResponse(buffer);
				foreach (ResponseHandler pingHandler in pingHandlers.Values)
					pingHandler.HandleResponse(response);
				pingHandlers.Clear();
			}

			if (!reconnected)
				return;

			if (response == null)
			{
				response = Helper.BuildResponse(buffer);
				response.ActionId = responseActionId;
			}
#if LOGGER
			logger.Info("Reconnected - DispatchEvent : " + response);
#endif
			#region Support background reconnect
			if (response is ChallengeResponse)
			{
				string key = null;
				if (response.IsSuccess())
				{
					ChallengeResponse challengeResponse = (ChallengeResponse)response;
					string challenge = challengeResponse.Challenge;
					try
					{
						Util.MD5Support md = Util.MD5Support.GetInstance();
						if (challenge != null)
							md.Update(UTF8Encoding.UTF8.GetBytes(challenge));
						if (password != null)
							md.Update(UTF8Encoding.UTF8.GetBytes(password));
						key = Helper.ToHexString(md.DigestData);
					}
#if LOGGER
					catch (Exception ex)
					{
						logger.Error("Unable to create login key using MD5 Message Digest", ex);
#else
					catch
					{
#endif
						key = null;
					}
				}
				bool fail = true;
				if (!string.IsNullOrEmpty(key))
					try
					{
						Action.LoginAction loginAction = new Action.LoginAction(username, "MD5", key);
						SendAction(loginAction, null);
						fail = false;
					}
					catch { }
				if (fail)
					if (keepAliveAfterAuthenticationFailure)
						reconnect(true);
					else
						disconnect(true);
			}
			else if (response is ManagerError)
			{
				if (keepAliveAfterAuthenticationFailure)
					reconnect(true);
				else
					disconnect(true);
			}
			else if (response is ManagerResponse)
			{
				if (response.IsSuccess())
				{
					reconnected = false;
					enableEvents = true;
					reconnectEnable = keepAlive;
					ConnectEvent ce = new ConnectEvent(this);
					ce.Reconnect = true;
					ce.ProtocolIdentifier = protocolIdentifier;
					fireEvent(ce);
				}
				else if (keepAliveAfterAuthenticationFailure)
					reconnect(true);
				else
					disconnect(true);
			}
			#endregion
		}
Beispiel #15
0
 public void HandleResponse(ManagerResponse response)
 {
     TaskCompletionSource.TrySetResult(response);
 }
 public void Free()
 {
     autoEvent = null;
     action = null;
     response = null;
 }
Beispiel #17
0
 protected void deleteTLS(int tlsEnable, string certDestination)
 {
     updateSipConfig = new UpdateConfigAction(SIP_CONFIG, SIP_CONFIG);
     if (tlsEnable == 1)
     {
         updateSipConfig.AddCommand(UpdateConfigAction.ACTION_DELETE, "globals", "tlsenable", "tls", "tls");
         updateSipConfig.AddCommand(UpdateConfigAction.ACTION_DELETE, "globals", "tlscertfile", certDestination, certDestination);
         managerResponse = managerConnection.SendAction(updateSipConfig);
         if (!managerResponse.IsSuccess() && !rollbackState)
         {
             throw new ManagerException(managerResponse.Message);
         }
     }
 }
Beispiel #18
0
 protected List<string> getUsersByAsterisk(string asteriskName)
 {
     List<string> usersByAsteriskList = new List<string>();
     managerResponse = managerConnection.SendAction(new GetConfigAction(SIP_CONFIG));
     if (managerResponse.IsSuccess())
     {
         GetConfigResponse responseConfig = (GetConfigResponse)managerResponse;
         foreach (int key in responseConfig.Categories.Keys)
         {
             string sipCategory = responseConfig.Categories[key];
             if (sipCategory.Length == 9 && sipCategory.All(char.IsDigit))
             {
                 usersByAsteriskList.Add(sipCategory);
             }
         }
         return usersByAsteriskList;
     }
     else
         throw new ManagerException(managerResponse.Message);
 }
Beispiel #19
0
 protected List<string> getUserDetail(string prefix)
 {
     List<string> usersDetailList = new List<string>();
     managerResponse = managerConnection.SendAction(new GetConfigAction(SIP_CONFIG));
     if (managerResponse.IsSuccess())
     {
         GetConfigResponse responseConfig = (GetConfigResponse)managerResponse;
         foreach (int key in responseConfig.Categories.Keys)
         {
             string sipCategory = responseConfig.Categories[key];
             if (sipCategory.Equals(prefix))
             {
                 foreach (int keyLine in responseConfig.Lines(key).Keys)
                 {
                     usersDetailList.Add(responseConfig.Lines(key)[keyLine]);
                 }
                 break;
             }
         }
         return usersDetailList;
     }
     else
     {
         throw new ManagerException(managerResponse.Message);
     }
 }
Beispiel #20
0
 protected void deleteTrunk(List<Asterisks> asteriskList)
 {
     updateSipConfig = new UpdateConfigAction(SIP_CONFIG, SIP_CONFIG);
     foreach (Asterisks asterisk in asteriskList)
     {
         updateSipConfig.AddCommand(UpdateConfigAction.ACTION_DELCAT, asterisk.name_Asterisk);
     }
     managerResponse = managerConnection.SendAction(updateSipConfig);
     if (!managerResponse.IsSuccess() && !rollbackState)
     {
         throw new ManagerException(managerResponse.Message);
     }
 }
Beispiel #21
0
 protected void deleteTrunk(string trunkName)
 {
     updateSipConfig = new UpdateConfigAction(SIP_CONFIG, SIP_CONFIG);
     updateSipConfig.AddCommand(UpdateConfigAction.ACTION_DELCAT, trunkName);
     managerResponse = managerConnection.SendAction(updateSipConfig);
     if (!managerResponse.IsSuccess() && !rollbackState)
     {
         throw new ManagerException(managerResponse.Message);
     }
 }
Beispiel #22
0
 protected void addTLS(int tlsEnabled, string certDestination, List<Asterisks> asteriskList)
 {
     if (tlsEnabled == 1)
     {
         updateSipConfig = new UpdateConfigAction(SIP_CONFIG, SIP_CONFIG, true);
         updateSipConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, "globals", "tlsenable", "tls");
         updateSipConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, "globals", "tlscertfile", certDestination);
         foreach (Asterisks asterisk in asteriskList)
         {
             if (asterisk.tls_enabled == 1)
                 updateSipConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, asterisk.name_Asterisk, "transport", "tls");
         }
         managerResponse = managerConnection.SendAction(updateSipConfig);
         if (!managerResponse.IsSuccess() && !rollbackState)
         {
             throw new ManagerException(managerResponse.Message);
         }
     }
 }
Beispiel #23
0
 protected void relocateUser(string userNumber, List<string> userDetailList, out string originalContext)
 {
     originalContext = null;
     updateSipConfig = new UpdateConfigAction(SIP_CONFIG, SIP_CONFIG);
     updateSipConfig.AddCommand(UpdateConfigAction.ACTION_NEWCAT, userNumber);
     foreach (string item in userDetailList)
     {
         string[] items = item.Split('=');
         if (item.StartsWith("context"))
         {
             originalContext = items[1];
             updateSipConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, userNumber, "context", "trunksFromWebApp");
         }
         else
         {
             updateSipConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, userNumber, items[0], items[1]);
         }
     }
     managerResponse = managerConnection.SendAction(updateSipConfig);
     if (!managerResponse.IsSuccess() && !rollbackState)
     {
         throw new ManagerException(managerResponse.Message);
     }
 }
 /// <summary>
 ///     Creates a new instance.
 /// </summary>
 /// <param name="result">the result to store the response in</param>
 /// <param name="thread">the thread to interrupt when the response has been received</param>
 public ResponseHandler(ManagerAction action, AutoResetEvent autoEvent)
 {
     response = null;
     this.action = action;
     this.autoEvent = autoEvent;
 }
Beispiel #25
0
 protected void returnOriginalContext(string userName, string originalContext)
 {
     updateSipConfig = new UpdateConfigAction(SIP_CONFIG, SIP_CONFIG, true);
     updateSipConfig.AddCommand(UpdateConfigAction.ACTION_UPDATE, userName, "context", originalContext, "trunksFromWebApp");
     managerResponse = managerConnection.SendAction(updateSipConfig);
     if (!managerResponse.IsSuccess() && !rollbackState)
     {
         throw new ManagerException(managerResponse.Message);
     }
 }
 public virtual void HandleResponse(ManagerResponse response)
 {
     this.response = response;
     if (autoEvent != null)
         this.autoEvent.Set();
 }
Beispiel #27
0
 protected void sendUpdateDialPlanRequest(UpdateMessages message, TransferedUser transferedUser, string newCurrentAsterisk)
 {
     updateExtensionsConfig = new UpdateConfigAction(EXTENSIONS_CONFIG, EXTENSIONS_CONFIG, true);
     switch (message)
     {
         case UpdateMessages.addToTrunkContextInOriginal:
             updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, transferedUser.original_asterisk, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN})");
             break;
         case UpdateMessages.addToOriginalContext:
             updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, transferedUser.original_context, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")");
             break;
         case UpdateMessages.addToOthersAsteriskDialPlans:
             updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, transferedUser.original_asterisk, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")");
             break;
         case UpdateMessages.deleteInOriginalContext:
             updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_DELETE, transferedUser.original_context, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")");
             break;
         case UpdateMessages.deleteFromSourceAsteriskDialPlan:
             updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_DELETE, transferedUser.original_asterisk, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN})", transferedUser.name_user + ",1,Dial(SIP/${EXTEN})");
             break;
         case UpdateMessages.deleteFromRestAsteriskDialPlan:
             updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_DELETE, transferedUser.original_asterisk, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")");
             break;
         case UpdateMessages.updateDialPlanInDestinationAsterisk:
             updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_UPDATE, transferedUser.original_asterisk, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN})", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")");
             break;
         case UpdateMessages.updateInCurrentAsteriskDialPlan:
             updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_UPDATE, transferedUser.original_asterisk, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")", transferedUser.name_user + ",1,Dial(SIP/${EXTEN})");
             break;
         case UpdateMessages.updateInOriginalAsteriskDialPlan:
             updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_UPDATE, transferedUser.original_context, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + newCurrentAsterisk + ")", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")");
             break;
         case UpdateMessages.updateInRestAsteriskDialPlan:
             updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_UPDATE, transferedUser.original_asterisk, "exten", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + newCurrentAsterisk + ")", transferedUser.name_user + ",1,Dial(SIP/${EXTEN}@" + transferedUser.current_asterisk + ")");
             break;
         default:
             break;
     }
     managerResponse = managerConnection.SendAction(updateExtensionsConfig);
     if (!managerResponse.IsSuccess() && !rollbackState)
     {
         throw new ManagerException(managerResponse.Message);
     }
 }
Beispiel #28
0
		internal void DispatchResponse(ManagerResponse response)
		{
#if LOGGER
			logger.Debug("Dispatch response : {0}", response);
#endif
			DispatchResponse(null, response);
		}
Beispiel #29
0
 protected void updateContext(string oldContextName, string newContextName, string newPrefix)
 {
     string createdPrefix = Utils.createPrefix(newPrefix);
     updateExtensionsConfig = new UpdateConfigAction(EXTENSIONS_CONFIG, EXTENSIONS_CONFIG);
     updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_UPDATE, "trunksFromWebApp", "include", newContextName, oldContextName);
     updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_DELCAT, oldContextName);
     updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_NEWCAT, newContextName);
     updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, newContextName, "exten", "_" + createdPrefix + ",1,NoOp()");
     updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, newContextName, "exten", "_" + createdPrefix + ",n,Dial(SIP/${EXTEN}@" + newContextName + ")");
     updateExtensionsConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, newContextName, "exten", "_" + createdPrefix + ",n,HangUp()");
     managerResponse = managerConnection.SendAction(updateExtensionsConfig);
     if (!managerResponse.IsSuccess() && !rollbackState)
     {
         throw new ManagerException(managerResponse.Message);
     }
 }
Beispiel #30
0
        /// <summary>
        ///     Constructs an instance of ManagerResponse based on a map of attributes.
        /// </summary>
        /// <param name="attributes">the attributes and their values. The keys of this map must be all lower case.</param>
        /// <returns>the response with the given attributes.</returns>
        internal static ManagerResponse BuildResponse(Dictionary<string, string> attributes)
        {
            ManagerResponse response;

            string responseType = attributes["response"].ToLower(CultureInfo);

            // Determine type
            if (responseType == "error")
                response = new ManagerError();
            else if (attributes.ContainsKey("challenge"))
                response = new ChallengeResponse();
            else if (attributes.ContainsKey("mailbox") && attributes.ContainsKey("waiting"))
                response = new MailboxStatusResponse();
            else if (attributes.ContainsKey("mailbox") && attributes.ContainsKey("newmessages") &&
                     attributes.ContainsKey("oldmessages"))
                response = new MailboxCountResponse();
            else if (attributes.ContainsKey("exten") && attributes.ContainsKey("context") &&
                     attributes.ContainsKey("hint") && attributes.ContainsKey("status"))
                response = new ExtensionStateResponse();
            else
                response = new ManagerResponse();

            SetAttributes(response, attributes);
            return response;
        }
Beispiel #31
0
 protected void addTrunk(string trunkName, string hostIP, int currentTlsEnabled, int otherTlsEnabled)
 {
     updateSipConfig = new UpdateConfigAction(SIP_CONFIG, SIP_CONFIG);
     updateSipConfig.AddCommand(UpdateConfigAction.ACTION_NEWCAT, trunkName);
     updateSipConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, trunkName, "host", hostIP);
     updateSipConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, trunkName, "type", "peer");
     updateSipConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, trunkName, "context", "trunksFromWebApp");
     if (currentTlsEnabled == 1 && otherTlsEnabled == 1)
     {
         updateSipConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, trunkName, "transport", "tls");
     }
     managerResponse = managerConnection.SendAction(updateSipConfig);
     if (!managerResponse.IsSuccess() && !rollbackState)
     {
         throw new ManagerException(managerResponse.Message);
     }
 }