forked from Montesuma80/3cx-web-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drop.cs
67 lines (64 loc) · 2.26 KB
/
drop.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Text;
using TCX.Configuration;
using TCX.PBXAPI;
using System.Threading;
using System.IO;
using System.Reflection;
using System.Linq;
using System.Net;
namespace WebAPI
{
public class dropcall
{
public static string dropcallid(string args1)
{
Console.ForegroundColor = ConsoleColor.Green;
Logger.WriteLine("ActiveConnection Number for this Extension: " + args1);
Console.ResetColor();
string mod2 = "";
int callidisset = 0;
using (var dn = PhoneSystem.Root.GetDNByNumber(args1))
{
if (dn.ID != 0)
{
Logger.WriteLine($"Call {dn.ID}:");
}
using (var connections = dn.GetActiveConnections().GetDisposer())
{
if (connections.Count() == 0)
{
return "false";
}
var alltakenconnections = connections.ToDictionary(x => x, y => y.OtherCallParties);
foreach (var kv in alltakenconnections)
{
callidisset = 1;
var owner = kv.Key;
Console.ForegroundColor = ConsoleColor.Green;
Logger.WriteLine($"Call {kv.Key.CallID}:");
Logger.WriteLine($"ID {kv.Key.ID}:");
Logger.WriteLine("Active Connection Number is:");
Logger.WriteLine(mod2);
Console.ResetColor();
mod2 = "" + kv.Key.ID;
}
}
}
if (callidisset != 0)
{
PhoneSystem.Root.GetByID<ActiveConnection>(int.Parse(mod2)).Drop();
return "true";
}
else if (callidisset == 0)
{
return "false";
}
else
{
return "other error";
}
}
}
}