This commit is contained in:
Seth Reid 2016-12-06 09:26:13 +13:00
Родитель e5965e8098
Коммит 9906e98cf0
16 изменённых файлов: 209 добавлений и 60 удалений

Просмотреть файл

@ -9,5 +9,8 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.Common.Models
public string Username { get; set; }
public string Password { get; set; }
public string ApiRegistrationProvider { get; set; }
public string EnterpriseSenderNumber { get; set; }
public string RegistrationID { get; set; }
}
}

Просмотреть файл

@ -12,6 +12,11 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.Common.Models
public string Password { get; set; }
public string ApiRegistrationProviderType { get; set; }
// Erricsson Only
public string EnterpriseSenderNumber { get; set; }
public string RegistrationID { get; set; }
public string SmsEndpointBaseUrl { get; set; }
// when more providers are available take as param
public ApiRegistrationTableEntity()
{

Просмотреть файл

@ -12,6 +12,12 @@ using DeviceManagement.Infrustructure.Connectivity.Models.Other;
using DeviceManagement.Infrustructure.Connectivity.Models.Security;
using DeviceManagement.Infrustructure.Connectivity.Models.TerminalDevice;
using resource = DeviceManagement.Infrustructure.Connectivity.EricssonSubscriptionService.resource;
using System.Net.Http;
using Newtonsoft.Json;
using System.IO;
using System.Text;
using DeviceManagement.Infrustructure.Connectivity.Exceptions;
using DeviceManagement.Infrustructure.Connectivity.Models.Jasper;
namespace DeviceManagement.Infrustructure.Connectivity.Clients
{
@ -190,7 +196,7 @@ namespace DeviceManagement.Infrustructure.Connectivity.Clients
});
}
public List<SimState> GetSimStatesFromEricssonSimStateEnum()
{
return Enum.GetNames(typeof(subscriptionStatus)).Select(simStateName => new SimState()
@ -205,14 +211,14 @@ namespace DeviceManagement.Infrustructure.Connectivity.Clients
var subscriptionManagementClient = EricssonServiceBuilder.GetSubscriptionManagementClient(_credentialProvider.Provide());
//TODO SR should we wait for this process to be complete? It is long running I think
return subscriptionManagementClient.RequestSubscriptionPackageChange(new RequestSubscriptionPackageChange()
{
subscriptionPackage = updatedPackage,
resource = new resource()
{
subscriptionPackage = updatedPackage,
resource = new resource()
{
id = iccid,
type = "icc"
}
});
id = iccid,
type = "icc"
}
});
}
public ReconnectResponse ReconnectTerminal(string iccid)
@ -228,9 +234,45 @@ namespace DeviceManagement.Infrustructure.Connectivity.Clients
});
}
public bool SendSms(string iccid, string smsText)
public HttpWebResponse SendSMS(string msisdn, string messageContent)
{
return true;
var creds = (EricssonCredentials)_credentialProvider.Provide();
var senderAddress = creds.EnterpriseSenderNumber;
var smsEndpointBaseUrl = creds.SmsEndpointBaseUrl;
if (string.IsNullOrWhiteSpace(senderAddress) || string.IsNullOrWhiteSpace(smsEndpointBaseUrl))
{
throw new ApplicationException("You have not provided an EnterpriseSenderAddress and/or a SmsEndpointBaseUrl");
}
var uri = new Uri(creds.BaseUrl);
var webAddr = $"https://{smsEndpointBaseUrl}/dcpapi/smsmessaging/v1/outbound/tel: {senderAddress}/requests";
var httpWebRequest = (HttpWebRequest)WebRequest.Create(webAddr);
httpWebRequest.ContentType = "application/json; charset=utf-8";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
var request = new SendSmsRequest()
{
outboundSMSMessageRequest = new Outboundsmsmessagerequest()
{
address = new string[] { msisdn },
senderAddress = senderAddress,
outboundSMSTextMessage = new Outboundsmstextmessage()
{
message = messageContent
}
}
};
streamWriter.Write(JsonConvert.SerializeObject(request));
streamWriter.Flush();
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
return httpResponse;
}
private bool isAnActiveState(subscriptionStatus status)
@ -263,7 +305,7 @@ namespace DeviceManagement.Infrustructure.Connectivity.Clients
{
if (simStateList.All(s => s.Name != simState))
{
simStateList.Add(new SimState() {IsActive = true, Name = simState });
simStateList.Add(new SimState() { IsActive = true, Name = simState });
}
return simStateList;
}
@ -303,6 +345,24 @@ namespace DeviceManagement.Infrustructure.Connectivity.Clients
return ensureCurrentStateIsInList(result, currentState);
}
private class SendSmsRequest
{
public Outboundsmsmessagerequest outboundSMSMessageRequest { get; set; }
}
private class Outboundsmsmessagerequest
{
public string[] address { get; set; }
public string senderAddress { get; set; }
public Outboundsmstextmessage outboundSMSTextMessage { get; set; }
public string senderName { get; set; }
}
private class Outboundsmstextmessage
{
public string message { get; set; }
}
}
}

