예제 #1
0
        public void BatchInfinityProcess()
        {
            var allBatches = _managerbatchType.GetEnabledBatchType();

            foreach (var batch in allBatches)
            {
                //Check already added
                var checkAddedd = (from allTask in allTasks where  CompareObject.AreObjectsEqual(allTask, batch) select allTask).ToList();
                if (checkAddedd.Count == 0)
                {
                    var task = new Task(() => AssignTaskForProcessing(batch), TaskCreationOptions.LongRunning);
                    task.Start();
                    allTasks.Add(batch);
                }
            }

            //Check to delete
            foreach (var task in allTasks)
            {
                var checkExistance = (from batche in allBatches where  CompareObject.AreObjectsEqual(task, batche) select batche).ToList();
                if (checkExistance.Count == 0)
                {
                    allTasks.Remove(task);
                }
            }
        }
예제 #2
0
        public void SaveUpdatedTransaction()
        {
            // needs an update here to update variant link in orderitem
            repository.Save();

            // save change history
            var changed  = order.ToModel(transactionType, caller_sessionid);
            var comparer = new CompareObject();
            var diff     = comparer.Compare(original, changed, currency);

            if (diff.Count != 0)
            {
                repository.AddChangeHistory(
                    caller_sessionid,
                    order.id,
                    transactionType == TransactionType.ORDER ? ChangeHistoryType.ORDERS : ChangeHistoryType.INVOICE,
                    diff
                    );
            }

            repository.UpdateProductsOutOfStock(senderDomain.id);
            order.lastUpdate = DateTime.UtcNow;
            repository.Save();
#if LUCENE
            // index order
            var indexer = new LuceneWorker(repository, new IdName(senderDomain.id, senderDomain.name));
            indexer.AddToIndex(LuceneIndexType.TRANSACTION, order);
#endif
        }
예제 #3
0
        public void ValidateDoesNotThrowWhenComparedObjectsAreEqual() {
            object otherObject = new CompareObject("test");
            CompareObject currentObject = new CompareObject("test");
            ValidationContext testContext = new ValidationContext(otherObject, null, null);

            CompareAttribute attr = new CompareAttribute("CompareProperty");
            attr.Validate(currentObject.CompareProperty, testContext);
        }
        public void ValidateDoesNotThrowWhenComparedDoublesAreEqual()
        {
            var mainObject = new CompareObject<double>(4);
            var otherObject = new CompareObject<double>(4);
            _testContext = new ValidationContext(otherObject, null, null);

            Because(mainObject.CompareProperty);
        }
        public void ValidateThrowsWhenComparedDoublesAreLessThan()
        {
            var mainObject = new CompareObject<double>(4);
            var otherObject = new CompareObject<double>(14);
            _testContext = new ValidationContext(otherObject, null, null);

            Because(mainObject.CompareProperty);
        }
        public static void Validate_does_not_throw_when_compared_objects_are_equal()
        {
            var otherObject = new CompareObject("test");
            var currentObject = new CompareObject("test");
            var testContext = new ValidationContext(otherObject, null, null);

            var attribute = new CompareAttribute("CompareProperty");
            AssertEx.DoesNotThrow(() => attribute.Validate(currentObject.CompareProperty, testContext));
        }
        public static void Validate_EqualObjects_DoesNotThrow()
        {
            var otherObject = new CompareObject("test");
            var currentObject = new CompareObject("test");
            var testContext = new ValidationContext(otherObject, null, null);

            var attribute = new CompareAttribute("CompareProperty");
            attribute.Validate(currentObject.CompareProperty, testContext);
        }
        public static void CompareAttribute_can_be_derived_from_and_override_is_valid()
        {
            var otherObject = new CompareObject("a");
            var currentObject = new CompareObject("b");
            var testContext = new ValidationContext(otherObject, null, null);

            var attribute = new DerivedCompareAttribute("CompareProperty");
            AssertEx.DoesNotThrow(() => attribute.Validate(currentObject.CompareProperty, testContext));
        }
        public void EqualToAttributeCanBeDerivedFromAndOverrideIsValid()
        {
            object otherObject = new CompareObject("a");
            CompareObject currentObject = new CompareObject("b");
            ValidationContext testContext = new ValidationContext(otherObject, null, null);

            DerivedEqualToAttribute attr = new DerivedEqualToAttribute("CompareProperty");
            attr.Validate(currentObject.CompareProperty, testContext);
        }
