Exemplo n.º 1
0
 protected void ConnectorPropertyGetHandlers(ConnectorPart part, Func <SocketsPart> knownLeft = null, Func <SocketsPart> knownRight = null, Func <ConnectorPart> knownInverse = null)
 {
     // Add handlers that will load content for id's just-in-time (although sometimes we'll have special rules e.g. drafts)
     part.LeftContentField.Loader(knownLeft ?? (() => LoadSocketContent(part, part.Record.LeftContentItem_id, part.Record.LeftContentVersionId)));
     part.RightContentField.Loader(knownRight ?? (() => LoadSocketContent(part, part.Record.RightContentItem_id, part.Record.RightContentVersionId)));
     part.InverseConnectorField.Loader(knownInverse ?? (() => LoadConnectorContent(part, part.Record.InverseConnector_id, part.Record.InverseConnectorVersionId)));
 }
Exemplo n.º 2
0
 private ConnectorPart LoadConnectorContent(ConnectorPart part, int?leftId, int?leftVersionId)
 {
     if (leftId.HasValue)
     {
         if (part.ContentItem.VersionRecord != null && part.ContentItem.VersionRecord.Latest && !part.ContentItem.VersionRecord.Published)
         {
             return(Services.ContentManager.Get <ConnectorPart>(leftId.Value, VersionOptions.Latest));
         }
         return(Services.ContentManager.Get <ConnectorPart>(leftId.Value, VersionOptions.Published));
     }
     return(null);
 }
Exemplo n.º 3
0
 private SocketsPart LoadSocketContent(ConnectorPart part, int leftId, int?leftVersionId)
 {
     if (leftId != 0)
     {
         if (part.ContentItem.VersionRecord != null && part.ContentItem.VersionRecord.Latest && !part.ContentItem.VersionRecord.Published)
         {
             return(Services.ContentManager.Get <SocketsPart>(leftId, VersionOptions.Latest));
         }
         return(Services.ContentManager.Get <SocketsPart>(leftId, VersionOptions.Published));
     }
     return(null);
 }
Exemplo n.º 4
0
 protected static void ConnectorPropertySetHandlers(ActivatedContentContext context, ConnectorPart part)
 {
     // add handlers that will update records when part properties are set
     part.LeftContentField.Setter(sock => {
         part.Record.LeftContentItem_id = sock == null
                                          // TODO: Throw exception for null socket?
             ? 0
             : sock.ContentItem.Id;
         part.Record.LeftContentVersionId = sock == null
             ? 0
             : (sock.ContentItem.VersionRecord == null ? (int?)null : sock.ContentItem.VersionRecord.Id);
         return(sock);
     });
     part.RightContentField.Setter(sock => {
         part.Record.RightContentItem_id = sock == null
                                           // TODO: Throw exception for null socket?
             ? 0
             : sock.ContentItem.Id;
         part.Record.RightContentVersionId = sock == null
             ? 0
             : (sock.ContentItem.VersionRecord == null ? (int?)null : sock.ContentItem.VersionRecord.Id);
         return(sock);
     });
     part.InverseConnectorField.Setter(conn => {
         part.Record.InverseConnector_id = conn == null
                                           // TODO: Throw exception for null socket?
             ? 0
             : conn.ContentItem.Id;
         part.Record.InverseConnectorVersionId = conn == null
             ? 0
             : (conn.ContentItem.VersionRecord == null ? (int?)null : conn.ContentItem.VersionRecord.Id);
         return(conn);
     });
 }
Exemplo n.º 5
0
 protected static void ConnectorPropertySetHandlers(ActivatedContentContext context, ConnectorPart part) {
     // add handlers that will update records when part properties are set
     part.LeftContentField.Setter(sock => {
         part.Record.LeftContentItem_id = sock == null
             // TODO: Throw exception for null socket?
             ? 0
             : sock.ContentItem.Id;
         part.Record.LeftContentVersionId = sock == null
             ? 0
             : (sock.ContentItem.VersionRecord == null ? (int?)null : sock.ContentItem.VersionRecord.Id);
         return sock;
     });
     part.RightContentField.Setter(sock => {
         part.Record.RightContentItem_id = sock == null
             // TODO: Throw exception for null socket?
             ? 0
             : sock.ContentItem.Id;
         part.Record.RightContentVersionId = sock == null
             ? 0
             : (sock.ContentItem.VersionRecord == null ? (int?)null : sock.ContentItem.VersionRecord.Id);
         return sock;
     });
     part.InverseConnectorField.Setter(conn => {
         part.Record.InverseConnector_id = conn == null
             // TODO: Throw exception for null socket?
             ? 0
             : conn.ContentItem.Id;
         part.Record.InverseConnectorVersionId = conn == null
             ? 0
             : (conn.ContentItem.VersionRecord == null ? (int?)null : conn.ContentItem.VersionRecord.Id);
         return conn;
     });
 }
Exemplo n.º 6
0
 private ConnectorPart LoadConnectorContent(ConnectorPart part, int? leftId, int? leftVersionId) {
     if (leftId.HasValue) {
         if (part.ContentItem.VersionRecord != null && part.ContentItem.VersionRecord.Latest && !part.ContentItem.VersionRecord.Published) {
             return Services.ContentManager.Get<ConnectorPart>(leftId.Value, VersionOptions.Latest);
         }
         return Services.ContentManager.Get<ConnectorPart>(leftId.Value, VersionOptions.Published);
     }
     return null;
 }
