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); } }
private static void checkManagerAPI() { manager = new ManagerConnection(ASTERISK_HOST, ASTERISK_PORT, ASTERISK_LOGINNAME, ASTERISK_LOGINPWD); // Register user event class manager.RegisterUserEventClass(typeof(UserAgentLoginEvent)); // Add or Remove events manager.UserEvents += new UserEventHandler(dam_UserEvents); // Dont't display this event manager.NewExten += new NewExtenEventHandler(manager_IgnoreEvent); // Display all other manager.UnhandledEvent += new ManagerEventHandler(dam_Events); // +++ Only to debug purpose manager.FireAllEvents = true; // manager.DefaultEventTimeout = 0; // manager.DefaultResponseTimeout = 0; manager.PingInterval = 0; // +++ try { manager.Login(); // Login only (fast) Console.WriteLine("Asterisk version : " + manager.Version); } catch (Exception ex) { Console.WriteLine(ex); Console.ReadLine(); manager.Logoff(); return; } { Console.WriteLine("\nGetConfig action"); ManagerResponse response = manager.SendAction(new GetConfigAction("manager.conf")); if (response.IsSuccess()) { GetConfigResponse responseConfig = (GetConfigResponse)response; foreach (int key in responseConfig.Categories.Keys) { Console.WriteLine(string.Format("{0}:{1}", key, responseConfig.Categories[key])); foreach (int keyLine in responseConfig.Lines(key).Keys) { Console.WriteLine(string.Format("\t{0}:{1}", keyLine, responseConfig.Lines(key)[keyLine])); } } } else Console.WriteLine(response); } { Console.WriteLine("\nUpdateConfig action"); UpdateConfigAction config = new UpdateConfigAction("manager.conf", "manager.conf"); config.AddCommand(UpdateConfigAction.ACTION_NEWCAT, "testadmin"); config.AddCommand(UpdateConfigAction.ACTION_APPEND, "testadmin", "secret", "blabla"); ManagerResponse response = manager.SendAction(config); Console.WriteLine(response); } // Originate call example Console.WriteLine("\nPress ENTER key to originate call.\n" + "Start phone (or connect) or make a call to see events.\n" + "After all events press a key to originate call."); Console.ReadLine(); OriginateAction oc = new OriginateAction(); oc.Context = ORIGINATE_CONTEXT; oc.Priority = "1"; oc.Channel = ORIGINATE_CHANNEL; oc.CallerId = ORIGINATE_CALLERID; oc.Exten = ORIGINATE_EXTEN; oc.Timeout = ORIGINATE_TIMEOUT; // oc.Variable = "VAR1=abc|VAR2=def"; // oc.SetVariable("VAR3", "ghi"); ManagerResponse originateResponse = manager.SendAction(oc, oc.Timeout); Console.WriteLine("Response:"); Console.WriteLine(originateResponse); Console.WriteLine("Press ENTER key to next test."); Console.ReadLine(); // // Display result of Show Queues command // { CommandAction command = new CommandAction(); CommandResponse response = new CommandResponse(); if (manager.AsteriskVersion == AsteriskVersion.ASTERISK_1_6) command.Command = "queue show"; else command.Command = "show queues"; try { response = (CommandResponse)manager.SendAction(command); Console.WriteLine("Result of " + command.Command); foreach (string str in response.Result) Console.WriteLine("\t" + str); } catch (Exception err) { Console.WriteLine("Response error: " + err); } Console.WriteLine("Press ENTER to next test or CTRL-C to exit."); Console.ReadLine(); } // // Display Queues and Members // ResponseEvents re; try { re = manager.SendEventGeneratingAction(new QueueStatusAction()); } catch (EventTimeoutException e) { // this happens with Asterisk 1.0.x as it doesn't send a QueueStatusCompleteEvent re = e.PartialResult; } foreach (ManagerEvent e in re.Events) { if (e is QueueParamsEvent) { QueueParamsEvent qe = (QueueParamsEvent)e; Console.WriteLine("QueueParamsEvent" + "\n\tQueue:\t\t" + qe.Queue + "\n\tServiceLevel:\t" + qe.ServiceLevel); } else if (e is QueueMemberEvent) { QueueMemberEvent qme = (QueueMemberEvent)e; Console.WriteLine("QueueMemberEvent" + "\n\tQueue:\t\t" + qme.Queue + "\n\tLocation:\t" + qme.Location); } else if (e is QueueEntryEvent) { QueueEntryEvent qee = (QueueEntryEvent)e; Console.WriteLine("QueueEntryEvent" + "\n\tQueue:\t\t" + qee.Queue + "\n\tChannel:\t" + qee.Channel + "\n\tPosition:\t" + qee.Position); } } Console.WriteLine("Press ENTER to next test or CTRL-C to exit."); Console.ReadLine(); // // To test create 3 extensions: // 1 - SIP/4012 w/o voicemail (with eyeBeam softphone) // 2 - IAX2/4008 w/o voicemail (with iaxComm softphone) // 3 - SIP/4010 w/ voicemal but no phone connect // RedirectCall: call from IAX2/4008 to SIP/4012 // Don't answer on SIP/4012 and call must redirect to SIP/4010 (to voicemail really) // Dial event used to define redirect channel Console.WriteLine("Redirect Call from " + ORIGINATE_CHANNEL + " to " + ORIGINATE_EXTRA_CHANNEL + " or press ESC."); // Wait for Dial Event from ORIGINATE_CHANNEL DialEventHandler de = new DialEventHandler(dam_Dial); manager.Dial += de; while (transferChannel == null) { System.Threading.Thread.Sleep(100); if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape) break; } manager.Dial -= de; // Now send Redirect action RedirectAction ra = new RedirectAction(); ra.Channel = transferChannel; ra.ExtraChannel = ORIGINATE_EXTRA_CHANNEL; ra.Context = ORIGINATE_CONTEXT; ra.Exten = ORIGINATE_EXTRA_EXTEN; ra.Priority = 1; try { ManagerResponse mr = manager.SendAction(ra, 10000); Console.WriteLine("Transfer Call" + "\n\tResponse:" + mr.Response + "\n\tMessage:" + mr.Message ); } catch (Exception ex) { Console.WriteLine(ex.Message); } // Monitor call. // Call from IA2/4008 to SIP/4012 // Link event used to define monitor channel Console.WriteLine("Monitor call. Please call " + ORIGINATE_CHANNEL + " and answer or press ESC."); // Wait for Link event LinkEventHandler le = new LinkEventHandler(dam_Link); manager.Link += le; while (monitorChannel == null) { System.Threading.Thread.Sleep(100); if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape) break; } manager.Link -= le; // Now send Monitor action MonitorAction ma = new MonitorAction(); ma.Channel = monitorChannel; ma.File = "voicefile"; ma.Format = "gsm"; ma.Mix = true; try { ManagerResponse mr = manager.SendAction(ma, 10000); Console.WriteLine("Monitor Call" + "\n\tResponse:" + mr.Response); } catch (Exception ex) { Console.WriteLine(ex.Message); } manager.Logoff(); }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } } }
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); } }
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); } }
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); } } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
protected void addTrunk(List<Asterisks> asteriskList) { updateSipConfig = new UpdateConfigAction(SIP_CONFIG, SIP_CONFIG); foreach (Asterisks asterisk in asteriskList) { updateSipConfig.AddCommand(UpdateConfigAction.ACTION_NEWCAT, asterisk.name_Asterisk); updateSipConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, asterisk.name_Asterisk, "host", asterisk.ip_address); updateSipConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, asterisk.name_Asterisk, "type", "peer"); updateSipConfig.AddCommand(UpdateConfigAction.ACTION_APPEND, asterisk.name_Asterisk, "context", "trunksFromWebApp"); } managerResponse = managerConnection.SendAction(updateSipConfig); if (!managerResponse.IsSuccess() && !rollbackState) { throw new ManagerException(managerResponse.Message); } }