예제 #10
0
        public static void Validate_CustomDerivedClass_DoesNotThrow()
        {
            var otherObject   = new CompareObject("a");
            var currentObject = new CompareObject("b");
            var testContext   = new ValidationContext(otherObject, null, null);

            var attribute = new DerivedCompareAttribute("CompareProperty");

            attribute.Validate(currentObject.CompareProperty, testContext);
        }
예제 #11
0
        public static void Validate_EqualObjects_DoesNotThrow()
        {
            var otherObject   = new CompareObject("test");
            var currentObject = new CompareObject("test");
            var testContext   = new ValidationContext(otherObject, null, null);

            var attribute = new CompareAttribute("CompareProperty");

            attribute.Validate(currentObject.CompareProperty, testContext);
        }
예제 #12
0
        public static void CompareAttribute_can_be_derived_from_and_override_is_valid()
        {
            var otherObject   = new CompareObject("a");
            var currentObject = new CompareObject("b");
            var testContext   = new ValidationContext(otherObject, null, null);

            var attribute = new DerivedCompareAttribute("CompareProperty");

            AssertEx.DoesNotThrow(() => attribute.Validate(currentObject.CompareProperty, testContext));
        }
예제 #13
0
        public void EqualToAttributeCanBeDerivedFromAndOverrideIsValid()
        {
            object            otherObject   = new CompareObject("a");
            CompareObject     currentObject = new CompareObject("b");
            ValidationContext testContext   = new ValidationContext(otherObject, null, null);

            DerivedEqualToAttribute attr = new DerivedEqualToAttribute("CompareProperty");

            attr.Validate(currentObject.CompareProperty, testContext);
        }
예제 #14
0
        public static void Validate_does_not_throw_when_compared_objects_are_equal()
        {
            var otherObject   = new CompareObject("test");
            var currentObject = new CompareObject("test");
            var testContext   = new ValidationContext(otherObject, null, null);

            var attribute = new CompareAttribute("CompareProperty");

            AssertEx.DoesNotThrow(() => attribute.Validate(currentObject.CompareProperty, testContext));
        }
예제 #15
0
        public void ValidateDoesNotThrowWhenComparedObjectsAreEqual()
        {
            object            otherObject   = new CompareObject("test");
            CompareObject     currentObject = new CompareObject("test");
            ValidationContext testContext   = new ValidationContext(otherObject, null, null);

            EqualToAttribute attr = new EqualToAttribute("CompareProperty");

            attr.Validate(currentObject.CompareProperty, testContext);
        }
        public void ValidateThrowsWithOtherPropertyDisplayName()
        {
            CompareObject currentObject = new CompareObject("a");
            object otherObject = new CompareObject("b");

            ValidationContext testContext = new ValidationContext(otherObject, null, null);
            testContext.DisplayName = "CurrentProperty";

            CompareAttribute attr = new CompareAttribute("ComparePropertyWithDisplayName");
            Assert.Throws<ValidationException>(
                delegate { attr.Validate(currentObject.CompareProperty, testContext); }, "'CurrentProperty' and 'DisplayName' do not match.");
        }
예제 #17
0
        public static void Validate_throws_with_OtherProperty_DisplayName()
        {
            var currentObject = new CompareObject("a");
            var otherObject = new CompareObject("b");

            var testContext = new ValidationContext(otherObject, null, null);
            testContext.DisplayName = "CurrentProperty";

            var attribute = new CompareAttribute("ComparePropertyWithDisplayName");
            Assert.Throws<ValidationException>(
                () => attribute.Validate(currentObject.CompareProperty, testContext));
        }
        public void ValidateThrowsWhenComparedObjectsAreNotEqual()
        {
            CompareObject currentObject = new CompareObject("a");
            object otherObject = new CompareObject("b");

            ValidationContext testContext = new ValidationContext(otherObject, null, null);
            testContext.DisplayName = "CurrentProperty";

            EqualToAttribute attr = new EqualToAttribute("CompareProperty");

            attr.Validate(currentObject.CompareProperty, testContext);
        }
