Пример #1
0
        public void TestCustomFormatResult()
        {
            string template = @"<html tal:attributes=""value 1.05""> </html>";
            string expected = @"<html value=""1,05""> </html>";

            ITemplate t = new CustomTemplate(template);

            string actual = t.Render(globals);

            Assert.AreEqual(expected, actual, "{1} - {0}template: {2}{0}actual: {3}{0}expected: {4}",
                            Environment.NewLine, "Conversion using invariant culture failed", template, actual, expected);
        }
Пример #2
0
        private Dictionary <string, string> PreHandleCustomItem(Dictionary <string, string> replacementsDictionary)
        {
            var templateFolder = UserOptionsHelper.GetOption <string>(UserOptionProperties.CustomTemplatesPath);

            _addFile = CustomTemplateHandler.ValidateTemplateFolder(templateFolder);
            if (!_addFile)
            {
                return(replacementsDictionary);
            }

            _addFile = CustomTemplateHandler.ValidateTemplateFile(templateFolder);
            if (!_addFile)
            {
                return(replacementsDictionary);
            }

            var templates = CustomTemplateHandler.GetTemplateConfig(templateFolder);

            if (templates == null)
            {
                _addFile = false;
                return(replacementsDictionary);
            }

            var results = CustomTemplateHandler.GetTemplatesByLanguage(templates, "CSharp");

            if (results.Count == 0)
            {
                MessageBox.Show(Resource.MessageBox_AddCustomTemplate);
                _addFile = false;
                return(replacementsDictionary);
            }

            var templatePicker = CustomTemplateHandler.GetCustomTemplate(results);

            if (templatePicker.SelectedTemplate == null)
            {
                _addFile = false;
                return(replacementsDictionary);
            }

            _customTemplate = templatePicker.SelectedTemplate;

            var content = CustomTemplateHandler.GetTemplateContent(templateFolder, _customTemplate, replacementsDictionary);

            replacementsDictionary.Add("$customtemplate$", content);

            return(replacementsDictionary);
        }
Пример #3
0
        public static void AddTemplateReferences(CustomTemplate customTemplate, Project project)
        {
            if (customTemplate.CustomTemplateReferences.Count <= 0)
            {
                return;
            }

            if (!(project?.Object is VSProject vsproject))
            {
                return;
            }

            foreach (CustomTemplateReference reference in customTemplate.CustomTemplateReferences)
            {
                CrmDeveloperExtensions2.Core.Vs.ProjectWorker.AddProjectReference(vsproject, reference.Name);
            }
        }
Пример #4
0
        public static void InstallTemplateNuGetPackages(DTE dte, CustomTemplate customTemplate, Project project)
        {
            if (customTemplate.CustomTemplateNuGetPackages.Count <= 0)
            {
                return;
            }

            var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));

            if (componentModel == null)
            {
                return;
            }

            var installer = componentModel.GetService <IVsPackageInstaller>();

            foreach (CustomTemplateNuGetPackage package in customTemplate.CustomTemplateNuGetPackages)
            {
                AddPackage(installer, package, project);
            }
        }
Пример #5
0
        public static string GetTemplateContent(string templateFolder, CustomTemplate template, Dictionary <string, string> replacementsDictionary)
        {
            string path = Path.Combine(templateFolder, template.RelativePath);

            if (!File.Exists(path))
            {
                return(null);
            }

            string content = File.ReadAllText(path);

            if (!template.CoreReplacements)
            {
                return(content);
            }

            foreach (KeyValuePair <string, string> keyValuePair in replacementsDictionary)
            {
                content = content.Replace(keyValuePair.Key, keyValuePair.Value);
            }

            return(content);
        }
