Пример #1
0
        private void _processClasses(int retryCount, List <AllowedChildClassInfo> allAllowedChildInfos, string coreConfigName, Stream stream, IDeserializer deserializer, Stopwatch watch, string serializationPath, IEnumerable <string> classTypes, IEnumerable <string> ignoreFields)
        {
            var retryClasses = new List <string>();
            var concretePath = this.GetRootPath(serializationPath);
            var yamlFiles    = Directory.EnumerateFiles(concretePath, "*.yaml", SearchOption.AllDirectories);

            foreach (string yamlFile in yamlFiles)
            {
                watch.Reset();
                watch.Start();
                var yamlFileContent = File.ReadAllText(yamlFile);
                var bridgeClassInfo = deserializer.Deserialize <BridgeClassInfo>(yamlFileContent);
                if (classTypes.Any(x => x.ToLower() == bridgeClassInfo.ClassName.ToLower()))
                {
                    var newDCI = DataClassInfoProvider.GetDataClassInfo(bridgeClassInfo.ClassName);
                    if (newDCI == null)
                    {
                        newDCI = new DataClassInfo();
                    }
                    foreach (var field in bridgeClassInfo.FieldValues)
                    {
                        if (!ignoreFields.Contains(field.Key))
                        {
                            newDCI[field.Key] = field.Value;
                        }
                    }
                    DataClassInfoProvider.SetDataClassInfo(newDCI);
                    foreach (var allowedType in bridgeClassInfo.AllowedChildTypes)
                    {
                        var matchingClass = new ObjectQuery("cms.class", false).Where("ClassName", QueryOperator.Equals, allowedType)?.Column("ClassID")?.FirstOrDefault();
                        if (matchingClass != null)
                        {
                            matchingClass["ClassID"]?.ToString();

                            var acci = new AllowedChildClassInfo()
                            {
                                ChildClassID = int.Parse(matchingClass["ClassID"]?.ToString()), ParentClassID = newDCI.ClassID
                            };
                            allAllowedChildInfos.Add(acci);
                        }
                        else
                        {
                            retryClasses.Add(allowedType);
                        }
                    }

                    foreach (var siteGUID in bridgeClassInfo.AssignedSites)
                    {
                        var site = SiteInfoProvider.GetSiteInfoByGUID(siteGUID);
                        ClassSiteInfoProvider.AddClassToSite(newDCI.ClassID, site.SiteID);
                    }

                    foreach (var bcq in bridgeClassInfo.Queries)
                    {
                        var qi = QueryInfoProvider.GetQueries().Where("QueryGUID", QueryOperator.Equals, bcq.Value.QueryGUID).FirstOrDefault();
                        if (qi == null)
                        {
                            qi = new QueryInfo();
                        }
                        qi.ClassID                  = newDCI.ClassID;
                        qi.QueryName                = bcq.Key;
                        qi.QueryTypeID              = bcq.Value.QueryTypeID;
                        qi.QueryText                = bcq.Value.QueryText;
                        qi.QueryIsLocked            = bcq.Value.QueryIsLocked;
                        qi.QueryIsCustom            = bcq.Value.QueryIsCustom;
                        qi.QueryRequiresTransaction = bcq.Value.QueryRequiresTransaction;
                        qi.QueryConnectionString    = bcq.Value.QueryConnectionString;
                        qi.QueryGUID                = bcq.Value.QueryGUID;
                        QueryInfoProvider.SetQueryInfo(qi);
                    }
                    byte[] bytes = Encoding.UTF8.GetBytes($"Synced {coreConfigName}: {yamlFile.Replace(concretePath, "")} - {watch.ElapsedMilliseconds}ms");
                    stream.Write(bytes, 0, bytes.Length);
                    stream.WriteByte(10);
                    stream.Flush();
                }
                watch.Stop();
            }
            retryCount--;
            if (retryCount > 0 && retryClasses.Count > 0)
            {
                _processClasses(retryCount, allAllowedChildInfos, coreConfigName, stream, deserializer, watch, serializationPath, retryClasses, ignoreFields);
            }
        }