Пример #1
0
 public void UpdateFrom(StylesTreeItem treeItem)
 {
     _styleRebuildedString = treeItem._styleRebuildedString;
     if (string.IsNullOrEmpty(_styleOriginalString) || _styleOriginalString.Length < treeItem._styleOriginalString.Length)
     {
         _styleOriginalString = treeItem._styleOriginalString;
     }
 }
Пример #2
0
        protected StylesTreeItem ComputeParents(StylesTreeItem newStyle)
        {
            var computedParents = newStyle.ExtractParentStyles();
            computedParents = computedParents.OrderBy(x => x.Complexity).ToList();
            var integratedParents = computedParents.Select(GetOrCreateParent).ToList();

            newStyle.SetParents(integratedParents);
            return newStyle;
        }
Пример #3
0
        public bool ContentEqualsTo(StylesTreeItem item)
        {
            #region test lists count

            if (item._musicGenresIdxs.Count != _musicGenresIdxs.Count)
            {
                return(false);
            }
            if (item._subStylesIdxs.Count != _subStylesIdxs.Count)
            {
                return(false);
            }
            if (item._styleAlterationsIdxs.Count != _styleAlterationsIdxs.Count)
            {
                return(false);
            }

            #endregion

            #region test musicGenres

            foreach (var musicGenresIdx in item._musicGenresIdxs)
            {
                if (!_musicGenresIdxs.Contains(musicGenresIdx))
                {
                    return(false);
                }
            }

            #endregion

            #region test subStyles

            foreach (var subStylesIdx in item._subStylesIdxs)
            {
                if (!_subStylesIdxs.Contains(subStylesIdx))
                {
                    return(false);
                }
            }

            #endregion

            #region test styleAlterations

            foreach (var styleAlterationsIdx in item._styleAlterationsIdxs)
            {
                if (!_styleAlterationsIdxs.Contains(styleAlterationsIdx))
                {
                    return(false);
                }
            }

            #endregion

            return(true);
        }
Пример #4
0
        protected StylesTreeItem ComputeParents(StylesTreeItem newStyle)
        {
            var computedParents = newStyle.ExtractParentStyles();

            computedParents = computedParents.OrderBy(x => x.Complexity).ToList();
            var integratedParents = computedParents.Select(GetOrCreateParent).ToList();

            newStyle.SetParents(integratedParents);
            return(newStyle);
        }
Пример #5
0
        private void CreateStylesTreeItem(StylesTreeItem stylesTreeItem)
        {
            stylesTreeItem.ID = _idGenerator.NewID();

            Debug.Assert(!(_stylesTreeItems.Select(x => x.ID).Contains(stylesTreeItem.ID)));
            Debug.Assert(GetStylesTreeItem(stylesTreeItem) == null);

            _stylesTreeItems.Add(stylesTreeItem);

            return;
        }
Пример #6
0
        private void CreateStylesTreeItem(StylesTreeItem stylesTreeItem)
        {
            stylesTreeItem.ID = _idGenerator.NewID();

            Debug.Assert(!(_stylesTreeItems.Select(x => x.ID).Contains(stylesTreeItem.ID)));
            Debug.Assert(GetStylesTreeItem(stylesTreeItem) == null);

            _stylesTreeItems.Add(stylesTreeItem);

            return;
        }
Пример #7
0
        private StylesTreeItem CreateOrUpdateStylesTreeItem(StylesTreeItem stylesTreeItem)
        {
            StylesTreeItem result = stylesTreeItem;
            if (TryGetStylesTreeItem(ref result))
            {
                result.UpdateFrom(stylesTreeItem);
                return result;
            }

            CreateStylesTreeItem(stylesTreeItem);
            return stylesTreeItem;
        }
Пример #8
0
        private StylesTreeItem GetOrCreateParent(StylesTreeItem stylesTreeItem)
        {
            StylesTreeItem result = stylesTreeItem;

            if (!TryGetStylesTreeItem(ref result))
            {
                ComputeParents(stylesTreeItem);
                return(CreateOrUpdateStylesTreeItem(stylesTreeItem));
            }

            return(result);
        }
Пример #9
0
        private bool TryGetStylesTreeItem(ref StylesTreeItem stylesTreeItem)
        {
            var result = GetStylesTreeItem(stylesTreeItem);

            if (result == null)
            {
                return(false);
            }

            stylesTreeItem = result;
            return(true);
        }
Пример #10
0
        private StylesTreeItem CreateOrUpdateStylesTreeItem(StylesTreeItem stylesTreeItem)
        {
            StylesTreeItem result = stylesTreeItem;

            if (TryGetStylesTreeItem(ref result))
            {
                result.UpdateFrom(stylesTreeItem);
                return(result);
            }

            CreateStylesTreeItem(stylesTreeItem);
            return(stylesTreeItem);
        }
Пример #11
0
        public bool ContentEqualsTo(StylesTreeItem item)
        {
            #region test lists count

            if(item._musicGenresIdxs.Count != _musicGenresIdxs.Count)
                return false;
            if(item._subStylesIdxs.Count != _subStylesIdxs.Count)
                return false;
            if (item._styleAlterationsIdxs.Count != _styleAlterationsIdxs.Count)
                return false;

            #endregion

            #region test musicGenres

            foreach (var musicGenresIdx in item._musicGenresIdxs)
            {
                if(!_musicGenresIdxs.Contains(musicGenresIdx))
                    return false;
            }

            #endregion

            #region test subStyles

            foreach (var subStylesIdx in item._subStylesIdxs)
            {
                if (!_subStylesIdxs.Contains(subStylesIdx))
                    return false;
            }

            #endregion

            #region test styleAlterations

            foreach (var styleAlterationsIdx in item._styleAlterationsIdxs)
            {
                if (!_styleAlterationsIdxs.Contains(styleAlterationsIdx))
                    return false;
            }

            #endregion

            return true;
        }
Пример #12
0
        private StylesTreeItem GetOrCreateParent(StylesTreeItem stylesTreeItem)
        {
            StylesTreeItem result = stylesTreeItem;
            if (!TryGetStylesTreeItem(ref result))
            {
                ComputeParents(stylesTreeItem);
                return CreateOrUpdateStylesTreeItem(stylesTreeItem);
            }

            return result;
        }
Пример #13
0
        private bool TryGetStylesTreeItem(ref StylesTreeItem stylesTreeItem)
        {
            var result = GetStylesTreeItem(stylesTreeItem);
            if (result == null)
            {
                return false;
            }

            stylesTreeItem = result;
            return true;
        }
Пример #14
0
 private StylesTreeItem GetStylesTreeItem(StylesTreeItem treeItem)
 {
     return _stylesTreeItems.Where(x => x.ContentEqualsTo(treeItem)).SingleOrDefault();
 }
Пример #15
0
 private StylesTreeItem GetStylesTreeItem(StylesTreeItem treeItem)
 {
     return(_stylesTreeItems.Where(x => x.ContentEqualsTo(treeItem)).SingleOrDefault());
 }
Пример #16
0
 public void UpdateFrom(StylesTreeItem treeItem)
 {
     _styleRebuildedString = treeItem._styleRebuildedString;
     if (string.IsNullOrEmpty(_styleOriginalString) || _styleOriginalString.Length < treeItem._styleOriginalString.Length)
     {
         _styleOriginalString = treeItem._styleOriginalString;
     }
 }