Esempio n. 1
0
        private void SetBindingInfo(RenderContext context, ref string objecttype, ref string nameorid)
        {
            if (string.IsNullOrEmpty(this.BindingValue))
            {
                return;
            }

            string objectkey    = this.BindingValue;
            int    lastDotIndex = this.BindingValue.LastIndexOf(".");

            if (lastDotIndex > -1)
            {
                objectkey = this.BindingValue.Substring(0, lastDotIndex);
            }

            object value = context.DataContext.GetValue(objectkey);

            if (value == null)
            {
                return;
            }
            if (value is DataMethodResult)
            {
                value = ((DataMethodResult)value).Value;
            }
            if (value is TextContentViewModel)
            {
                TextContentViewModel textcontent = value as TextContentViewModel;
                objecttype = "content";
                nameorid   = textcontent.Id.ToString();
            }
        }
Esempio n. 2
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            this._navigationhelper.OnNavigatedTo(e);
            _textContentVM = Resources["textContentSource"] as TextContentViewModel;
            _textContentVM.GetContent();
            _translateModel = Resources["languageCollection"] as LanguageTranslateModel;

            var recognizeModel = e.Parameter as ImageRecognizeViewModel;

            if (recognizeModel != null)
            {
                // Nên là Recog Image
                //previewImage.Source = recognizeModel.Image;
                //recognizeModel.RecognizedImage = recognizeModel.RecognizedImage.Resize(
                //    (int)this.previewImage.Width,
                //    (int)this.previewImage.Height,
                //    WriteableBitmapExtensions.Interpolation.Bilinear
                //    );
                //recognizeModel.ShowRecognizedRect();
                previewImage.Source = recognizeModel.RecognizedImage;
            }

            //fromLanguage.SelectedItem = "English";
            _translateModel.From = LanguageTranslateModel.GetRecognizeLanguage();
            _translateModel.To   = await LanguageTranslateModel.GetLocalityLanguage();

            fromLanguage.SelectedItem = _translateModel.From;
            toLanguage.SelectedItem   = _translateModel.To;
        }
