Ejemplo n.º 1
0
 public void SetUp()
 {
     Matcher     = new RangeConstraint(40, 49);
     GoodValues  = new object[] { 40, 42, 48 };
     BadValues   = new object[] { 39, 49, 50, "42", null };
     Description = "between 40 and 49";
 }
Ejemplo n.º 2
0
        public void Should_match_when_parameter_is_optional()
        {
            var constraint = new RangeConstraint<int>(1, 5, true);

            var matched = constraint.Match(new Mock<HttpContextBase>().Object, new Route("{controller}/{action}", new Mock<IRouteHandler>().Object), "alias", new RouteValueDictionary { { "alias", null } }, RouteDirection.IncomingRequest);

            Assert.True(matched);
        }
Ejemplo n.º 3
0
        public void Should_not_match_when_value_is_not_in_range()
        {
            var constraint = new RangeConstraint<int>(1, 5);

            var matched = constraint.Match(new Mock<HttpContextBase>().Object, new Route("{controller}/{action}", new Mock<IRouteHandler>().Object), "page", new RouteValueDictionary { { "page", 6 } }, RouteDirection.IncomingRequest);

            Assert.False(matched);
        }
Ejemplo n.º 4
0
        public void Should_fail_when_value_lies_outside_of_range(int value, int from, int to, bool inclusive)
        {
            var config = new TestConfig {
                Field = value
            };
            var constraint = new RangeConstraint <TestConfig, int>(c => c.Field, from, to, inclusive);

            constraint.ShouldFailOn(config);
        }
Ejemplo n.º 5
0
        public void Should_match_when_parameter_is_optional()
        {
            var constraint = new RangeConstraint <int>(1, 5, true);

            var matched = constraint.Match(new Mock <HttpContextBase>().Object, new Route("{controller}/{action}", new Mock <IRouteHandler>().Object), "alias", new RouteValueDictionary {
                { "alias", null }
            }, RouteDirection.IncomingRequest);

            Assert.True(matched);
        }
Ejemplo n.º 6
0
        public void Should_match_when_value_is_in_range()
        {
            var constraint = new RangeConstraint <int>(1, 5, true);

            var matched = constraint.Match(new Mock <HttpContextBase>().Object, new Route("{controller}/{action}", new Mock <IRouteHandler>().Object), "page", new RouteValueDictionary {
                { "page", 3 }
            }, RouteDirection.IncomingRequest);

            Assert.True(matched);
        }
Ejemplo n.º 7
0
        public void Should_not_match_when_unable_to_convert()
        {
            var constraint = new RangeConstraint <int>(1, 5);

            var matched = constraint.Match(new Mock <HttpContextBase>().Object, new Route("{controller}/{action}", new Mock <IRouteHandler>().Object), "page", new RouteValueDictionary {
                { "page", "xyz" }
            }, RouteDirection.IncomingRequest);

            Assert.False(matched);
        }
Ejemplo n.º 8
0
        public void SetUp()
        {
#if CLR_2_0 || CLR_4_0
            theConstraint = rangeConstraint = new RangeConstraint <int>(5, 42);
#else
            theConstraint = rangeConstraint = new RangeConstraint(5, 42);
#endif
            expectedDescription  = "in range (5,42)";
            stringRepresentation = "<range 5 42>";
        }
Ejemplo n.º 9
0
        public void TestRangeConstraint()
        {
            {
                var             solver = new SimpleConstraintSolver();
                NumericVariable a      = solver.CreateVariable("a");

                var r = new Range(3, 4, EPS);
                RangeConstraint.CreateRangeConstraint(a, r);
                solver.Solve(_noAbortCheck);
                Assert.AreEqual(r, a.Value);
            }
        }
Ejemplo n.º 10
0
 public static RangeConstraintModel Convert(RangeConstraint rangeConstraint, long attributeId)
 {
     return(new RangeConstraintModel(attributeId)
     {
         Id = rangeConstraint.Id,
         Negated = rangeConstraint.Negated,
         Description = rangeConstraint.Description,
         Min = rangeConstraint.Lowerbound,
         Max = rangeConstraint.Upperbound,
         MinInclude = rangeConstraint.LowerboundIncluded,
         MaxInclude = rangeConstraint.UpperboundIncluded,
         FormalDescription = rangeConstraint.FormalDescription
     });
 }
Ejemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rangeConstraintNode"></param>
        /// <returns></returns>
        static public RangeConstraint BuildRangeConstraint(XmlNode rangeConstraintNode, TypeCode typeCode)
        {
            RangeConstraint rc         = null;
            string          fromString = rangeConstraintNode.SelectSingleNode(ConstraintNodeNames.From).InnerText;
            string          toString   = rangeConstraintNode.SelectSingleNode(ConstraintNodeNames.To).InnerText;

            IComparable from = (IComparable)Convert.ChangeType(fromString, typeCode);
            IComparable to   = (IComparable)Convert.ChangeType(toString, typeCode);

            // TODO: 2010-07-29 change form, to data type
            //
            rc = new RangeConstraint(from, to);
            return(rc);
        }
Ejemplo n.º 12
0
        internal RangeConstraint SaveConstraint(RangeConstraint constraint, DataContainer container)
        {
            Contract.Requires(constraint.Lowerbound <= constraint.Upperbound);
            Contract.Requires(container != null);

            Contract.Ensures(Contract.Result <RangeConstraint>() != null && Contract.Result <RangeConstraint>().Id >= 0);

            constraint.DataContainer = container;
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <RangeConstraint> repo = uow.GetRepository <RangeConstraint>();
                repo.Put(constraint);
                uow.Commit();
            }
            return(constraint);
        }
