Exemplo n.º 1
0
        /// <summary>
        /// Evaluates a defined <see cref="Binding"/> on the given object
        /// </summary>
        /// <param name="binding">The <see cref="Binding"/> to evaluate</param>
        /// <param name="source">the object to evaluate</param>
        /// <returns></returns>
        public static object?Eval(Binding?binding, object?source)
        {
            if (binding is null)
            {
                throw new ArgumentNullException(nameof(binding));
            }

            Binding newBinding = new Binding
            {
                Source                = source,
                AsyncState            = binding.AsyncState,
                BindingGroupName      = binding.BindingGroupName,
                BindsDirectlyToSource = binding.BindsDirectlyToSource,
                Path               = binding.Path,
                Converter          = binding.Converter,
                ConverterCulture   = binding.ConverterCulture,
                ConverterParameter = binding.ConverterParameter,
                FallbackValue      = binding.FallbackValue,
                IsAsync            = binding.IsAsync,
                Mode               = BindingMode.OneWay,
                StringFormat       = binding.StringFormat,
                TargetNullValue    = binding.TargetNullValue
            };

            return(Eval(newBinding));
        }
 /// <summary>
 ///  Constructor for BindingCompleteEventArgs.
 /// </summary>
 public BindingCompleteEventArgs(
     Binding?binding,
     BindingCompleteState state,
     BindingCompleteContext context)
     : this(binding, state, context, string.Empty, null, false)
 {
 }
Exemplo n.º 3
0
        bool TryCustomParsers(Binding parentBinding, string property, [NotNullWhen(true)] out Binding?subBinding)
        {
            subBinding = null;
            if (string.IsNullOrEmpty(parentBinding.Item) || string.IsNullOrEmpty(property))
            {
                return(false);
            }

            if (parentBinding.Item.Contains("#{")) //Shortcut the inner variable replacement if no templates are detected
            {
                try
                {
                    parentBinding = ParseTemplate(parentBinding, out string[] _);
                }
                catch (InvalidOperationException ex)
                {
                    if (ex.Message.Contains("self referencing loop"))
                    {
                        return(false);
                    }
                }
            }


            return(JsonParser.TryParse(parentBinding, property, out subBinding));
        }
Exemplo n.º 4
0
        internal static bool TryParse(Binding parentBinding, string property, [NotNullWhen(true)] out Binding?subBinding)
        {
            subBinding = null;

            try
            {
                var obj = JsonConvert.DeserializeObject(parentBinding.Item);

                if (obj is JValue jvalue)
                {
                    return(TryParseJValue(jvalue, out subBinding));
                }

                var jarray = obj as JArray;
                if (jarray != null)
                {
                    return(TryParseJArray(jarray, property, out subBinding));
                }

                var jobj = obj as JObject;
                if (jobj != null)
                {
                    return(TryParseJObject(jobj, property, out subBinding));
                }
            }
            catch (JsonException)
            {
                return(false);
            }
            return(false);
        }
 /// <summary>
 ///  Constructor for BindingCompleteEventArgs.
 /// </summary>
 public BindingCompleteEventArgs(
     Binding?binding,
     BindingCompleteState state,
     BindingCompleteContext context,
     string?errorText)
     : this(binding, state, context, errorText, null, true)
 {
 }
 /// <summary>
 ///  Constructor for BindingCompleteEventArgs.
 /// </summary>
 public BindingCompleteEventArgs(
     Binding?binding,
     BindingCompleteState state,
     BindingCompleteContext context,
     string?errorText,
     Exception?exception)
     : this(binding, state, context, errorText, exception, true)
 {
 }
Exemplo n.º 7
0
 /// <summary>
 /// Sets a variable value.
 /// </summary>
 /// <param name="name">The name of the variable.</param>
 /// <param name="value">The value of the variable.</param>
 public void Set(string name, string?value)
 {
     if (name == null)
     {
         return;
     }
     variables[name] = value;
     binding         = null;
     Save();
 }
