public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ParameterInfo          parameter = context.Parameter;
            ManualTriggerAttribute attribute = parameter.GetCustomAttribute <ManualTriggerAttribute>(inherit: false);

            if (attribute == null)
            {
                return(Task.FromResult <ITriggerBinding>(null));
            }

            // Can bind to user types, and all the Read Types supported by StreamValueBinder
            IEnumerable <Type> supportedTypes = StreamValueBinder.GetSupportedTypes(FileAccess.Read);
            bool isSupportedTypeBinding       = ValueBinder.MatchParameterType(parameter, supportedTypes);
            bool isUserTypeBinding            = !isSupportedTypeBinding && Utility.IsValidUserType(parameter.ParameterType);

            if (!isSupportedTypeBinding && !isUserTypeBinding)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                  "Can't bind ManualTriggerAttribute to type '{0}'.", parameter.ParameterType));
            }

            return(Task.FromResult <ITriggerBinding>(new ManualTriggerBinding(context.Parameter, isUserTypeBinding)));
        }
Exemple #2
0
        protected void rptOperators_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.DataItem is User)
            {
                var user = (User)e.Item.DataItem;
                ValueBinder.BindLiteral(e.Item, "litName", user.FullName);

                var litCount = e.Item.FindControl("litCount") as Literal;
                if (litCount != null)
                {
                    int total = Module.TotalCustomer(_date, _date, user);

                    if (!_totalMap.ContainsKey(user.Id))
                    {
                        _totalMap.Add(user.Id, 0);
                    }
                    _totalMap[user.Id] += total;

                    ValueBinder.BindLiteral(e.Item, "litCount", total.ToString());
                }

                var litTotal = e.Item.FindControl("litTotal") as Literal;
                if (litTotal != null)
                {
                    litTotal.Text = _totalMap[user.Id].ToString();
                }
            }
        }
Exemple #3
0
        /// <inheritdoc/>
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ParameterInfo        parameter = context.Parameter;
            FileTriggerAttribute attribute = parameter.GetCustomAttribute <FileTriggerAttribute>(inherit: false);

            if (attribute == null)
            {
                return(Task.FromResult <ITriggerBinding>(null));
            }

            // next, verify that the type is one of the types we support
            IEnumerable <Type> types = StreamValueBinder.GetSupportedTypes(FileAccess.Read)
                                       .Union(new Type[] { typeof(FileStream), typeof(FileSystemEventArgs), typeof(FileInfo) });

            if (!ValueBinder.MatchParameterType(context.Parameter, types))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                  "Can't bind FileTriggerAttribute to type '{0}'.", parameter.ParameterType));
            }

            return(Task.FromResult <ITriggerBinding>(new FileTriggerBinding(_config, parameter, _logger)));
        }
Exemple #4
0
        protected void rptDates_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.DataItem is BookingHistory)
            {
                var history = (BookingHistory)e.Item.DataItem;

                if (_prev != null)
                {
                    if (_prev.StartDate == history.StartDate)
                    {
                        e.Item.Visible = false;
                        return;
                    }
                }

                try
                {
                    ValueBinder.BindLiteral(e.Item, "litTime", history.Date.ToString("dd-MMM-yyyy HH:mm"));
                    ValueBinder.BindLiteral(e.Item, "litUser", history.User.FullName);
                    ValueBinder.BindLiteral(e.Item, "litTo", history.StartDate.ToString("dd/MM/yyyy"));
                }
                catch (Exception) { }

                if (_prev != null)
                {
                    try
                    {
                        ValueBinder.BindLiteral(e.Item, "litFrom", _prev.StartDate.ToString("dd/MM/yyyy"));
                    }
                    catch (Exception) { }
                }
                _prev = history;
            }
        }