Ejemplo n.º 13
0
        internal RangeConstraint Update(RangeConstraint entity)
        {
            Contract.Requires(entity != null, "provided entity can not be null");
            Contract.Requires(entity.Id >= 0, "provided entity must have a permanent ID");

            Contract.Ensures(Contract.Result <RangeConstraint>() != null && Contract.Result <RangeConstraint>().Id >= 0, "No entity is persisted!");

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <RangeConstraint> repo = uow.GetRepository <RangeConstraint>();
                repo.Merge(entity);
                var merged = repo.Get(entity.Id);
                repo.Put(merged);
                uow.Commit();
            }
            return(entity);
        }
Ejemplo n.º 14
0
        internal bool Delete(RangeConstraint entity)
        {
            Contract.Requires(entity != null);
            Contract.Requires(entity.Id >= 0);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <RangeConstraint> repo = uow.GetRepository <RangeConstraint>();

                entity = repo.Reload(entity);
                //delete the unit
                repo.Delete(entity);
                // commit changes
                uow.Commit();
            }
            // if any problem was detected during the commit, an exception will be thrown!
            return(true);
        }
Ejemplo n.º 15
0
        public DataAttribute storeRangeConstraint(RangeConstraintModel constraintModel)
        {
            DataContainerManager dcManager = null;

            try
            {
                dcManager = new DataContainerManager();

                DataAttribute dataAttribute = dcManager.DataAttributeRepo.Get(constraintModel.AttributeId);

                if (constraintModel.Max != 0 || constraintModel.Min != 0)
                {
                    if (constraintModel.Id == 0)
                    {
                        RangeConstraint constraint = new RangeConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, constraintModel.Description, constraintModel.Negated, null, null, null, constraintModel.Min, constraintModel.MinInclude, constraintModel.Max, constraintModel.MaxInclude);
                        dcManager.AddConstraint(constraint, dataAttribute);
                    }
                    else
                    {
                        for (int i = 0; i < dataAttribute.Constraints.Count; i++)
                        {
                            if (dataAttribute.Constraints.ElementAt(i).Id == constraintModel.Id)
                            {
                                ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Description        = constraintModel.Description;
                                ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Negated            = constraintModel.Negated;
                                ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Lowerbound         = constraintModel.Min;
                                ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).LowerboundIncluded = constraintModel.MinInclude;
                                ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Upperbound         = constraintModel.Max;
                                ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).UpperboundIncluded = constraintModel.MaxInclude;
                                break;
                            }
                        }
                    }
                }
                return(dataAttribute);
            }
            finally
            {
                dcManager.Dispose();
            }
        }
Ejemplo n.º 16
0
 public void AddConstraint(RangeConstraint constraint, DataContainer container)
 {
     helper.SaveConstraint(constraint, container);
 }
Ejemplo n.º 17
0
 public void SetUp()
 {
     theConstraint        = rangeConstraint = new RangeConstraint(5, 42);
     expectedDescription  = "in range (5,42)";
     stringRepresentation = "<range 5 42>";
 }
Ejemplo n.º 18
0
 public static RangeConstraintModel Convert(RangeConstraint rangeConstraint, long attributeId)
 {
     return new RangeConstraintModel(attributeId)
     {
         Id = rangeConstraint.Id,
         Negated = rangeConstraint.Negated,
         Description = rangeConstraint.Description,
         Min = rangeConstraint.Lowerbound,
         Max = rangeConstraint.Upperbound,
         MinInclude = rangeConstraint.LowerboundIncluded,
         MaxInclude = rangeConstraint.UpperboundIncluded,
         FormalDescription = rangeConstraint.FormalDescription
     };
 }
Ejemplo n.º 19
0
 public void RemoveConstraint(RangeConstraint constraint)
 {
     helper.Delete(constraint);
 }
 public void SetUp()
 {
     theConstraint = rangeConstraint = new RangeConstraint(5, 42);
     expectedDescription = "in range (5,42)";
     stringRepresentation = "<range 5 42>";
 }
Ejemplo n.º 21
0
 public void RemoveConstraint(RangeConstraint constraint)
 {
     constraint.DataContainer = null;
     helper.Delete(constraint);
 }
Ejemplo n.º 22
0
 public JsonResult getRangeConstraintFormalDescription(bool invert, double min, double max, bool mininclude, bool maxinclude)
 {
     RangeConstraint temp = new RangeConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, "", invert, null, null, null, min, mininclude, max, maxinclude);
     return Json((temp.FormalDescription), JsonRequestBehavior.AllowGet);
 }
Ejemplo n.º 23
0
 public void RemoveConstraint(RangeConstraint constraint)
 {
     constraint.DataContainer = null;
     helper.Delete(constraint);
 }
Ejemplo n.º 24
0
        internal RangeConstraint SaveConstraint(RangeConstraint constraint, DataContainer container)
        {
            Contract.Requires(constraint.Lowerbound <= constraint.Upperbound);
            Contract.Requires(container != null);

            Contract.Ensures(Contract.Result<RangeConstraint>() != null && Contract.Result<RangeConstraint>().Id >= 0);

            constraint.DataContainer = container;
            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<RangeConstraint> repo = uow.GetRepository<RangeConstraint>();
                repo.Put(constraint);
                uow.Commit();
            }
            return (constraint);
        }