Exemplo n.º 7
0
 private SocketsPart LoadSocketContent(ConnectorPart part, int leftId, int? leftVersionId) {
     if (leftId != 0) {
         if (part.ContentItem.VersionRecord != null && part.ContentItem.VersionRecord.Latest && !part.ContentItem.VersionRecord.Published) {
             return Services.ContentManager.Get<SocketsPart>(leftId, VersionOptions.Latest);
         }
         return Services.ContentManager.Get<SocketsPart>(leftId, VersionOptions.Published);
     }
     return null;
 }
Exemplo n.º 8
0
 protected void ConnectorPropertyGetHandlers(ConnectorPart part, Func<SocketsPart> knownLeft = null, Func<SocketsPart> knownRight = null, Func<ConnectorPart> knownInverse = null) {
     // Add handlers that will load content for id's just-in-time (although sometimes we'll have special rules e.g. drafts)
     part.LeftContentField.Loader(knownLeft ?? (() => LoadSocketContent(part,part.Record.LeftContentItem_id, part.Record.LeftContentVersionId)));
     part.RightContentField.Loader(knownRight ?? (() => LoadSocketContent(part, part.Record.RightContentItem_id, part.Record.RightContentVersionId)));
     part.InverseConnectorField.Loader(knownInverse ?? (() => LoadConnectorContent(part, part.Record.InverseConnector_id, part.Record.InverseConnectorVersionId)));
 }
        public PreparedQueryPlan PrepareQuery(HarmonyQueryCompilationContext compilationContext)
        {
            var rootExpr               = RootExpressions[_valueBufferParameter];
            var processedOns           = new List <object>();
            var flatList               = new List <Tuple <HarmonyTableExpression, QueryBuffer.TypeBuffer> >();
            var typeBuffers            = new QueryBuffer.TypeBuffer[] { GetTypeBuffer(rootExpr, flatList) };
            var expressionTableMapping = flatList.ToDictionary(kvp => kvp.Item1.RootExpression.ConvertedParameter as Expression, kvp => kvp.Item1 as IHarmonyQueryTable, new ExpressionValueComparer());
            var tableList              = flatList.Select(tpl => tpl.Item1 as IHarmonyQueryTable).ToList();

            //extract all of expressions that might represent a given table and add them to the mapping dictionary
            foreach (var table in tableList)
            {
                foreach (var alias in ((HarmonyTableExpression)table).Aliases)
                {
                    if (!expressionTableMapping.ContainsKey(alias))
                    {
                        expressionTableMapping.Add(alias, table);
                    }
                }
            }

            var whereBuilder = new WhereExpressionBuilder(rootExpr.IsCaseSensitive, tableList, expressionTableMapping);

            var processedWheres = new List <Object>();
            var orderBys        = new List <Tuple <FileIO.Queryable.FieldReference, bool> >();

            foreach (var expr in rootExpr.WhereExpressions)
            {
                whereBuilder.VisitForWhere(expr, processedWheres, processedOns);
            }

            foreach (var tpl in flatList)
            {
                foreach (var expr in tpl.Item1.OnExpressions)
                {
                    var madeOn = whereBuilder.VisitForOn(expr);
                    if (madeOn != null)
                    {
                        processedOns.Add(madeOn);
                        if (tpl.Item2.JoinOn == null)
                        {
                            tpl.Item2.JoinOn = madeOn;
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }
                }

                if (tpl.Item1 != rootExpr)
                {
                    foreach (var expr in tpl.Item1.WhereExpressions)
                    {
                        var madeOn = whereBuilder.VisitForOn(expr);
                        if (madeOn != null)
                        {
                            processedOns.Add(madeOn);
                            if (tpl.Item2.JoinOn != null)
                            {
                                madeOn = new ConnectorPart()
                                {
                                    Op = WhereClauseConnector.AndOperator, Left = tpl.Item2.JoinOn, Right = madeOn
                                }
                            }
                            ;

                            tpl.Item2.JoinOn = madeOn;
                        }
                    }
                }

                foreach (var expr in tpl.Item1.OrderByExpressions)
                {
                    var fieldRef = whereBuilder.VisitForOrderBy(expr.Item1);
                    if (fieldRef != null)
                    {
                        orderBys.Add(Tuple.Create(fieldRef, expr.Item2));
                    }
                }
            }

            var queryBuffer = new QueryBuffer(flatList.Select(tpl => tpl.Item2).ToList());

            var fieldReferences = new Dictionary <int, List <FieldDataDefinition> >();

            foreach (var queryExpr in flatList)
            {
                if (queryExpr.Item1.ReferencedFields.Count > 0)
                {
                    var bufferIndex = queryBuffer.TypeBuffers.IndexOf(queryExpr.Item2);
                    fieldReferences.Add(bufferIndex, queryExpr.Item1.ReferencedFields);
                }
            }

            var queryPlan = new PreparedQueryPlan(true, processedWheres, fieldReferences, processedOns,
                                                  orderBys, queryBuffer, "");

            return(queryPlan);
        }