Example #1
0
        public void Deregister(IEndpointRequest request)
        {
            var id = request.Parameter <long>("id");

            var response = new Response
            {
                Id      = id,
                Success = true
            };

#if DEBUG
            Trace.WriteLine("LiveUpdate de-registration #" + id);
#endif
            lock (_connectedClients)
            {
                Client client;
                if (_connectedClients.TryGetValue(id, out client))
                {
                    _connectedClients.Remove(id);
                    client.Dispose();
                }
            }

            request.Success(response);
        }
        private void RetrieveTest(IEndpointRequest request)
        {
            var testName = request.Parameter <string>("name");
            var test     = _segmentTestingFramework.GetAllTests().FirstOrDefault(t => string.Equals(t.Name, testName, StringComparison.OrdinalIgnoreCase));

            if (test == null)
            {
                request.NotFound();
            }
            else
            {
                request.Success(new Test
                {
                    Name                    = test.Name,
                    DisplayName             = test.DisplayName,
                    Description             = test.Description,
                    StartUtc                = test.StartUtc,
                    EndUtc                  = test.EndUtc,
                    EnvironmentName         = test.EnvironmentName,
                    PageNames               = test.PageNames,
                    SerializableScenarioMap = test.ScenarioMap.Select(m => new ScenarioMapEntry
                    {
                        SegmentKey   = m.Item1,
                        ScenarioName = m.Item2
                    }).ToArray()
                });
            }
        }
Example #3
0
        private void CreateLayout(IEndpointRequest request)
        {
            var layout           = request.Body <LayoutRecord>();
            var websiteVersionId = request.Parameter <long?>("websiteVersionId");
            var scenario         = request.Parameter <string>("scenario");

            var result = _dataLayer.CreateLayout(request.Identity, layout);

            if (!result.Success)
            {
                request.BadRequest(result.DebugMessage);
                return;
            }

            layout = _dataLayer.GetLayout(result.NewRecordId, l => l);
            if (layout == null)
            {
                request.HttpStatus(
                    HttpStatusCode.InternalServerError,
                    "After creating the new layout it could not be found in the database");
                return;
            }

            if (websiteVersionId.HasValue)
            {
                _dataLayer.AddLayoutToWebsiteVersion(request.Identity, layout.RecordId, 1, websiteVersionId.Value, scenario);
            }
            request.Success(layout);
        }
Example #4
0
        private void UpdateEnvironment(IEndpointRequest request)
        {
            var environmentId = request.Parameter <long>("id");
            var changes       = request.Body <List <PropertyChange> >();

            if (changes.Any(c => c.PropertyName == "websiteVersionId"))
            {
                var authorization = request.OwinContext.GetFeature <IAuthorization>();
                if (authorization != null)
                {
                    if (!authorization.HasPermission(Permissions.ChangeEnvironmentVersion, environmentId.ToString()))
                    {
                        request.HttpStatus(HttpStatusCode.Forbidden,
                                           "You do not have permission '" + Permissions.ChangeEnvironmentVersion +
                                           " on environment with id=" + environmentId);
                    }
                    return;
                }
            }

            var result = _dataLayer.UpdateEnvironment(request.Identity, environmentId, changes);

            if (result.Success)
            {
                var environment = _dataLayer.GetEnvironment(environmentId, e => e);
                request.Success(environment);
            }
            else
            {
                request.BadRequest(result.DebugMessage);
            }
        }
Example #5
0
        public void Add(
            IEndpointRequest request,

            [EndpointParameter(
                 EndpointParameterType.FormField,
                 Description = "The first number to add")]
            double a,

            [EndpointParameter(
                 EndpointParameterType.FormField,
                 Description = "The second number to add")]
            double b,

            [EndpointParameter(
                 EndpointParameterType.FormField,
                 ParserType = typeof(AnyValue <string>),
                 Description = "The path of the page to return the results on")]
            string r)
        {
            request.OwinContext.Set(
                typeof(ArithmeticResult).FullName,
                new ArithmeticResult {
                Result = a + " + " + b + " = " + (a + b)
            });
            request.Rewrite(r);
        }
Example #6
0
        private void CreateRegionVersion(IEndpointRequest request)
        {
            var regionVersion    = request.Body <RegionVersionRecord>();
            var websiteVersionId = request.Parameter <long?>("websiteVersionId");
            var scenario         = request.Parameter <string>("scenario");

            var result = _dataLayer.CreateRegionVersion(request.Identity, regionVersion);

            if (!result.Success)
            {
                request.BadRequest(result.DebugMessage);
                return;
            }

            regionVersion = _dataLayer.GetRegionVersion(result.NewRecordId, (p, v) => v);
            if (regionVersion == null)
            {
                request.HttpStatus(
                    HttpStatusCode.InternalServerError,
                    "After creating the new region version it could not be found in the database");
                return;
            }

            if (websiteVersionId.HasValue)
            {
                _dataLayer.AddRegionToWebsiteVersion(request.Identity, regionVersion.RecordId, websiteVersionId.Value, scenario);
            }

            request.Success(regionVersion);
        }
