Esempio n. 1
0
 private void UpdateQuickInfo([NotNull] TemplateFields templateFields, [NotNull] XElement root)
 {
     ItemName.Text         = templateFields.Name;
     QuickInfoIcon.Source  = templateFields.Icon.GetSource();
     ItemIdTextBlock.Value = TemplateUri.ItemId.ToString();
     PathTextBlock.Value   = root.GetAttributeValue("path");
 }
Esempio n. 2
0
        public void RemoveTemplate([NotNull] TemplateFields templateFields)
        {
            Assert.ArgumentNotNull(templateFields, nameof(templateFields));

            Model.Remove(templateFields);
            Refresh();
        }
Esempio n. 3
0
        public void AddTemplate([NotNull] ItemUri templateUri, bool primary)
        {
            Debug.ArgumentNotNull(templateUri, nameof(templateUri));

            var template = new TemplateFields(templateUri, primary);

            Model.Add(template);

            LoadFields(template, templateUri);
        }
Esempio n. 4
0
    public static Panel GetEditColumn(string ShowType, Column c, string v)
    {
        if (ShowType == EditShowType.Text.ToString())
        {
            TextField field = new TextField(c, v);

            return(field.Panel);
        }
        else if (ShowType == EditShowType.DateTime.ToString())
        {
            DateTimeField field = new DateTimeField(c, v);
            return(field.Panel);
        }
        else if (ShowType == EditShowType.Check.ToString())
        {
            CheckField field = new CheckField(c, v);
            return(field.Panel);
        }
        else if (ShowType == EditShowType.DropDownList.ToString())
        {
            DropDownField field = new DropDownField(c, v);
            return(field.Panel);
        }
        else if (ShowType == EditShowType.CheckList.ToString())
        {
            CheckListField field = new CheckListField(c, v);
            return(field.Panel);
        }
        else if (ShowType == EditShowType.RadioList.ToString())
        {
            RadioListField field = new RadioListField(c, v);
            return(field.Panel);
        }
        else if (ShowType == EditShowType.picUpload.ToString())
        {
            UploadImgField field = new UploadImgField(c, v);
            return(field.Panel);
        }
        else if (ShowType == EditShowType.MultiText.ToString())
        {
            MultiTextField field = new MultiTextField(c, v);
            return(field.Panel);
        }
        else if (ShowType == EditShowType.Editor.ToString())
        {
            EditorField field = new EditorField(c, v);
            return(field.Panel);
        }
        else if (ShowType == EditShowType.docUpload.ToString())
        {
            UploadFileField field = new UploadFileField(c, v);
            return(field.Panel);
        }
        else if (ShowType == EditShowType.Hidden.ToString())
        {
            Panel       p     = new Panel();
            HiddenField field = new HiddenField();
            field.ID    = c.ColumnName + "_value";
            field.Value = v;
            p.Controls.Add(field);
            return(p);
        }
        else if (ShowType == EditShowType.Template.ToString())
        {
            Page page = HttpContext.Current.Handler as Page;
            if (page != null)
            {
                Control ctrl = page.LoadControl(c.EditTempLate);

                TemplateFields field = new TemplateFields(c, v, ctrl);
                return(field.Panel);
            }
            else
            {
                return(null);
            }
        }
        else
        {
            TextField field = new TextField(c, v);

            return(field.Panel);
        }
    }
