Ejemplo n.º 1
0
        void IDextopAssemblyPreprocessor.ProcessAssemblies(DextopApplication application, IList <Assembly> assemblies, Stream outputStream, Stream cacheStream)
        {
            var typeFilter = TypeFilter ?? ((x, y) => true);

            using (var sw = new StreamWriter(outputStream))
            {
                var jw = new DextopJsWriter(sw);
                foreach (var model in application.ModelManager.models)
                {
                    WriteModel(jw, model.Value);
                }

                foreach (var a in assemblies)
                {
                    var list = AssemblyHelper.GetTypeAttributeDictionaryForAssembly <DextopModelAttribute>(a, false);
                    foreach (var t in list)
                    {
                        if (typeFilter(t.Key, this))
                        {
                            var model = application.ModelManager.BuildModel(t.Key, t.Value);
                            WriteModel(jw, model);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Writes the children to the items property.
 /// </summary>
 /// <param name="jw">The jw.</param>
 protected virtual void WriteItems(DextopJsWriter jw)
 {
     if (Items.Count > 0)
     {
         jw.AddProperty("items", Items);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Write the properties from the bag to the writer. This method can be overrided for advanced scenarios.
        /// </summary>
        /// <param name="jw">The writer.</param>
        protected override void WriteProperties(DextopJsWriter jw)
        {
            jw.DefaultProperty("itemId", itemId);
            jw.DefaultProperty("xtype", xtype);
            if (itemId != null)
            {
                jw.AddLocalizationProperty("title", title, itemId + "TitleText");
            }
            else
            {
                jw.DefaultProperty("title", title);
            }
            if (layout != null)
            {
                jw.AddProperty("layout", layout);
            }
            jw.DefaultRawProperty("defaults", defaults);
            jw.DefaultRawProperty("fieldDefaults", fieldDefaults);
            jw.DefaultProperty("margin", margin);
            jw.DefaultProperty("style", style);
            jw.DefaultProperty("bodyStyle", bodyStyle);
            jw.DefaultProperty("border", border);
            jw.DefaultProperty("autoHeight", autoHeight);
            jw.DefaultProperty("anchor", anchor);
            jw.DefaultProperty("width", width);
            jw.DefaultProperty("columnWidth", columnWidth);
            jw.DefaultProperty("flex", flex);

            base.WriteProperties(jw);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Processes the assemblies and generates the code.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="assemblies">The assemblies.</param>
        /// <param name="outputStream">The output stream.</param>
        public void ProcessAssemblies(DextopApplication application, IList <Assembly> assemblies, Stream outputStream)
        {
            using (var sw = new StreamWriter(outputStream))
            {
                var jw = new DextopJsWriter(sw);
                foreach (var model in application.ModelManager.models)
                {
                    WriteModel(jw, model.Value);
                }

                foreach (var a in assemblies)
                {
                    var list = AssemblyHelper.GetTypeAttributeDictionaryForAssembly <DextopModelAttribute>(a, false);
                    foreach (var t in list)
                    {
                        var model = application.ModelManager.BuildModel(t.Key, new DextopModelTypeMeta
                        {
                            IdField   = t.Value.Id,
                            ModelName = t.Value.Name
                        });
                        WriteModel(jw, model);
                    }
                }
            }
        }
Ejemplo n.º 5
0
 private static void WriteModel(DextopJsWriter jw, DextopModel model)
 {
     jw.WriteLine("Ext.define('{0}',", model.Meta.ModelName);
     jw.WriteObject(model);
     jw.WriteLine(");");
     jw.Flush();
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Write the properties from the bag to the writer. This method can be overrided for advanced scenarios.
        /// </summary>
        /// <param name="jw">The writer.</param>
        protected override void WriteProperties(DextopJsWriter jw)
        {
            jw.AddProperty("name", name);
            jw.AddLocalizationProperty("fieldLabel", fieldLabel, ItemName + "FieldLabelText");
            jw.DefaultProperty("xtype", xtype);
            jw.AddLocalizationProperty("boxLabel", boxLabel, ItemName + "BoxLabelText");
            jw.DefaultProperty("anchor", anchor);
            jw.AddLocalizationProperty("emptyText", emptyText, ItemName + "EmptyText");
            jw.DefaultProperty("readOnly", readOnly);
            jw.DefaultProperty("allowBlank", allowBlank);
            jw.DefaultProperty("inputType", inputType);
            jw.DefaultProperty("vtype", vtype);
            jw.DefaultProperty("vtypeText", vtypeText);
            jw.DefaultProperty("flex", flex);
            jw.DefaultProperty("labelAlign", labelAlign);
            jw.DefaultProperty("margin", margin);
            jw.DefaultProperty("width", width);
            jw.DefaultProperty("style", style);
            jw.DefaultProperty("fieldStyle", fieldStyle);
            jw.DefaultProperty("cls", cls);
            jw.DefaultProperty("fieldCls", fieldCls);

            jw.AddRawProperty(xtype == "checkboxfield" ? "checked" : "value", String.Format("options.data['{0}']", name));

            base.WriteProperties(jw);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Writes the children to the items property.
 /// </summary>
 /// <param name="jw">The jw.</param>
 protected override void WriteItems(DextopJsWriter jw)
 {
     if (Items.Count > 0)
     {
         jw.WritePropertyName("items");
         jw.Write("[");
         bool first = true;
         if (PrependItems != null)
         {
             foreach (var item in PrependItems)
             {
                 if (first)
                 {
                     first = false;
                 }
                 else
                 {
                     jw.Write(", ");
                 }
                 jw.Write("dict['{0}']", item);
             }
         }
         for (var i = 0; i < Items.Count; i++)
         {
             if (first)
             {
                 first = false;
             }
             else
             {
                 jw.Write(", ");
             }
             if (Items[i].ItemName != null)
             {
                 jw.Write("dict['{0}']", Items[i].ItemName);
             }
             else
             {
                 jw.WriteObject(Items[i]);
             }
         }
         if (AppendItems != null)
         {
             foreach (var item in AppendItems)
             {
                 if (first)
                 {
                     first = false;
                 }
                 else
                 {
                     jw.Write(", ");
                 }
                 jw.Write("dict['{0}']", item);
             }
         }
         jw.Write("]");
     }
 }
Ejemplo n.º 8
0
        void IDextopAssemblyPreprocessor.ProcessAssemblies(DextopApplication application, IList <System.Reflection.Assembly> assemblies, Stream outputStream, Stream cacheStream)
        {
            var typeFilter = TypeFilter ?? ((x, y) => true);

            using (var w = new StreamWriter(outputStream))
            {
                var jw = new DextopJsWriter(w, DextopJsWriterOptions.Localization);
                foreach (var assembly in assemblies)
                {
                    var formTypes = AssemblyHelper.GetTypeAttributeDictionaryForAssembly <DextopFormAttribute>(assembly, false);
                    foreach (var formTypeAttribute in formTypes)
                    {
                        if (typeFilter(formTypeAttribute.Key, this))
                        {
                            var type       = formTypeAttribute.Key;
                            var formFields = DextopFormBuilder.BuildForm(type);
                            var name       = application.MapTypeName(type, ".form");
                            jw.Write("Ext.define('{0}', ", name);
                            jw.StartLocalizationScope();
                            jw.StartBlock();
                            jw.AddProperty("extend", "Dextop.ItemFactory");
                            jw.StartFunctionBlock("getDictionary", "options");
                            jw.WriteLine("options = options || {};");
                            jw.WriteLine("options.data = options.data || {};");
                            jw.WriteLine("var dict = Ext.apply({}, options.apply);");
                            WriteDictRecursively(jw, formFields);
                            jw.WriteLine("return dict;");
                            jw.CloseBlock();
                            jw.StartFunctionBlock("buildItems", "dict");
                            jw.Write("return [");
                            for (var i = 0; i < formFields.Count; i++)
                            {
                                if (i > 0)
                                {
                                    jw.Write(", ");
                                }
                                if (formFields[i].ItemName != null)
                                {
                                    jw.Write("dict['{0}']", formFields[i].ItemName);
                                }
                                else
                                {
                                    jw.WriteObject(formFields[i]);
                                }
                            }
                            jw.Write("];");
                            jw.CloseBlock();//function
                            jw.WriteLocalizations();
                            jw.CloseBlock();
                            jw.WriteLine(");"); //Ext.define(
                            jw.WriteLine();

                            jw.Flush();
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Write the properties from the bag to the writer. This method can be overrided for advanced scenarios.
 /// </summary>
 /// <param name="jw">The writer.</param>
 protected override void WriteProperties(DextopJsWriter jw)
 {
     base.WriteProperties(jw);
     WriteItems(jw);
     if (!String.IsNullOrEmpty(Raw))
     {
         jw.WriteRawJs(Raw);
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Write the properties from the bag to the writer. This method can be overrided for advanced scenarios.
        /// </summary>
        /// <param name="jw">The writer.</param>
        protected override void WriteProperties(DextopJsWriter jw)
        {
            if (id != dataIndex)
            {
                jw.DefaultProperty("id", id);
            }
            jw.AddLocalizationProperty("text", text, id + "Text");
            jw.AddLocalizationProperty("tooltip", tooltip, id + "TooltipText");
            jw.DefaultProperty("flex", flex);
            jw.DefaultProperty("width", width);
            jw.DefaultProperty("renderer", renderer);
            jw.DefaultProperty("format", format);
            jw.DefaultProperty("tpl", tpl);
            jw.DefaultProperty("align", align);
            jw.DefaultProperty("hidden", hidden);
            jw.DefaultProperty("sortable", sortable);

            if (_columns == null || _columns.Count == 0)
            {
                jw.AddProperty("dataIndex", dataIndex);
                jw.AddProperty("type", type);
                jw.DefaultProperty("required", required);
                jw.DefaultProperty("tooltipTpl", tooltipTpl);
                jw.DefaultProperty("readonly", readOnly);
                jw.DefaultProperty("menuDisabled", menuDisabled);
                jw.DefaultProperty("filterable", filterable);
                jw.DefaultProperty("locked", locked);
                jw.DefaultProperty("hasHeaderFilter", hasHeaderFilter);
            }
            else
            {
                jw.WritePropertyName("columns");
                jw.Write("[");
                for (var i = 0; i < _columns.Count; i++)
                {
                    if (i > 0)
                    {
                        jw.Write(", ");
                    }
                    if ((jw.Options & DextopJsWriterOptions.ItemFactory) != 0)
                    {
                        jw.Write("dict[\"{0}\"]", _columns[i].id);
                    }
                    else
                    {
                        jw.WriteObject(_columns[i]);
                    }
                }
                jw.Write("]");
            }
            base.WriteProperties(jw);
        }
Ejemplo n.º 11
0
 private void WriteDictRecursively(DextopJsWriter jw, IList <DextopFormObject> formFields)
 {
     foreach (var field in formFields)
     {
         WriteDictRecursively(jw, field.Items);
         if (field.ItemName != null)
         {
             jw.Write("dict[\"{0}\"] = ", field.ItemName);
             jw.WriteObject(field);
             jw.WriteLine(";");
         }
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Write the properties from the bag to the writer. This method can be overrided for advanced scenarios.
 /// </summary>
 /// <param name="jw">The writer.</param>
 protected override void WriteProperties(DextopJsWriter jw)
 {
     jw.AddProperty("field", field);
     jw.AddProperty("type", type);
     jw.DefaultProperty("min", min);
     jw.DefaultProperty("max", max);
     if (list != null)
     {
         jw.AddRawProperty("list", DextopUtil.Encode(list));
     }
     jw.DefaultProperty("matcher", matcher);
     base.WriteProperties(jw);
 }
Ejemplo n.º 13
0
        private void WriteDictRecursively(DextopJsWriter jw, IList <DextopGridColumn> headers)
        {
            foreach (var field in headers)
            {
                if (field.HasColumns)
                {
                    WriteDictRecursively(jw, field.Columns);
                }

                jw.Write("dict[\"{0}\"] = ", field.id);
                jw.WriteObject(field);
                jw.WriteLine(";");
            }
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Write the properties from the bag to the writer. This method can be overrided for advanced scenarios.
 /// </summary>
 /// <param name="jw">The writer.</param>
 protected override void WriteProperties(DextopJsWriter jw)
 {
     jw.AddProperty("extend", "Ext.data.Model");
     if (Fields != null)
     {
         jw.AddProperty("fields", Fields);
     }
     if (Validations != null && Validations.Count > 0)
     {
         jw.AddProperty("validations", Validations);
     }
     jw.DefaultProperty("idProperty", idProperty);
     base.WriteProperties(jw);
 }
Ejemplo n.º 15
0
        void IDextopAssemblyPreprocessor.ProcessAssemblies(DextopApplication application, IList <Assembly> assemblies, Stream outputStream, Stream cacheStream)
        {
            var typeFilter = TypeFilter ?? ((x, y) => true);

            using (var w = new StreamWriter(outputStream))
            {
                var jw = new DextopJsWriter(w, DextopJsWriterOptions.Localization | DextopJsWriterOptions.ItemFactory);
                foreach (var assembly in assemblies)
                {
                    var headerTypes = AssemblyHelper.GetTypeAttributeDictionaryForAssembly <DextopGridAttribute>(assembly, false);

                    foreach (var cap in headerTypes)
                    {
                        if (typeFilter(cap.Key, this))
                        {
                            var type    = cap.Key;
                            var headers = DextopGridManager.BuildHeaders(type);
                            var name    = application.MapTypeName(type, ".columns");
                            jw.Write("Ext.define('{0}', ", name);
                            jw.StartLocalizationScope();
                            jw.StartBlock();
                            jw.AddProperty("extend", "Dextop.ItemFactory");
                            jw.StartFunctionBlock("getDictionary");
                            jw.WriteLine("var dict = {};");
                            WriteDictRecursively(jw, headers);
                            jw.WriteLine("return dict;");
                            jw.CloseBlock();
                            jw.StartFunctionBlock("buildItems", "dict");
                            jw.Write("return [");
                            for (var i = 0; i < headers.Count; i++)
                            {
                                if (i > 0)
                                {
                                    jw.Write(", ");
                                }
                                jw.Write("dict['{0}']", headers[i].id);
                            }
                            jw.Write("];");
                            jw.CloseBlock();//function
                            jw.WriteLocalizations();
                            jw.CloseBlock();
                            jw.WriteLine(");"); //Ext.define(

                            jw.Flush();
                        }
                    }
                }
            }
        }
Ejemplo n.º 16
0
            /// <summary>
            /// Write the properties from the bag to the writer. This method can be overrided for advanced scenarios.
            /// </summary>
            /// <param name="jw">The writer.</param>
            protected override void WriteProperties(DextopJsWriter jw)
            {
                jw.AddProperty("name", name);
                jw.DefaultProperty("type", type);
                jw.DefaultProperty("defaultValue", defaultValue);
                if (useNull == true)
                {
                    jw.AddProperty("useNull", useNull);
                }
                if (persist == false)
                {
                    jw.AddProperty("persist", false);
                }
                jw.DefaultProperty("mapping", mapping);
                jw.DefaultRawProperty("sortType", sortType);
                jw.DefaultRawProperty("convert", convert);
                jw.DefaultProperty("sortDir", sortDir);

                base.WriteProperties(jw);
            }
Ejemplo n.º 17
0
        public void ProcessAssemblies(DextopApplication application, IList <Assembly> assemblies, Stream output)
        {
            using (var tw = new StreamWriter(output))
            {
                DextopJsWriter jw       = new DextopJsWriter(tw);
                var            assembly = this.GetType().Assembly;
                var            data     = AssemblyHelper.GetTypeAttributeDictionaryForAssembly <DemoAttribute>(assembly, false);
                jw.ExtNamespace("Showcase");
                jw.Write("Showcase.Demos = [");
                bool first = true;

                HashSet <String> levels     = new HashSet <string>();
                HashSet <String> categories = new HashSet <string>();
                HashSet <String> topics     = new HashSet <string>();

                foreach (var entry in data)
                {
                    var att = entry.Value;
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        jw.Write(", ");
                    }
                    jw.StartBlock();
                    jw.AddProperty("id", att.Id);
                    jw.DefaultProperty("title", att.Title);
                    jw.DefaultProperty("description", att.Description);
                    jw.AddProperty("clientLauncher", att.ClientLauncher);
                    LevelAttribute level;
                    if (AttributeHelper.TryGetAttribute <LevelAttribute>(entry.Key, out level, false))
                    {
                        jw.AddProperty("level", level.Name);
                    }
                    TopicAttribute topic;
                    if (AttributeHelper.TryGetAttribute <TopicAttribute>(entry.Key, out topic, false))
                    {
                        jw.AddProperty("topic", topic.Name);
                    }
                    CategoryAttribute cat;
                    if (AttributeHelper.TryGetAttribute <CategoryAttribute>(entry.Key, out cat, false))
                    {
                        jw.AddProperty("category", cat.Name);
                    }

                    jw.AddProperty("sourceUrlBase", DextopUtil.AbsolutePath(String.Format("source/{0}", att.Id)));
                    jw.AddProperty("cacheBuster", GetCacheBuster(att));

                    jw.CloseBlock();
                    ((ShowcaseApplication)application).RegisterDemo(att.Id, entry.Key);

                    if (!levels.Contains(level.Name))
                    {
                        levels.Add(level.Name);
                    }

                    if (!topics.Contains(topic.Name))
                    {
                        topics.Add(topic.Name);
                    }

                    if (!categories.Contains(cat.Name))
                    {
                        categories.Add(cat.Name);
                    }
                }
                jw.WriteLine("];");
                jw.WriteLine();
                jw.Write("Showcase.Topics = ");
                jw.Write(DextopUtil.Encode(topics.ToArray()));
                jw.WriteLine(";");
                jw.WriteLine();
                jw.Write("Showcase.Levels = ");
                jw.Write(DextopUtil.Encode(levels.ToArray()));
                jw.WriteLine(";");
                jw.WriteLine();
                jw.Write("Showcase.Categories = ");
                jw.Write(DextopUtil.Encode(categories.ToArray()));
                jw.WriteLine(";");
            }
        }