예제 #19
0
        public void ValidateThrowsWhenPropertyNameIsUnknown()
        {
            CompareObject currentObject = new CompareObject("a");
            object        otherObject   = new CompareObject("b");

            ValidationContext testContext = new ValidationContext(otherObject, null, null);

            testContext.DisplayName = "CurrentProperty";

            EqualToAttribute attr = new EqualToAttribute("UnknownPropertyName");

            attr.Validate(currentObject.CompareProperty, testContext);
        }
예제 #20
0
        public void ValidateThrowsWhenPropertyNameIsUnknown() {
            CompareObject currentObject = new CompareObject("a");
            object otherObject = new CompareObject("b");

            ValidationContext testContext = new ValidationContext(otherObject, null, null);
            testContext.DisplayName = "CurrentProperty";

            CompareAttribute attr = new CompareAttribute("UnknownPropertyName");
            ExceptionHelper.ExpectException<System.ComponentModel.DataAnnotations.ValidationException>(
                () => attr.Validate(currentObject.CompareProperty, testContext),
                "Could not find a property named UnknownPropertyName."
            );
        }
예제 #21
0
        public void ValidateThrowsWhenComparedObjectsAreNotEqual() {
            CompareObject currentObject = new CompareObject("a");
            object otherObject = new CompareObject("b");

            ValidationContext testContext = new ValidationContext(otherObject, null, null);
            testContext.DisplayName = "CurrentProperty";

            CompareAttribute attr = new CompareAttribute("CompareProperty");
            ExceptionHelper.ExpectException<System.ComponentModel.DataAnnotations.ValidationException>(
                delegate {
                    attr.Validate(currentObject.CompareProperty, testContext);
                }, "'CurrentProperty' and 'CompareProperty' do not match.");
        }
예제 #22
0
        public static void Validate_throws_when_PropertyName_is_unknown()
        {
            var currentObject = new CompareObject("a");
            var otherObject = new CompareObject("b");

            var testContext = new ValidationContext(otherObject, null, null);
            testContext.DisplayName = "CurrentProperty";

            var attribute = new CompareAttribute("UnknownPropertyName");
            Assert.Throws<ValidationException>(
                () => attribute.Validate(currentObject.CompareProperty, testContext));
            // cannot check error message - not defined on ret builds
        }
예제 #23
0
        public void ValidateThrowsWithOtherPropertyDisplayName()
        {
            CompareObject currentObject = new CompareObject("a");
            object        otherObject   = new CompareObject("b");

            ValidationContext testContext = new ValidationContext(otherObject, null, null);

            testContext.DisplayName = "CurrentProperty";

            CompareAttribute attr = new CompareAttribute("ComparePropertyWithDisplayName");

            Assert.Throws <ValidationException>(
                delegate { attr.Validate(currentObject.CompareProperty, testContext); }, "'CurrentProperty' and 'DisplayName' do not match.");
        }
예제 #24
0
        public static void Validate_throws_with_OtherProperty_DisplayName()
        {
            var currentObject = new CompareObject("a");
            var otherObject   = new CompareObject("b");

            var testContext = new ValidationContext(otherObject, null, null);

            testContext.DisplayName = "CurrentProperty";

            var attribute = new CompareAttribute("ComparePropertyWithDisplayName");

            Assert.Throws <ValidationException>(
                () => attribute.Validate(currentObject.CompareProperty, testContext));
        }
예제 #25
0
        /// <summary>
        /// Build compare validation
        /// </summary>
        /// <param name="modelType">Model type</param>
        /// <param name="compareValue">Compare value</param>
        /// <param name="compareType">Compare type</param>
        /// <param name="parameterExpression">Parameter expression</param>
        /// <param name="funcType">Func type</param>
        /// <param name="parameterArray">Parameter array</param>
        /// <param name="compareOperator">Compare operator</param>
        /// <param name="fieldInstance">field instance</param>
        void BuildCompareValidation(Type modelType, object compareValue, CompareObject compareType, ParameterExpression parameterExpression, Type funcType, Array parameterArray, CompareOperator compareOperator, object fieldInstance)
        {
            MethodInfo compareMethod = ValidationMethods.FirstOrDefault(c => c.Name == "SetCompareValidation");

            if (compareMethod == null)
            {
                return;
            }
            //object compareValue = rule.Value;
            switch (compareType)
            {
            case CompareObject.Field:
                string[]   comparePropertyNameArray = compareValue.ToString().LSplit(".");
                Expression comparePropertyExpress   = null;
                foreach (string pname in comparePropertyNameArray)
                {
                    if (comparePropertyExpress == null)
                    {
                        comparePropertyExpress = Expression.PropertyOrField(parameterExpression, pname);
                    }
                    else
                    {
                        comparePropertyExpress = Expression.PropertyOrField(comparePropertyExpress, pname);
                    }
                }
                var compareLambdaExpression = LambdaMethod.MakeGenericMethod(funcType).Invoke(null, new object[]
                {
                    Expression.Convert(comparePropertyExpress, typeof(object)), parameterArray
                });
                if (compareLambdaExpression == null)
                {
                    return;
                }
                compareValue = compareLambdaExpression;
                break;

            default:
                if (compareOperator == CompareOperator.In || compareOperator == CompareOperator.NotIn)
                {
                    IEnumerable <dynamic> valueArray = compareValue.ToString().LSplit(",");
                    compareValue = valueArray;
                }
                break;
            }
            compareMethod.MakeGenericMethod(modelType).Invoke(null, new object[]
            {
                compareOperator, compareValue, fieldInstance
            });
        }