Ejemplo n.º 25
0
        private void addConstraintsTo()
        {
            DataContainerManager dcManager = new DataContainerManager();
            var attr = dcManager.DataAttributeRepo.Get(1);

            var c1 = new RangeConstraint(ConstraintProviderSource.Internal, "", "en-US", "should be between 1 and 12 meter", true, null, null, null, 1.00, true, 12.00, true);
            dcManager.AddConstraint(c1, attr);
            var v1 = c1.IsSatisfied(14);

            var c2 = new PatternConstraint(ConstraintProviderSource.Internal, "", "en-US", "a simple email validation constraint", false, null, null, null, @"^\S+@\S+$", false);
            dcManager.AddConstraint(c2, attr);
            var v2 = c2.IsSatisfied("*****@*****.**");

            List<DomainItem> items = new List<DomainItem>() { new DomainItem () {Key = "A", Value = "This is A" },
                                                              new DomainItem () {Key = "B", Value = "This is B" },
                                                              new DomainItem () {Key = "C", Value = "This is C" },
                                                              new DomainItem () {Key = "D", Value = "This is D" },
                                                            };
            var c3 = new DomainConstraint(ConstraintProviderSource.Internal, "", "en-US", "a simple domain validation constraint", false, null, null, null, items);
            dcManager.AddConstraint(c3, attr);
            var v3 = c3.IsSatisfied("A");
            v3 = c3.IsSatisfied("E");
            c3.Negated = true;
            v3 = c3.IsSatisfied("A");

            var c4 = new ComparisonConstraint(ConstraintProviderSource.Internal, "", "en-US", "a comparison validation constraint", false, null, null, null
                , ComparisonOperator.GreaterThanOrEqual, ComparisonTargetType.Value, "", ComparisonOffsetType.Ratio, 1.25);
            dcManager.AddConstraint(c4, attr);
            var v4 = c4.IsSatisfied(14, 10);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// In this thread, try to create a model that uses the given amount of memory
        /// </summary>
        /// <param name="solverType">The type of the underlying solver to be used.</param>
        /// <param name="memoryGb">The amount of memory in GB to be used by this worker.</param>
        private void SonnetStressTestWorker(Type solverType, double memoryGb)
        {
            try
            {
                string threadid = System.Threading.Thread.CurrentThread.Name;
                Model  model    = new Model();
                Solver solver   = new Solver(model, solverType);

                Console.WriteLine("Available Memory (GB) Now: " + Utils.AvailableMemoryGb);
                Console.WriteLine("Current process Memory (GB) Now: " + Utils.ProcessMemoryGb);
                Console.WriteLine("Attempting to use (GB): " + memoryGb);
                // N = 3K, M = 30K, Z=100 requires about 110MB in 32-bit and 140MB in 64-bit mode.
                // Note: Arguably only M and Z matter, but we scall also N
                double f;
                if (IntPtr.Size == 4)
                {
                    f = memoryGb / 0.110;
                }
                else
                {
                    f = memoryGb / 0.140;
                }

                // Somehow the memory usage is much less on Windows 10 with .NET 4.7, so multiply by 13
                // the stress test
                int N = (int)(f * 3000);  // number of variables
                int M = (int)(f * 30000); // number of rangeconstraints
                int p = M / 10;
                int Z = 100;              // number nonzeros per constraint

                Variable   x    = new Variable();
                Variable[] vars = Variable.New(N);

                for (int m = 0; m < M; m++)
                {
                    if (m % p == 0)
                    {
                        Console.WriteLine(string.Format("Thread {0}: Building {1}", threadid, (1.0 * m / M).ToString("p")));
                    }
                    Expression expr = new Expression();
                    expr.Add(x);

                    for (int z = 0; z < Z; z++)
                    {
                        int i = (z + m) % N; // always between 0 and N-1
                        expr.Add(vars[i]);
                    }

                    int available = m;

                    string          rowName = "MyConstraint(" + m + ")";
                    RangeConstraint con     = (RangeConstraint)model.Add(rowName,
                                                                         -model.Infinity <= expr <= available);

                    expr.Assemble();
                    Assert.IsTrue(expr.NumberOfCoefficients == Z + 1);

                    expr.Clear();
                }

                Console.WriteLine(string.Format("Thread {0}: Start Generate... (this can take a while)", threadid));

                solver.Generate();

                Assert.IsTrue(solver.OsiSolver.getNumRows() == model.NumberOfConstraints);
                Assert.IsTrue(model.NumberOfConstraints == M);
                Assert.IsTrue(solver.OsiSolver.getNumElements() == M * (Z + 1));
                GC.Collect();
                Console.WriteLine("Available Memory (GB) Now: " + Utils.AvailableMemoryGb);
                Console.WriteLine("Current process Memory (GB) Now: " + Utils.ProcessMemoryGb);
                Console.WriteLine(string.Format("Thread {0}: Finished", threadid));
                model.Clear();
                Console.WriteLine(string.Format("Thread {0}: Closed", threadid));
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());
                Console.WriteLine(exception.StackTrace.ToString());
                Console.WriteLine("Available Memory (GB) Now: " + Utils.AvailableMemoryGb);
                Console.WriteLine("Current process Memory (GB) Now: " + Utils.ProcessMemoryGb);

                Assert.Fail("Stress test failed. Could be out-of-memory.");
                throw;
                // could be out-of-memory... Can we examine the SEHException?
            }
        }
Ejemplo n.º 27
0
        internal bool Delete(RangeConstraint entity)
        {
            Contract.Requires(entity != null);
            Contract.Requires(entity.Id >= 0);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<RangeConstraint> repo = uow.GetRepository<RangeConstraint>();

                entity = repo.Reload(entity);
                //delete the unit
                repo.Delete(entity);
                // commit changes
                uow.Commit();
            }
            // if any problem was detected during the commit, an exception will be thrown!
            return (true);
        }
