Mini Kabibi Habibi
using System;
using System.Data.Services;
using System.Data.Services.Common;
using System.Data.Services.Providers;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Web;
using DataServicesJSONP;
namespace DXSK8.Service {
[JSONPSupportBehavior]
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class api : DataService<SK8DataContainer>, IServiceProvider {
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config) {
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.UseVerboseErrors = true;
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
}
protected override SK8DataContainer CreateDataSource() {
return new SK8DataContainer(SessionConnectionProvider.GetConnection());
}
public object GetService(Type serviceType) {
if(serviceType == typeof(IDataServiceStreamProvider)) {
// Return the stream provider to the data service.
return new ImageStreamProvider(this.CurrentDataSource);
}
return null;
}
[WebInvoke(Method = "POST")]
public int RegisterNotificationChannel(string clientId, string channelUrl) {
var channels = CurrentDataSource.NotificationChannels;
NotificationChannel channel = channels.FirstOrDefault(c => c.ClientId == clientId);
if(channel == null) {
channel = new NotificationChannel();
channels.AddObject(channel);
}
channel.ClientId = clientId;
channel.Url = channelUrl;
channel.UpdatedOn = DateTime.UtcNow;
CurrentDataSource.SaveChanges();
return channel.Id;
}
[WebGet]
public void TestPush() {
CurrentDataSource.NotifyForInventory(CurrentDataSource.Inventorys.First(), new PushNotifications());
}
[WebInvoke]
public void StartSession() {
SessionConnectionProvider.GetConnection();
}
}
}