Exemple #5
0
    public override async Task SetParametersAsync(ParameterView parameters)
    {
        await base.SetParametersAsync(parameters);

        if (Binding != null)
        {
            _binder = ValueBinder.Create(Binding);
            if (Label == null)
            {
                Label = _binder.ValueLabel.Titleize();
            }
            if (!Hidden && ChildContent == null)
            {
                var func = Binding.Compile();
                ChildContent = item => builder => builder.AddContent(1, func.Invoke(item));
            }
            if (SortBy && SortByExpression == null)
            {
                SortByExpression = (q, d) => q.OrderByDirection(d, Binding);
            }
            if (SearchBy && SearchByPredicate == null)
            {
                SearchByPredicate = (input) => PredicateBuilder.Contains(
                    Binding, input.SearchValue !, SearchByCaseInsensitive);
            }
        }
    }
        public Task <IBinding> TryCreateAsync(BindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            var parameter = context.Parameter;
            var attribute = parameter.GetCustomAttributes(typeof(FtpAttribute), inherit: false);

            if (attribute == null || attribute.Length == 0)
            {
                return(Task.FromResult <IBinding>(null));
            }

            // TODO: Include any other parameter types this binding supports in this check
            var supportedTypes = new List <Type> {
                typeof(FtpMessage)
            };

            if (!ValueBinder.MatchParameterType(context.Parameter, supportedTypes))
            {
                throw new InvalidOperationException($"Can't bind {nameof(FtpAttribute)} to type '{parameter.ParameterType}'.");
            }

            return(Task.FromResult <IBinding>(new FtpBinding(_config, parameter, _trace, (FtpAttribute)attribute[0])));
        }