Просмотреть файл

@ -39,6 +39,7 @@
<Compile Include="Constants\JasperApiConstants.cs" />
<Compile Include="Exceptions\CellularConnectivityException.cs" />
<Compile Include="Argument.cs" />
<Compile Include="Models\Ericsson\EricssonCredentials.cs" />
<Compile Include="Models\Other\SubscriptionPackage.cs" />
<Compile Include="Models\Constants\ApiRegistrationProviderTypes.cs" />
<Compile Include="Models\Jasper\JasperCredentials.cs" />
@ -476,6 +477,10 @@
</WebReferenceUrl>
</ItemGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.EnterpriseServices" />
@ -544,9 +549,7 @@
<None Include="Service References\DeviceReconnect\configuration.svcinfo" />
<None Include="Service References\DeviceReconnect\configuration91.svcinfo" />
</ItemGroup>
<ItemGroup>
<Folder Include="Models\Ericsson\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

Просмотреть файл

@ -0,0 +1,12 @@
using DeviceManagement.Infrustructure.Connectivity.Models.Other;
using DeviceManagement.Infrustructure.Connectivity.Models.Security;
namespace DeviceManagement.Infrustructure.Connectivity.Models.Jasper
{
public class EricssonCredentials : CellularCredentials
{
public string EnterpriseSenderNumber { get; set; }
public string RegistrationID { get; set; }
public string SmsEndpointBaseUrl { get; set; }
}
}

Просмотреть файл

@ -1,14 +1,9 @@
using DeviceManagement.Infrustructure.Connectivity.Models.Security;
using DeviceManagement.Infrustructure.Connectivity.Models.Other;
using DeviceManagement.Infrustructure.Connectivity.Models.Security;
namespace DeviceManagement.Infrustructure.Connectivity.Models.Jasper
{
public class JasperCredentials : ICredentials
public class JasperCredentials : CellularCredentials
{
//todo : how can I structure this to allow multiple telcos?
public string LicenceKey { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string BaseUrl { get; set; }
public string ApiRegistrationProvider { get; set; }
}
}

Просмотреть файл

@ -214,7 +214,7 @@ namespace DeviceManagement.Infrustructure.Connectivity.Services
return result;
}
public bool SendSms(string iccid, string smsText)
public bool SendSms(string iccid, string msisdn, string smsText)
{
bool result;
var registrationProvider = _credentialProvider.Provide().ApiRegistrationProvider;
@ -229,7 +229,8 @@ namespace DeviceManagement.Infrustructure.Connectivity.Services
break;
case ApiRegistrationProviderTypes.Ericsson:
var ericssonClient = new EricssonCellularClient(_credentialProvider);
result = ericssonClient.SendSms(iccid, smsText);
var httpResponse = ericssonClient.SendSMS(msisdn, smsText);
result = true;
break;
default:
throw new IndexOutOfRangeException($"Could not find a service for '{registrationProvider}' provider");

Просмотреть файл

@ -20,6 +20,6 @@ namespace DeviceManagement.Infrustructure.Connectivity.Services
bool UpdateSimState(string iccid, string updatedState);
bool UpdateSubscriptionPackage(string iccid, string updatedPackage);
bool ReconnectTerminal(string iccid);
bool SendSms(string iccid, string smsText);
bool SendSms(string iccid, string msisdn, string smsText);
}
}

Просмотреть файл

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net451" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net451" />
</packages>

Просмотреть файл

