Пример #1
0
 public UsxParser(string bookId, IStylesheet stylesheet, XmlNodeList nodeList)
 {
     m_bookId     = bookId;
     m_bookNum    = BCVRef.BookToNumber(m_bookId);
     m_stylesheet = stylesheet;
     m_nodeList   = nodeList;
 }
Пример #2
0
    public XElement Serialize(IStylesheet stylesheet, bool includeProperties)
    {
        var xml = new XElement(
            "Stylesheet",
            new XElement("Name", stylesheet.Alias),
            new XElement("FileName", stylesheet.Path),
            new XElement("Content", new XCData(stylesheet.Content !)));

        if (!includeProperties)
        {
            return(xml);
        }

        var props = new XElement("Properties");

        xml.Add(props);

        if (stylesheet.Properties is not null)
        {
            foreach (IStylesheetProperty prop in stylesheet.Properties)
            {
                props.Add(new XElement(
                              "Property",
                              new XElement("Name", prop.Name),
                              new XElement("Alias", prop.Alias),
                              new XElement("Value", prop.Value)));
            }
        }

        return(xml);
    }
Пример #3
0
 /// <inheritdoc />
 public bool ValidateStylesheet(IStylesheet stylesheet)
 {
     using (var scope = ScopeProvider.CreateScope(autoComplete: true))
     {
         return(_stylesheetRepository.ValidateStylesheet(stylesheet));
     }
 }
        public void Can_Perform_Update()
        {
            // Arrange
            using (ScopeProvider.CreateScope())
            {
                IStylesheetRepository repository = CreateRepository();

                // Act
                var stylesheet = new Stylesheet("test-update.css")
                {
                    Content = "body { color:#000; } .bold {font-weight:bold;}"
                };
                repository.Save(stylesheet);

                IStylesheet stylesheetUpdate = repository.Get("test-update.css");
                stylesheetUpdate.Content = "body { color:#000; }";
                repository.Save(stylesheetUpdate);

                IStylesheet stylesheetUpdated = repository.Get("test-update.css");

                // Assert
                Assert.That(stylesheetUpdated, Is.Not.Null);
                Assert.That(stylesheetUpdated.HasIdentity, Is.True);
                Assert.That(stylesheetUpdated.Content, Is.EqualTo("body { color:#000; }"));
            }
        }
Пример #5
0
        /// <inheritdoc />
        public void DeleteStylesheet(string path, int userId = Constants.Security.SuperUserId)
        {
            using (IScope scope = ScopeProvider.CreateScope())
            {
                IStylesheet stylesheet = _stylesheetRepository.Get(path);
                if (stylesheet == null)
                {
                    scope.Complete();
                    return;
                }

                EventMessages eventMessages        = EventMessagesFactory.Get();
                var           deletingNotification = new StylesheetDeletingNotification(stylesheet, eventMessages);
                if (scope.Notifications.PublishCancelable(deletingNotification))
                {
                    scope.Complete();
                    return; // causes rollback
                }

                _stylesheetRepository.Delete(stylesheet);

                scope.Notifications.Publish(new StylesheetDeletedNotification(stylesheet, eventMessages).WithStateFrom(deletingNotification));
                Audit(AuditType.Delete, userId, -1, "Stylesheet");

                scope.Complete();
            }
        }
 // Umbraco.Code.MapAll -FileType -Notifications -Path -Snippet
 private static void Map(IStylesheet source, CodeFileDisplay target, MapperContext context)
 {
     target.Content     = source.Content;
     target.Id          = source.Id.ToString();
     target.Name        = source.Name;
     target.VirtualPath = source.VirtualPath;
 }
