예제 #1
0
파일: Setter.cs 프로젝트: sshaddicts/A2v10
        public void SetProperty(XamlElement elem, IDictionary <String, PropertyInfo> props)
        {
            if (!props.TryGetValue(Property, out PropertyInfo prop))
            {
                throw new XamlException($"The property '{Property}' not found in '{elem.GetType().Name}'");
            }
            var valBind = GetBinding(nameof(Value));

            if (valBind != null)
            {
                elem.SetBinding(Property, valBind);
                return;
            }
            if (Value == null)
            {
                return;
            }
            if (prop.PropertyType.IsEnum)
            {
                var converter = TypeDescriptor.GetConverter(prop.PropertyType);
                var enumVal   = converter.ConvertFromString(Value.ToString());
                prop.SetValue(elem, enumVal);
            }
            else
            {
                var propType = prop.PropertyType;
                if (propType.IsNullableType())
                {
                    propType = Nullable.GetUnderlyingType(propType);
                }
                var val = Convert.ChangeType(Value, propType);
                prop.SetValue(elem, val);
            }
        }
예제 #2
0
        public static Object Read(String code)
        {
            using var st  = new StringReader(code);
            using var rdr = XmlReader.Create(st);

            XamlElement root = new XamlElement(null);

            while (rdr.Read())
            {
                switch (rdr.NodeType)
                {
                case XmlNodeType.Whitespace:
                case XmlNodeType.Comment:
                    continue;

                case XmlNodeType.Element:
                    var elem = root.AddElement(rdr);
                    continue;
                }
                if (rdr.NodeType == XmlNodeType.Whitespace)
                {
                    continue;
                }

                Console.WriteLine($"{rdr.NodeType}: {rdr.Name}={rdr.Value}");
            }
            return(null);
        }
예제 #3
0
        public XamlElement AddElement(XmlReader rdr)
        {
            var elem = new XamlElement(rdr.LocalName);

            elem.FillAttributes(rdr);
            Console.WriteLine(elem.Name);
            return(elem);
        }
예제 #4
0
파일: Style.cs 프로젝트: sshaddicts/A2v10
        public void Set(XamlElement elem)
        {
            var props = elem.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
            var d     = new Dictionary <String, PropertyInfo>();

            foreach (var prop in props)
            {
                d.Add(prop.Name, prop);
            }
            foreach (var setter in this)
            {
                setter.SetProperty(elem, d);
            }
        }
예제 #5
0
 public void Set(XamlElement elem)
 {
     if (Root.Styles == null)
     {
         return;
     }
     if (Root.Styles.TryGetValue(StyleName, out Style style))
     {
         style.Set(elem);
     }
     else
     {
         throw new XamlException($"Style '{StyleName}' not found");
     }
 }
예제 #6
0
 internal void SetParent(XamlElement parent)
 {
     Parent = parent;
 }
예제 #7
0
 public void SetParent(XamlElement parent)
 {
     Parent = parent;
 }