Esempio n. 5
0
        //async Task<BitmapImage> renderImageWithTemplateContextAsync()
        //{
        //    //var filename = System.IO.Path.Combine(_config.SlidesConfiguration.TemplatePath, template);
        //    if (Template == null || TemplateFields == null)
        //    {
        //        return null;
        //    }
        //    if (!File.Exists(Template) && File.Exists(Path.Combine(_config.SlidesConfiguration.TemplatePath, Template)))
        //    {
        //        Template = Path.Combine(_config.SlidesConfiguration.TemplatePath, Template);
        //    }
        //    else if (!File.Exists(Template))
        //    {
        //        return null;
        //    }

        //    var templateHtml = File.ReadAllText(Template);

        //    foreach (Match m in Regex.Matches(templateHtml, pattern))
        //    {
        //        var variable = m.Groups[1].Value;
        //        var matchedValue = m.Value;
        //        var replaceField = TemplateFields.FirstOrDefault(x => x.Title == variable);
        //        var replaceValue = "";
        //        if (replaceField != null)
        //            replaceValue = replaceField.Value;
        //        templateHtml = templateHtml.Replace(matchedValue, replaceValue);
        //    }

        //    // Replace ##index## with offseted Values
        //    const string indexpattern = "##(.*?)##";
        //    foreach (Match m in Regex.Matches(templateHtml, indexpattern))
        //    {
        //        var variable = Convert.ToInt32(m.Groups[1].Value);
        //        var matchedValue = m.Value;
        //        var replaceValue = (IndexOffset + variable).ToString();
        //        templateHtml = templateHtml.Replace(matchedValue, replaceValue);
        //    }

        //    // Background Management
        //    const string bgpattern = "\"backgroundimage\": ?\"(?<image>.*?)\"";
        //    Match mbg = Regex.Match(templateHtml, bgpattern);
        //    if (mbg.Success && !String.IsNullOrEmpty(Background))
        //    {
        //        var variable = mbg.Groups[1].Value;
        //        var filepath = Background.Replace("\\", "/"); //"file://" +
        //        templateHtml = templateHtml.Replace(variable, filepath);
        //    }

        //    // Render the image
        //    var rendered = HTMLRenderer.RenderHtml(templateHtml, _config.SlidesConfiguration.TemplatePath);

        //    return rendered;
        //}

        private string RenderImageWithTemplateContext(string generationProperties)
        {
            //var filename = System.IO.Path.Combine(_config.SlidesConfiguration.TemplatePath, template);
            if (Template == null || TemplateFields == null)
            {
                return(null);
            }
            if (!File.Exists(Template) && File.Exists(Path.Combine(Config.SlidesConfiguration.TemplatePath, Template)))
            {
                Template = Path.Combine(Config.SlidesConfiguration.TemplatePath, Template);
            }
            else if (!File.Exists(Template) && File.Exists(Path.Combine(Config.SlidesConfiguration.TemplatePath, Path.GetFileName(Template))))
            {
                Template = Path.Combine(Config.SlidesConfiguration.TemplatePath, Path.GetFileName(Template));
            }
            else if (!File.Exists(Template))
            {
                return(null);
            }

            var templateHtml = File.ReadAllText(Template);

            // Pattern used to replace template variables
            string pattern = "@@(?<variable>.*?)(=(?<default>.*))?@@";

            foreach (Match m in Regex.Matches(templateHtml, pattern))
            {
                var variable     = m.Groups["variable"].Value;
                var matchedValue = m.Value;
                var replaceField = TemplateFields.FirstOrDefault(x => x.Title == variable);
                var replaceValue = "";
                if (replaceField != null)
                {
                    replaceValue = replaceField.Value;
                }
                templateHtml = templateHtml.Replace(matchedValue, replaceValue);
            }

            // Replace ##index## with offseted Values
            const string indexpattern = "##(.*?)##";

            foreach (Match m in Regex.Matches(templateHtml, indexpattern))
            {
                var variable     = Convert.ToInt32(m.Groups[1].Value);
                var matchedValue = m.Value;
                var replaceValue = (IndexOffset + variable).ToString();
                templateHtml = templateHtml.Replace(matchedValue, replaceValue);
            }

            // Background Management
            const string bgpattern = "\"backgroundimage\": ?\"(?<image>.*?)\"";
            Match        mbg       = Regex.Match(templateHtml, bgpattern);

            if (mbg.Success && !String.IsNullOrEmpty(Background))
            {
                var variable = mbg.Groups[1].Value;
                var filepath = Background.Replace("\\", "/"); //"file://" +
                var localRex = new Regex(@"^\w:\/+", RegexOptions.IgnoreCase);
                if (localRex.IsMatch(filepath))
                {
                    // Add Local file:/// prefix for path with Drive
                    filepath = "file:///" + filepath;
                }
                templateHtml = templateHtml.Replace(variable, filepath);
            }

            // Render the image
            var rendered = HTMLRenderer.RenderHtml(html: templateHtml,
                                                   pathToWorkingDir: Config.SlidesConfiguration.TemplatePath,
                                                   zoomFactorOptions: generationProperties);

            return(rendered);
        }