Esempio n. 3
0
        public static TextContentViewModel ToView(TextContent Content, string lang, List <ContentProperty> Properties)
        {
            if (Content == null)
            {
                return(null);
            }
            TextContentViewModel model = new TextContentViewModel();

            model.Id            = Content.Id;
            model.ParentId      = Content.ParentId;
            model.FolderId      = Content.FolderId;
            model.ContentTypeId = Content.ContentTypeId;
            model.UserKey       = Content.UserKey;
            model.LastModified  = Content.LastModified;
            model.Order         = Content.Order;
            model.Online        = Content.Online;
            model.Embedded      = Content.Embedded;
            model.CreationDate  = Content.CreationDate;

            var langcontent = Content.GetContentStore(lang);

            if (langcontent != null)
            {
                model.Values = langcontent.FieldValues;
            }

            if (Properties != null)
            {
                foreach (var item in Properties.Where(o => !o.IsSystemField && !o.MultipleLanguage))
                {
                    if (!model.Values.ContainsKey(item.Name) || string.IsNullOrEmpty(model.Values[item.Name]))
                    {
                        bool found = false;
                        foreach (var citem in Content.Contents)
                        {
                            foreach (var fielditem in citem.FieldValues)
                            {
                                if (fielditem.Key == item.Name)
                                {
                                    model.Values[item.Name] = fielditem.Value;
                                    found = true;
                                    break;
                                }
                            }
                            if (found)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            return(model);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="FileContentSearchParameters" /> class.
 /// </summary>
 /// <param name="containingText">The containing text.</param>
 /// <param name="containingTextMatchCase">if set to <c>true</c> [containing text match case].</param>
 /// <param name="containingTextNot">if set to <c>true</c> [containing text not].</param>
 /// <param name="containingTextRegex">if set to <c>true</c> [containing text regex].</param>
 /// <param name="containingTextRegexOptions">The containing text regex options.</param>
 /// <param name="contentViewModel">The content view model.</param>
 public FileContentSearchParameters(
     string containingText,
     bool containingTextMatchCase,
     bool containingTextNot,
     bool containingTextRegex,
     RegexOptions containingTextRegexOptions,
     TextContentViewModel contentViewModel)
 {
     ContainingText             = containingText;
     ContainingTextMatchCase    = containingTextMatchCase;
     ContainingTextNot          = containingTextNot;
     ContainingTextRegex        = containingTextRegex;
     ContainingTextRegexOptions = containingTextRegexOptions;
     ContentViewModel           = contentViewModel;
 }
Esempio n. 5
0
        public static string GetTitle(SiteDb sitedb, TextContentViewModel contentview)
        {
            if (contentview == null || !contentview.Values.Any())
            {
                return(string.Empty);
            }

            Guid contentTypeId = contentview.ContentTypeId;

            if (contentTypeId == default(Guid))
            {
                var folder = sitedb.ContentFolders.Get(contentview.FolderId);
                if (folder != null)
                {
                    contentTypeId = folder.ContentTypeId;
                }
            }

            if (contentTypeId != default(Guid))
            {
                var columns = sitedb.ContentTypes.GetTitleColumns(contentTypeId);
                if (columns != null && columns.Any())
                {
                    string title = string.Empty;

                    foreach (var item in columns)
                    {
                        var value = contentview.GetValue(item);
                        title += value + " ";
                    }

                    if (!string.IsNullOrWhiteSpace(title))
                    {
                        return(title.Trim());
                    }
                }
            }
            return(contentview.Values.First().Value);
        }
Esempio n. 6
0
        private string GetNameOrId(RenderContext context)
        {
            if (string.IsNullOrEmpty(this.BindingValue))
            {
                return(null);
            }

            string objectkey = this.BindingValue;

            int lastDotIndex = this.BindingValue.LastIndexOf(".");

            if (lastDotIndex > -1)
            {
                objectkey = this.BindingValue.Substring(0, lastDotIndex);
                //Modify by cz
                if (objectkey.IndexOf("{") > -1)
                {
                    objectkey = objectkey.TrimStart('{');
                }
            }

            object value = context.DataContext.GetValue(objectkey);

            if (value == null)
            {
                return(null);
            }
            if (value is DataMethodResult)
            {
                value = ((DataMethodResult)value).Value;
            }
            if (value is TextContentViewModel)
            {
                TextContentViewModel textcontent = value as TextContentViewModel;

                return(textcontent.Id.ToString());
            }
            return(null);
        }
Esempio n. 7
0
        private string RenderTextContent(RenderContext context, TextContentViewModel contentitem)
        {
            if (contentitem == null)
            {
                return(null);
            }
            string result = "\r\n<!--#kooboo";

            if (this.IsEndBinding)
            {
                result += "--end=true";
                result += "--objecttype='contentrepeater'";

                if (!string.IsNullOrEmpty(this.Boundary))
                {
                    result += "--boundary='" + this.Boundary + "'";
                }
                result += "-->\r\n";
                return(result);
            }
            else
            {
                result += "--objecttype='contentrepeater'";

                result += "--nameorid='" + contentitem.Id.ToString() + "'";
                result += "--folderid='" + contentitem.FolderId.ToString() + "'";

                result += "--bindingvalue='" + this.ItemAliasKey + "'";


                if (!string.IsNullOrEmpty(this.Boundary))
                {
                    result += "--boundary='" + this.Boundary + "'";
                }
                result += "-->\r\n";
                return(result);
            }
        }
Esempio n. 8
0
        public object Convert(object[] value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            FlowDocument doc         = new FlowDocument();
            var          fileContent = value[1] as string;

            if (!(value[0] is int) || fileContent == null)
            {
                return(doc);
            }

            var fileCount = (int)value[0];

            if (fileCount != 1)
            {
                var paragraph = new Paragraph();
                paragraph.Inlines.Add(String.Format("{0} files selected.", fileCount));
                doc.Blocks.Add(paragraph);
            }
            else
            {
                var tooBig   = (bool)value[2];
                var isBinary = (bool)value[3];
                if (tooBig)
                {
                    doc.Blocks.Add(new Paragraph(new Run("Selected file is too big to display.")));
                }
                else if (isBinary)
                {
                    var paragraph = new Paragraph();
                    paragraph.Inlines.Add("Binary file selected, see Binary Content tab.");
                    doc.Blocks.Add(paragraph);
                }
                else
                {
                    var contentSearchParameters = value[6] as FileContentSearchParameters;
                    var showFullContent         = (bool)value[4] || String.IsNullOrEmpty(contentSearchParameters.ContainingText) || contentSearchParameters.ContainingTextNot;
                    _linesOfContext = (int)value[5];
                    var paragraphs = new List <Paragraph>();

                    if (!String.IsNullOrEmpty(contentSearchParameters.ContainingText) &&
                        !contentSearchParameters.ContainingTextNot &&
                        contentSearchParameters.ContainingTextRegex)
                    {
                        // Regex highlighting must support multi-line so we do this way differently.
                        var options = contentSearchParameters.ContainingTextMatchCase ? RegexOptions.None : RegexOptions.IgnoreCase;
                        options |= contentSearchParameters.ContainingTextRegexOptions;

                        Regex regex = null;
                        try
                        {
                            regex = new Regex(contentSearchParameters.ContainingText, options);
                        }
                        catch (ArgumentException)
                        {
                            // It's possible for the user to enter an invalid regex, just ignore.
                        }

                        int index = 0;
                        if (regex != null)
                        {
                            var matches = regex.Matches(fileContent);
                            foreach (Match match in matches)
                            {
                                var nonHighlighted = fileContent.Substring(index, match.Index - index);
                                var highlighted    = fileContent.Substring(match.Index, match.Length);
                                if (nonHighlighted.EndsWith("\r"))
                                {
                                    nonHighlighted = nonHighlighted.Substring(0, nonHighlighted.Length - 1);
                                }
                                if (highlighted.EndsWith("\r"))
                                {
                                    highlighted = highlighted.Substring(0, highlighted.Length - 1);
                                }


                                bool append = paragraphs.Count > 0;
                                foreach (var line in TextContentViewModel.SplitStringIntoLines(nonHighlighted))
                                {
                                    var run = new Run(line);
                                    if (append)
                                    {
                                        paragraphs[paragraphs.Count - 1].Inlines.Add(run);
                                        append = false;
                                    }
                                    else
                                    {
                                        var paragraph = new Paragraph();
                                        paragraph.Inlines.Add(run);
                                        paragraphs.Add(paragraph);
                                    }
                                }

                                append = true;
                                foreach (var line in TextContentViewModel.SplitStringIntoLines(highlighted))
                                {
                                    var run = new Run(line)
                                    {
                                        Background = _yellow
                                    };
                                    if (append)
                                    {
                                        paragraphs[paragraphs.Count - 1].Inlines.Add(run);
                                        append = false;
                                    }
                                    else
                                    {
                                        var paragraph = new Paragraph();
                                        paragraph.Inlines.Add(run);
                                        paragraphs.Add(paragraph);
                                    }
                                }

                                index = match.Index + match.Length;
                            }

                            if (index < fileContent.Length)
                            {
                                bool append = paragraphs.Count > 0;
                                foreach (var line in TextContentViewModel.SplitStringIntoLines(fileContent.Substring(index)))
                                {
                                    var run = new Run(line);
                                    if (append)
                                    {
                                        paragraphs[paragraphs.Count - 1].Inlines.Add(run);
                                        append = false;
                                    }
                                    else
                                    {
                                        var paragraph = new Paragraph();
                                        paragraph.Inlines.Add(run);
                                        paragraphs.Add(paragraph);
                                    }
                                }
                            }
                        }
                        else
                        {
                            foreach (var line in TextContentViewModel.SplitStringIntoLines(fileContent))
                            {
                                var paragraph = new Paragraph();
                                paragraph.Inlines.Add(new Run(line));
                                paragraphs.Add(paragraph);
                            }
                        }
                    }
                    else
                    {
                        using (StringReader reader = new StringReader(fileContent))
                        {
                            string line;
                            while ((line = reader.ReadLine()) != null)
                            {
                                var paragraph = new Paragraph();
                                if (String.IsNullOrEmpty(contentSearchParameters.ContainingText) || contentSearchParameters.ContainingTextNot)
                                {
                                    paragraph.Inlines.Add(new Run(line));
                                }
                                else
                                {
                                    var comparison = contentSearchParameters.ContainingTextMatchCase ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase;
                                    int index      = 0;

                                    while (true)
                                    {
                                        var nextIndex = line.IndexOf(contentSearchParameters.ContainingText, index, comparison);
                                        if (nextIndex >= 0)
                                        {
                                            paragraph.Inlines.Add(new Run(line.Substring(index, nextIndex - index)));
                                            var run = new Run(line.Substring(nextIndex, contentSearchParameters.ContainingText.Length));
                                            run.Background = _yellow;
                                            paragraph.Inlines.Add(run);
                                            index = nextIndex + contentSearchParameters.ContainingText.Length;
                                        }
                                        else
                                        {
                                            var run = new Run(line.Substring(index));
                                            paragraph.Inlines.Add(run);
                                            break;
                                        }
                                    }
                                }

                                paragraphs.Add(paragraph);
                            }
                        }
                    }

                    if (!showFullContent)
                    {
                        var  lineNumbers  = new List <string>();
                        bool elipsesAdded = false;
                        var  indexesAdded = new List <int>();
                        for (int i = 0; i < paragraphs.Count; i++)
                        {
                            var para = paragraphs[i];
                            if (ContainsHighlighting(para))
                            {
                                int originalLineIndex = i;
                                int indexAFewLinesAgo = Math.Max(0, i - _linesOfContext);
                                i = Math.Min(paragraphs.Count - 1, i + _linesOfContext);
                                while (indexAFewLinesAgo <= i)
                                {
                                    if (!indexesAdded.Contains(indexAFewLinesAgo))
                                    {
                                        if (indexAFewLinesAgo > originalLineIndex && ContainsHighlighting(paragraphs[indexAFewLinesAgo]))
                                        {
                                            i = indexAFewLinesAgo - 1;
                                            break;
                                        }
                                        doc.Blocks.Add(paragraphs[indexAFewLinesAgo]);
                                        indexesAdded.Add(indexAFewLinesAgo);
                                        lineNumbers.Add((indexAFewLinesAgo + 1).ToString());
                                    }
                                    indexAFewLinesAgo++;
                                }
                                elipsesAdded = false;
                            }
                            else if (!elipsesAdded)
                            {
                                var elipsesPara = new Paragraph();
                                var elipsesText = GetElipsesText();
                                elipsesPara.Inlines.Add(elipsesText);
                                lineNumbers.Add(""); // Add a blank line number
                                doc.Blocks.Add(elipsesPara);
                                elipsesAdded = true;
                            }
                        }
                        contentSearchParameters.ContentViewModel.SetLineNumbers(lineNumbers);
                    }
                    else
                    {
                        doc.Blocks.AddRange(paragraphs);
                        var lineNumbers = new List <string>();
                        for (int i = 1; i <= paragraphs.Count; i++)
                        {
                            lineNumbers.Add(i.ToString());
                        }
                        contentSearchParameters.ContentViewModel.SetLineNumbers(lineNumbers);
                    }
                }
            }

            double longestLine = 0;

            foreach (Paragraph p in doc.Blocks)
            {
                StringBuilder lineText = new StringBuilder();

                foreach (Run r in p.Inlines)
                {
                    lineText.Append(r.Text);
                }

                var           line = lineText.ToString();
                FormattedText f    = new FormattedText(line,
                                                       Thread.CurrentThread.CurrentUICulture,
                                                       FlowDirection.LeftToRight,
                                                       new Typeface("Consolas"), 12, Brushes.Black);

                longestLine = f.Width > longestLine ? f.Width : longestLine;
            }

            doc.PageWidth = longestLine + 50;
            return(doc);
        }
Esempio n. 9
0
 private string GetLangTexContentBody(TextContentViewModel model)
 {
     return(string.Join(" ", model.Values));
 }
Esempio n. 10
0
        public static TextContentViewModel ToListDisplayView(TextContent Content, ContentType ContentType, string lang = null)
        {
            Dictionary <string, string> displayFields = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            var fields = ContentType.Properties.FindAll(o => o.IsSummaryField && !o.IsSystemField);

            if (fields == null || fields.Count() == 0)
            {
                fields = ContentType.Properties.FindAll(o => !o.IsSystemField && o.DataType == Data.Definition.DataTypes.String);
            }

            if (fields == null || fields.Count() == 0)
            {
                fields = ContentType.Properties.FindAll(o => !o.IsSystemField);
            }

            foreach (var item in fields)
            {
                if (!displayFields.ContainsKey(item.Name))
                {
                    displayFields.Add(item.Name, item.DisplayName);
                }
            }


            if (Content == null)
            {
                return(null);
            }
            TextContentViewModel model = new TextContentViewModel();

            model.Id            = Content.Id;
            model.ParentId      = Content.ParentId;
            model.FolderId      = Content.FolderId;
            model.ContentTypeId = Content.ContentTypeId;
            model.UserKey       = Content.UserKey;
            model.LastModified  = Content.LastModified;
            model.Order         = Content.Order;
            model.Online        = Content.Online;
            model.Embedded      = Content.Embedded;
            model.CreationDate  = Content.CreationDate;

            var content = Content.GetContentStore(lang);

            if (content != null)
            {
                foreach (var item in content.FieldValues)
                {
                    if (displayFields.ContainsKey(item.Key))
                    {
                        var displayname = displayFields[item.Key];

                        model.Values[displayname] = item.Value;
                    }
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(Content.UserKey))
                {
                    var userKeyField = ContentType.Properties.Find(o => o.Name == "UserKey");
                    model.Values[userKeyField.DisplayName] = Content.UserKey;
                }
            }
            return(model);
        }
Esempio n. 11
0
        internal static void CheckAndAssignDefaultValue(List <object> values, DataMethodCompiled CompiledMethod, Render.FrontContext context, Guid CurrentMethodId)
        {
            if (!values.Where(o => o == null).Any())
            {
                return;
            }

            int count   = CompiledMethod.Parameters.Count();
            var keylist = CompiledMethod.Parameters.Keys.ToList();

            bool IsContentList = CompiledMethod.DeclareType == typeof(Kooboo.Sites.DataSources.ContentList);

            bool IsContentQueried = false;

            bool IsTextContentMethod = CompiledMethod.ReturnType == typeof(TextContentViewModel) || Kooboo.Lib.Reflection.TypeHelper.GetGenericType(CompiledMethod.ReturnType) == typeof(TextContentViewModel);

            TextContentViewModel samplecontent = null;


            bool IsByCategory = IsQueryByCategory(CompiledMethod);


            for (int i = 0; i < count; i++)
            {
                if (values[i] == null)
                {
                    var paraname = keylist[i];

                    if (IsContentList)
                    {
                        //int PageSize, int PageNumber, string SortField, Boolean IsAscending
                        if (paraname == "PageSize" || paraname == "PageNumber" || paraname == "SortField" || paraname == "IsAscending")
                        {
                            var x        = keylist[i];
                            var paratype = CompiledMethod.Parameters[x];
                            values[i] = GetDefaultValueForDataType(paratype);
                        }
                    }

                    if (IsByCategory)
                    {
                        if (paraname.ToLower() == "id")
                        {
                            values[i] = default(Guid);
                            continue;
                        }
                        else if (paraname.ToLower() == "userkey")
                        {
                            values[i] = string.Empty;
                            continue;
                        }
                    }

                    if (!IsContentQueried)
                    {
                        if (IsTextContentMethod)
                        {
                            var folderid = TryGetFolderGuid(CompiledMethod.ParameterBindings);
                            samplecontent = context.SiteDb.TextContent.GetDefaultContentFromFolder(folderid, context.RenderContext.Culture);
                        }
                        IsContentQueried = true;
                    }

                    if (samplecontent != null)
                    {
                        var key   = GetBindingKey(paraname, CompiledMethod.ParameterBindings);
                        var value = Kooboo.Lib.Reflection.Dynamic.GetObjectMember(samplecontent, key);

                        if (value != null)
                        {
                            values[i] = value;
                        }
                    }

                    if (values[i] == null)
                    {
                        var x        = keylist[i];
                        var paratype = CompiledMethod.Parameters[x];
                        values[i] = GetDefaultValueForDataType(paratype);
                    }
                }
            }
        }