Example #7
0
        private void CreatePage(IEndpointRequest request)
        {
            var page             = request.Body <PageRecord>();
            var websiteVersionId = request.Parameter <long?>("websiteVersionId");
            var scenario         = request.Parameter <string>("scenario");

            var result = _dataLayer.CreatePage(request.Identity, page);

            if (!result.Success)
            {
                request.BadRequest(result.DebugMessage);
                return;
            }

            page = _dataLayer.GetPage(result.NewRecordId, p => p);
            if (page == null)
            {
                request.HttpStatus(
                    HttpStatusCode.InternalServerError,
                    "After creating the new page it could not be found in the database");
                return;
            }

            if (websiteVersionId.HasValue)
            {
                _dataLayer.AddPageToWebsiteVersion(request.Identity, page.RecordId, 1, websiteVersionId.Value, scenario);
            }
            request.Success(page);
        }
        private void GetElementVersions(IEndpointRequest request)
        {
            var type = request.Parameter <string>("type");
            var id   = request.Parameter <long>("id");

            var response = new ElementVersionsResponse
            {
                RecordId   = id,
                RecordType = type
            };

            response.Versions = _dataLayer.GetElementVersions(id, r => new ElementVersionResponse
            {
                VersionId   = r.RecordId,
                Version     = r.Version,
                Name        = r.DisplayName,
                Description = r.Description
            });

            foreach (var version in response.Versions)
            {
                version.Usages = _dataLayer.GetElementUsage(version.VersionId, r => new ElementVersionUsageResponse
                {
                    WebsiteVersionId         = r.WebsiteVersionId,
                    SegmentationScenarioName = r.Scenario
                });
            }

            request.Success(response);
        }
        public void New(IEndpointRequest request)
        {
            var        which = request.Parameter <Which>("which");
            TestPerson person;

            switch (which)
            {
            case Which.One:
                person = request.Body <TestPerson>();
                break;

            case Which.Two:
                person = new TestPerson {
                    FirstName = "John", LastName = "Doe"
                };
                break;

            case Which.Three:
                person = new TestPerson {
                    FirstName = "Jane", LastName = "Doe"
                };
                break;

            default:
                request.NoContent();
                return;
            }

            person.FullName = person.FirstName + " " + person.LastName;
            request.Success(person);
        }
Example #10
0
            private void GetTemplate(IEndpointRequest request)
            {
                var templatePath = request.Parameter <string>("path");
                var template     = _nameManager.ResolveTemplate(templatePath);

                if (template == null)
                {
                    request.NotFound("Unknown template " + templatePath);
                }
                else
                {
                    using (var htmlWriter = _htmlWriterFactory.Create())
                    {
                        var context = new TemplateRenderContext(_assetmanager, htmlWriter);
                        using (template.WritePageArea(context, PageArea.Body))
                        {
                            using (var html = _stringBuilderFactory.Create())
                            {
                                htmlWriter.ToStringBuilder(html);
                                request.Success(html.ToString());
                            }
                        }
                    }
                }
            }
        private void UpdateScenario(IEndpointRequest request)
        {
            var scenario = request.Body <Scenario>();

            _segmentTestingFramework.UpdateScenario(scenario);
            request.Success(scenario);
        }
        private void CreateScenario(IEndpointRequest request)
        {
            var scenario = request.Body <Scenario>();

            scenario.Name = _segmentTestingFramework.CreateScenario(scenario);
            request.Success(scenario);
        }
Example #13
0
        private void DashboardDrawing(IEndpointRequest request)
        {
            var dasboardName = request.Parameter <string>("name");
            var diagram      = _diagramGenerator.GenerateDashboardDrawing(dasboardName);
            var svg          = _diagramGenerator.ProduceSvg(diagram);

            request.Success(svg);
        }
Example #14
0
        private void NodeDrawing(IEndpointRequest request)
        {
            var nodeName = request.Parameter <string>("nodename");
            var diagram  = _diagramGenerator.GenerateNodeDrawing(nodeName);
            var svg      = _diagramGenerator.ProduceSvg(diagram);

            request.Success(svg);
        }
        private void AllScenarios(IEndpointRequest request)
        {
            var scenarios = _segmentTestingFramework.GetAllScenarios();

            request.Success(scenarios.Select(s => new Scenario
            {
                Name        = s.Name,
                DisplayName = s.DisplayName,
                Description = s.Description
            }));
        }
        private void UpdateTest(IEndpointRequest request)
        {
            var test = request.Body <Test>();

            if (test.SerializableScenarioMap != null)
            {
                test.ScenarioMap = test.SerializableScenarioMap.Select(m => new Tuple <string, string>(m.SegmentKey, m.ScenarioName)).ToArray();
            }

            _segmentTestingFramework.UpdateTest(test);
            request.Success(test);
        }
Example #17
0
        public void Subtract(IEndpointRequest request)
        {
            var a = request.Parameter <double>("a");
            var b = request.Parameter <double>("b");
            var r = request.Parameter <string>("r");

            request.OwinContext.Set(
                typeof(ArithmeticResult).FullName,
                new ArithmeticResult {
                Result = a + " - " + b + " = " + (a - b)
            });
            request.Rewrite(r);
        }
