Exemplo n.º 1
0
        private void _processCoreConfig(BridgeCoreConfig coreConfig, Stream stream)
        {
            string       serializationFolder = BridgeConfiguration.GetConfig().SerializationFolder;
            var          deserializer        = new DeserializerBuilder().Build();
            TreeProvider tree  = new TreeProvider(MembershipContext.AuthenticatedUser);
            var          watch = new Stopwatch();

            //have this driven by config
            var serializationPath    = $"{serializationFolder}/core/{coreConfig.Name}";
            var classTypes           = coreConfig.GetClassTypes();
            var ignoreFields         = coreConfig.GetIgnoreFields();
            var allAllowedChildInfos = new List <AllowedChildClassInfo>();


            int retryCount = 3;

            _processClasses(retryCount, allAllowedChildInfos, coreConfig.Name, stream, deserializer, watch, serializationPath, classTypes, ignoreFields);
            //at this point we should have all children, lets post process these
            foreach (var allowedChildClass in allAllowedChildInfos)
            {
                AllowedChildClassInfoProvider.SetAllowedChildClassInfo(allowedChildClass);
            }
        }
Exemplo n.º 2
0
        private void _processCoreConfig(BridgeCoreConfig coreConfig, Stream stream)
        {
            var    serializer          = new SerializerBuilder().ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitNull).Build();
            string serializationFolder = BridgeConfiguration.GetConfig().SerializationFolder;
            var    watch = new Stopwatch();

            _clearTempFolder();
            watch.Start();
            //have this driven by config
            var serializationPath     = $"{serializationFolder}/core/{coreConfig.Name}";
            var tempGUID              = DateTime.Now.Ticks.ToString();
            var tempSerializationPath = $"{serializationFolder}/temp/{tempGUID}/{coreConfig.Name}";
            var classTypes            = coreConfig.GetClassTypes();
            var fieldsToIgnore        = coreConfig.GetIgnoreFields();

            ProviderHelper.ClearHashtables("cms.class", false);
            foreach (var classType in classTypes)
            {
                var dci = DataClassInfoProvider.GetDataClassInfo(classType);
                if (dci != null)
                {
                    var mappedItem = dci.Adapt <BridgeClassInfo>();
                    mappedItem.FieldValues = new Dictionary <string, object>();

                    foreach (string columnName in dci.ColumnNames)
                    {
                        if (!fieldsToIgnore.Contains(columnName))
                        {
                            var columnValue = dci.GetValue(columnName);
                            mappedItem.FieldValues.Add(columnName, columnValue);
                        }
                    }

                    var assignedSites = new List <Guid>();
                    foreach (SiteInfo assignedSite in dci.AssignedSites)
                    {
                        assignedSites.Add(assignedSite.SiteGUID);
                    }
                    mappedItem.AssignedSites = assignedSites;

                    var allowedChildClasses = AllowedChildClassInfoProvider.GetAllowedChildClasses().Where("ParentClassID", QueryOperator.Equals, dci["ClassID"].ToString()).Column("ChildClassID").ToList();

                    var allowedChildrenTypes = new List <string>();
                    foreach (AllowedChildClassInfo allowedChildClass in allowedChildClasses)
                    {
                        var className = new ObjectQuery("cms.class").Where("ClassID", QueryOperator.Equals, allowedChildClass.ChildClassID).Column("ClassName").FirstOrDefault()["ClassName"].ToString();
                        allowedChildrenTypes.Add(className);
                    }
                    mappedItem.AllowedChildTypes = allowedChildrenTypes;

                    var classQueries = QueryInfoProvider.GetQueries().Where("ClassID", QueryOperator.Equals, dci.ClassID).ToList();
                    var queries      = new Dictionary <string, BridgeClassQuery>();
                    foreach (var classQuery in classQueries)
                    {
                        var bcq = classQuery.Adapt <BridgeClassQuery>();
                        queries.Add(classQuery.QueryName, bcq);
                    }
                    mappedItem.Queries = queries;

                    var stringBuilder = new StringBuilder();
                    var res           = serializer.Serialize(mappedItem);
                    stringBuilder.AppendLine(res);

                    var      pathToMatching = $"{tempSerializationPath}/{mappedItem.ClassName.ToLower()}.yaml";
                    var      tempPath       = this.GetRootPath(pathToMatching);
                    FileInfo file           = new FileInfo(tempPath);
                    file.Directory.Create(); // If the directory already exists, this method does nothing.
                    File.WriteAllText(tempPath, res);
                }
            }
            watch.Stop();
            _outputToStream(stream, $"Generating temp {coreConfig.Name} - {watch.ElapsedMilliseconds}ms");
            _processDifferences(stream, watch, serializationPath, tempSerializationPath);
        }