Exemplo n.º 8
0
        public void SetDataContext(object dataContext)
        {
            _viewModelRef = new WeakReferenceEx <TabViewModel <TKey> >((TabViewModel <TKey>)dataContext);

            _textBinding?.Detach();
            _textBinding = this.SetBinding(() => _viewModelRef.Target.BadgeText).WhenSourceChanges(UpdateBadge);

            _visibilityBinding?.Detach();
            _visibilityBinding = this.SetBinding(() => _viewModelRef.Target.IsBadgeVisible).WhenSourceChanges(UpdateBadge);
        }
        public static void SetElementStyle(this DataGridBoundColumn column, Binding?languageBinding, Binding?flowDirectionBinding)
        {
            var elementStyle = new Style(typeof(TextBlock), column.ElementStyle);
            var setters      = elementStyle.Setters;

            setters.Add(new Setter(FrameworkElement.LanguageProperty, languageBinding));
            setters.Add(new Setter(FrameworkElement.FlowDirectionProperty, flowDirectionBinding));

            elementStyle.Seal();
            column.ElementStyle = elementStyle;
        }
Exemplo n.º 10
0
        private static bool TryParseJArray(JArray jarray, string property, [NotNullWhen(true)] out Binding?subBinding)
        {
            int index;

            subBinding = null;

            if (!int.TryParse(property, out index))
            {
                return(false);
            }

            subBinding = ConvertJTokenToBinding(jarray[index]);
            return(true);
        }
 /// <summary>
 ///  Constructor for BindingCompleteEventArgs.
 /// </summary>
 public BindingCompleteEventArgs(
     Binding?binding,
     BindingCompleteState state,
     BindingCompleteContext context,
     string?errorText,
     Exception?exception,
     bool cancel)
     : base(cancel)
 {
     Binding = binding;
     BindingCompleteState   = state;
     BindingCompleteContext = context;
     ErrorText = errorText ?? string.Empty;
     Exception = exception;
 }