예제 #8
0
        internal String GetCommand(RenderContext context, Boolean indirect = false, String argument = null, XamlElement src = null)
        {
            if (indirect)
            {
                if (!IsIndirectSupported)
                {
                    throw new XamlException($"Command '{Command}' is not available in this context");
                }
            }
            switch (Command)
            {
            case CommandType.Unknown:
                throw new NotImplementedException($"Command required for BindCmd extension");

            case CommandType.Refresh:
            case CommandType.Reload:
                return($"$reload({CommandArgument(context, nullable: true)})");

            case CommandType.Requery:
                return("$requery()");

            case CommandType.Save:
                return($"$save({{toast: {GetToast(context)}, options:{GetOptionsValid(context)}}})");

            case CommandType.Clear:
                return($"{CommandArgument(context)}.$empty()");

            case CommandType.Close:
                if (src != null)
                {
                    var inlineModal = src.FindParent <InlineDialog>();
                    if (inlineModal != null)
                    {
                        return($"$inlineClose('{inlineModal.Id}', false)");
                    }
                }
                return(context.IsDialog ? "$modalClose(false)" : "$close()");

            case CommandType.CloseOk:
                return(context.IsDialog ? "$modalClose(true)" : throw new XamlException("The command 'CloseOk' is allowed for Dialogs only"));

            case CommandType.SaveAndClose:
                if (context.IsDialog)
                {
                    return($"$modalSaveAndClose(true, {GetOptionsValid(context)})");
                }
                return($"$saveAndClose({{toast: {GetToast(context)}}})");

            case CommandType.OpenSelected:
                return($"$openSelected({CommandUrl(context, decorate: true)}, {CommandArgument(context)}, {NewWindowJS}, {UpdateAfterArgument(context)})");

            case CommandType.OpenSelectedFrame:
                return($"$openSelectedFrame({CommandUrl(context, decorate: true)}, {CommandArgument(context)}, {UpdateAfterArgument(context)})");

            case CommandType.Select:
                return($"$modalSelect({CommandArgument(context)}, {GetOptionsValid(context)})");

            case CommandType.SelectChecked:
                return($"$modalSelectChecked({CommandArgument(context)})");

            case CommandType.RemoveSelected:
                return($"$removeSelected({CommandArgument(context)}, {GetConfirm(context)})");

            case CommandType.DbRemove:
                return($"$dbRemove({CommandArgument(context)}, {GetConfirm(context)}, {GetOptions(context)})");

            case CommandType.DbRemoveSelected:
                return($"$dbRemoveSelected({CommandArgument(context)}, {GetConfirm(context)}, {GetOptions(context)})");

            case CommandType.MailTo:
                return(null);

            case CommandType.Navigate:
                return($"$navigateSimple({CommandUrl(context)}, {NewWindowJS})");

            case CommandType.NavigateExternal:
                return($"$navigateExternal({CommandUrl(context, decorate:false, skipCheck:true)}, {NewWindowJS})");

            case CommandType.Download:
                return($"$download({CommandUrl(context)})");

            case CommandType.Attachment:
                return($"$attachment({CommandUrl(context)}, {CommandArgument(context)}, {GetOptions(context)})");

            case CommandType.Help:
                return($"$showHelp({CommandUrl(context)})");

            case CommandType.Print:
                return($"$print()");

            case CommandType.Open:
                if (indirect)
                {
                    var argSting = "this";
                    if (!IsArgumentEmpty(context))
                    {
                        argSting = CommandArgument(context);
                    }
                    // arg4 may contain a single quote!!!
                    return($"{{cmd:$navigate, eval: true, arg1:{CommandUrl(context, true)}, arg2:'{argSting}', arg3:{NewWindowJS}, arg4:{UpdateAfterArgument(context)}}}");
                }
                else
                {
                    return($"$navigate({CommandUrl(context)}, {CommandArgument(context)}, {NewWindowJS}, {UpdateAfterArgument(context)})");
                }

            case CommandType.Create:
                return($"$navigate({CommandUrl(context)}, {CommandArgument(context, nullable:true)}, {NewWindowJS}, {UpdateAfterArgument(context)}, {GetOptions(context)})");

            case CommandType.Remove:
                if (indirect)
                {
                    return($"{{cmd:$remove, arg1:'this'}}");
                }
                else
                {
                    return($"$remove({CommandArgumentOrThis(context)}, {GetConfirm(context)})");
                }

            case CommandType.Append:
                return($"{CommandArgument(context)}.$append()");

            case CommandType.Prepend:
                return($"{CommandArgument(context)}.$prepend()");

            case CommandType.Browse:
                return($"$dialog('browse', {CommandUrl(context)}, {CommandArgument(context)}, {GetData(context)})");

            case CommandType.Execute:
                if (indirect)
                {
                    var arg2 = IsArgumentEmpty(context) ? "this" : CommandArgument(context);
                    return($"{{cmd:$exec, arg1:'{GetName()}', arg2:'{arg2}', arg3: {GetConfirm(context)}, arg4: {GetOptions(context)}}}");
                }
                if (argument != null)
                {
                    return($"$exec('{GetName()}', {argument}, {GetConfirm(context)}, {GetOptions(context)})");
                }
                return($"$exec('{GetName()}', {CommandArgument(context, nullable: true)}, {GetConfirm(context)}, {GetOptions(context)})");

            case CommandType.Invoke:
                return($"$invokeServer({CommandUrl(context)}, {CommandArgument(context)}, {GetConfirm(context)}, {GetOptions(context)})");

            case CommandType.ExecuteSelected:
                return($"$execSelected('{GetName()}', {CommandArgument(context)}, {GetConfirm(context)})");

            case CommandType.Report:
                return($"$report({GetReportName(context)}, {CommandArgument(context, nullable: true)}, " +
                       $"{GetOptions(context)}, {CommandUrlOptional(context)}, {GetData(context)})");

            case CommandType.Export:
                return($"$export({CommandArgument(context, nullable:true)}, {CommandUrlOptional(context)}, {GetData(context)}, {GetOptions(context)})");

            case CommandType.ExportTo:
                return($"$exportTo('{Format}', {CommandFileName(context)})");

            case CommandType.File:
                return($"$file({CommandUrl(context)}, {CommandArgument(context)}, {GetOptionsForFile(context)})");

            case CommandType.Dialog:
                if (Action == DialogAction.Unknown)
                {
                    throw new XamlException($"Action required for {Command} command");
                }
                String  action    = Action.ToString().ToKebabCase();
                Boolean bNullable = false;
                if (Action == DialogAction.Show)
                {
                    bNullable = true;                             // Nullable actions ???
                }
                if (indirect)
                {
                    String arg3 = "this";
                    if (!IsArgumentEmpty(context))
                    {
                        arg3 = CommandArgument(context);
                    }
                    // command, url, data
                    return($"{{cmd:$dialog, isDialog:true, arg1:'{action}', arg2:{CommandUrl(context, decorate:true)}, arg3: '{arg3}'}}");
                }
                return($"$dialog('{action}', {CommandUrl(context)}, {CommandArgument(context, bNullable)}, {GetData(context, func:true)}, {GetOptions(context)})");

            case CommandType.EUSign:
                return($"$eusign({CommandUrl(context)}, {CommandArgument(context)})");

            default:
                throw new NotImplementedException($"command '{Command}' yet not implemented");
            }
        }