Exemple #7
0
        protected void rptGroups_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.DataItem is QuestionGroup)
            {
                QuestionGroup group = (QuestionGroup)e.Item.DataItem;
                ValueBinder.BindLiteral(e.Item, "litGroupName", group.Name);
                TextBox txtComment = (TextBox)e.Item.FindControl("txtComment");

                Repeater rptQuestions = (Repeater)e.Item.FindControl("rptQuestions");
                _currentOptions         = group.Selections;
                rptQuestions.DataSource = group.Questions;
                rptQuestions.DataBind();

                foreach (AnswerGroup grp in _currentSheet.Groups)
                {
                    if (grp.Group.Id == group.Id)
                    {
                        txtComment.Text = grp.Comment;
                        break;
                    }
                }

                if (group.Questions.Count > 0)
                {
                    _hasQuestion = true;
                    Repeater rptOptions = (Repeater)e.Item.FindControl("rptOptions");
                    rptOptions.DataSource = _currentOptions;
                    rptOptions.DataBind();
                }
                else
                {
                    _hasQuestion = false;
                }
            }
        }
        public Task <IBinding> TryCreateAsync(BindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            // Determine whether we should bind to the current parameter
            ParameterInfo   parameter = context.Parameter;
            SampleAttribute attribute = parameter.GetCustomAttribute <SampleAttribute>(inherit: false);

            if (attribute == null)
            {
                return(Task.FromResult <IBinding>(null));
            }

            // TODO: Include any other parameter types this binding supports in this check
            if (!ValueBinder.MatchParameterType(context.Parameter, StreamValueBinder.SupportedTypes))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                  "Can't bind SampleAttribute to type '{0}'.", parameter.ParameterType));
            }

            return(Task.FromResult <IBinding>(new SampleBinding(parameter)));
        }
        public Task <IBinding> TryCreateAsync(BindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            ParameterInfo parameter = context.Parameter;
            FtpAttribute  attribute = parameter.GetCustomAttribute <FtpAttribute>(inherit: false);

            if (attribute == null)
            {
                return(Task.FromResult <IBinding>(null));
            }

            string path = attribute.Path;

            if (_nameResolver != null)
            {
                path = _nameResolver.ResolveWholeString(path);
            }
            BindingTemplate bindingTemplate = BindingTemplate.FromString(path);

            bindingTemplate.ValidateContractCompatibility(context.BindingDataContract);

            IEnumerable <Type> types = StreamValueBinder.GetSupportedTypes(FileAccess.Read);

            if (!ValueBinder.MatchParameterType(context.Parameter, types))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                  "Can't bind FtpAttribute to type '{0}'.", parameter.ParameterType));
            }

            return(Task.FromResult <IBinding>(new FtpBinding(_config, parameter, bindingTemplate)));
        }
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ParameterInfo        parameter = context.Parameter;
            HttpTriggerAttribute attribute = parameter.GetCustomAttribute <HttpTriggerAttribute>(inherit: false);

            if (attribute == null)
            {
                return(Task.FromResult <ITriggerBinding>(null));
            }

            // Can bind to user types, HttpRequestMessage, object (for dynamic binding support) and all the Read
            // Types supported by StreamValueBinder
            IEnumerable <Type> supportedTypes = StreamValueBinder.GetSupportedTypes(FileAccess.Read)
                                                .Union(new Type[] { typeof(HttpRequest), typeof(object), typeof(HttpRequestMessage) });
            bool isSupportedTypeBinding = ValueBinder.MatchParameterType(parameter, supportedTypes);
            bool isUserTypeBinding      = !isSupportedTypeBinding && IsValidUserType(parameter.ParameterType);

            if (!isSupportedTypeBinding && !isUserTypeBinding)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                  "Can't bind HttpTriggerAttribute to type '{0}'.", parameter.ParameterType));
            }

            return(Task.FromResult <ITriggerBinding>(new HttpTriggerBinding(attribute, context.Parameter, isUserTypeBinding, _responseHook)));
        }
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ParameterInfo        parameter = context.Parameter;
            HttpTriggerAttribute attribute = parameter.GetCustomAttribute <HttpTriggerAttribute>(inherit: false);

            if (attribute == null)
            {
                return(Task.FromResult <ITriggerBinding>(null));
            }

            bool isSupportedTypeBinding = ValueBinder.MatchParameterType(parameter, _supportedTypes);
            bool isUserTypeBinding      = !isSupportedTypeBinding && IsValidUserType(parameter.ParameterType);

            if (!isSupportedTypeBinding && !isUserTypeBinding)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                  "Can't bind HttpTriggerAttribute to type '{0}'.", parameter.ParameterType));
            }

            return(Task.FromResult <ITriggerBinding>(new HttpTriggerBinding(attribute, context.Parameter, isUserTypeBinding, _responseHook)));
        }
        protected void rptStatus_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.DataItem is BookingHistory)
            {
                var history = (BookingHistory)e.Item.DataItem;

                if (_prev != null)
                {
                    if (_prev.Status == history.Status)
                    {
                        e.Item.Visible = false;
                        return;
                    }
                }

                ValueBinder.BindLiteral(e.Item, "litTime", history.Date.ToString("dd-MMM-yyyy HH:mm"));
                ValueBinder.BindLiteral(e.Item, "litUser", history.User.FullName);
                ValueBinder.BindLiteral(e.Item, "litTo", history.Status.ToString());
                if (_prev != null)
                {
                    ValueBinder.BindLiteral(e.Item, "litFrom", _prev.Status.ToString());
                }
                _prev = history;
            }
        }
        protected void rptRooms_OnItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.DataItem is BookingHistory)
            {
                var history = (BookingHistory)e.Item.DataItem;

                if (history.NewRoom != null)
                {
                    if (history.OldRoom == history.NewRoom)
                    {
                        e.Item.Visible = false;
                        return;
                    }


                    ValueBinder.BindLiteral(e.Item, "litTime", history.Date.ToString("dd-MMM-yyyy HH:mm"));
                    ValueBinder.BindLiteral(e.Item, "litUser", history.User.FullName);
                    ValueBinder.BindLiteral(e.Item, "litFrom", history.OldRoom != null ? history.OldRoom.Name : "");
                    ValueBinder.BindLiteral(e.Item, "litTo", history.NewRoom.Name);
                }
                else
                {
                    e.Item.Visible = false;
                }
            }
        }
Exemple #14
0
        public void FunctionCall <T>(T value)
        {
            var vh     = new ReadWriteValueHolder <T>(value);
            var exp    = CreateExpression(() => vh.GetValue());
            var binder = ValueBinder.Create(exp);

            binder.CanSetValue.Should().BeFalse();
            binder.ValueLabel.Should().Be(nameof(vh.GetValue));
            binder.TargetType.Should().Be(typeof(T));
        }