@ -30,6 +30,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Infr
BaseUrl = apiRegistrationModel.BaseUrl,
Username = apiRegistrationModel.Username,
LicenceKey = apiRegistrationModel.LicenceKey,
EnterpriseSenderNumber = apiRegistrationModel.EnterpriseSenderNumber,
ApiRegistrationProviderType = apiRegistrationModel.ApiRegistrationProvider.ToString()
};
@ -62,6 +63,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Infr
BaseUrl = apiRegistrationTableEntity.BaseUrl,
LicenceKey = apiRegistrationTableEntity.LicenceKey,
Password = apiRegistrationTableEntity.Password,
EnterpriseSenderNumber = apiRegistrationTableEntity.EnterpriseSenderNumber,
ApiRegistrationProvider = apiRegistrationTableEntity.ApiRegistrationProviderType
};

Просмотреть файл

@ -306,7 +306,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
var iccid = device.SystemProperties.ICCID;
if (string.IsNullOrWhiteSpace(iccid)) throw new InvalidOperationException("Device does not have an ICCID. Cannot complete cellular actions.");
CellularActionUpdateResponseModel result = await processActionRequests(iccid, model.CellularActions);
CellularActionUpdateResponseModel result = await processActionRequests(device, model.CellularActions);
var viewModel = generateSimInformationViewModel(iccid, result);
return PartialView("_CellularInformation", viewModel);
}
@ -395,8 +395,10 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
return devices.Results;
}
private async Task<CellularActionUpdateResponseModel> processActionRequests(string iccid, List<CellularActionModel> actions)
private async Task<CellularActionUpdateResponseModel> processActionRequests(DeviceModel device, List<CellularActionModel> actions)
{
var iccid = device.SystemProperties.ICCID;
var terminal = _cellularExtensions.GetSingleTerminalDetails(new Iccid(iccid));
var completedActions = new List<CellularActionModel>();
var failedActions = new List<CellularActionModel>();
foreach (var action in actions)

Просмотреть файл

@ -110,7 +110,8 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
public bool SendSms(string iccid, string smsText)
{
return _cellularService.SendSms(iccid, smsText);
var terminal = GetSingleTerminalDetails(new Iccid(iccid));
return _cellularService.SendSms(iccid, terminal.Msisdn.Id, smsText);
}
private IEnumerable<Iccid> GetUsedIccidList(IList<DeviceModel> devices)

Просмотреть файл

@ -1,6 +1,9 @@
using DeviceManagement.Infrustructure.Connectivity.Models.Other;
using DeviceManagement.Infrustructure.Connectivity.Models.Constants;
using DeviceManagement.Infrustructure.Connectivity.Models.Jasper;
using DeviceManagement.Infrustructure.Connectivity.Models.Other;
using DeviceManagement.Infrustructure.Connectivity.Models.Security;
using Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Infrastructure.Repository;
using System;
namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.Helpers
{
@ -16,14 +19,32 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
public ICredentials Provide()
{
var apiRegistration = _registrationRepository.RecieveDetails();
return new CellularCredentials()
switch (apiRegistration.ApiRegistrationProvider)
{
BaseUrl = apiRegistration.BaseUrl,
LicenceKey = apiRegistration.LicenceKey,
Password = apiRegistration.Password,
Username = apiRegistration.Username,
ApiRegistrationProvider = apiRegistration.ApiRegistrationProvider
};
case ApiRegistrationProviderTypes.Jasper:
return new JasperCredentials()
{
BaseUrl = apiRegistration.BaseUrl,
LicenceKey = apiRegistration.LicenceKey,
Password = apiRegistration.Password,
Username = apiRegistration.Username,
ApiRegistrationProvider = apiRegistration.ApiRegistrationProvider
};
case ApiRegistrationProviderTypes.Ericsson:
return new EricssonCredentials()
{
BaseUrl = apiRegistration.BaseUrl,
LicenceKey = apiRegistration.LicenceKey,
Password = apiRegistration.Password,
Username = apiRegistration.Username,
ApiRegistrationProvider = apiRegistration.ApiRegistrationProvider,
EnterpriseSenderNumber = apiRegistration.EnterpriseSenderNumber,
RegistrationID = apiRegistration.RegistrationID
};
default:
throw new IndexOutOfRangeException($"Could not find a service for '{apiRegistration.ApiRegistrationProvider}' provider");
}
}
}
}

Просмотреть файл

@ -37,6 +37,10 @@
<HintPath>..\packages\Microsoft.Web.Services3.3.0.0.0\lib\net20\Microsoft.Web.Services3.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.EnterpriseServices" />

Просмотреть файл

