コード例 #1
0
        public JField ConvertField(XField field, ParentObjectInfo parentInfo)
        {
            if (field.ID == null)
            {
                throw new Exception("Объект field не может быть преобразован в JField");
            }

            if (string.IsNullOrEmpty(parentInfo.CardVersion))
            {
                throw new Exception("У поля " + field.Alias + " отсутствует версия (карточки)");
            }

            if (parentInfo.CardLibID == null || parentInfo.CardLibID == Guid.Empty)
            {
                throw new Exception("У поля " + field.Alias + " отсутствует идентификатор библиотеки карточек");
            }

            if (parentInfo.CardID == null || parentInfo.CardID == Guid.Empty)
            {
                throw new Exception("У поля " + field.Alias + " отсутствует идентификатор карточки");
            }

            if (parentInfo.SectionID == null || parentInfo.SectionID == Guid.Empty)
            {
                throw new Exception("У поля " + field.Alias + " отсутствует идентификатор секции");
            }

            var version = new JFieldVersion
            {
                SystemVersion = parentInfo.SystemVersion,
                Version       = parentInfo.CardVersion,
                FieldType     = field.Type,
                RefType       = field.RefType,
                RefSection    = field.RefSection,
                DefaultValue  = field.DefaultValue,
                EnumValues    = field.Enum != null?field.Enum.Select(t => $"{t.Alias}[{t.Value}]").ToArray() : new string[0],
            };

            var jField = new JField
            {
                ID              = field.ID,
                Alias           = field.Alias,
                Name            = GetRuName(field.Names),
                CardLibID       = parentInfo.CardLibID,
                CardID          = parentInfo.CardID,
                ParentSectionID = parentInfo.SectionID,
                Versions        = new List <JFieldVersion> {
                    version
                }
            };

            return(jField);
        }
コード例 #2
0
        public JSection ConvertSection(XSection section, ParentObjectInfo parentInfo)
        {
            if (section.ID == null)
            {
                throw new Exception("Объект section не может быть преобразован в JSection");
            }

            if (string.IsNullOrEmpty(parentInfo.CardVersion))
            {
                throw new Exception("У секции " + section.Alias + " отсутствует версия (карточки)");
            }

            if (parentInfo.CardLibID == null || parentInfo.CardLibID == Guid.Empty)
            {
                throw new Exception("У секции " + section.Alias + " отсутствует идентификатор библиотеки карточек");
            }

            if (parentInfo.CardID == null || parentInfo.CardID == Guid.Empty)
            {
                throw new Exception("У секции " + section.Alias + " отсутствует идентификатор карточки");
            }

            var version = new JSectionVersion
            {
                SystemVersion                      = parentInfo.SystemVersion,
                Version                            = parentInfo.CardVersion,
                Sections                           = section.Sections != null?section.Sections.Select(t => t.ID).ToArray() : new Guid[0],
                                            Fields = section.Fields != null?section.Fields.Select(t => t.ID).ToArray() : new Guid[0],
            };

            if (section.Sections != null)
            {
                version.Sections = section.Sections.Select(t => t.ID).ToArray();
            }

            var jSection = new JSection
            {
                ID              = section.ID,
                Alias           = section.Alias,
                CardLibID       = parentInfo.CardLibID,
                CardID          = parentInfo.CardID,
                Name            = GetRuName(section.Names),
                ParentSectionID = parentInfo.SectionID,
                Versions        = new List <JSectionVersion> {
                    version
                }
            };

            return(jSection);
        }
コード例 #3
0
        public JCard ConvertCard(XCard card, ParentObjectInfo parentInfo)
        {
            if (card.ID == null)
            {
                throw new Exception("Объект card не может быть преобразован в JCard");
            }

            if (string.IsNullOrEmpty(card.Version))
            {
                throw new Exception("У карточки " + card.Alias + " отсутствует версия");
            }

            if (card.Sections == null || card.Sections.Length == 0)
            {
                throw new Exception("У карточки " + card.Alias + " отсутствуют секции");
            }

            if (parentInfo.CardLibID == null || parentInfo.CardLibID == Guid.Empty)
            {
                throw new Exception("У карточки " + card.Alias + " отсутствует идентификатор библиотеки карточек");
            }

            var version = new JCardVersion
            {
                SystemVersion = parentInfo.SystemVersion,
                Version       = card.Version,
                Sections      = card.Sections.Select(t => t.ID).ToArray()
            };

            var jCard = new JCard
            {
                ID        = card.ID,
                Alias     = card.Alias,
                Name      = GetRuName(card.Names),
                CardLibID = parentInfo.CardLibID,
                Versions  = new List <JCardVersion>()
                {
                    version
                }
            };

            return(jCard);
        }
コード例 #4
0
        public JCardLib ConvertCardLib(XCardLibrary cardLib, ParentObjectInfo parentInfo)
        {
            if (cardLib.ID == null)
            {
                throw new Exception("Объект cardLib не может быть преобразован в JCardLib");
            }

            if (string.IsNullOrEmpty(cardLib.Version))
            {
                throw new Exception("В библиотеке карточек " + cardLib.Alias + " отсутствует версия");
            }

            if (cardLib.CardsID == null || cardLib.CardsID.Any() == false)
            {
                throw new Exception("В библиотеке карточек " + cardLib.Alias + " отсутствуют карточки");
            }

            var version = new JCardLibVersion
            {
                SystemVersion = parentInfo.SystemVersion,
                Version       = cardLib.Version,
                Cards         = cardLib.CardsID
            };

            var jCardLib = new JCardLib
            {
                ID       = cardLib.ID,
                Alias    = cardLib.Alias,
                Name     = GetRuName(cardLib.Names),
                Versions = new List <JCardLibVersion> {
                    version
                }
            };

            return(jCardLib);
        }