Exemple #15
0
        public void ReadWritePropertyWithUnary()
        {
            var vh     = new ReadWriteValueHolder <int>(42);
            var exp    = CreateExpression(() => - vh.Value);
            var binder = ValueBinder.Create(exp);

            binder.CanSetValue.Should().BeTrue();
            binder.ValueLabel.Should().Be(nameof(vh.Value));
            binder.TargetType.Should().Be(vh.GetType());
        }
Exemple #16
0
        public void ReadOnlyProperty <T>(T value)
        {
            var vh     = new ReadOnlyValueHolder <T>(value);
            var exp    = CreateExpression(() => vh.Value);
            var binder = ValueBinder.Create(exp);

            binder.CanSetValue.Should().BeFalse();
            binder.ValueLabel.Should().Be(nameof(vh.Value));
            binder.TargetType.Should().Be(vh.GetType());
        }
        public Task<IValueProvider> BindAsync(object value, ValueBindingContext context)
        {
            if (value == null || !_parameter.ParameterType.IsAssignableFrom(value.GetType()))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unable to convert value to {0}.", _parameter.ParameterType));
            }

            IValueProvider valueProvider = new ValueBinder(value, _parameter.ParameterType);
            return Task.FromResult<IValueProvider>(valueProvider);
        }
 protected void rptQuestionsReport_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.DataItem is Question)
     {
         _currentQuestion = (Question)e.Item.DataItem;
         ValueBinder.BindLiteral(e.Item, "litQuestion", _currentQuestion.Name);
         Repeater rptAnswerData = (Repeater)e.Item.FindControl("rptAnswerData");
         rptAnswerData.DataSource = _currentQuestion.Group.Selections;
         rptAnswerData.DataBind();
     }
 }
        public Task <IValueProvider> BindAsync(object value, ValueBindingContext context)
        {
            if (value == null || !_parameter.ParameterType.IsAssignableFrom(value.GetType()))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unable to convert value to {0}.", _parameter.ParameterType));
            }

            IValueProvider valueProvider = new ValueBinder(value, _parameter.ParameterType);

            return(Task.FromResult <IValueProvider>(valueProvider));
        }
 protected void rptOptions_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.DataItem is Question)
     {
         Question     question = (Question)e.Item.DataItem;
         AnswerOption op       = _currentGroup.AnswerSheet.GetOption(question);
         if (op.Option > 0)
         {
             ValueBinder.BindLiteral(e.Item, "litOption", _currentGroup.Group.Selections[op.Option - 1]);
         }
     }
 }
        protected void rptVoucherList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.DataItem is VoucherBatch)
            {
                var batch = (VoucherBatch)e.Item.DataItem;

                if (batch.Agency != null)
                {
                    ValueBinder.BindLiteral(e.Item, "litAgency", batch.Agency.Name);
                }
                ValueBinder.BindLiteral(e.Item, "litTotal", batch.Quantity);
                var criterion = Expression.And(Expression.Eq("Deleted", false),
                                               Expression.And(Expression.Eq("Batch.Id", batch.Id),
                                                              Expression.Not(Expression.Eq("Status", StatusType.Cancelled)))
                                               );
                var bookingUsedBatchVoucher = Module.GetObject <Booking>(criterion, 0, 0);
                int countVoucherUsed        = 0;
                if (bookingUsedBatchVoucher != null)
                {
                    foreach (Booking booking in bookingUsedBatchVoucher)
                    {
                        countVoucherUsed = countVoucherUsed + booking.VoucherCode.Split(new char[] { ';' }).Length;
                    }
                }
                ValueBinder.BindLiteral(e.Item, "litRemain", batch.Quantity - countVoucherUsed);

                if (countVoucherUsed > 0)
                {
                    var hplBookings = (HyperLink)e.Item.FindControl("hplBookings");
                    hplBookings.Visible     = true;
                    hplBookings.NavigateUrl = string.Format("BookingList.aspx?NodeId={0}&SectionId={1}&batchid={2}",
                                                            Node.Id, Section.Id, batch.Id);
                }

                ValueBinder.BindLiteral(e.Item, "litValidUntil", batch.ValidUntil.ToString("dd/MM/yyyy"));
                if (!string.IsNullOrEmpty(batch.ContractFile))
                {
                    var hplContract = (HyperLink)e.Item.FindControl("hplContract");
                    hplContract.Text        = @"Download file";
                    hplContract.NavigateUrl = batch.ContractFile;
                }

                var hplName = (HyperLink)e.Item.FindControl("hplName");
                hplName.Text        = batch.Name;
                hplName.NavigateUrl = string.Format("VoucherEdit.aspx?NodeId={0}&SectionId={1}&batchid={2}", Node.Id,
                                                    Section.Id, batch.Id);

                var hplEdit = (HyperLink)e.Item.FindControl("hplEdit");
                hplEdit.NavigateUrl = string.Format("VoucherEdit.aspx?NodeId={0}&SectionId={1}&batchid={2}", Node.Id,
                                                    Section.Id, batch.Id);
            }
        }
        protected void rptContacts_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.DataItem is AgencyContact)
            {
                var contact = (AgencyContact)e.Item.DataItem;

                if (!contact.Enabled)
                {
                    e.Item.Visible = false;
                    return;
                }

                var ltrName = (Literal)e.Item.FindControl("ltrName");
                ltrName.Text = contact.Name;

                var hplName = (HyperLink)e.Item.FindControl("hplName");
                hplName.NavigateUrl = "javascript:";

                if (_editPermission)
                {
                    string url = string.Format("AgencyContactEdit.aspx?NodeId={0}&SectionId={1}&contactid={2}",
                                               Node.Id, Section.Id, contact.Id);
                    hplName.Attributes.Add("onclick", CMS.ServerControls.Popup.OpenPopupScript(url, "Contact", 300, 400));
                }

                var linkEmail = (HyperLink)e.Item.FindControl("hplEmail");
                linkEmail.Text        = contact.Email;
                linkEmail.NavigateUrl = string.Format("mailto:{0}", contact.Email);

                ValueBinder.BindLiteral(e.Item, "litPosition", contact.Position);
                ValueBinder.BindLiteral(e.Item, "litPhone", contact.Phone);

                if (contact.IsBooker)
                {
                    ValueBinder.BindLiteral(e.Item, "litBooker", "Booker");
                }

                var lbtDelete = (LinkButton)e.Item.FindControl("lbtDelete");
                lbtDelete.Visible         = _editPermission;
                lbtDelete.CommandArgument = contact.Id.ToString();

                {
                    var hplCreateMeeting = (HyperLink)e.Item.FindControl("hplCreateMeeting");
                    hplCreateMeeting.NavigateUrl = "javascript:";
                    string url = string.Format("EditMeeting.aspx?NodeId={0}&SectionId={1}&contact={2}",
                                               Node.Id, Section.Id, contact.Id);
                    hplCreateMeeting.Attributes.Add("onclick",
                                                    CMS.ServerControls.Popup.OpenPopupScript(url, "Contract", 300, 400));
                }
            }
        }
        protected void rptAnswerData_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.DataItem is string)
            {
                string str    = e.Item.DataItem.ToString();
                int    choice = _currentQuestion.Group.Selections.IndexOf(str) + 1;
                // Đếm số choice = 1
                int total;
                int count = Module.ChoiceReport(Request.QueryString, _currentQuestion, choice, out total);

                ValueBinder.BindLiteral(e.Item, "litCount", count);
                ValueBinder.BindLiteral(e.Item, "litPercentage", ((double)count * 100 / total).ToString("#0.##") + "%");
            }
        }