Ejemplo n.º 28
0
        internal RangeConstraint Update(RangeConstraint entity)
        {
            Contract.Requires(entity != null, "provided entity can not be null");
            Contract.Requires(entity.Id >= 0, "provided entity must have a permanent ID");

            Contract.Ensures(Contract.Result<RangeConstraint>() != null && Contract.Result<RangeConstraint>().Id >= 0, "No entity is persisted!");

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<RangeConstraint> repo = uow.GetRepository<RangeConstraint>();
                repo.Put(entity); // Merge is required here!!!!
                uow.Commit();
            }
            return (entity);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Get metadata for deploying a package to the given resource group
        /// </summary>
        /// <param name='parameters'>
        /// Required. Parameters for operation
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// A standard service response including an HTTP status code and
        /// request ID.
        /// </returns>
        public async Task <GetDeploymentTemplateMetadataResponse> GetMetadataAsync(GetDeploymentMetadataRequest parameters, CancellationToken cancellationToken)
        {
            // Validate
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("parameters", parameters);
                TracingAdapter.Enter(invocationId, this, "GetMetadataAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/subscriptions/";
            if (this.Client.Credentials.SubscriptionId != null)
            {
                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
            }
            url = url + "/providers/Microsoft.AppService/deploymenttemplates/";
            if (parameters.MicroserviceId != null)
            {
                url = url + Uri.EscapeDataString(parameters.MicroserviceId);
            }
            url = url + "/listmetadata";
            List <string> queryParameters = new List <string>();

            queryParameters.Add("api-version=2015-03-01-preview");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Post;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    GetDeploymentTemplateMetadataResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new GetDeploymentTemplateMetadataResponse();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            DeploymentTemplateMetadata metadataInstance = new DeploymentTemplateMetadata();
                            result.Metadata = metadataInstance;

                            JToken valueValue = responseDoc["value"];
                            if (valueValue != null && valueValue.Type != JTokenType.Null)
                            {
                                JToken microserviceIdValue = valueValue["microserviceId"];
                                if (microserviceIdValue != null && microserviceIdValue.Type != JTokenType.Null)
                                {
                                    string microserviceIdInstance = ((string)microserviceIdValue);
                                    metadataInstance.MicroserviceId = microserviceIdInstance;
                                }

                                JToken displayNameValue = valueValue["displayName"];
                                if (displayNameValue != null && displayNameValue.Type != JTokenType.Null)
                                {
                                    string displayNameInstance = ((string)displayNameValue);
                                    metadataInstance.DisplayName = displayNameInstance;
                                }

                                JToken appSettingsArray = valueValue["appSettings"];
                                if (appSettingsArray != null && appSettingsArray.Type != JTokenType.Null)
                                {
                                    foreach (JToken appSettingsValue in ((JArray)appSettingsArray))
                                    {
                                        ParameterMetadata parameterMetadataInstance = new ParameterMetadata();
                                        metadataInstance.Parameters.Add(parameterMetadataInstance);

                                        JToken nameValue = appSettingsValue["name"];
                                        if (nameValue != null && nameValue.Type != JTokenType.Null)
                                        {
                                            string nameInstance = ((string)nameValue);
                                            parameterMetadataInstance.Name = nameInstance;
                                        }

                                        JToken typeValue = appSettingsValue["type"];
                                        if (typeValue != null && typeValue.Type != JTokenType.Null)
                                        {
                                            string typeInstance = ((string)typeValue);
                                            parameterMetadataInstance.Type = typeInstance;
                                        }

                                        JToken displayNameValue2 = appSettingsValue["displayName"];
                                        if (displayNameValue2 != null && displayNameValue2.Type != JTokenType.Null)
                                        {
                                            string displayNameInstance2 = ((string)displayNameValue2);
                                            parameterMetadataInstance.DisplayName = displayNameInstance2;
                                        }

                                        JToken descriptionValue = appSettingsValue["description"];
                                        if (descriptionValue != null && descriptionValue.Type != JTokenType.Null)
                                        {
                                            string descriptionInstance = ((string)descriptionValue);
                                            parameterMetadataInstance.Description = descriptionInstance;
                                        }

                                        JToken tooltipValue = appSettingsValue["tooltip"];
                                        if (tooltipValue != null && tooltipValue.Type != JTokenType.Null)
                                        {
                                            string tooltipInstance = ((string)tooltipValue);
                                            parameterMetadataInstance.Tooltip = tooltipInstance;
                                        }

                                        JToken uiHintValue = appSettingsValue["uiHint"];
                                        if (uiHintValue != null && uiHintValue.Type != JTokenType.Null)
                                        {
                                            string uiHintInstance = ((string)uiHintValue);
                                            parameterMetadataInstance.UIHint = uiHintInstance;
                                        }

                                        JToken defaultValueValue = appSettingsValue["defaultValue"];
                                        if (defaultValueValue != null && defaultValueValue.Type != JTokenType.Null)
                                        {
                                            string defaultValueInstance = ((string)defaultValueValue);
                                            parameterMetadataInstance.DefaultValue = defaultValueInstance;
                                        }

                                        JToken constraintsValue = appSettingsValue["constraints"];
                                        if (constraintsValue != null && constraintsValue.Type != JTokenType.Null)
                                        {
                                            ParameterConstraints constraintsInstance = new ParameterConstraints();
                                            parameterMetadataInstance.Constraints = constraintsInstance;

                                            JToken requiredValue = constraintsValue["required"];
                                            if (requiredValue != null && requiredValue.Type != JTokenType.Null)
                                            {
                                                bool requiredInstance = ((bool)requiredValue);
                                                constraintsInstance.Required = requiredInstance;
                                            }

                                            JToken hiddenValue = constraintsValue["hidden"];
                                            if (hiddenValue != null && hiddenValue.Type != JTokenType.Null)
                                            {
                                                bool hiddenInstance = ((bool)hiddenValue);
                                                constraintsInstance.Hidden = hiddenInstance;
                                            }

                                            JToken allowedValuesArray = constraintsValue["allowedValues"];
                                            if (allowedValuesArray != null && allowedValuesArray.Type != JTokenType.Null)
                                            {
                                                foreach (JToken allowedValuesValue in ((JArray)allowedValuesArray))
                                                {
                                                    constraintsInstance.AllowedValues.Add(((string)allowedValuesValue));
                                                }
                                            }

                                            JToken rangeValue = constraintsValue["range"];
                                            if (rangeValue != null && rangeValue.Type != JTokenType.Null)
                                            {
                                                RangeConstraint rangeInstance = new RangeConstraint();
                                                constraintsInstance.Range = rangeInstance;

                                                JToken lowerBoundValue = rangeValue["lowerBound"];
                                                if (lowerBoundValue != null && lowerBoundValue.Type != JTokenType.Null)
                                                {
                                                    int lowerBoundInstance = ((int)lowerBoundValue);
                                                    rangeInstance.LowerBound = lowerBoundInstance;
                                                }

                                                JToken upperBoundValue = rangeValue["upperBound"];
                                                if (upperBoundValue != null && upperBoundValue.Type != JTokenType.Null)
                                                {
                                                    int upperBoundInstance = ((int)upperBoundValue);
                                                    rangeInstance.UpperBound = upperBoundInstance;
                                                }
                                            }

                                            JToken lengthValue = constraintsValue["length"];
                                            if (lengthValue != null && lengthValue.Type != JTokenType.Null)
                                            {
                                                LengthConstraint lengthInstance = new LengthConstraint();
                                                constraintsInstance.Length = lengthInstance;

                                                JToken minValue = lengthValue["min"];
                                                if (minValue != null && minValue.Type != JTokenType.Null)
                                                {
                                                    int minInstance = ((int)minValue);
                                                    lengthInstance.Min = minInstance;
                                                }

                                                JToken maxValue = lengthValue["max"];
                                                if (maxValue != null && maxValue.Type != JTokenType.Null)
                                                {
                                                    int maxInstance = ((int)maxValue);
                                                    lengthInstance.Max = maxInstance;
                                                }
                                            }

                                            JToken containsCharactersValue = constraintsValue["containsCharacters"];
                                            if (containsCharactersValue != null && containsCharactersValue.Type != JTokenType.Null)
                                            {
                                                string containsCharactersInstance = ((string)containsCharactersValue);
                                                constraintsInstance.ContainsCharacters = containsCharactersInstance;
                                            }

                                            JToken notContainsCharactersValue = constraintsValue["notContainsCharacters"];
                                            if (notContainsCharactersValue != null && notContainsCharactersValue.Type != JTokenType.Null)
                                            {
                                                string notContainsCharactersInstance = ((string)notContainsCharactersValue);
                                                constraintsInstance.NotContainsCharacters = notContainsCharactersInstance;
                                            }

                                            JToken hasDigitValue = constraintsValue["hasDigit"];
                                            if (hasDigitValue != null && hasDigitValue.Type != JTokenType.Null)
                                            {
                                                bool hasDigitInstance = ((bool)hasDigitValue);
                                                constraintsInstance.HasDigit = hasDigitInstance;
                                            }

                                            JToken hasLetterValue = constraintsValue["hasLetter"];
                                            if (hasLetterValue != null && hasLetterValue.Type != JTokenType.Null)
                                            {
                                                bool hasLetterInstance = ((bool)hasLetterValue);
                                                constraintsInstance.HasLetter = hasLetterInstance;
                                            }

                                            JToken hasPunctuationValue = constraintsValue["hasPunctuation"];
                                            if (hasPunctuationValue != null && hasPunctuationValue.Type != JTokenType.Null)
                                            {
                                                bool hasPunctuationInstance = ((bool)hasPunctuationValue);
                                                constraintsInstance.HasPunctuation = hasPunctuationInstance;
                                            }

                                            JToken numericValue = constraintsValue["numeric"];
                                            if (numericValue != null && numericValue.Type != JTokenType.Null)
                                            {
                                                bool numericInstance = ((bool)numericValue);
                                                constraintsInstance.Numeric = numericInstance;
                                            }
                                        }
                                    }
                                }

                                JToken dependsOnArray = valueValue["dependsOn"];
                                if (dependsOnArray != null && dependsOnArray.Type != JTokenType.Null)
                                {
                                    foreach (JToken dependsOnValue in ((JArray)dependsOnArray))
                                    {
                                        MicroserviceMetadata microserviceMetadataInstance = new MicroserviceMetadata();
                                        metadataInstance.DependsOn.Add(microserviceMetadataInstance);

                                        JToken microserviceIdValue2 = dependsOnValue["microserviceId"];
                                        if (microserviceIdValue2 != null && microserviceIdValue2.Type != JTokenType.Null)
                                        {
                                            string microserviceIdInstance2 = ((string)microserviceIdValue2);
                                            microserviceMetadataInstance.MicroserviceId = microserviceIdInstance2;
                                        }

                                        JToken displayNameValue3 = dependsOnValue["displayName"];
                                        if (displayNameValue3 != null && displayNameValue3.Type != JTokenType.Null)
                                        {
                                            string displayNameInstance3 = ((string)displayNameValue3);
                                            microserviceMetadataInstance.DisplayName = displayNameInstance3;
                                        }

                                        JToken appSettingsArray2 = dependsOnValue["appSettings"];
                                        if (appSettingsArray2 != null && appSettingsArray2.Type != JTokenType.Null)
                                        {
                                            foreach (JToken appSettingsValue2 in ((JArray)appSettingsArray2))
                                            {
                                                ParameterMetadata parameterMetadataInstance2 = new ParameterMetadata();
                                                microserviceMetadataInstance.Parameters.Add(parameterMetadataInstance2);

                                                JToken nameValue2 = appSettingsValue2["name"];
                                                if (nameValue2 != null && nameValue2.Type != JTokenType.Null)
                                                {
                                                    string nameInstance2 = ((string)nameValue2);
                                                    parameterMetadataInstance2.Name = nameInstance2;
                                                }

                                                JToken typeValue2 = appSettingsValue2["type"];
                                                if (typeValue2 != null && typeValue2.Type != JTokenType.Null)
                                                {
                                                    string typeInstance2 = ((string)typeValue2);
                                                    parameterMetadataInstance2.Type = typeInstance2;
                                                }

                                                JToken displayNameValue4 = appSettingsValue2["displayName"];
                                                if (displayNameValue4 != null && displayNameValue4.Type != JTokenType.Null)
                                                {
                                                    string displayNameInstance4 = ((string)displayNameValue4);
                                                    parameterMetadataInstance2.DisplayName = displayNameInstance4;
                                                }

                                                JToken descriptionValue2 = appSettingsValue2["description"];
                                                if (descriptionValue2 != null && descriptionValue2.Type != JTokenType.Null)
                                                {
                                                    string descriptionInstance2 = ((string)descriptionValue2);
                                                    parameterMetadataInstance2.Description = descriptionInstance2;
                                                }

                                                JToken tooltipValue2 = appSettingsValue2["tooltip"];
                                                if (tooltipValue2 != null && tooltipValue2.Type != JTokenType.Null)
                                                {
                                                    string tooltipInstance2 = ((string)tooltipValue2);
                                                    parameterMetadataInstance2.Tooltip = tooltipInstance2;
                                                }

                                                JToken uiHintValue2 = appSettingsValue2["uiHint"];
                                                if (uiHintValue2 != null && uiHintValue2.Type != JTokenType.Null)
                                                {
                                                    string uiHintInstance2 = ((string)uiHintValue2);
                                                    parameterMetadataInstance2.UIHint = uiHintInstance2;
                                                }

                                                JToken defaultValueValue2 = appSettingsValue2["defaultValue"];
                                                if (defaultValueValue2 != null && defaultValueValue2.Type != JTokenType.Null)
                                                {
                                                    string defaultValueInstance2 = ((string)defaultValueValue2);
                                                    parameterMetadataInstance2.DefaultValue = defaultValueInstance2;
                                                }

                                                JToken constraintsValue2 = appSettingsValue2["constraints"];
                                                if (constraintsValue2 != null && constraintsValue2.Type != JTokenType.Null)
                                                {
                                                    ParameterConstraints constraintsInstance2 = new ParameterConstraints();
                                                    parameterMetadataInstance2.Constraints = constraintsInstance2;

                                                    JToken requiredValue2 = constraintsValue2["required"];
                                                    if (requiredValue2 != null && requiredValue2.Type != JTokenType.Null)
                                                    {
                                                        bool requiredInstance2 = ((bool)requiredValue2);
                                                        constraintsInstance2.Required = requiredInstance2;
                                                    }

                                                    JToken hiddenValue2 = constraintsValue2["hidden"];
                                                    if (hiddenValue2 != null && hiddenValue2.Type != JTokenType.Null)
                                                    {
                                                        bool hiddenInstance2 = ((bool)hiddenValue2);
                                                        constraintsInstance2.Hidden = hiddenInstance2;
                                                    }

                                                    JToken allowedValuesArray2 = constraintsValue2["allowedValues"];
                                                    if (allowedValuesArray2 != null && allowedValuesArray2.Type != JTokenType.Null)
                                                    {
                                                        foreach (JToken allowedValuesValue2 in ((JArray)allowedValuesArray2))
                                                        {
                                                            constraintsInstance2.AllowedValues.Add(((string)allowedValuesValue2));
                                                        }
                                                    }

                                                    JToken rangeValue2 = constraintsValue2["range"];
                                                    if (rangeValue2 != null && rangeValue2.Type != JTokenType.Null)
                                                    {
                                                        RangeConstraint rangeInstance2 = new RangeConstraint();
                                                        constraintsInstance2.Range = rangeInstance2;

                                                        JToken lowerBoundValue2 = rangeValue2["lowerBound"];
                                                        if (lowerBoundValue2 != null && lowerBoundValue2.Type != JTokenType.Null)
                                                        {
                                                            int lowerBoundInstance2 = ((int)lowerBoundValue2);
                                                            rangeInstance2.LowerBound = lowerBoundInstance2;
                                                        }

                                                        JToken upperBoundValue2 = rangeValue2["upperBound"];
                                                        if (upperBoundValue2 != null && upperBoundValue2.Type != JTokenType.Null)
                                                        {
                                                            int upperBoundInstance2 = ((int)upperBoundValue2);
                                                            rangeInstance2.UpperBound = upperBoundInstance2;
                                                        }
                                                    }

                                                    JToken lengthValue2 = constraintsValue2["length"];
                                                    if (lengthValue2 != null && lengthValue2.Type != JTokenType.Null)
                                                    {
                                                        LengthConstraint lengthInstance2 = new LengthConstraint();
                                                        constraintsInstance2.Length = lengthInstance2;

                                                        JToken minValue2 = lengthValue2["min"];
                                                        if (minValue2 != null && minValue2.Type != JTokenType.Null)
                                                        {
                                                            int minInstance2 = ((int)minValue2);
                                                            lengthInstance2.Min = minInstance2;
                                                        }

                                                        JToken maxValue2 = lengthValue2["max"];
                                                        if (maxValue2 != null && maxValue2.Type != JTokenType.Null)
                                                        {
                                                            int maxInstance2 = ((int)maxValue2);
                                                            lengthInstance2.Max = maxInstance2;
                                                        }
                                                    }

                                                    JToken containsCharactersValue2 = constraintsValue2["containsCharacters"];
                                                    if (containsCharactersValue2 != null && containsCharactersValue2.Type != JTokenType.Null)
                                                    {
                                                        string containsCharactersInstance2 = ((string)containsCharactersValue2);
                                                        constraintsInstance2.ContainsCharacters = containsCharactersInstance2;
                                                    }

                                                    JToken notContainsCharactersValue2 = constraintsValue2["notContainsCharacters"];
                                                    if (notContainsCharactersValue2 != null && notContainsCharactersValue2.Type != JTokenType.Null)
                                                    {
                                                        string notContainsCharactersInstance2 = ((string)notContainsCharactersValue2);
                                                        constraintsInstance2.NotContainsCharacters = notContainsCharactersInstance2;
                                                    }

                                                    JToken hasDigitValue2 = constraintsValue2["hasDigit"];
                                                    if (hasDigitValue2 != null && hasDigitValue2.Type != JTokenType.Null)
                                                    {
                                                        bool hasDigitInstance2 = ((bool)hasDigitValue2);
                                                        constraintsInstance2.HasDigit = hasDigitInstance2;
                                                    }

                                                    JToken hasLetterValue2 = constraintsValue2["hasLetter"];
                                                    if (hasLetterValue2 != null && hasLetterValue2.Type != JTokenType.Null)
                                                    {
                                                        bool hasLetterInstance2 = ((bool)hasLetterValue2);
                                                        constraintsInstance2.HasLetter = hasLetterInstance2;
                                                    }

                                                    JToken hasPunctuationValue2 = constraintsValue2["hasPunctuation"];
                                                    if (hasPunctuationValue2 != null && hasPunctuationValue2.Type != JTokenType.Null)
                                                    {
                                                        bool hasPunctuationInstance2 = ((bool)hasPunctuationValue2);
                                                        constraintsInstance2.HasPunctuation = hasPunctuationInstance2;
                                                    }

                                                    JToken numericValue2 = constraintsValue2["numeric"];
                                                    if (numericValue2 != null && numericValue2.Type != JTokenType.Null)
                                                    {
                                                        bool numericInstance2 = ((bool)numericValue2);
                                                        constraintsInstance2.Numeric = numericInstance2;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
Ejemplo n.º 30
0
        private DataAttribute storeConstraint(ConstraintModel constraintModel, DataAttribute dataAttribute)
        {
            DataContainerManager dcManager = null;

            try
            {
                dcManager = new DataContainerManager();

                if (constraintModel is RangeConstraintModel)
                {
                    RangeConstraintModel rcm = (RangeConstraintModel)constraintModel;

                    if (rcm.Id == 0)
                    {
                        RangeConstraint constraint = new RangeConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, rcm.Description, rcm.Negated, null, null, null, rcm.Min, rcm.MinInclude, rcm.Max, rcm.MaxInclude);
                        dcManager.AddConstraint(constraint, dataAttribute);
                    }
                    else
                    {
                        for (int i = 0; i < dataAttribute.Constraints.Count; i++)
                        {
                            if (dataAttribute.Constraints.ElementAt(i).Id == rcm.Id)
                            {
                                ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Description        = rcm.Description;
                                ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Negated            = rcm.Negated;
                                ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Lowerbound         = rcm.Min;
                                ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).LowerboundIncluded = rcm.MinInclude;
                                ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Upperbound         = rcm.Max;
                                ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).UpperboundIncluded = rcm.MaxInclude;
                                break;
                            }
                        }
                    }
                }

                if (constraintModel is PatternConstraintModel)
                {
                    PatternConstraintModel pcm = (PatternConstraintModel)constraintModel;

                    if (pcm.Id == 0)
                    {
                        PatternConstraint constraint = new PatternConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, pcm.Description, pcm.Negated, null, null, null, pcm.MatchingPhrase, true);
                        dcManager.AddConstraint(constraint, dataAttribute);
                    }
                    else
                    {
                        for (int i = 0; i < dataAttribute.Constraints.Count; i++)
                        {
                            if (dataAttribute.Constraints.ElementAt(i).Id == pcm.Id)
                            {
                                ((PatternConstraint)dataAttribute.Constraints.ElementAt(i)).Description    = pcm.Description;
                                ((PatternConstraint)dataAttribute.Constraints.ElementAt(i)).Negated        = pcm.Negated;
                                ((PatternConstraint)dataAttribute.Constraints.ElementAt(i)).MatchingPhrase = pcm.MatchingPhrase;
                                break;
                            }
                        }
                    }
                }

                if (constraintModel is DomainConstraintModel)
                {
                    DomainConstraintModel dcm = (DomainConstraintModel)constraintModel;

                    List <DomainItem> items = createDomainItems(dcm.Terms);

                    dcm.Terms = cutSpaces(dcm.Terms);

                    if (items.Count > 0)
                    {
                        if (dcm.Id == 0)
                        {
                            DomainConstraint constraint = new DomainConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, dcm.Description, dcm.Negated, null, null, null, items);
                            dcManager.AddConstraint(constraint, dataAttribute);
                        }
                        else
                        {
                            DomainConstraint temp = new DomainConstraint();
                            for (int i = 0; i < dataAttribute.Constraints.Count; i++)
                            {
                                if (dataAttribute.Constraints.ElementAt(i).Id == dcm.Id)
                                {
                                    temp = (DomainConstraint)dataAttribute.Constraints.ElementAt(i);
                                    temp.Materialize();
                                    temp.Description = dcm.Description;
                                    temp.Negated     = dcm.Negated;
                                    temp.Items       = items;
                                    dcManager.AddConstraint(temp, dataAttribute);
                                    break;
                                }
                            }
                        }
                    }
                }

                return(dataAttribute);
            }
            finally
            {
                dcManager.Dispose();
            }
        }
Ejemplo n.º 31
0
        private DataAttribute storeConstraint(ConstraintModel constraintModel, DataAttribute dataAttribute)
        {
            DataContainerManager dcManager = new DataContainerManager();

            if (constraintModel is RangeConstraintModel)
            {
                RangeConstraintModel rcm = (RangeConstraintModel)constraintModel;

                if (rcm.Id == 0)
                {
                    RangeConstraint constraint = new RangeConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, rcm.Description, rcm.Negated, null, null, null, rcm.Min, rcm.MinInclude, rcm.Max, rcm.MaxInclude);
                    dcManager.AddConstraint(constraint, dataAttribute);
                }
                else
                {
                    for(int i = 0; i < dataAttribute.Constraints.Count; i++)
                    {
                        if (dataAttribute.Constraints.ElementAt(i).Id == rcm.Id)
                        {
                            ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Description = rcm.Description;
                            ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Negated = rcm.Negated;
                            ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Lowerbound = rcm.Min;
                            ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).LowerboundIncluded = rcm.MinInclude;
                            ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Upperbound = rcm.Max;
                            ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).UpperboundIncluded = rcm.MaxInclude;
                            break;
                        }
                    }
                }
            }

            if (constraintModel is PatternConstraintModel)
            {
                PatternConstraintModel pcm = (PatternConstraintModel)constraintModel;

                if (pcm.Id == 0)
                {
                    PatternConstraint constraint = new PatternConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, pcm.Description, pcm.Negated, null, null, null, pcm.MatchingPhrase, false);
                    dcManager.AddConstraint(constraint, dataAttribute);
                }
                else
                {
                    for (int i = 0; i < dataAttribute.Constraints.Count; i++)
                    {
                        if (dataAttribute.Constraints.ElementAt(i).Id == pcm.Id)
                        {
                            ((PatternConstraint)dataAttribute.Constraints.ElementAt(i)).Description = pcm.Description;
                            ((PatternConstraint)dataAttribute.Constraints.ElementAt(i)).Negated = pcm.Negated;
                            ((PatternConstraint)dataAttribute.Constraints.ElementAt(i)).MatchingPhrase = pcm.MatchingPhrase;
                            break;
                        }
                    }
                }
            }

            if (constraintModel is DomainConstraintModel)
            {
                DomainConstraintModel dcm = (DomainConstraintModel)constraintModel;

                List<DomainItem> items = createDomainItems(dcm.Terms);

                dcm.Terms = cutSpaces(dcm.Terms);

                if (items.Count > 0)
                {
                    if (dcm.Id == 0)
                    {
                        DomainConstraint constraint = new DomainConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, dcm.Description, dcm.Negated, null, null, null, items);
                        dcManager.AddConstraint(constraint, dataAttribute);
                    }
                    else
                    {
                        DomainConstraint temp = new DomainConstraint();
                        for (int i = 0; i < dataAttribute.Constraints.Count; i++)
                        {
                            if (dataAttribute.Constraints.ElementAt(i).Id == dcm.Id)
                            {
                                temp = (DomainConstraint)dataAttribute.Constraints.ElementAt(i);
                                temp.Materialize();
                                temp.Description = dcm.Description;
                                temp.Negated = dcm.Negated;
                                temp.Items = items;
                                dcManager.AddConstraint(temp, dataAttribute);
                                break;
                            }
                        }
                    }
                }
            }

            return dataAttribute;
        }
