Notification used for Azure Notification Hub's DirectSend - ios

I trying to implement DirectSend for ANH .NET SDK.
NotificationHubClient.SendDirectNotificationAsync(Notification notification, string deviceHandle);
I am wondering what is the best way to work with this Notification object? There is no documentation on this anywhere, unlike all of the SendNative calls that exist on the ANH client.
The abstract Notification class's constructor
public Notification(Dictionary<string, string> additionalHeaders, string tag);
What are the headers I need to include? At the moment I don't have any
Does it have to include a tag? I am not planning on using Installations or Registrations on my hub, so I won't have any tags to work with anyways?
I am assuming I need to make my own concrete types of Notifications and set all the other properties on this object, such as PlatformType, ContentType, and such?

Notification is an abstract class. There are per platform specific notification classes like: AppleNotification/AdmNotification/GCMNotification/WindowsNotification. You should use class corresponding to the platform you are targeting.
The below API helps to pass the additional platform specific headers. And there is no need to pass any tags for direct send.
public Notification(Dictionary<string, string> additionalHeaders, string tag);
You can find more information about DirectSend here: https://msdn.microsoft.com/en-us/library/azure/mt608572.aspx

Related

Get classes that have fields annotated with Redstone's #Field()

I have some Dart classes in my project where I annotate some fields with Redstone Mapper's #Field() annotation.
How can I get all these classes at runtime?
I've seen the private Map _cache in redstone_mapper_factory... but it's private.
I'm aware of that I can use the Reflection package to scan these classes myself, however all of them are already being detected and stored by the Redstone mapper so I'd like to leverage that.
You can use dart:mirror to do that.
But I don't think it's possible to get that by redstone, you should probably ask on github, even do the change yourself if you want and do a pull request, it should not be difficult, it is just a getter on _cache.
https://github.com/redstone-dart/redstone_mapper

Correct client-server framework architecture approach (different server versions)