Exemple #24
0
        protected void rptQuestion_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.DataItem is Question)
            {
                Question question = (Question)e.Item.DataItem;
                ValueBinder.BindLiteral(e.Item, "litQuestion", question.Content);

                _currentQuestion = question;

                Repeater rptOptions = (Repeater)e.Item.FindControl("rptOptions");
                rptOptions.DataSource = _currentOptions;
                rptOptions.DataBind();
            }
        }
Exemple #25
0
        public void RootStringConstant()
        {
            var x      = CreateExpression(() => "foo");
            var binder = ValueBinder.Create(x);

            binder.CanSetValue.Should().BeFalse();
            binder.ValueLabel.Should().BeNull();
            binder.TargetType.Should().Be(typeof(string));
            binder.TargetRoot.ToString().Should().Be(x.ToString());

            var targetPathLabels = string.Join(".", binder.TargetPath.Select(x => x.Label));

            targetPathLabels.Should().Be(nameof(System.String));
        }
Exemple #26
0
        public void RootField <T>(T value)
        {
            var localValue = value;
            var exp        = CreateExpression(() => localValue);
            var binder     = ValueBinder.Create(exp);

            binder.CanSetValue.Should().BeTrue();
            binder.ValueLabel.Should().Be(nameof(localValue));
            binder.TargetType.Should().Be(((MemberExpression)exp.Body).Expression.Type);

            //binder.TargetRoot.ToString().Should().Be(x.ToString());
            //var targetPathLabels = string.Join(".", binder.TargetPath.Select(x => x.Label));
            //targetPathLabels.Should().Be(pathLabels);
        }