예제 #26
0
        public static void Validate_throws_when_PropertyName_is_unknown()
        {
            var currentObject = new CompareObject("a");
            var otherObject   = new CompareObject("b");

            var testContext = new ValidationContext(otherObject, null, null);

            testContext.DisplayName = "CurrentProperty";

            var attribute = new CompareAttribute("UnknownPropertyName");

            Assert.Throws <ValidationException>(
                () => attribute.Validate(currentObject.CompareProperty, testContext));
            // cannot check error message - not defined on ret builds
        }
예제 #27
0
        public void ValidateThrowsWhenPropertyNameIsUnknown()
        {
            CompareObject currentObject = new CompareObject("a");
            object        otherObject   = new CompareObject("b");

            ValidationContext testContext = new ValidationContext(otherObject, null, null);

            testContext.DisplayName = "CurrentProperty";

            CompareAttribute attr = new CompareAttribute("UnknownPropertyName");

            ExceptionHelper.ExpectException <System.ComponentModel.DataAnnotations.ValidationException>(
                () => attr.Validate(currentObject.CompareProperty, testContext),
                "Could not find a property named UnknownPropertyName."
                );
        }
예제 #28
0
        public void ValidateThrowsWhenComparedObjectsAreNotEqual()
        {
            CompareObject currentObject = new CompareObject("a");
            object        otherObject   = new CompareObject("b");

            ValidationContext testContext = new ValidationContext(otherObject, null, null);

            testContext.DisplayName = "CurrentProperty";

            CompareAttribute attr = new CompareAttribute("CompareProperty");

            ExceptionHelper.ExpectException <System.ComponentModel.DataAnnotations.ValidationException>(
                delegate {
                attr.Validate(currentObject.CompareProperty, testContext);
            }, "'CurrentProperty' and 'CompareProperty' do not match.");
        }
예제 #29
0
        public void ValidateThrowsWhenPropertyNameIsUnknown()
        {
            CompareObject currentObject = new CompareObject("a");
            object        otherObject   = new CompareObject("b");

            ValidationContext testContext = new ValidationContext(otherObject, null, null);

            testContext.DisplayName = "CurrentProperty";

            CompareAttribute attr = new CompareAttribute("UnknownPropertyName");

            Assert.Throws <ValidationException>(
                () => attr.Validate(currentObject.CompareProperty, testContext),
                "Could not find a property named UnknownPropertyName."
                );
        }
예제 #30
0
파일: BLL.cs 프로젝트: trongtai1801/MyGym
 public static void GenericSort(object[] list, CompareObject cmp)
 {
     for (int i = 0; i < list.Length - 1; i++)
     {
         for (int j = i + 1; j < list.Length; j++)
         {
             if (cmp(list[i], list[j]))
             {
                 object temp;
                 temp    = list[i];
                 list[i] = list[j];
                 list[j] = temp;
             }
         }
     }
 }
        public void ErrorMessageTest()
        {
            var currentObject = new CompareObject("a");
            object otherObject = new CompareObject("b");

            var testContext = new ValidationContext(otherObject, null, null);
            testContext.DisplayName = "CurrentProperty";

            var attribute = new EqualToAttribute("CompareProperty")
            {
                ErrorMessage = "SampleErrorMessage"
            };

            var result = attribute.GetValidationResult(currentObject, new ValidationContext(otherObject, null, null));

            Assert.AreEqual("SampleErrorMessage", result.ErrorMessage);
        }
        public void ErrorResourcesTest()
        {
            var currentObject = new CompareObject("a");
            object otherObject = new CompareObject("b");

            var testContext = new ValidationContext(otherObject, null, null);
            testContext.DisplayName = "CurrentProperty";

            var attribute = new EqualToAttribute("CompareProperty")
                                {
                                    ErrorMessageResourceName = "ErrorMessage",
                                    ErrorMessageResourceType = typeof (ErrorResources)
                                };

            var result = attribute.GetValidationResult(currentObject, new ValidationContext(otherObject, null, null));

            Assert.AreEqual(ErrorResources.ErrorMessage, result.ErrorMessage);
        }