Пример #7
0
        public static List <BookScript> ParseBooks(IEnumerable <UsxDocument> books, IStylesheet stylesheet, Action <int> reportProgressAsPercent)
        {
            var numBlocksPerBook = new ConcurrentDictionary <string, int>();
            var blocksInBook     = new ConcurrentDictionary <string, XmlNodeList>();

            Parallel.ForEach(books, usxDoc =>
            {
                var nodeList = usxDoc.GetChaptersAndParas();
                blocksInBook.AddOrUpdate(usxDoc.BookId, nodeList, (s, list) => nodeList);
                numBlocksPerBook.AddOrUpdate(usxDoc.BookId, nodeList.Count, (s, i) => nodeList.Count);
            });
            int allBlocks = numBlocksPerBook.Values.Sum();

            int completedBlocks = 0;
            var bookScripts     = new List <BookScript>(blocksInBook.Count);

            Parallel.ForEach(blocksInBook, book =>
            {
                var bookId     = book.Key;
                var bookScript = new UsxParser(bookId, stylesheet, book.Value).CreateBookScript();
                lock (bookScripts)
                    bookScripts.Add(bookScript);
                Logger.WriteEvent("Added bookScript ({0}, {1})", bookId, bookScript.BookId);
                completedBlocks += numBlocksPerBook[bookId];
                reportProgressAsPercent?.Invoke(MathUtilities.Percent(completedBlocks, allBlocks, 99));
            });

            // This code is an attempt to figure out how we are getting null reference exceptions on the Sort call (See PG-275 & PG-287)
            // The above call to lock bookScripts probably fixes the problem!!! :-) We hope...
            foreach (var bookScript in bookScripts)
            {
                if (bookScript?.BookId == null)
                {
                    var nonNullBookScripts    = bookScripts.Where(b => b != null).Select(b => b.BookId);
                    var nonNullBookScriptsStr = Join(";", nonNullBookScripts);
                    var initialMessage        = bookScript == null ? "BookScript is null." : "BookScript has null BookId.";
                    throw new ApplicationException($"{initialMessage} Number of BookScripts: {bookScripts.Count}. " +
                                                   $"BookScripts which are NOT null: {nonNullBookScriptsStr}");
                }
            }

            try
            {
                bookScripts.Sort((a, b) => BCVRef.BookToNumber(a.BookId).CompareTo(BCVRef.BookToNumber(b.BookId)));
            }
            catch (NullReferenceException n)
            {
                // This code is an attempt to figure out how we are getting null reference exceptions on the Sort call (See PG-275 & PG-287)
                StringBuilder sb = new StringBuilder();
                foreach (var bookScript in bookScripts)
                {
                    sb.Append(Environment.NewLine).Append(bookScript.BookId).Append("(").Append(BCVRef.BookToNumber(bookScript.BookId)).Append(")");
                }
                throw new NullReferenceException("Null reference exception while sorting books." + sb, n);
            }

            reportProgressAsPercent?.Invoke(100);
            return(bookScripts);
        }
Пример #8
0
    private Color GetTextColor()
    {
        IStylesheet stylesheet = Main.StaticData.UI.Stylesheet;
        Color       result     = stylesheet.GetValue <Color>(textColorPreset);

        result.a *= alphaMultiplier;
        return(result);
    }
 // Umbraco.Code.MapAll -Trashed -Udi -Icon
 private static void Map(IStylesheet source, EntityBasic target, MapperContext context)
 {
     target.Alias    = source.Alias;
     target.Id       = source.Id;
     target.Key      = source.Key;
     target.Name     = source.Name;
     target.ParentId = -1;
     target.Path     = source.Path;
 }
        public void Can_Perform_Get()
        {
            // Arrange
            using (ScopeProvider.CreateScope())
            {
                IStylesheetRepository repository = CreateRepository();

                // Act
                IStylesheet stylesheet = repository.Get("styles.css");

                // Assert
                Assert.That(stylesheet, Is.Not.Null);
                Assert.That(stylesheet.HasIdentity, Is.True);
                Assert.That(stylesheet.Content, Is.EqualTo("body {background:#EE7600; color:#FFF;}"));
                //// Assert.That(repository.ValidateStylesheet(stylesheet), Is.True); //TODO this can't be activated before we handle file systems correct
            }
        }
Пример #11
0
        public static void ApplyStyles <TView>(this TView view, string styleName) where TView : IStyleable
        {
            if (String.IsNullOrWhiteSpace(styleName))
            {
                return;
            }

            UIView parent = view.Superview;

            while (parent != null && !(parent is IRootView))
            {
                parent = parent.Superview;
            }

            IStylesheet stylesheet = null;

            if (parent is IRootView root)
            {
                stylesheet = root.Stylesheet;
            }

            if (stylesheet == null)
            {
                return;
            }

            //todo: refactor
            //todo: performance?

            IStyle <IStyleable> style;

            stylesheet.Styles.TryGetValue(styleName, out style);

            var uiStyle = style as Style <TView>;

            if (uiStyle == null)
            {
                return;
            }

            foreach (var styling in uiStyle.Stylings)
            {
                styling(view);
            }
        }
Пример #12
0
    protected override void LoadDataInternal()
    {
        stylesheet = Main.StaticData.UI.Stylesheet;
        lockSpritePreset.String = "Lock";
        slot = GetSlot();

        if (slot.IsLocked)
        {
            OnLocked();
        }
        else if (slot.IsEmpty)
        {
            OnEmpty();
        }
        else
        {
            OnFull();
        }
    }