Exemple #27
0
    public override async Task SetParametersAsync(ParameterView parameters)
    {
        await base.SetParametersAsync(parameters);

        if (Binding != null)
        {
            _binder = ValueBinder.Create(Binding);
            if (Label == null)
            {
                Label = _binder.ValueLabel.Titleize();
            }
            if (Expression == null)
            {
                Expression = (q, d) => q.OrderByDirection(d, Binding);
            }
        }
    }
Exemple #28
0
        public DoubleValueBinderExtension(string range, int round)
        {
            var values = range
                         .Remove("[ ] ( )".Split(" ").ToArray())
                         .Split(":")
                         .ToArray();
            var from            = values[0].ParseToDoubleInvariant();
            var to              = values[1].ParseToDoubleInvariant();
            var isFromInclusive = range.StartsWith("[");
            var isToInclusive   = range.EndsWith("]");

            _testMode = new ValueBinder <double>(
                ((Func <string, double?>)ParsingEx.TryParseToDoubleInvariant).ToOldTryParse(),
                mv => mv.ToStringInvariant(),
                v => (isFromInclusive ? v >= from : v > from) && (isToInclusive ? v <= to : v < to),
                mv => mv.Round(round));
        }
        protected void rptPendings_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.DataItem is Booking)
            {
                var booking = (Booking)e.Item.DataItem;
                var hplCode = e.Item.FindControl("hplCode") as HyperLink;
                if (hplCode != null)
                {
                    hplCode.Text        = string.Format(BookingFormat, booking.Id);
                    hplCode.NavigateUrl = string.Format("BookingView.aspx?NodeId={0}&SectionId={1}&bi={2}",
                                                        Node.Id, Section.Id, booking.Id);
                }

                var hplAgency = e.Item.FindControl("hplAgency") as HyperLink;
                if (hplAgency != null)
                {
                    hplAgency.Text        = booking.Agency.Name;
                    hplAgency.NavigateUrl = string.Format("AgencyEdit.aspx?NodeId={0}&SectionId={1}&AgencyId={2}",
                                                          Node.Id, Section.Id, booking.Agency.Id);
                }

                ValueBinder.BindLiteral(e.Item, "litRooms", booking.RoomName);
                ValueBinder.BindLiteral(e.Item, "litTrip", booking.Trip.Name);
                //ValueBinder.BindLiteral(e.Item, "litPartner", booking.Agency.Name);
                if (booking.Deadline.HasValue)
                {
                    ValueBinder.BindLiteral(e.Item, "litPending", booking.Deadline.Value.ToString("HH:mm dd/MM/yyyy"));
                }

                var lblCreatedBy = e.Item.FindControl("lblCreatedBy") as Label;
                if (lblCreatedBy != null)
                {
                    lblCreatedBy.Text = booking.CreatedBy.FullName;
                    ValueBinder.BindLiteral(e.Item, "litCreatedBy", booking.CreatedBy.FullName);
                    ValueBinder.BindLiteral(e.Item, "litCreatorPhone", booking.CreatedBy.Website);
                    ValueBinder.BindLiteral(e.Item, "litCreatorEmail", booking.CreatedBy.Email);
                }
                if (booking.Agency.Sale != null)
                {
                    ValueBinder.BindLabel(e.Item, "lblSaleInCharge", booking.Agency.Sale.FullName);
                    ValueBinder.BindLiteral(e.Item, "litSale", booking.Agency.Sale.FullName);
                    ValueBinder.BindLiteral(e.Item, "litSalePhone", booking.Agency.Sale.Website);
                    ValueBinder.BindLiteral(e.Item, "litSaleEmail", booking.Agency.Sale.Email);
                }
            }
        }
