Exemple #1
0
    void ensureInegrity(object stateInfo)
    {
        try {
            setThreadDescription("Ensuring data uniqueness");
            SqlQuery query = new SqlQuery(WAFRuntime.Engine.Dao);
            DataAccessObject dao = WAFRuntime.Engine.Dao;

            // Node table
            setThreadDescription("Fixing Node table..."); int fixCount = 0;
            foreach (int nodeId in dao.GetDuplicateNodeRecords()) {
                if (dao.FixDuplicateNodeRecords(nodeId)) fixCount++;
            }
            //if (fixCount > 0) WFContext.Notify("Fixed " + fixCount + " duplicate records in the node table. ");

            // NodeCsd table
            setThreadDescription("Fixing Node Csd table..."); fixCount = 0;
            foreach (int[] ids in dao.GetDuplicateNodeCsdRecords()) {
                if (dao.FixDuplicateNodeCsdRecords(ids[0], ids[1])) fixCount++;
            }
            //if (fixCount > 0) WFContext.Notify("Fixed " + fixCount + " duplicate records in the nodeCsd table. ");

            // Content table
            setThreadDescription("Fixing Content table..."); fixCount = 0;
            foreach (int[] ids in dao.GetDuplicateContentBaseRecords()) {
                if (dao.FixDuplicateContentBaseRecords(ids[0], ids[1], ids[2])) fixCount++;
            }
            //if (fixCount > 0) WAFRuntime.Notify("Fixed " + fixCount + " duplicate records in the content table. ");

            // Class tables
            foreach (MemDefContentClass classDef in WAFRuntime.Engine.Definition.ContentClass.Values) {
                setThreadDescription("Fixing Class table '" + classDef.ClassName + "'..."); fixCount = 0;
                List<int> contentIds = dao.GetDuplicateContentClassRecords(classDef.Id);
                foreach (int contentId in contentIds) {
                    if (dao.FixDuplicateContentClassRecords(classDef.Id, contentId)) fixCount++;
                }
            }
            //if (fixCount > 0) WAFRuntime.Notify("Fixed " + fixCount + " duplicate records in class tables. ");

            foreach (MemDefRelation relDef in WAFRuntime.Engine.Definition.Relation.Values) {
            }

            foreach (MemDefProperty propDef in WAFRuntime.Engine.Definition.Property.Values) {
                if (propDef.BasePropertyClassId == PropertyBaseClass.InnerContents) {
                }
            }

            AqlAlias alias = new AqlAlias();
            alias.IgnoreSessionCulture = true;
            alias.IgnoreSessionRevision = true;
            alias.IncludeDeletedContents = true;
            alias.IncludeDeletedNodes = true;

            setThreadDescription("Refreshing derived flag...");
            foreach (int siteId in WAFRuntime.Engine.GetAllSiteIds()) {
                foreach (int lcid in WAFRuntime.Engine.GetSiteAllLCIDs(siteId)) {
                    UniqueList<int> cultInSite = new UniqueList<int>(WAFRuntime.Engine.GetSiteLCIDs(siteId));
                    if (!cultInSite.Contains(lcid)) {
                        // if lcid is not in site, set all contents in this lcis to derived...
                        // get all nodes in site
                        SqlAliasNode node = new SqlAliasNode();
                        SqlAliasContent content = new SqlAliasContent();
                        SqlJoinExpression joinExp = new SqlJoinExpression();
                        joinExp.Add(node.Id, content.NodeId);
                        SqlFromInnerJoin join = new SqlFromInnerJoin(node, content, joinExp);
                        SqlQuery select = new SqlQuery(WAFRuntime.Engine.Dao);
                        select.Select(content.ContentId);
                        select.From(join);
                        select.Where(node.SiteId == siteId);
                        select.Where(content.LCID == lcid);
                        select.Where(content.IsDerived == false);
                        List<int> cIds = new List<int>();
                        using (SqlDataReader dr = select.ExecuteReader()) {
                            while (dr.Read()) cIds.Add(dr.GetInt(0));
                        }
                        foreach (int contentId in cIds) {
                            SqlQuery update = new SqlQuery(WAFRuntime.Engine.Dao);
                            update.Update(Sql.Table.Content);
                            update.Set(Sql.Field.Content.IsDerived, true);
                            update.Where(Sql.Field.Content.LCID == lcid);
                            update.Where(Sql.Field.Content.ContentId == contentId);
                            update.ExecuteNonQuery();
                        }
                        if (isThreadCancelled()) return;
                    }
                }
            }

            setThreadDescription("Retrieving node ids...");
            SqlQuery sqlQuery = new SqlQuery(WAFRuntime.Engine.Dao);
            List<int> nodeIds = new List<int>();
            List<int> classIds = new List<int>();
            sqlQuery.From(Sql.Table.Node);
            sqlQuery.Distinct = true;
            sqlQuery.Select(Sql.Field.Node.Id);
            sqlQuery.Select(Sql.Field.Node.ContentClassId);
            using (SqlDataReader sqlDr = sqlQuery.ExecuteReader()) {
                while (sqlDr.Read()) {
                    nodeIds.Add(sqlDr.GetInt(0));
                    classIds.Add(sqlDr.GetInt(1));
                }
            }
            int n = 0;
            foreach (int nodeId in nodeIds) {
                WAFRuntime.Engine.Dao.RebuildDerivedContents(nodeId, classIds[n]);
                setThreadDescription("Ensuring derived content records: " + (++n) + " of " + nodeIds.Count + "...");
                if (isThreadCancelled()) return;
            }

            setThreadDescription("Retrieving content ids...");

            AqlQuery q = WAFRuntime.SystemSession.CreateQuery();
            alias.IgnoreSessionRevision = true;
            alias.IgnoreSessionCulture = true;
            q.From(alias);
            q.Select(alias.ContentId);
            q.Select(alias.ContentClassId);
            List<int> coIds = new List<int>();
            classIds = new List<int>();
            AqlResultSet rs = q.Distinct().Execute();
            while (rs.Read()) {
                coIds.Add((int)rs[0]);
                classIds.Add((int)rs[1]);
            }
            WAFRuntime.Engine.Dao.AddContentIdsInnerContent(ref coIds, ref classIds);

            n = 0;
            foreach (int contentId in coIds) {
                WAFRuntime.Engine.Dao.EnsureContentRecords(contentId, classIds[n], 0);
                setThreadDescription("Ensuring class table records: " + (++n) + " of " + coIds.Count + "...");
                if (isThreadCancelled()) return;
            }

            WAFRuntime.Engine.ClearCache();

            completeThread("DONE. Database integrity check is complete.");
        } catch (Exception error) {
            completeThread("ERROR: " + error.Message);
        }
    }