Пример #13
0
        /// <inheritdoc />
        public void SaveStylesheet(IStylesheet stylesheet, int userId = Constants.Security.SuperUserId)
        {
            using (IScope scope = ScopeProvider.CreateScope())
            {
                EventMessages eventMessages      = EventMessagesFactory.Get();
                var           savingNotification = new StylesheetSavingNotification(stylesheet, eventMessages);
                if (scope.Notifications.PublishCancelable(savingNotification))
                {
                    scope.Complete();
                    return;
                }


                _stylesheetRepository.Save(stylesheet);
                scope.Notifications.Publish(new StylesheetSavedNotification(stylesheet, eventMessages).WithStateFrom(savingNotification));
                Audit(AuditType.Save, userId, -1, "Stylesheet");

                scope.Complete();
            }
        }
Пример #14
0
        /// <inheritdoc />
        public void SaveStylesheet(IStylesheet stylesheet, int userId = Constants.Security.SuperUserId)
        {
            using (var scope = ScopeProvider.CreateScope())
            {
                var saveEventArgs = new SaveEventArgs <IStylesheet>(stylesheet);
                if (scope.Events.DispatchCancelable(SavingStylesheet, this, saveEventArgs))
                {
                    scope.Complete();
                    return;
                }


                _stylesheetRepository.Save(stylesheet);
                saveEventArgs.CanCancel = false;
                scope.Events.Dispatch(SavedStylesheet, this, saveEventArgs);

                Audit(AuditType.Save, userId, -1, UmbracoObjectTypes.Stylesheet.GetName());
                scope.Complete();
            }
        }
Пример #15
0
    protected override void LoadDataInternal()
    {
        IStylesheet stylesheet = Main.StaticData.UI.Stylesheet;
        int         i          = 0;

        Text text = gameObject.GetComponent <Text>();

        if (text != null)
        {
            text.fontSize = (int)stylesheet.GetValue <float>(fontSizePreset);
            text.color    = GetTextColor();
        }

        TMPro.TextMeshProUGUI tmpText = gameObject.GetComponent <TMPro.TextMeshProUGUI>();
        if (tmpText != null)
        {
            tmpText.fontSize = stylesheet.GetValue <float>(fontSizePreset);
            tmpText.color    = GetTextColor();
        }
    }
Пример #16
0
 public virtual void AddStyle(IStyle style, IStylesheet stylesheet)
 {
 }