Пример #6
0
        public void TestCustomFormatResult()
        {
            string template = @"<html tal:attributes=""value 1.05""> </html>";
            string expected = @"<html value=""1,05""> </html>";

            ITemplate t = new CustomTemplate(template);

            string actual = t.Render(globals);
            Assert.AreEqual(expected, actual, "{1} - {0}template: {2}{0}actual: {3}{0}expected: {4}",
                Environment.NewLine, "Conversion using invariant culture failed", template, actual, expected);
        }
        /// <summary>
        /// Creates the child controls in a control derived from System.Web.UI.WebControls.CompositeControl.
        /// </summary>
        protected override void CreateChildControls()
        {
            Controls.Clear();

            IntializeControlsDefaultValues();

            /********************************/
            /******** CREATE CONTROLS *******/
            /********************************/



            //*********************//
            //*** USE TEMPLATES ***//
            //*********************//


            //outer box
            string style = string.Empty;

            style = "shopping_cart";

            Controls.Add(new LiteralControl("<table style='width: 100%' cellpadding='0' cellspacing='0' border='0'>"));
            Controls.Add(new LiteralControl("  <tr>"));

            Controls.Add(new LiteralControl("    <td class=\"" + style + "\" >"));


            //if the page developer does not explicitly add a <HeaderTemplate> tag
            //in ShoppingCartControl's declarative syntax
            if (HeaderTemplate == null)
            {
                if (this.DesignMode)
                {
                    ITemplate defaultTemplate = new MobileDefaultHeaderTemplate("Product", "Quantity", "SubTotal", "Delete");
                    defaultTemplate.InstantiateIn(this);
                }
                else
                {
                    if (this.DataSource != null)
                    {
                        CartItemCollection cic = this.DataSource;
                        if (cic.Count != 0)
                        {
                            ITemplate defaultTemplate = new MobileDefaultHeaderTemplate("Product", "Quantity", "SubTotal", "Delete");
                            defaultTemplate.InstantiateIn(this);
                        }
                        else
                        {
                            Topic     emptyCartTopic  = new Topic(this.EmptyCartTopicName);
                            ITemplate defaultTemplate = new MobileDefaultHeaderTemplate(emptyCartTopic.Contents);
                            defaultTemplate.InstantiateIn(this);
                        }
                    }
                    else
                    {
                        ITemplate defaultTemplate = new MobileDefaultHeaderTemplate("Product", "Quantity", "SubTotal", "Delete");
                        defaultTemplate.InstantiateIn(this);
                    }
                }
            }
            else
            {
                if (this.DataSource != null)
                {
                    CartItemCollection cic = (CartItemCollection)this.DataSource;
                    if (cic.Count != 0)
                    {
                        CustomTemplate headerTemplateItem = new CustomTemplate();
                        headerTemplateItem.ID = "headerTemplateItem";
                        HeaderTemplate.InstantiateIn(headerTemplateItem);

                        Controls.Add(new LiteralControl("      <table style='width : 100%;' cellpadding='0' cellspacing='0' border='0'>"));
                        Controls.Add(new LiteralControl("        <tr>"));
                        Controls.Add(new LiteralControl("          <td>"));
                        Controls.Add(headerTemplateItem);
                        Controls.Add(new LiteralControl("          </td>"));
                        Controls.Add(new LiteralControl("        </tr>"));
                        Controls.Add(new LiteralControl("      </table>"));
                    }
                    else
                    {
                        Topic     emptyCartTopic  = new Topic(this.EmptyCartTopicName);
                        ITemplate defaultTemplate = new MobileDefaultHeaderTemplate(emptyCartTopic.Contents);
                        defaultTemplate.InstantiateIn(this);
                    }
                }
                else
                {
                    CustomTemplate headerTemplateItem = new CustomTemplate();
                    headerTemplateItem.ID = "headerTemplateItem";
                    HeaderTemplate.InstantiateIn(headerTemplateItem);

                    Controls.Add(new LiteralControl("      <table style='width : 100%;' cellpadding='0' cellspacing='0' border='0'>"));
                    Controls.Add(new LiteralControl("        <tr>"));
                    Controls.Add(new LiteralControl("          <td>"));
                    Controls.Add(headerTemplateItem);
                    Controls.Add(new LiteralControl("          </td>"));
                    Controls.Add(new LiteralControl("        </tr>"));
                    Controls.Add(new LiteralControl("      </table>"));
                }
            }

            ShoppingCart cart = null;

            //ITEMS Template
            if (DataSource != null)
            {
                Items.Clear();
                int alternateItem = 0;
                CartItemCollection sortedCartItemForMinicart = new CartItemCollection();
                sortedCartItemForMinicart = this.DataSource;


                Panel pnlItems = new Panel();
                pnlItems.ID       = "pnlCartItems";
                pnlItems.CssClass = "cart_items";

                foreach (CartItem cItem in sortedCartItemForMinicart)
                {
                    cart = cItem.ThisShoppingCart;
                    if (alternateItem > 0)
                    {
                        // alternating separator
                        pnlItems.Controls.Add(new LiteralControl("<div style='border-top: solid 1px #444444'></div>"));
                    }

                    item = new MobileShoppingCartControlItem(this.LineItemSettings);

                    item.CartItem    = cItem;
                    item.AllowEdit   = this.AllowEdit;
                    item.DisplayMode = this.DisplayMode;
                    if (cItem.ThisShoppingCart.CartType == CartTypeEnum.Deleted)
                    {
                        item.IsDeleted = true;
                    }
                    Items.Add(item);
                    pnlItems.Controls.Add(item);

                    alternateItem++;
                }

                Controls.Add(pnlItems);
            }

            if (DesignMode)
            {
                Controls.Add(new LiteralControl("<table style='width: 100%;' cellpadding='0' cellspacing='0' border='0'>"));

                Controls.Add(new LiteralControl("  <tr>"));

                //dummy line item description
                Controls.Add(new LiteralControl("    <td style='width:60%' valign='top'>"));
                Controls.Add(new LiteralControl("      <table style='width: 100%;' cellpadding='0' cellspacing='0' border='0'>"));

                Controls.Add(new LiteralControl("        <tr>"));
                Controls.Add(new LiteralControl("          <td>Product Name : Unbound</td>"));
                Controls.Add(new LiteralControl("        </tr>"));

                Controls.Add(new LiteralControl("        <tr>"));
                Controls.Add(new LiteralControl("          <td>SKU : Unbound</td>"));
                Controls.Add(new LiteralControl("        </tr>"));

                Controls.Add(new LiteralControl("        <tr>"));
                Controls.Add(new LiteralControl("          <td>Size : Unbound</td>"));
                Controls.Add(new LiteralControl("        </tr>"));

                Controls.Add(new LiteralControl("        <tr>"));
                Controls.Add(new LiteralControl("          <td>Color : Unbound</td>"));
                Controls.Add(new LiteralControl("        </tr>"));

                Controls.Add(new LiteralControl("      </table>"));
                Controls.Add(new LiteralControl("    </td>"));

                //dummy quantity & delete button
                TextBox txtQuantity = new TextBox();
                txtQuantity.Text = "Unbound";

                LinkButton lnkDelete = new LinkButton();
                lnkDelete.Text = "shoppingcart.cs.107".StringResource();

                Controls.Add(new LiteralControl("    <td style='width:15%' valign='top'>"));
                Controls.Add(txtQuantity);
                Controls.Add(lnkDelete);
                Controls.Add(new LiteralControl("    </td>"));

                //dummy extended price
                Controls.Add(new LiteralControl("    <td style='width:25%;' align='right' valign='top'>Unbound"));
                Controls.Add(new LiteralControl("    </td>"));

                Controls.Add(new LiteralControl("  </tr>"));


                Controls.Add(new LiteralControl("</table>"));
            }
            else
            {
                if (FooterTemplate == null)
                {
                    ITemplate defaultTemplate = new DefaulFooterTemplate();
                    defaultTemplate.InstantiateIn(this);
                }
                else
                {
                    CustomTemplate footerTemplateItem = new CustomTemplate();
                    footerTemplateItem.ID = "footerTemplateItem";
                    FooterTemplate.InstantiateIn(footerTemplateItem);

                    Controls.Add(new LiteralControl("<div>"));
                    Controls.Add(footerTemplateItem);
                    Controls.Add(new LiteralControl("</div>"));
                }
            }
            //end outer box
            Controls.Add(new LiteralControl("    </td>"));
            Controls.Add(new LiteralControl("  </tr>"));
            Controls.Add(new LiteralControl("</table>"));
        }