예제 #33
0
        public void ErrorMessageTest()
        {
            var    currentObject = new CompareObject("a");
            object otherObject   = new CompareObject("b");

            var testContext = new ValidationContext(otherObject, null, null);

            testContext.DisplayName = "CurrentProperty";

            var attribute = new EqualToAttribute("CompareProperty")
            {
                ErrorMessage = "SampleErrorMessage"
            };

            var result = attribute.GetValidationResult(currentObject, new ValidationContext(otherObject, null, null));

            Assert.AreEqual("SampleErrorMessage", result.ErrorMessage);
        }
예제 #34
0
        public void ErrorResourcesTest()
        {
            var    currentObject = new CompareObject("a");
            object otherObject   = new CompareObject("b");

            var testContext = new ValidationContext(otherObject, null, null);

            testContext.DisplayName = "CurrentProperty";

            var attribute = new EqualToAttribute("CompareProperty")
            {
                ErrorMessageResourceName = "ErrorMessage",
                ErrorMessageResourceType = typeof(ErrorResources)
            };

            var result = attribute.GetValidationResult(currentObject, new ValidationContext(otherObject, null, null));

            Assert.AreEqual(ErrorResources.ErrorMessage, result.ErrorMessage);
        }
        public void GlobalizedErrorResourcesTest()
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-MX");

            var currentObject = new CompareObject("a");
            object otherObject = new CompareObject("b");

            var testContext = new ValidationContext(otherObject, null, null);
            testContext.DisplayName = "CurrentProperty";

            var attribute = new EqualToAttribute("CompareProperty")
            {
                ErrorMessageResourceName = "ErrorMessage",
                ErrorMessageResourceType = typeof(ErrorResources)
            };

            var result = attribute.GetValidationResult(currentObject, new ValidationContext(otherObject, null, null));

            Assert.AreEqual("mensaje de error", result.ErrorMessage);
        }
예제 #36
0
        public void GlobalizedErrorResourcesTest()
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-MX");

            var    currentObject = new CompareObject("a");
            object otherObject   = new CompareObject("b");

            var testContext = new ValidationContext(otherObject, null, null);

            testContext.DisplayName = "CurrentProperty";

            var attribute = new EqualToAttribute("CompareProperty")
            {
                ErrorMessageResourceName = "ErrorMessage",
                ErrorMessageResourceType = typeof(ErrorResources)
            };

            var result = attribute.GetValidationResult(currentObject, new ValidationContext(otherObject, null, null));

            Assert.AreEqual("mensaje de error", result.ErrorMessage);
        }
