Ejemplo n.º 1
0
        /*--------------------------------------------------------------------------------------------*/
        public static TBack Back <T, TBack>(this T pElem, IWeaverStepAs <TBack> pAlias)
            where T : IWeaverElement where TBack : IWeaverElement
        {
            var f = new WeaverStepBack <TBack>(pAlias);

            pElem.Path.AddItem(f);
            return(pAlias.Item);
        }
Ejemplo n.º 2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public WeaverStepBack(IWeaverStepAs <T> pBackToItem)
        {
            int i = pBackToItem.PathIndex;

            if (i < 0)
            {
                throw new WeaverStepException(this,
                                              "The specified return item is not present in the current path.");
            }

            BackToItem = pBackToItem;
            vLabel     = pBackToItem.Label;
        }
Ejemplo n.º 3
0
 ////////////////////////////////////////////////////////////////////////////////////////////////
 /*--------------------------------------------------------------------------------------------*/
 public static T As <T>(this T pElem, out IWeaverStepAs <T> pAlias) where T : IWeaverElement
 {
     pAlias = new WeaverStepAs <T>(pElem);
     pElem.Path.AddItem(pAlias);
     return(pElem);
 }
Ejemplo n.º 4
0
        /*--------------------------------------------------------------------------------------------*/
        public override string BuildParameterizedString()
        {
            int thisI     = Path.IndexOfItem(this);
            var sb        = new StringBuilder("table(" + Alias.Name + "=new Table())");
            var asSteps   = new List <IWeaverStepAs>();
            int prevI     = -1;
            int prevLevel = -1;

            // Collect all the "as" aliases. Reverse the order of any contiguous aliases. This matches
            // the odd Gremlin functionality (possibly a bug). This results in (pseudocode):
            // g.v(1).as('id').as('name').table(t){it.name}{it.id}; //note the id/name order swap

            for (int i = 0; i < thisI; ++i)
            {
                IWeaverPathItem item = Path.ItemAtIndex(i);
                IWeaverStepAs   a    = (item as IWeaverStepAs);

                if (a == null)
                {
                    continue;
                }

                if (i - 1 == prevI)
                {
                    asSteps.Insert(prevLevel, a);
                }
                else
                {
                    asSteps.Add(a);
                    prevLevel = asSteps.Count - 1;
                }

                prevI = i;
            }

            // Append column closures for each "as" alias. Non-column aliases are given the empty "{}"
            // closure. The column can be property or object based, and the closure script can
            // (optionally) can be appended or replaced.

            foreach (IWeaverStepAs a in asSteps)
            {
                IWeaverStepAsColumn col = (a as IWeaverStepAsColumn);
                if (col == null)
                {
                    sb.Append("{}");
                    continue;
                }

                if (col.ReplaceScript != null)
                {
                    sb.Append("{" + col.ReplaceScript + "}");
                    continue;
                }

                if (col.PropName != null)
                {
                    string p = Path.Query.AddStringParam(col.PropName);
                    sb.Append("{it.getProperty(" + p + ")" + col.AppendScript + "}");
                    continue;
                }

                sb.Append("{it" + col.AppendScript + "}");
            }

            return(sb.ToString());
        }