Exemplo n.º 12
0
        public static void SetEditingElementStyle(this DataGridBoundColumn column, Binding?languageBinding, Binding?flowDirectionBinding)
        {
            var textBoxStyle = new Style(typeof(TextBox), column.EditingElementStyle);
            var setters      = textBoxStyle.Setters;

            setters.Add(new EventSetter(UIElement.PreviewKeyDownEvent, (KeyEventHandler)EditingElement_PreviewKeyDown));
            setters.Add(new Setter(TextBoxBase.AcceptsReturnProperty, true));

            setters.Add(new Setter(Spellcheck.IsEnabledProperty, true));
            setters.Add(new Setter(FrameworkElement.LanguageProperty, languageBinding));

            setters.Add(new Setter(FrameworkElement.FlowDirectionProperty, flowDirectionBinding));

            textBoxStyle.Seal();

            column.EditingElementStyle = textBoxStyle;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Creates a new instance.
        /// </summary>
        /// <param name="input">The object or binding to which the converter should be applied to.</param>
        /// <param name="desiredSize">The desired size for the image.</param>
        /// <param name="targetVisualBinding">The target visual on which the image/icon should be shown.</param>
        public ObjectToImageConverter(object input, object desiredSize, Binding?targetVisualBinding)
        {
            if (desiredSize is Size desiredSizeValue &&
                (desiredSizeValue.IsEmpty ||
                 DoubleUtil.AreClose(desiredSizeValue.Width, 0) ||
                 DoubleUtil.AreClose(desiredSizeValue.Height, 0)))
            {
                throw new ArgumentException("DesiredSize must not be empty and width/height must be greater than 0.", nameof(desiredSize));
            }

            this.IconBinding = input as Binding ?? new Binding {
                Source = input
            };
            this.DesiredSizeBinding = desiredSize as Binding ?? new Binding {
                Source = desiredSize
            };
            this.TargetVisualBinding = targetVisualBinding;
        }
Exemplo n.º 14
0
        public override VoidObject VisitAssignExpr(Expr.Assign expr)
        {
            base.VisitAssignExpr(expr);

            Binding?binding = getVariableOrFunctionBinding(expr);

            // 'null' here can either be because of an internal error (failure to locate a binding that _should_ exist),
            // or a completely valid case when trying to reassign an undefined variable. Regretfully, we cannot
            // distinguish between these two scenarios at the moment.
            if (binding?.IsImmutable == true)
            {
                immutabilityValidationErrorCallback(new ImmutabilityValidationError(
                                                        expr.Name,
                                                        $"{binding.ObjectTypeTitleized} '{expr.Name.Lexeme}' is immutable and cannot be modified."
                                                        ));
            }

            return(VoidObject.Void);
        }
Exemplo n.º 15
0
        void ShowWatermark()
        {
            if (string.IsNullOrEmpty(Text) && !string.IsNullOrEmpty(Watermark))
            {
                isWatermarked = true;

                //save the existing binding so it can be restored
                textBinding = BindingOperations.GetBinding(this, TextProperty);

                //blank out the existing binding so we can throw in our Watermark
                BindingOperations.ClearBinding(this, TextProperty);

                //set the signature watermark gray
                Foreground = BrushCache.GetBrush(Colors.LightGray);

                //display our watermark text
                Text = Watermark;
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Evaluates a defined <see cref="Binding"/> on the given <see cref="DependencyObject"/>
        /// </summary>
        /// <param name="binding">The <see cref="Binding"/> to evaluate</param>
        /// <param name="dependencyObject">optional: The <see cref="DependencyObject"/> to evaluate</param>
        /// <returns>The resulting object</returns>
        public static object?Eval(Binding?binding, DependencyObject?dependencyObject)
        {
            if (binding is null)
            {
                throw new ArgumentNullException(nameof(binding));
            }

            dependencyObject ??= new DependencyObject();

            if (string.IsNullOrEmpty(binding.StringFormat))
            {
                BindingOperations.SetBinding(dependencyObject, DummyProperty, binding);
                return(dependencyObject.GetValue(DummyProperty));
            }
            else
            {
                BindingOperations.SetBinding(dependencyObject, DummyTextProperty, binding);
                return(dependencyObject.GetValue(DummyTextProperty));
            }
        }
Exemplo n.º 17
0
        Binding?WalkTo(SymbolExpression expression, out string[] missingTokens)
        {
            ValidateThatRecursionIsNotOccuring(expression);
            symbolStack.Push(expression);

            try
            {
                Binding?val = binding;
                missingTokens = new string[0];

                expression = CopyExpression(expression);

                foreach (var step in expression.Steps)
                {
                    var iss = step as Identifier;
                    if (iss != null)
                    {
                        Binding?newVal;
                        if (val.TryGetValue(iss.Text, out newVal))
                        {
                            val = newVal;
                            continue;
                        }

                        if (TryCustomParsers(val, iss.Text, out newVal))
                        {
                            val = newVal;
                            continue;
                        }
                    }
                    else
                    {
                        if (step is Indexer ix)
                        {
                            if (ix.IsSymbol || ix.Index == null)
                            {
                                // Substitution should have taken place in previous CopyExpression above.
                                // If not then it must not be found.
                                return(null);
                            }

                            if (ix.Index == "*" && val?.Indexable.Count > 0)
                            {
                                val = val.Indexable.First().Value;
                                continue;
                            }

                            if (val != null && val.Indexable.TryGetValue(ix.Index, out Binding? newVal))
                            {
                                val = newVal;
                                continue;
                            }

                            if (val != null && TryCustomParsers(val, ix.Index, out newVal))
                            {
                                val = newVal;
                                continue;
                            }
                        }
                        else
                        {
                            throw new NotImplementedException("Unknown step type: " + step);
                        }
                    }

                    if (parent == null)
                    {
                        return(null);
                    }

                    return(parent.WalkTo(expression, out missingTokens));
                }
                return(ParseTemplate(val, out missingTokens));
            }
            finally
            {
                symbolStack.Pop();
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// Evaluates a defined <see cref="Binding"/> on the given <see cref="DependencyObject"/>
 /// </summary>
 /// <param name="binding">The <see cref="Binding"/> to evaluate</param>
 /// <returns>The resulting object</returns>
 public static object?Eval(Binding?binding)
 {
     return(Eval(binding, null));
 }
Exemplo n.º 19
0
 private static void AddLanguageColumn(this ICollection <DataGridColumn> columns, DataGridBoundColumn column, Binding languageBinding, Binding?flowDirectionBinding)
 {
     column.SetElementStyle(languageBinding, flowDirectionBinding);
     column.SetEditingElementStyle(languageBinding, flowDirectionBinding);
     columns.Add(column);
 }
Exemplo n.º 20
0
        ///// <summary>
        /////     This method loads the endpoint/binding configuration from the server's MEX endpoint
        /////     and builds the lists for each service contractTypeName.
        ///// </summary>
        //private void FillAllServiceEndpointsCollection(List<MexEndpointInfo>? mexEndpoints)
        //{
        //    if (mexEndpoints is null || mexEndpoints.Count == 0) return;

        //    foreach (MexEndpointInfo mexEndpoinnt in mexEndpoints)
        //    {
        //        if (!string.IsNullOrEmpty(mexEndpoinnt.Url))
        //        {
        //            try
        //            {
        //                //ServiceEndpointCollection endpoints = MetadataResolver.Resolve(typeof(IResourceManagement),
        //                //                    MexEndpointAddress, MetadataExchangeClientMode.MetadataExchange);
        //                // ---> fails because the default buffer size is too small
        //                // Alternate approach:
        //                var mexBnd = new WSHttpBinding(_mexSecurityMode, _mexReliableEnabled);
        //                mexBnd.MaxReceivedMessageSize = _mexReceiveBufferSize;
        //                var mexClient = new MetadataExchangeClient(mexBnd);

        //                //ServiceEndpointCollection endpoints = MetadataResolver.Resolve(contracts,
        //                //                    MexEndpointAddress, MetadataExchangeClientMode.MetadataExchange, mexClient );
        //                // result is empty for unknown reasons
        //                // Alternate approach:
        //                MetadataSet metadataSet = mexClient.GetMetadata(new EndpointAddress(mexEndpoinnt.Url));
        //                var importer = new WsdlImporter(metadataSet);
        //                Collection<ContractDescription> contractDescriptions = importer.ImportAllContracts();

        //                //Resolve wsdl into ServiceEndpointCollection
        //                var mexUriBuilder = new UriBuilder(mexEndpoinnt.Url);
        //                _allServiceEndpointsCollection = MetadataResolver.Resolve(contractDescriptions,
        //                    mexUriBuilder.Uri,
        //                    MetadataExchangeClientMode.
        //                        MetadataExchange, mexClient);

        //                break;
        //            }
        //            catch (Exception ex)
        //            {
        //                // do nothing if this mex ep doesn't work
        //                Trace.Fail(ex.Message, ex.StackTrace);
        //            }
        //        }
        //    }
        //}

        /// <summary>
        ///     This method loads the endpoint/binding configuration
        ///     and builds the lists for each service contractTypeName.
        /// </summary>
        private void FillAllServiceEndpointsCollection(IEnumerable <EndpointConfigurationEx> endpointConfigurationExList)
        {
            _allServiceEndpointsCollection = new Collection <ServiceEndpoint>();

            foreach (EndpointConfigurationEx endpointConfigurationEx in endpointConfigurationExList)
            {
                try
                {
                    Binding?binding = null;
                    // TODO: Add other cases.
                    switch (endpointConfigurationEx.BindingType)
                    {
                    case "NetTcpBinding":
                    {
                        SecurityMode securityMode;
                        Enum.TryParse(endpointConfigurationEx.SecurityMode, out securityMode);
                        binding = new NetTcpBinding(securityMode);
                    }
                    break;

                    case "BasicHttpBinding":
                    {
                        BasicHttpSecurityMode securityMode;
                        Enum.TryParse(endpointConfigurationEx.SecurityMode, out securityMode);
                        binding = new BasicHttpBinding(securityMode);
                    }
                    break;
                    }
                    if (binding is null)
                    {
                        continue;
                    }
                    var serviceEndpoint =
                        new ServiceEndpoint(new ContractDescription(endpointConfigurationEx.ContractType),
                                            binding, new EndpointAddress(endpointConfigurationEx.EndpointUrl));
                    _allServiceEndpointsCollection.Add(serviceEndpoint);
                }
                catch (Exception)
                {
                }
            }

            /*
             * var uri =
             *  new Uri("net.tcp://" + _serverEntry.ServerDescription.HostName +
             *          ":60081/SszCtcmXiServer/ResourceManagement");
             * var serviceEndpoint = new ServiceEndpoint(new ContractDescription(typeof (IResourceManagement).Name),
             *                                          new NetTcpBinding(SecurityMode.None), new EndpointAddress(uri));
             * _allServiceEndpointsCollection.Add(serviceEndpoint);
             *
             * uri =
             *  new Uri("net.tcp://" + _serverEntry.ServerDescription.HostName +
             *          ":60081/SszCtcmXiServer/Read");
             * serviceEndpoint = new ServiceEndpoint(new ContractDescription(typeof (IRead).Name),
             *                                      new NetTcpBinding(SecurityMode.None), new EndpointAddress(uri));
             * _allServiceEndpointsCollection.Add(serviceEndpoint);
             *
             * uri =
             *  new Uri("net.tcp://" + _serverEntry.ServerDescription.HostName +
             *          ":60081/SszCtcmXiServer/Write");
             * serviceEndpoint = new ServiceEndpoint(new ContractDescription(typeof (IWrite).Name),
             *                                      new NetTcpBinding(SecurityMode.None), new EndpointAddress(uri));
             * _allServiceEndpointsCollection.Add(serviceEndpoint);
             *
             * uri =
             *  new Uri("net.tcp://" + _serverEntry.ServerDescription.HostName +
             *          ":60081/SszCtcmXiServer/Callback");
             * serviceEndpoint = new ServiceEndpoint(new ContractDescription(typeof (IRegisterForCallback).Name),
             *                                      new NetTcpBinding(SecurityMode.None), new EndpointAddress(uri));
             * _allServiceEndpointsCollection.Add(serviceEndpoint);
             *
             * uri =
             *  new Uri("net.tcp://" + _serverEntry.ServerDescription.HostName +
             *          ":60081/SszCtcmXiServer/Poll");
             * serviceEndpoint = new ServiceEndpoint(new ContractDescription(typeof (IPoll).Name),
             *                                      new NetTcpBinding(SecurityMode.None), new EndpointAddress(uri));
             * _allServiceEndpointsCollection.Add(serviceEndpoint);
             *
             *
             * var serviceEndpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(IResourceManagement)));
             * _serviceEndpointCollection.Add(serviceEndpoint);
             *
             * serviceEndpoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(IRead)));
             * _serviceEndpointCollection.Add(serviceEndpoint);
             *
             * serviceEndpoint = new ServiceEndpoint(new ContractDescription(typeof(IWrite).Name));
             * _serviceEndpointCollection.Add(serviceEndpoint);
             *
             * serviceEndpoint = new ServiceEndpoint(new ContractDescription(typeof(IRegisterForCallback).Name));
             * _serviceEndpointCollection.Add(serviceEndpoint);
             *
             * serviceEndpoint = new ServiceEndpoint(new ContractDescription(typeof(IPoll).Name));
             * _serviceEndpointCollection.Add(serviceEndpoint);
             */
        }
Exemplo n.º 21
0
 internal static bool TryGet <TUnit>(this Binding?binding, [MaybeNullWhen(false)] out QuantityFormat <TUnit> format)
     where TUnit : struct, IUnit, IEquatable <TUnit>
 {
     if (binding is { StringFormat : { } stringFormat })
Exemplo n.º 22
0
 public bool GetLocalBinding(Expr expr, out Binding?binding)
 {
     return(localBindings.TryGetValue(expr, out binding));
 }