Esempio n. 6
0
        /// <summary>
        /// Read the templates variables
        /// </summary>
        /// <returns>Returns true if changes happened</returns>
        private bool ReadTemplateFields()
        {
            if (Template == null || TemplateFields == null)
            {
                return(false);
            }
            if (!File.Exists(Template) && File.Exists(Path.Combine(Config.SlidesConfiguration.TemplatePath, Template)))
            {
                Template = Path.Combine(Config.SlidesConfiguration.TemplatePath, Template);
            }
            else if (!File.Exists(Template) && File.Exists(Path.Combine(Config.SlidesConfiguration.TemplatePath, Path.GetFileName(Template))))
            {
                Template = Path.Combine(Config.SlidesConfiguration.TemplatePath, Path.GetFileName(Template));
            }
            else if (!File.Exists(Template))
            {
                return(false);
            }

            var templateHtml = File.ReadAllText(Template);

            // Pattern used to replace template variables
            string pattern = "@@(?<variable>.*?)(=(?<default>.*))?@@";

            var changes = false;

            if (TemplateFields == null)
            {
                TemplateFields = new DispatchedObservableCollection <ManagerTemplateField>();
            }
            var matches = Regex.Matches(templateHtml, pattern);

            foreach (Match m in matches)
            {
                var    variable       = m.Groups["variable"].Value;
                var    defaultvalue   = m.Groups["default"].Value;
                var    isDefaultValue = false;
                string replaceValue   = null;
                if (Context != null && Context.HasValue(variable))
                {
                    replaceValue = Context.GetValue(variable);
                }
                else if (!string.IsNullOrEmpty(defaultvalue))
                {
                    replaceValue   = defaultvalue;
                    isDefaultValue = true;

                    //// Add to context if any
                    //if (Context != null)
                    //{
                    //    Context.Data.Add(new DataMessage()
                    //    {je
                    //        Data = null,
                    //        DataType = "string",
                    //        Key = variable,
                    //        Value = defaultvalue
                    //    });
                    //}
                }

                // Add all fields to template fields
                if (TemplateFields.Any(x => x.Title == variable))
                {
                    // If already in there check if value changed
                    var existing = TemplateFields.First(x => x.Title == variable);
                    if (!isDefaultValue && String.Compare(existing.Value, replaceValue, StringComparison.Ordinal) != 0)
                    {
                        // Update value
                        if (replaceValue != null)
                        {
                            existing.Value = replaceValue;
                            changes        = true;
                        }
                    }
                }
                else
                {
                    // Only add once to list
                    TemplateFields.Add(new ManagerTemplateField(variable, replaceValue));
                    changes = true;
                }
            }
            return(changes);
        }