Ejemplo n.º 32
0
        private RangeConstraint GetRangeConstraint(double min, double max,string description, bool negated, bool lowerBoundIncluded, bool upperBoundIncluded,  MetadataAttribute attr)
        {
            RangeConstraint constraint = new RangeConstraint(ConstraintProviderSource.Internal, "", "en-US", description, negated, null, null, null, min, lowerBoundIncluded, max, upperBoundIncluded);
            dataContainerManager.AddConstraint(constraint, attr);

            return constraint;
        }
Ejemplo n.º 33
0
 public void AddConstraint(RangeConstraint constraint, DataContainer container)
 {
     helper.SaveConstraint(constraint, container);
 }
 public RangeConstraintGenerator(BaseFieldGenerator field, RangeConstraint rule)
 {
     _field = field;
     _rule = rule;
 }
Ejemplo n.º 35
0
        public JsonResult getRangeConstraintFormalDescription(bool invert, bool mininclude, bool maxinclude, double min = 0, double max = 0)
        {
            RangeConstraint temp = new RangeConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, "", invert, null, null, null, min, mininclude, max, maxinclude);

            return(Json((temp.FormalDescription), JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 36
0
        public DataAttribute storeRangeConstraint(RangeConstraintModel constraintModel)
        {
            DataContainerManager dcManager = new DataContainerManager();
            DataAttribute dataAttribute = dcManager.DataAttributeRepo.Get(constraintModel.AttributeId);

            if (constraintModel.Max != 0 || constraintModel.Min != 0)
            {
                if (constraintModel.Id == 0)
                {
                    RangeConstraint constraint = new RangeConstraint(ConstraintProviderSource.Internal, "", AppConfiguration.Culture.Name, constraintModel.Description, constraintModel.Negated, null, null, null, constraintModel.Min, constraintModel.MinInclude, constraintModel.Max, constraintModel.MaxInclude);
                    dcManager.AddConstraint(constraint, dataAttribute);
                }
                else
                {
                    for (int i = 0; i < dataAttribute.Constraints.Count; i++)
                    {
                        if (dataAttribute.Constraints.ElementAt(i).Id == constraintModel.Id)
                        {
                            ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Description = constraintModel.Description;
                            ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Negated = constraintModel.Negated;
                            ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Lowerbound = constraintModel.Min;
                            ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).LowerboundIncluded = constraintModel.MinInclude;
                            ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).Upperbound = constraintModel.Max;
                            ((RangeConstraint)dataAttribute.Constraints.ElementAt(i)).UpperboundIncluded = constraintModel.MaxInclude;
                            break;
                        }
                    }
                }
            }
            return dataAttribute;
        }
Ejemplo n.º 37
0
 public void ShouldThrowExceptionIfFromIsLessThanTo()
 {
     var comparer = new GenericComparer<int>();
     rangeConstraint = new RangeConstraint( 42, 5 );
     rangeConstraint.Using(comparer).ApplyTo(19);
 }
Ejemplo n.º 38
0
 public void RemoveConstraint(RangeConstraint constraint)
 {
     helper.Delete(constraint);
 }