Пример #17
0
        public bool InsertRTF(InsertionPoint insertionPoint, string rtfToInsert, out Action makeSelection)
        {
            makeSelection = () => DoNothing();
            int styleIndex;
            int index = rtfToInsert.IndexOf("{\\colortbl") + 10;
            Dictionary <int, Color> colorTable = GetColorTable(rtfToInsert.Substring(index));

            index = rtfToInsert.IndexOf("{\\stylesheet{") + 13;
            var textToInsert = new List <ITsString>();
            // The actual text (with formatting information stripped out) that we will insert into our view
            IStylesheet stylesheet = insertionPoint.RootBox.Style.Stylesheet;
            IStyle      nextStyle;
            var         tempStylesheet = new Dictionary <string, IStyle>();
            // Indicates the paragraph style that should be applied to each paragraph of the inserted text.
            var        paraStylePlacements = new List <IStyle>();
            ITsStrBldr bldr = TsStrFactoryClass.Create().MakeString("", 1).GetBldr();

            while (true)
            {
                nextStyle = FindNextRtfStyle(rtfToInsert.Substring(index), colorTable, true, out styleIndex);
                if (nextStyle == null)
                {
                    break;
                }
                if (stylesheet.Style(nextStyle.Name) == null)
                {
                    AddStyle(nextStyle, stylesheet);
                }
                int styleIndexStart;
                FindNextStyleStart(rtfToInsert.Substring(index), true, out styleIndexStart);
                if (!tempStylesheet.ContainsKey(rtfToInsert.Substring(index + styleIndexStart, 6)))
                {
                    tempStylesheet.Add(rtfToInsert.Substring(index + styleIndexStart, 6), nextStyle);
                }
                index += styleIndex;
            }
            index++;
            while (true)
            {
                string nextStyleName = FindNextStyleStart(rtfToInsert.Substring(index), false, out styleIndex);
                if (nextStyleName == null)
                {
                    break;
                }
                nextStyle = tempStylesheet.FirstOrDefault(style => style.Key.StartsWith(nextStyleName)).Value;
                if (nextStyle == null)
                {
                    index    += styleIndex - 6;
                    nextStyle = FindNextRtfStyle(rtfToInsert.Substring(index), colorTable, false, out styleIndex);
                }
                if (stylesheet.Style(nextStyle.Name) == null)
                {
                    AddStyle(nextStyle, stylesheet);
                }
                if (nextStyle.IsParagraphStyle)
                {
                    if (rtfToInsert.IndexOf("}}", index) < styleIndex)
                    {
                        break;
                    }
                    index += styleIndex;
                    int substringIndex = rtfToInsert.IndexOf(" {", index);
                    if (substringIndex != -1 && (rtfToInsert.Substring(substringIndex).StartsWith(" {\\*\\cs") || rtfToInsert.Substring(substringIndex).StartsWith(" {\\rtlch")))
                    {
                        nextStyleName = FindNextStyleStart(rtfToInsert.Substring(index) + nextStyle.Name.Length, false, out styleIndex);
                        paraStylePlacements.Add(nextStyle);
                        if (nextStyleName == null)
                        {
                            break;
                        }
                        nextStyle = tempStylesheet.FirstOrDefault(style => style.Key.StartsWith(nextStyleName)).Value;
                        if (nextStyle == null)
                        {
                            index    += styleIndex - 6;
                            nextStyle = FindNextRtfStyle(rtfToInsert.Substring(index), colorTable, false, out styleIndex);
                        }
                        if (stylesheet.Style(nextStyle.Name) == null)
                        {
                            AddStyle(nextStyle, stylesheet);
                        }
                    }
                    else
                    {
                        bldr.ReplaceTsString((bldr.Text ?? string.Empty).Length, (bldr.Text ?? string.Empty).Length,
                                             TsStrFactoryClass.Create().MakeString(
                                                 rtfToInsert.Substring(rtfToInsert.IndexOf(" ", index) + 1,
                                                                       rtfToInsert.IndexOf("}", index) - rtfToInsert.IndexOf(" ", index) - 1)
                                                 .Replace(@"\par", ""), 1));
                        paraStylePlacements.Add(nextStyle);
                        if (rtfToInsert.Substring(rtfToInsert.IndexOf("}", index) - 4, 4) == @"\par")
                        {
                            textToInsert.Add(bldr.GetString());
                            bldr = TsStrFactoryClass.Create().MakeString("", 1).GetBldr();
                        }
                        continue;
                    }
                }
                else if (((textToInsert.Count == 0 && bldr.Text == null) || rtfToInsert.Substring(index - 15, 4) == @"\par"))
                {
                    paraStylePlacements.Add(null);
                }
                if (rtfToInsert.IndexOf("}}", index) < styleIndex)
                {
                    break;
                }
                index += styleIndex;
                int oldLength = (bldr.Text ?? string.Empty).Length;

                bldr.ReplaceTsString(oldLength, oldLength,
                                     TsStrFactoryClass.Create().MakeString(
                                         rtfToInsert.Substring(rtfToInsert.IndexOf(" ", index) + 1,
                                                               rtfToInsert.IndexOf("}", index) - rtfToInsert.IndexOf(" ", index) - 1)
                                         .Replace(@"\par", ""), 1));
                bldr.SetStrPropValue(oldLength, (bldr.Text ?? string.Empty).Length, (int)FwTextPropType.ktptNamedStyle, nextStyle.Name);

                if (rtfToInsert.Substring(rtfToInsert.IndexOf("}", index) - 4, 4) == @"\par")
                {
                    textToInsert.Add(bldr.GetString());
                    bldr = TsStrFactoryClass.Create().MakeString("", 1).GetBldr();
                }
            }
            int ipPosition = insertionPoint.StringPosition;

            if (textToInsert.Count == 1)
            {
                insertionPoint.Hookup.InsertText(insertionPoint, textToInsert[0]);
                insertionPoint.ApplyStyle(paraStylePlacements.FirstOrDefault().Name);
            }
            else if (textToInsert.Count > 1)
            {
                if (!InsertLines(new MultiLineInsertData(insertionPoint, textToInsert, paraStylePlacements), out makeSelection))
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
            return(true);
        }
Пример #18
0
 public UsxParser(string bookId, IStylesheet stylesheet, XmlNodeList nodeList)
 {
     m_bookId     = bookId;
     m_stylesheet = stylesheet;
     m_nodeList   = nodeList;
 }
Пример #19
0
        public static List <BookScript> ParseProject(IEnumerable <UsxDocument> books, IStylesheet stylesheet, BackgroundWorker projectWorker)
        {
            var numBlocksPerBook = new ConcurrentDictionary <string, int>();
            var blocksInBook     = new ConcurrentDictionary <string, XmlNodeList>();

            Parallel.ForEach(books, bookScript =>
            {
                var nodeList = bookScript.GetChaptersAndParas();
                blocksInBook.AddOrUpdate(bookScript.BookId, nodeList, (s, list) => nodeList);
                numBlocksPerBook.AddOrUpdate(bookScript.BookId, nodeList.Count, (s, i) => nodeList.Count);
            });
            int allProjectBlocks = numBlocksPerBook.Values.Sum();

            int completedProjectBlocks = 0;
            var bookScripts            = new List <BookScript>(blocksInBook.Count);

            Parallel.ForEach(blocksInBook, book =>
            {
                var bookId = book.Key;
                Logger.WriteEvent("Creating bookScript ({0})", bookId);
                var parser     = new UsxParser(bookId, stylesheet, book.Value);
                var bookScript = new BookScript(bookId, parser.Parse());
                SingleVoiceReason singleVoiceReason;
                bookScript.SingleVoice = BookMetadata.DefaultToSingleVoice(bookId, out singleVoiceReason);
                bookScript.PageHeader  = parser.PageHeader;
                bookScript.MainTitle   = parser.MainTitle;
                Logger.WriteEvent("Created bookScript ({0}, {1})", bookId, bookScript.BookId);
                lock (bookScripts)
                    bookScripts.Add(bookScript);
                Logger.WriteEvent("Added bookScript ({0}, {1})", bookId, bookScript.BookId);
                completedProjectBlocks += numBlocksPerBook[bookId];
                projectWorker.ReportProgress(MathUtilities.Percent(completedProjectBlocks, allProjectBlocks, 99));
            });

            // This code is an attempt to figure out how we are getting null reference exceptions on the Sort call (See PG-275 & PG-287)
            // The above call to lock bookScripts probably fixes the problem!!! :-) We hope...
            foreach (var bookScript in bookScripts)
            {
                if (bookScript == null || bookScript.BookId == null)
                {
                    var nonNullBookScripts    = bookScripts.Where(b => b != null).Select(b => b.BookId);
                    var nonNullBookScriptsStr = string.Join(";", nonNullBookScripts);
                    var initialMessage        = bookScript == null ? "BookScript is null." : "BookScript has null BookId.";
                    throw new ApplicationException(string.Format("{0} Number of BookScripts: {1}. BookScripts which are NOT null: {2}", initialMessage, bookScripts.Count, nonNullBookScriptsStr));
                }
            }

            try
            {
                bookScripts.Sort((a, b) => BCVRef.BookToNumber(a.BookId).CompareTo(BCVRef.BookToNumber(b.BookId)));
            }
            catch (NullReferenceException n)
            {
                // This code is an attempt to figure out how we are getting null reference exceptions on the Sort call (See PG-275 & PG-287)
                StringBuilder sb = new StringBuilder();
                foreach (var bookScript in bookScripts)
                {
                    sb.Append(Environment.NewLine).Append(bookScript.BookId).Append("(").Append(BCVRef.BookToNumber(bookScript.BookId)).Append(")");
                }
                throw new NullReferenceException("Null reference exception while sorting books." + sb, n);
            }

            projectWorker.ReportProgress(100);
            return(bookScripts);
        }
Пример #20
0
		public AssembledStylesCache(IStylesheet stylesheet)
		{
			Stylesheet = stylesheet;
		}
Пример #21
0
		/// <summary>
		/// Default constructor sets initial state
		/// </summary>
		public AssembledStyles(IStylesheet stylesheet)
		{
			m_styleCache = new AssembledStylesCache(stylesheet);
			FontWeight = (int)VwFontWeight.kvfwNormal;
			m_chrp.dympHeight = 10000; // default 10 pt
			SetFaceName(DefaultFontName);
			m_chrp.clrFore = ColorUtil.ConvertColorToBGR(Color.Black);
			m_chrp.clrUnder = m_chrp.clrFore;
			m_borderColor = Color.Black;
			m_chrp.clrBack = ColorUtil.ConvertColorToBGR(Color.Transparent);
			SetNonInheritedDefaults();
			m_styleCache.m_canonicalStyles[this] = this; // AFTER setting all props!!
		}
Пример #22
0
 public override void AddStyle(IStyle style, IStylesheet stylesheet)
 {
     ((DemoStyleSheet)stylesheet).SetStyle(style.Name, style);
 }