@ -6,27 +6,66 @@ using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Web.Services.Protocols;
using EricssonConsoleApiTester.ApiStatus;
using EricssonConsoleApiTester.DeviceReconnect;
using EricssonConsoleApiTester.RealtimeTrace;
using EricssonConsoleApiTester.SubscriptionManagement;
using EricssonConsoleApiTester.SubscriptionTraffic;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace EricssonConsoleApiTester
{
class Program
{
static async Task<HttpResponseMessage> SendSMS()
{
using (var client = new HttpClient())
{
var values = new Dictionary<string, string>
{
};
var content = new FormUrlEncodedContent(values);
return await client.PostAsync("https://<https://orange.dcp.ericsson.net/dcpapi/smsmessaging/v1/outbound/tel: 33604/requests", content);
}
}
static void Main(string[] args)
{
//echo tester
//var subscriptionTrafficClient = new SubscriptionTrafficClient();
//subscriptionTrafficClient.Endpoint.Address =
// EricssonEndpointBuilder.GetAuthorizedEndpoint(
// "https://orange.dcp.ericsson.net/dcpapi/SubscriptionTraffic ");
var binding = new BasicHttpBinding { Security = { Mode = BasicHttpSecurityMode.Transport } };
EndpointAddress endpointAddress = EricssonEndpointBuilder.GetAuthorizedEndpoint("https://orange.dcp.ericsson.net/dcpapi/ApiStatus");
//var response = subscriptionTrafficClient.query(new query()
//{
// resource = new SubscriptionTraffic.resource()
// {
// id = "901312000000466",
// type = resourceType.imsi
// }
//});
//Console.WriteLine("Done");
//SUBSCRIPTION MANAGEMENT
var subscriptionManClient = new SubscriptionManagementClient();
subscriptionManClient.Endpoint.Address =
EricssonEndpointBuilder.GetAuthorizedEndpoint(
"https://orange.dcp.ericsson.net/dcpapi/SubscriptionManagement");
//Task.Run(async () =>
//{
// var response = await SendSMS();
// Console.WriteLine(JsonConvert.SerializeObject(response));
//}).Wait();
////echo tester
//var binding = new BasicHttpBinding { Security = { Mode = BasicHttpSecurityMode.Transport } };
//EndpointAddress endpointAddress = EricssonEndpointBuilder.GetAuthorizedEndpoint("https://orange.dcp.ericsson.net/dcpapi/ApiStatus");
////SUBSCRIPTION MANAGEMENT
//var subscriptionManClient = new SubscriptionManagementClient();
//subscriptionManClient.Endpoint.Address =
// EricssonEndpointBuilder.GetAuthorizedEndpoint(
// "https://orange.dcp.ericsson.net/dcpapi/SubscriptionManagement");
//var response1 = subscriptionManClient.QuerySimResource(new QuerySimResource()
//{
@ -47,7 +86,7 @@ namespace EricssonConsoleApiTester
// }
//});
//var reconnectClient = new DeviceReconnectClient();
//reconnectClient.Endpoint.Address =
@ -106,20 +145,20 @@ namespace EricssonConsoleApiTester
// }
//});
//Subscription Traffic - potential for activity.
var subscriptionTrafficClient = new SubscriptionTrafficClient();
subscriptionTrafficClient.Endpoint.Address = EricssonEndpointBuilder.GetAuthorizedEndpoint(
"https://orange.dcp.ericsson.net/dcpapi/SubscriptionTraffic");
////Subscription Traffic - potential for activity.
//var subscriptionTrafficClient = new SubscriptionTrafficClient();
//subscriptionTrafficClient.Endpoint.Address = EricssonEndpointBuilder.GetAuthorizedEndpoint(
// "https://orange.dcp.ericsson.net/dcpapi/SubscriptionTraffic");
queryResponse subResp = subscriptionTrafficClient.query(new query()
{
resource = new SubscriptionTraffic.resource()
{
id = "901312000000466",
type = resourceType.imsi
}
});
Console.WriteLine("Hello");
//queryResponse subResp = subscriptionTrafficClient.query(new query()
//{
// resource = new SubscriptionTraffic.resource()
// {
// id = "901312000000466",
// type = resourceType.imsi
// }
//});
//Console.WriteLine("Hello");
////Realtime Trace - PDP? HLR?
//var realTimeClient = new RealtimeTraceClient();

Просмотреть файл

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Web.Services3" version="3.0.0.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
</packages>