I am trying to design and implement a framework to communicate with server (it's an iOS framework written in Swift). The challenge I am facing is the architecture - there are two ways of communicating with the server and I have to implement both (different versions). I really want to achieve having a stateless client, with methods such as: Client.authenticate() or Client.downloadFile(). The problem is when having two implementations I would end up with methods in my Client class like this one:
public class func authenticate(state: state) {
if (state.type == 1) {
Client1.authenticate(state)
} else {
Client2.authenticate(state)
}
}
Repeated for every single method...
I wanted to initially keep the client like this - stateless and static and have only state objects that hold the actual state as there could be many connections to the server with various states. By that I wanted to avoid having the client as an object and both holding the state and performing the calls to the server. The problem is that this approach is just...dirty I guess. What would be a more DRY, readable and sustainable way of doing this?
I don't fully understand your intention without more code samples, but the patterns I will present to you will surely clear things up for you.
If your Client class always uses either Client1 or Client2 (or more specifically, if your every client object state variable doesn't change through it's instances lifetime) you should use Dependency Injection.
You create a procol (Let's call it RemoteClient with authenticate method (and every other method that the server client should implement) and make Client1 and Client2 conform to that protocol.
Now you make your Client class to accept a RemoteClient in it's constructor.
Now whatever creates the Client object, it can decide what to inject into the constructor: the Client1 concrete class object, or Client2.
There's a lot of articles about Dependency Injection so I won't cover it in much detail.
Example article
You can also use the Strategy design pattern, which is very similiar but kind of different in intent:
Strategy design pattern
Difference between DI and Strategy
EDIT
After you've clarified what you want to do in comments below:
In that case, you can use reflection/metadata and use dictionary/map to invoke the client you want.
(pseudocode)
enum ServerType
{
client1,
client2
}
Dictionary* serversDictionary; // key = ServerType , value = object of protocol type RemoteLocation
static init
{
serversDictionary[client1] = Client1.self; // using swift class metadata
serversDictionary[client2] = Client2.self; // using swift class metadata
}
static authenticate(ServerType type) {
let locationToSendAuthTo = serversDictionary[type];
locationToSendAuthTo.authenticate(type);
}
I'm not sure if Swift works that way because I've just started using it. I'm not sure if you can call a static method on a class type. The docs are pretty thin on that.
More here:
Swift class introspection & generics

OpenRasta: Can I use a generic handler for versioning resources gracefully?

We have an OpenRasta service, and we'd like to use media types to version our resources. We'll have a different set of DTOs for each new version, distinguishable by namespace. For each version of the DTOs, we have a corresponding media type.
So DTOs will be mapped to media types like this:
Namespace.Dto.V1.MyResource -> application/vnd.Namespace.Dto.V1.MyResource+json
Namespace.Dto.V2.MyResource -> application/vnd.Namespace.Dto.V2.MyResource+json
The repository implementation will be specific to the version of the DTOs, but the interface is generic. I would like my handler and codec to be generic as well, so I don't need to copy/paste them for each version of the DTOs. So I want my routes to look like this:
ResourceSpace.Has.ResourcesOfType<V1.MyResource>()
.AtUri("MyResource/{resourceID}")
.HandledBy<MyResourceHandler<Dto.V1.MyResource>>()
.TranscodedBy<MyResourceCodec<Dto.V1.MyResource>>()
.ForMediaType(mediaTypeMapper.GetMediaType(typeof(Dto.V1.MyResource)));
//V2 of DTOs
ResourceSpace.Has.ResourcesOfType<V2.MyResource>()
.AtUri("MyResource/{resourceID}")
.HandledBy<MyResourceHandler<Dto.V2.MyResource>>()
.TranscodedBy<MyResourceCodec<Dto.V2.MyResource>>()
.ForMediaType(mediaTypeMapper.GetMediaType(typeof(Dto.V2.MyResource)));
Should this work? Right now, it appears that my service is handling requests with MyResourceHandler<Dto.V1.MyResource> regardless of the Accept header on a GET request, for example.
Any thoughts? We could change our scheme to use URIs like /v1/MyResource/ instead of using the accept header, but it would be great to get this working.
EDIT:
I should add that part of the reason we are using media types for versioning is because this is a service for internal use, not meant to be accessible on the public web.
You're registering two resource types on the same URI, only one will get selected, there's no way to do the distinction at request time.
I don't think versioning in URIs or media types is a good idea on the web. That said, for what you want (different mediatypes), then use the same resource type and use your codec to fill-in the same type from the incoming / outgoing data. That's teh responsibility of a codec in OR, making the junction between a DTO and a media type format.
On incoming requests, we need to know what resource type you want based on the URI. If you have two different types it ought to be different resources. that said if you do the following that'll work too:
ResourceSpace.Has.ResourcesNamed("myResource").AtUri("/myResource").HandledBy<ResourceV1Handler>().And.HandledBy<ResourceV2Handler>();
ResourceSpace.Has.ResourcesOfType<MyV1Resource>().WithoutUri.TranscodedBy<V1Codec>();
ResourceSpace.Has.ResourcesOfType<MyV2Resource>().WithoutUri.TranscodedBy<V2Codec>();
you can then write
public class handler {
public object Post(MyV1Resource resource) {}
public object Post(MyV2Resource resource) {}
}
and that'll work. What you won't be able to do is implement the get in that way, as OR assumes one resource type == one URI in most instances.
As for generics, if you use an IoC container, you can register your handlers in a generic fashion (aka register typeof(IHandler<>) with typeof(Handler<>)). This means any IHandler will get resolved to Handler. You can then simply register HandledBy>() in your registration and you're done. Same applies to codecs (but then again, codecs in OR are there to deal with media type issues, not just as serialization mechanisms, as serialization in itself is evil for the web and should be used seldomly).

Access Properties from utility classes used by Action

I just want to know if there's a way to access the properties from a utility class used by an Action class. To access the properties from an Action class we extend the ActionSupport and use the getText("property.key.name") method.
So, my question is -should every other class extend the ActionSupport to access properties, even though its not an Action class? or is there any other way?
Thanks
I wouldn't extend ActionSupport unless you're actually defining an action.
The S2/XW2 ActionSupport class uses com.opensymphony.xwork2.DefaultTextProvider; you might be able to use it in your own classes. I'm a little wary of this since I'm not convinced non-action classes should be accessing the web-app's resources, but I haven't given it much thought, so it could be valid. I also haven't tried to do it.
ActionSuport is kind of helper class being developed by S2 developers to supplement the Development as it provides many features OOTB.
getText() is one of the use-case where S2 provides a way to read the property files.This method is specific to S2 as it know how to transverse the hierarchy to read the property files and in what order.
There are many ways to read the property files in a application and few of them are
ResourceBundle
if you are using Spring, it has a very handy mechanism to read property files
- how-to-read-properties-file-in-spring
Apache Common also provides a way to read the file
Apache-Common
In short to read properties file there are many ways, S2 getText() is a way developed by the S2 to read the property file with respect to your actions.
//I wanna make you understand how struts doing it.
public class ActionSupport implements Action, Validateable, ValidationAware, TextProvider, LocaleProvider, Serializable {
//Action support implementation.
//Here TextProvider takes care about resource bundle thing.
}

ASMX web service, external WSDLs *without* wsdl.exe

I'm working on some legacy code, and I need an asmx to implement a particular wsdl, which is being provided to me.
I would like to receive the root element of the message as either an XmlDocument or XmlNode, rather than the wsdl.exe generated object graph. Is this even possible?
First of all, you should use svcutil.exe, not wsdl.exe, unless you have no other choices.
Second, you don't need either program to implement an external WSDL. Just go write your service so that the XML Serializer will properly serialize and deserialize the incoming message. In particular, if you like processing XML, try this:
[WebMethod]
public XmlElement SomeOperation(XmlElement parameter)
{
}
I believe that the same works with the newer XElement class.
In WCF (which is what you should be using, since Microsoft now considers ASMX web services to be "legacy technology"), I believe you should use the Message type:
[OperationContract]
Message SomeOperation(Message parameter);

Resources