Exemple #30
0
        public void RootIntConstant()
        {
            var x      = CreateExpression(() => 42);
            var binder = ValueBinder.Create(x);

            // Binder will process as conversion to box up the value
            var y = CreateExpression(() => (object)42);

            binder.CanSetValue.Should().BeFalse();
            binder.ValueLabel.Should().BeNull();
            binder.TargetType.Should().Be(typeof(int));
            binder.TargetRoot.ToString().Should().Be(y.ToString());

            var targetPathLabels = string.Join(".", binder.TargetPath.Select(x => x.Label));

            targetPathLabels.Should().Be(nameof(System.Int32));
        }
Exemple #31
0
        public Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ParameterInfo           parameter = context.Parameter;
            WebHookTriggerAttribute attribute = parameter.GetCustomAttribute <WebHookTriggerAttribute>(inherit: false);

            if (attribute == null)
            {
                return(Task.FromResult <ITriggerBinding>(null));
            }

            // Can bind to user types, HttpRequestMessage, WebHookContext, and all the Read
            // Types supported by StreamValueBinder
            IEnumerable <Type> supportedTypes = StreamValueBinder.GetSupportedTypes(FileAccess.Read)
                                                .Union(new Type[] { typeof(HttpRequestMessage), typeof(WebHookContext) });
            bool isSupportedTypeBinding = ValueBinder.MatchParameterType(parameter, supportedTypes);
            bool isUserTypeBinding      = !isSupportedTypeBinding && WebHookTriggerBinding.IsValidUserType(parameter.ParameterType);

            if (!isSupportedTypeBinding && !isUserTypeBinding)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                  "Can't bind WebHookTriggerAttribute to type '{0}'.", parameter.ParameterType));
            }

            if (!isUserTypeBinding && attribute.FromUri)
            {
                throw new InvalidOperationException("'FromUri' can only be set to True when binding to custom Types.");
            }

            // Validate route format
            if (!string.IsNullOrEmpty(attribute.Route))
            {
                string[] routeSegements = attribute.Route.Split('/');
                if (routeSegements.Length > 2)
                {
                    throw new InvalidOperationException("WebHook routes can only have a maximum of two segments.");
                }
            }

            return(Task.FromResult <ITriggerBinding>(new WebHookTriggerBinding(_dispatcher, context.Parameter, isUserTypeBinding, attribute)));
        }
        public void When_value_binder_is_added_then_it_can_be_retrieved_by_its_bound_property()
        {
            var view = new UserControl();
            var viewModel = new { Value = "my value" };
            var valueBinder = new ValueBinder<object>(view, UserControl.ContentProperty, p => viewModel.Value) {BindingMode = BindingMode.OneWay};

            var viewModelBinder = new ViewBinder<object>(view, viewModel);
            viewModelBinder.Add(valueBinder);

            var binder = viewModelBinder.GetPropertyBinder(view, UserControl.ContentProperty);
            Assert.AreEqual(valueBinder, binder);
        }