예제 #37
0
        private void btnAddCompare_Click(object sender, EventArgs e)
        {
            // Ceck if at least 1 sequence is selected in A and B
            if (this.controlSequencesA.SequencesSelected.Count == 0)
            {
                MessageBox.Show(this.FindForm(), "Please select at least one sequence in A to compare!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (this.controlSequencesB.SequencesSelected.Count == 0)
            {
                MessageBox.Show(this.FindForm(), "Please select at least one sequence in B to compare!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (string.IsNullOrEmpty(this.txtSavePath.Text))
            {
                MessageBox.Show(this.FindForm(), "Please select a savepath!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Check if the Filename already exists in another CompareObject
            foreach (object objAktuell in this.listBoxChosenCompares.Items)
            {
                if (objAktuell is CompareObject compObj && compObj.SavePath == this.txtSavePath.Text)
                {
                    MessageBox.Show(this.FindForm(), "The chosen filename is already in use by another Compare, please select another filename!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            // Create a new CompareObject
            CompareObject compareNew = new CompareObject(this.controlSequencesA.SequencesSelected, this.controlSequencesB.SequencesSelected, this.txtSavePath.Text);

            this.listBoxChosenCompares.Items.Add(compareNew);
            // And clear the items in the sequencelists
            this.controlSequencesA.ResetSelectedSequences();
            this.controlSequencesB.ResetSelectedSequences();
        }
예제 #38
0
        public ActionResult Update(long?id, string email, string address, string city, long?citySelected, string coPhone,
                                   string companyName, IEnumerable <int?> country, string fax, string firstName, int?permissions,
                                   string gender, string lastName, string notes, string phone, string postcode, string title, string password,
                                   IEnumerable <string> states_canadian, IEnumerable <string> states_other, IEnumerable <string> states_us,
                                   string billing_first_name, string billing_last_name, string billing_company, string billing_address, string billing_city, long?billing_citySelected,
                                   string billing_postcode, string billing_phone,
                                   string shipping_first_name, string shipping_last_name, string shipping_company, string shipping_address, string shipping_city, long?shipping_citySelected, string shipping_postcode, string shipping_phone)
        {
            if (!id.HasValue)
            {
                return(SendJsonErrorResponse("Missing ID"));
            }

            try
            {
                var contact = repository.GetContact(subdomainid.Value, id.Value);

                if (contact == null)
                {
                    return(SendJsonErrorResponse("Missing ID"));
                }

                var original = contact.ToModel(sessionid, subdomainid.Value);

                // no need to take into account whether an organisation is there because it will always be created
                contact.organisation1.address = address.Trim();
                if (citySelected.HasValue)
                {
                    var mcity = repository.GetCity(citySelected.Value);
                    contact.organisation1.MASTERcity = mcity;
                }
                else if (!string.IsNullOrEmpty(city))
                {
                    contact.organisation1.MASTERcity = repository.AddCity(city);
                }
                if (coPhone != null)
                {
                    contact.organisation1.phone = coPhone;
                }
                if (companyName != null)
                {
                    contact.organisation1.name = companyName;
                }
                if (country != null)
                {
                    contact.organisation1.country = country.ElementAtOrDefault(0);
                    contact.organisation1.state   = AddressHandler.GetState(country.ElementAtOrDefault(0), states_us.ElementAtOrDefault(0), states_canadian.ElementAtOrDefault(0), states_other.ElementAtOrDefault(0));
                }
                if (fax != null)
                {
                    contact.organisation1.fax = fax;
                }

                if (email != null)
                {
                    contact.email = email;
                }
                if (firstName != null)
                {
                    contact.firstName = firstName;
                }
                if (gender != null)
                {
                    contact.gender = gender;
                }
                if (lastName != null)
                {
                    contact.lastName = lastName;
                }
                if (phone != null)
                {
                    contact.phoneNumber = phone;
                }
                if (postcode != null)
                {
                    contact.organisation1.postcode = postcode;
                }

                // handle addresses
                var addressHandler = new AddressHandler(contact.organisation1, repository);
                addressHandler.SetShippingAndBillingAddresses(billing_first_name,
                                                              billing_last_name,
                                                              billing_company,
                                                              billing_address,
                                                              billing_city,
                                                              billing_citySelected,
                                                              billing_postcode,
                                                              billing_phone,
                                                              country.ElementAtOrDefault(1),
                                                              states_canadian.ElementAtOrDefault(1),
                                                              states_other.ElementAtOrDefault(1),
                                                              states_us.ElementAtOrDefault(1),
                                                              shipping_first_name,
                                                              shipping_last_name,
                                                              shipping_company,
                                                              shipping_address,
                                                              shipping_city,
                                                              shipping_citySelected,
                                                              shipping_postcode,
                                                              shipping_phone,
                                                              country.ElementAtOrDefault(2),
                                                              states_canadian.ElementAtOrDefault(2),
                                                              states_other.ElementAtOrDefault(2),
                                                              states_us.ElementAtOrDefault(2),
                                                              false);

                if (title != null)
                {
                    contact.title = title;
                }

                if (!string.IsNullOrEmpty(password))
                {
                    // password specified
                    contact.passwordHash = Crypto.Utility.ComputePasswordHash(email + password);
                }
                else
                {
                    // password removed
                    contact.passwordHash = null;
                }

                // list of fields that are allowed to be modified
                if (notes != null)
                {
                    contact.notes = notes;
                }

                // handle permissions
                if (permissions.HasValue)
                {
                    contact.permissions = permissions;
                }

                repository.AddActivity(sessionid.Value,
                                       new ActivityMessage(id.Value, sessionid,
                                                           ActivityMessageType.CONTACT_UPDATED,
                                                           new HtmlLink(contact.ToEmailName(true), id.Value).ToContactString()), subdomainid.Value);

                repository.Save();
#if LUCENE
                // update search index
                var indexer = new LuceneWorker(db, MASTERdomain.ToIdName());
                indexer.AddToIndex(LuceneIndexType.CONTACTS, contact);
#endif
                // get changed and store in database
                var changed  = contact.ToModel(sessionid, subdomainid.Value);
                var comparer = new CompareObject();
                var diff     = comparer.Compare(original, changed);
                if (diff.Count != 0)
                {
                    repository.AddChangeHistory(sessionid.Value, contact.id, ChangeHistoryType.CONTACT, diff);
                }
            }
            catch (Exception ex)
            {
                return(SendJsonErrorResponse(ex));
            }
            return(Json(id.ToJsonOKData()));
        }
        public static void Validate_CustomDerivedClass_DoesNotThrow()
        {
            var otherObject = new CompareObject("a");
            var currentObject = new CompareObject("b");
            var testContext = new ValidationContext(otherObject, null, null);

            var attribute = new DerivedCompareAttribute("CompareProperty");
            attribute.Validate(currentObject.CompareProperty, testContext);
        }
        public void ValidateThrowsWhenPropertyNameIsUnknown()
        {
            CompareObject currentObject = new CompareObject("a");
            object otherObject = new CompareObject("b");

            ValidationContext testContext = new ValidationContext(otherObject, null, null);
            testContext.DisplayName = "CurrentProperty";

            CompareAttribute attr = new CompareAttribute("UnknownPropertyName");
            Assert.Throws<ValidationException>(
                () => attr.Validate(currentObject.CompareProperty, testContext),
                "Could not find a property named UnknownPropertyName."
                );
        }
예제 #41
0
        void AssignTaskForProcessing(BatchType type)
        {
            var shouldRun = true;

            while (true)
            {
                if (shouldRun)
                {
                    try
                    {
                        shouldRun = false;
                        //Check Is Batch settinmgs Changes
                        var allBatchTypes = _managerbatchType.GetEnabledBatchType();
                        if (allBatchTypes.Count > 0)
                        {
                            var itsBatchType = (from batchType in allBatchTypes where Guid.Parse(batchType.TenantId.Value) == Guid.Parse(type.TenantId.Value) &&
                                                Guid.Parse(batchType.InternalId.Value) == Guid.Parse(type.InternalId.Value) select batchType).FirstOrDefault();
                            if (itsBatchType == null)
                            {
                                break;
                            }

                            var isExists = CompareObject.AreObjectsEqual(type, itsBatchType);
                            if (!isExists)
                            {
                                break;
                            }
                        }

                        //check scheduler
                        var batchtype = typeof(IBatchTypes);
                        var myType    = DataUtility.GetBatchTypeByContext((BatchTypeContextEnum)(Convert.ToInt16(type.Context.Value)));
                        if (myType != null)
                        {
                            var myObject = Activator.CreateInstance(myType);
                            // Retrieve the method you are looking for
                            MethodInfo preMethodInfo = batchtype.GetMethod("OnExecute");
                            //PostProcess
                            // Invoke the method on the instance we created above
                            var arrayList = new ArrayList
                            {
                                type
                            };
                            var result = (BatchTypeReturnMessage)preMethodInfo.Invoke(myObject, new object[] { arrayList });

                            shouldRun = true;
                            Thread.Sleep(!string.IsNullOrEmpty(type.IdleTime.Value) ? Convert.ToInt32(type.IdleTime.Value) :  10000);
                        }
                        else
                        {
                            shouldRun = true;
                            Thread.Sleep(!string.IsNullOrEmpty(type.IdleTime.Value) ? Convert.ToInt32(type.IdleTime.Value) :  10000);
                        }
                    }
                    catch (ThreadAbortException)
                    {
                        shouldRun = true;
                        Thread.ResetAbort();
                    }
                    catch (System.Exception)
                    {
                        shouldRun = true;
                    }
                }
            }
        }