示例#1
0
        public void ImportTableStyles(int publishmentSystemId)
        {
            if (!DirectoryUtils.IsDirectoryExists(_directoryPath))
            {
                return;
            }

            var publishmentSystemInfo = PublishmentSystemManager.GetPublishmentSystemInfo(publishmentSystemId);

            var importObject        = new ImportObject(publishmentSystemId);
            var tableNameCollection = importObject.GetTableNameCache();

            var styleDirectoryPaths = DirectoryUtils.GetDirectoryPaths(_directoryPath);

            foreach (var styleDirectoryPath in styleDirectoryPaths)
            {
                var tableName = PathUtils.GetDirectoryName(styleDirectoryPath);
                if (!string.IsNullOrEmpty(tableNameCollection?[tableName]))
                {
                    tableName = tableNameCollection[tableName];
                }

                ETableStyle tableStyle;

                if (BaiRongDataProvider.TableCollectionDao.IsTableExists(tableName))
                {
                    var tableType = BaiRongDataProvider.TableCollectionDao.GetTableType(tableName);
                    tableStyle = EAuxiliaryTableTypeUtils.GetTableStyle(tableType);
                }
                else
                {
                    tableStyle = PublishmentSystemManager.GetTableStyle(publishmentSystemInfo, tableName);
                }

                var attributeNamePaths = DirectoryUtils.GetDirectoryPaths(styleDirectoryPath);
                foreach (var attributeNamePath in attributeNamePaths)
                {
                    var attributeName = PathUtils.GetDirectoryName(attributeNamePath);
                    var filePaths     = DirectoryUtils.GetFilePaths(attributeNamePath);
                    foreach (var filePath in filePaths)
                    {
                        var feed = AtomFeed.Load(FileUtils.GetFileStreamReadOnly(filePath));

                        var taxis           = TranslateUtils.ToInt(AtomUtility.GetDcElementContent(feed.AdditionalElements, "Taxis"), 0);
                        var displayName     = AtomUtility.GetDcElementContent(feed.AdditionalElements, "DisplayName");
                        var helpText        = AtomUtility.GetDcElementContent(feed.AdditionalElements, "HelpText");
                        var isVisible       = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(feed.AdditionalElements, "IsVisible"));
                        var isVisibleInList = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(feed.AdditionalElements, "IsVisibleInList"));
                        var isSingleLine    = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(feed.AdditionalElements, "IsSingleLine"));
                        var inputType       = EInputTypeUtils.GetEnumType(AtomUtility.GetDcElementContent(feed.AdditionalElements, "InputType"));
                        var defaultValue    = AtomUtility.GetDcElementContent(feed.AdditionalElements, "DefaultValue");
                        var isHorizontal    = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(feed.AdditionalElements, "IsHorizontal"));
                        var extendValues    = AtomUtility.GetDcElementContent(feed.AdditionalElements, "ExtendValues");

                        int relatedIdentity;
                        if (tableStyle == ETableStyle.Site)
                        {
                            relatedIdentity = publishmentSystemId;
                        }
                        else
                        {
                            var orderString = AtomUtility.GetDcElementContent(feed.AdditionalElements, "OrderString");

                            if (!string.IsNullOrEmpty(orderString))
                            {
                                relatedIdentity = DataProvider.NodeDao.GetNodeId(publishmentSystemId, orderString);
                            }
                            else
                            {
                                relatedIdentity = publishmentSystemId;
                            }
                        }

                        if (relatedIdentity <= 0 ||
                            TableStyleManager.IsExists(relatedIdentity, tableName, attributeName))
                        {
                            continue;
                        }

                        var styleInfo = new TableStyleInfo(0, relatedIdentity, tableName, attributeName, taxis, displayName, helpText, isVisible, isVisibleInList, isSingleLine, EInputTypeUtils.GetValue(inputType), defaultValue, isHorizontal, extendValues);

                        var styleItems = new List <TableStyleItemInfo>();
                        foreach (AtomEntry entry in feed.Entries)
                        {
                            var itemTitle  = AtomUtility.GetDcElementContent(entry.AdditionalElements, "ItemTitle");
                            var itemValue  = AtomUtility.GetDcElementContent(entry.AdditionalElements, "ItemValue");
                            var isSelected = TranslateUtils.ToBool(AtomUtility.GetDcElementContent(entry.AdditionalElements, "IsSelected"));

                            styleItems.Add(new TableStyleItemInfo(0, 0, itemTitle, itemValue, isSelected));
                        }

                        if (styleItems.Count > 0)
                        {
                            styleInfo.StyleItems = styleItems;
                        }

                        TableStyleManager.InsertWithTaxis(styleInfo, tableStyle);
                    }
                }
            }
        }