Exemple #2
0
 public override NextCall Invoke(WorkflowMethod invoker)
 {
     WAFRuntime.Engine.Dao.DeleteIndex();
     SqlQuery q = new SqlQuery(Session.Engine.Dao);
     SqlAliasNode aNode = new SqlAliasNode();
     SqlAliasContent aContent = new SqlAliasContent();
     SqlJoinExpression je = new SqlJoinExpression();
     je.Add(aNode.Id, aContent.NodeId);
     SqlFromInnerJoin join = new SqlFromInnerJoin(aNode, aContent, je);
     q.From(join);
     var rNodeId = q.Select(aContent.NodeId);
     var rLCID = q.Select(aContent.LCID);
     var rRevision = q.Select(aContent.Revision);
     var rClassId = q.Select(aNode.ContentClassId);
     q.Distinct = true;
     List<CKeyNLRC> keys = new List<CKeyNLRC>();
     using (var result = q.ExecuteReader()) {
         while (result.Read()) keys.Add(new CKeyNLRC(rNodeId, rLCID, rRevision, rClassId));
     }
     WFContext.Engine.QueIndexContents(keys);
     WFContext.Notify("Indexing is cued for " + keys.Count + " contents.");
     return null;
 }
Exemple #3
0
 void addContentIdsFromContentTable(Dictionary<int, int> classIdByContentId)
 {
     var q = new SqlQuery(Engine.Dao);
     var node = new SqlAliasNode();
     var content = new SqlAliasContent();
     var je = new SqlJoinExpression();
     je.Add(node.Id, content.NodeId);
     SqlFromLeftJoin join = new SqlFromLeftJoin(node, content, je);
     q.From(join);
     var rClassId = q.Select(node.ContentClassId);
     var rContentId = q.Select(content.ContentId);
     using (var rs = q.ExecuteReader()) {
         while (rs.Read()) {
             updateDescription("Collecting valid content ids " + classIdByContentId.Count.ToString("### ### ##0") + ".");
             if (Info.BreakExecution) return;
             if (!classIdByContentId.ContainsKey(rContentId.Value)) {
                 classIdByContentId.Add(rContentId.Value, rClassId.Value);
             }
         }
     }
 }