Example #18
0
 public void Multiply(
     IEndpointRequest request,
     [EndpointParameter(EndpointParameterType.FormField)] double a,
     [EndpointParameter(EndpointParameterType.FormField)] double b,
     [EndpointParameter(EndpointParameterType.FormField)] string r)
 {
     request.OwinContext.Set(
         typeof(ArithmeticResult).FullName,
         new ArithmeticResult {
         Result = a + " x " + b + " = " + (a * b)
     });
     request.Rewrite(r);
 }
Example #19
0
        private void RetrieveComponentVersion(IEndpointRequest request)
        {
            var componentVersionId = request.Parameter <long>("id");
            var componentVersion   = _dataLayer.GetComponentVersion(componentVersionId, (p, v) => v);

            if (componentVersion == null)
            {
                request.NotFound("No component version with ID " + componentVersionId);
            }
            else
            {
                request.Success(componentVersion);
            }
        }
Example #20
0
        private void DeleteComponentVersion(IEndpointRequest request)
        {
            var componentVersionId = request.Parameter <long>("id");
            var result             = _dataLayer.DeleteComponentVersion(request.Identity, componentVersionId);

            if (result.Success)
            {
                request.Success(new { componentVersionId });
            }
            else
            {
                request.BadRequest(result.DebugMessage);
            }
        }
Example #21
0
        private void DataTypeVersions(IEndpointRequest request)
        {
            var id = request.Parameter <long>("id");
            var dataTypeVersions = _dataLayer.GetElementVersions(id, p => p as DataTypeVersionRecord);

            if (dataTypeVersions == null)
            {
                request.NotFound("No dataType with ID " + id);
            }
            else
            {
                request.Success(dataTypeVersions.Where(v => v != null));
            }
        }
Example #22
0
        private void RetrieveWebsiteVersion(IEndpointRequest request)
        {
            var id             = request.Parameter <long>("id");
            var websiteVersion = _dataLayer.GetWebsiteVersion(id, e => e);

            if (websiteVersion == null)
            {
                request.NotFound("No website version with ID " + id);
            }
            else
            {
                request.Success(websiteVersion);
            }
        }
Example #23
0
        private void RetrievePage(IEndpointRequest request)
        {
            var id   = request.Parameter <long>("id");
            var page = _dataLayer.GetPage(id, p => p);

            if (page == null)
            {
                request.NotFound("No page with ID " + id);
            }
            else
            {
                request.Success(page);
            }
        }
Example #24
0
        private void RetrieveRegionVersion(IEndpointRequest request)
        {
            var regionVersionId = request.Parameter <long>("id");
            var regionVersion   = _dataLayer.GetRegionVersion(regionVersionId, (p, v) => v);

            if (regionVersion == null)
            {
                request.NotFound("No region version with ID " + regionVersionId);
            }
            else
            {
                request.Success(regionVersion);
            }
        }
Example #25
0
        private void RetrievePageVersion(IEndpointRequest request)
        {
            var pageVersionId = request.Parameter <long>("id");
            var pageVersion   = _dataLayer.GetPageVersion(pageVersionId, (p, v) => v);

            if (pageVersion == null)
            {
                request.NotFound("No page version with ID " + pageVersionId);
            }
            else
            {
                request.Success(pageVersion);
            }
        }
Example #26
0
        private void DeleteRegion(IEndpointRequest request)
        {
            var id     = request.Parameter <long>("id");
            var result = _dataLayer.DeleteRegion(request.Identity, id);

            if (result.Success)
            {
                request.Success(new { id });
            }
            else
            {
                request.BadRequest(result.DebugMessage);
            }
        }
Example #27
0
        private void RetrieveRegion(IEndpointRequest request)
        {
            var id     = request.Parameter <long>("id");
            var region = _dataLayer.GetRegion(id, r => r);

            if (region == null)
            {
                request.NotFound("No region with ID " + id);
            }
            else
            {
                request.Success(region);
            }
        }
Example #28
0
        private void RetrieveEnvironment(IEndpointRequest request)
        {
            var id          = request.Parameter <long>("id");
            var environment = _dataLayer.GetEnvironment(id, e => e);

            if (environment == null)
            {
                request.NotFound("No environment with ID " + id);
            }
            else
            {
                request.Success(environment);
            }
        }
Example #29
0
        private void RetrieveLayout(IEndpointRequest request)
        {
            var id     = request.Parameter <long>("id");
            var layout = _dataLayer.GetLayout(id, l => l);

            if (layout == null)
            {
                request.NotFound("No layout with ID " + id);
            }
            else
            {
                request.Success(layout);
            }
        }
Example #30
0
        private void RetrieveLayoutVersion(IEndpointRequest request)
        {
            var layoutVersionId = request.Parameter <long>("id");
            var layoutVersion   = _dataLayer.GetLayoutVersion(layoutVersionId, (p, v) => v);

            if (layoutVersion == null)
            {
                request.NotFound("No layout version with ID " + layoutVersionId);
            }
            else
            {
                request.Success(layoutVersion);
            }
        }