Esempio n. 7
0
        private void LoadFields([NotNull] TemplateFields templateFields, [NotNull] ItemUri templateUri)
        {
            Debug.ArgumentNotNull(templateFields, nameof(templateFields));
            Debug.ArgumentNotNull(templateUri, nameof(templateUri));

            ExecuteCompleted c = delegate(string response, ExecuteResult result)
            {
                if (!DataService.HandleExecute(response, result))
                {
                    return;
                }

                var root = response.ToXElement();
                if (root == null)
                {
                    return;
                }

                templateFields.Name = root.GetAttributeValue("name");
                templateFields.Icon = new Icon(templateUri.Site, root.GetAttributeValue("icon"));

                if (templateFields.IsPrimary)
                {
                    UpdateQuickInfo(templateFields, root);
                }

                foreach (var element in root.Elements())
                {
                    var name = element.GetAttributeValue("name");

                    var field = new Field
                    {
                        TemplateFieldId  = new ItemId(new Guid(element.GetAttributeValue("id"))),
                        Name             = name,
                        Type             = element.GetAttributeValue("type"),
                        SortOrder        = element.GetAttributeInt("sortorder", 0),
                        SectionSortOrder = element.GetAttributeInt("sectionsortorder", 0),
                        SectionName      = element.GetAttributeValue("sectionname"),
                        SectionId        = element.GetAttributeValue("sectionid"),
                        TemplateName     = element.GetAttributeValue("templatename"),
                        TemplateIcon     = new Icon(templateUri.Site, element.GetAttributeValue("templateicon")),
                        IsInherited      = element.GetAttributeValue("isinherited") == @"true",
                        IsSystemField    = name.StartsWith(@"__"),
                    };

                    foreach (var tf in Model)
                    {
                        if (tf == templateFields)
                        {
                            continue;
                        }

                        foreach (var f in tf.Fields)
                        {
                            if (f.TemplateFieldId != field.TemplateFieldId)
                            {
                                continue;
                            }

                            field.SortOrder        = f.SortOrder;
                            field.SectionSortOrder = f.SectionSortOrder;
                            break;
                        }
                    }

                    templateFields.Fields.Add(field);
                }

                Refresh();
            };

            templateUri.Site.DataService.ExecuteAsync("Templates.GetTemplateFieldSorterFields", c, templateFields.TemplateUri.DatabaseName.Name, templateFields.TemplateUri.ItemId.ToString());
        }
        //async Task<BitmapImage> renderImageWithTemplateContextAsync()
        //{
        //    //var filename = System.IO.Path.Combine(_config.SlidesConfiguration.TemplatePath, template);
        //    if (Template == null || TemplateFields == null)
        //    {
        //        return null;
        //    }
        //    if (!File.Exists(Template) && File.Exists(Path.Combine(_config.SlidesConfiguration.TemplatePath, Template)))
        //    {
        //        Template = Path.Combine(_config.SlidesConfiguration.TemplatePath, Template);
        //    }
        //    else if (!File.Exists(Template))
        //    {
        //        return null;
        //    }

        //    var templateHtml = File.ReadAllText(Template);

        //    // Replace @@values@@ with context Values
        //    const string pattern = "@@(.*?)@@";
        //    foreach (Match m in Regex.Matches(templateHtml, pattern))
        //    {
        //        var variable = m.Groups[1].Value;
        //        var matchedValue = m.Value;
        //        var replaceField = TemplateFields.FirstOrDefault(x => x.Title == variable);
        //        var replaceValue = "";
        //        if (replaceField != null)
        //            replaceValue = replaceField.Value;
        //        templateHtml = templateHtml.Replace(matchedValue, replaceValue);
        //    }

        //    // Replace ##index## with offseted Values
        //    const string indexpattern = "##(.*?)##";
        //    foreach (Match m in Regex.Matches(templateHtml, indexpattern))
        //    {
        //        var variable = Convert.ToInt32(m.Groups[1].Value);
        //        var matchedValue = m.Value;
        //        var replaceValue = (IndexOffset + variable).ToString();
        //        templateHtml = templateHtml.Replace(matchedValue, replaceValue);
        //    }

        //    // Background Management
        //    const string bgpattern = "\"backgroundimage\": ?\"(?<image>.*?)\"";
        //    Match mbg = Regex.Match(templateHtml, bgpattern);
        //    if (mbg.Success && !String.IsNullOrEmpty(Background))
        //    {
        //        var variable = mbg.Groups[1].Value;
        //        var filepath = Background.Replace("\\", "/"); //"file://" +
        //        templateHtml = templateHtml.Replace(variable, filepath);
        //    }

        //    // Render the image
        //    var rendered = HTMLRenderer.RenderHtml(templateHtml, _config.SlidesConfiguration.TemplatePath);

        //    return rendered;
        //}

        private BitmapImage RenderImageWithTemplateContext()
        {
            //var filename = System.IO.Path.Combine(_config.SlidesConfiguration.TemplatePath, template);
            if (Template == null || TemplateFields == null)
            {
                return(null);
            }
            if (!File.Exists(Template) && File.Exists(Path.Combine(Config.SlidesConfiguration.TemplatePath, Template)))
            {
                Template = Path.Combine(Config.SlidesConfiguration.TemplatePath, Template);
            }
            else if (!File.Exists(Template) && File.Exists(Path.Combine(Config.SlidesConfiguration.TemplatePath, Path.GetFileName(Template))))
            {
                Template = Path.Combine(Config.SlidesConfiguration.TemplatePath, Path.GetFileName(Template));
            }
            else if (!File.Exists(Template))
            {
                return(null);
            }

            var templateHtml = File.ReadAllText(Template);

            // Replace @@values@@ with context Values
            const string pattern = "@@(.*?)@@";

            foreach (Match m in Regex.Matches(templateHtml, pattern))
            {
                var variable     = m.Groups[1].Value;
                var matchedValue = m.Value;
                var replaceField = TemplateFields.FirstOrDefault(x => x.Title == variable);
                var replaceValue = "";
                if (replaceField != null)
                {
                    replaceValue = replaceField.Value;
                }
                templateHtml = templateHtml.Replace(matchedValue, replaceValue);
            }

            // Replace ##index## with offseted Values
            const string indexpattern = "##(.*?)##";

            foreach (Match m in Regex.Matches(templateHtml, indexpattern))
            {
                var variable     = Convert.ToInt32(m.Groups[1].Value);
                var matchedValue = m.Value;
                var replaceValue = (IndexOffset + variable).ToString();
                templateHtml = templateHtml.Replace(matchedValue, replaceValue);
            }

            // Background Management
            const string bgpattern = "\"backgroundimage\": ?\"(?<image>.*?)\"";
            Match        mbg       = Regex.Match(templateHtml, bgpattern);

            if (mbg.Success && !String.IsNullOrEmpty(Background))
            {
                var variable = mbg.Groups[1].Value;
                var filepath = Background.Replace("\\", "/"); //"file://" +
                templateHtml = templateHtml.Replace(variable, filepath);
            }

            // Render the image
            var rendered = HTMLRenderer.RenderHtml(templateHtml, Config.SlidesConfiguration.TemplatePath);

            return(rendered);
        }
        /// <summary>
        /// Read the templates variables
        /// </summary>
        /// <returns>Returns true if changes happened</returns>
        private bool ReadTemplateFields()
        {
            if (Template == null || TemplateFields == null)
            {
                return(false);
            }
            if (!File.Exists(Template) && File.Exists(Path.Combine(Config.SlidesConfiguration.TemplatePath, Template)))
            {
                Template = Path.Combine(Config.SlidesConfiguration.TemplatePath, Template);
            }
            else if (!File.Exists(Template) && File.Exists(Path.Combine(Config.SlidesConfiguration.TemplatePath, Path.GetFileName(Template))))
            {
                Template = Path.Combine(Config.SlidesConfiguration.TemplatePath, Path.GetFileName(Template));
            }
            else if (!File.Exists(Template))
            {
                return(false);
            }

            var templateHtml = File.ReadAllText(Template);

            // Replace @@values@@ with context Values
            const string pattern = "@@(.*?)@@";

            var changes = false;

            if (TemplateFields == null)
            {
                TemplateFields = new DispatchedObservableCollection <ManagerTemplateField>();
            }
            foreach (Match m in Regex.Matches(templateHtml, pattern))
            {
                var    variable     = m.Groups[1].Value;
                string replaceValue = null;
                if (Context != null && Context.HasValue(variable))
                {
                    replaceValue = Context.GetValue(variable);
                }
                // Add all fields to template fields
                if (TemplateFields.Any(x => x.Title == variable))
                {
                    // If already in there check if value changed
                    var existing = TemplateFields.First(x => x.Title == variable);
                    if (String.Compare(existing.Value, replaceValue, StringComparison.Ordinal) != 0)
                    {
                        // Update value
                        if (replaceValue != null)
                        {
                            existing.Value = replaceValue;
                            changes        = true;
                        }
                    }
                }
                else
                {
                    // Only add once to list
                    TemplateFields.Add(new ManagerTemplateField(variable, replaceValue));
                    changes = true;
                }
            }
            return(changes);
        }