public ContentResult Authenticate(ExternalSynchronizationRequest request)
        {
            var authenticationRequest = JsonConvert.DeserializeObject <AuthenticationRequest>(request.RequestData, _partConverter);

            if (authenticationRequest.Password != ConfigurationManager.AppSettings["password"])
            {
                return(Content("", "application/json", Encoding.Unicode));
            }

            var dictionary = (Dictionary <Guid, SynchronizationSession>)(Request.RequestContext.HttpContext.Application["sessions"]
                                                                         ?? (Request.RequestContext.HttpContext.Application["sessions"] = new Dictionary <Guid, SynchronizationSession>()));

            var key = Guid.NewGuid();

            dictionary[key] = new SynchronizationSession();

            // clean up unnecesary sessions here, not perfect but it'll do
            foreach (var entry in dictionary.ToArray())
            {
                if (entry.Value.StartDateTime < DateTime.Now.AddDays(-1))
                {
                    dictionary.Remove(entry.Key);
                }
            }

            var json = JsonConvert.SerializeObject(new AuthenticationResponse {
                ApiKey = key
            }, _partConverter);

            return(Content(json, "application/json", Encoding.Unicode));
        }
 public ContentResult DeleteLocalizations(ExternalSynchronizationRequest request)
 {
     var providerPair = GetProviderPair(request);
     var deleteLocalizationsRequest = JsonConvert.DeserializeObject<DeleteLocalizationsRequest>(request.RequestData, _partConverter);
     providerPair.ValueManager.DeleteLocalizationsFor(deleteLocalizationsRequest.Part, deleteLocalizationsRequest.Key);
     var json = JsonConvert.SerializeObject(new FullContentResponse { AllValues = providerPair.ValueManager.GetAllValuesQualified().ToArray() }, _partConverter);
     return Content(json, "application/json", Encoding.Unicode);
 }
 public ContentResult CreateValue(ExternalSynchronizationRequest request)
 {
     var providerPair = GetProviderPair(request);
     var createValueRequest = JsonConvert.DeserializeObject<CreateValueRequest>(request.RequestData, _partConverter);
     providerPair.ValueManager.CreateValue(createValueRequest.Qualifier, createValueRequest.Value);
     var json = JsonConvert.SerializeObject(new FullContentResponse { AllValues = providerPair.ValueManager.GetAllValuesQualified().ToArray() }, _partConverter);
     return Content(json, "application/json", Encoding.Unicode);
 }
        public ContentResult SetAudits(ExternalSynchronizationRequest request)
        {
            var providerPair     = GetProviderPair(request);
            var setAuditsRequest = JsonConvert.DeserializeObject <SetAuditsRequest>(request.RequestData, _partConverter);

            providerPair.ValueManager.SetAudits(setAuditsRequest.Audits);
            var json = JsonConvert.SerializeObject(new SetAuditsResponse(), _partConverter);

            return(Content(json, "application/json", Encoding.Unicode));
        }
        public ContentResult DeleteLocalizations(ExternalSynchronizationRequest request)
        {
            var providerPair = GetProviderPair(request);
            var deleteLocalizationsRequest = JsonConvert.DeserializeObject <DeleteLocalizationsRequest>(request.RequestData, _partConverter);

            providerPair.ValueManager.DeleteLocalizationsFor(deleteLocalizationsRequest.Part, deleteLocalizationsRequest.Key);
            var json = JsonConvert.SerializeObject(new FullContentResponse {
                AllValues = providerPair.ValueManager.GetAllValuesQualified().ToArray()
            }, _partConverter);

            return(Content(json, "application/json", Encoding.Unicode));
        }
        public ContentResult CreateValue(ExternalSynchronizationRequest request)
        {
            var providerPair       = GetProviderPair(request);
            var createValueRequest = JsonConvert.DeserializeObject <CreateValueRequest>(request.RequestData, _partConverter);

            providerPair.ValueManager.CreateValue(createValueRequest.Qualifier, createValueRequest.Value);
            var json = JsonConvert.SerializeObject(new FullContentResponse {
                AllValues = providerPair.ValueManager.GetAllValuesQualified().ToArray()
            }, _partConverter);

            return(Content(json, "application/json", Encoding.Unicode));
        }
        public ContentResult GetAudits(ExternalSynchronizationRequest request)
        {
            var providerPair     = GetProviderPair(request);
            var getAuditsRequest = JsonConvert.DeserializeObject <GetAuditsRequest>(request.RequestData, _partConverter);

            providerPair.ValueManager.Reload();
            var json = JsonConvert.SerializeObject(new GetAuditsResponse {
                Audits = providerPair.ValueManager.GetAudits().ToArray()
            }, _partConverter);

            return(Content(json, "application/json", Encoding.Unicode));
        }
        private ProviderPair GetProviderPair(ExternalSynchronizationRequest synchronizationRequest)
        {
            var dictionary = (Dictionary <Guid, SynchronizationSession>)(Request.RequestContext.HttpContext.Application["sessions"]
                                                                         ?? (Request.RequestContext.HttpContext.Application["sessions"] = new Dictionary <Guid, SynchronizationSession>()));

            if (!dictionary.ContainsKey(synchronizationRequest.ApiKey))
            {
                throw new AuthenticationException();
            }

            var session = dictionary[synchronizationRequest.ApiKey];

            return(session.ProviderPairs.ContainsKey(synchronizationRequest.ProviderPairName)
                ? session.ProviderPairs[synchronizationRequest.ProviderPairName]
                : session.ProviderPairs[synchronizationRequest.ProviderPairName] =
                       ProviderPairFactory.CreateProviderPair(synchronizationRequest.ProviderPairName));
        }
        public ContentResult Authenticate(ExternalSynchronizationRequest request)
        {
            var authenticationRequest = JsonConvert.DeserializeObject<AuthenticationRequest>(request.RequestData, _partConverter);
            if (authenticationRequest.Password != ConfigurationManager.AppSettings["password"])
                return Content("", "application/json", Encoding.Unicode);

            var dictionary = (Dictionary<Guid, SynchronizationSession>)(Request.RequestContext.HttpContext.Application["sessions"]
                ?? (Request.RequestContext.HttpContext.Application["sessions"] = new Dictionary<Guid, SynchronizationSession>()));

            var key = Guid.NewGuid();
            dictionary[key] = new SynchronizationSession();

            // clean up unnecesary sessions here, not perfect but it'll do
            foreach (var entry in dictionary.ToArray())
            {
                if (entry.Value.StartDateTime < DateTime.Now.AddDays(-1))
                    dictionary.Remove(entry.Key);
            }

            var json = JsonConvert.SerializeObject(new AuthenticationResponse { ApiKey = key }, _partConverter);
            return Content(json, "application/json", Encoding.Unicode);
        }
        private ProviderPair GetProviderPair(ExternalSynchronizationRequest synchronizationRequest)
        {
            var dictionary = (Dictionary<Guid, SynchronizationSession>)(Request.RequestContext.HttpContext.Application["sessions"]
                ?? (Request.RequestContext.HttpContext.Application["sessions"] = new Dictionary<Guid, SynchronizationSession>()));

            if(!dictionary.ContainsKey(synchronizationRequest.ApiKey))
                throw new AuthenticationException();

            var session = dictionary[synchronizationRequest.ApiKey];

            return session.ProviderPairs.ContainsKey(synchronizationRequest.ProviderPairName)
                ? session.ProviderPairs[synchronizationRequest.ProviderPairName]
                : session.ProviderPairs[synchronizationRequest.ProviderPairName] =
                    ProviderPairFactory.CreateProviderPair(synchronizationRequest.ProviderPairName);
        }
 public ContentResult SetAudits(ExternalSynchronizationRequest request)
 {
     var providerPair = GetProviderPair(request);
     var setAuditsRequest = JsonConvert.DeserializeObject<SetAuditsRequest>(request.RequestData, _partConverter);
     providerPair.ValueManager.SetAudits(setAuditsRequest.Audits);
     var json = JsonConvert.SerializeObject(new SetAuditsResponse(), _partConverter);
     return Content(json, "application/json", Encoding.Unicode);
 }
 public ContentResult GetAudits(ExternalSynchronizationRequest request)
 {
     var providerPair = GetProviderPair(request);
     var getAuditsRequest = JsonConvert.DeserializeObject<GetAuditsRequest>(request.RequestData, _partConverter);
     providerPair.ValueManager.Reload();
     var json = JsonConvert.SerializeObject(new GetAuditsResponse { Audits = providerPair.ValueManager.GetAudits().ToArray() }, _partConverter);
     return Content(json, "application/json", Encoding.Unicode);
 }