Ejemplo n.º 1
0
        public SingleQuery Parse(JObject edm)
        {
            var root = edm.Properties().First();

            RootVisitor(root);

            singleQuery.AddMethod(QueryMethodType.Get);

            return(this.singleQuery);
        }
Ejemplo n.º 2
0
        /// <summary> Generates queries for modification info </summary>
        /// <param name="singleQuery"></param>
        /// <param name="modificationInfo"></param>
        /// <param name="isTransactionCreation"></param>
        /// <returns></returns>
        public static List <SingleQuery> GetModificationInfoQueries(this SingleQuery singleQuery, JToken modificationInfo, bool isTransactionCreation)
        {
            var result = new List <SingleQuery>();

            var addMethodNodes = singleQuery.NodesList.Where(x => x.MethodType == QueryMethodType.Add).ToList();
            var setMethodNodes = singleQuery.NodesList.Where(x => x.MethodType == QueryMethodType.Set).ToList();

            foreach (var methodNode in setMethodNodes)
            {
                for (var queryNodeItem = singleQuery.NodesList.First; queryNodeItem.Value != methodNode; queryNodeItem = queryNodeItem.Next)
                {
                    var queryNode      = queryNodeItem.Value;
                    var newSingleQuery = singleQuery.MakeCopyUntil(queryNode);
                    newSingleQuery.AddMethod(QueryMethodType.Set)
                    .AddArgument(x => x.ArgumentSubjectQuery  = SingleQuery.CreateQuery.AddProperty(ObjectHelper.UpdatedInfoPropName),
                                 x => x.ArgumentValueConstant = modificationInfo.ToString());

                    if (isTransactionCreation)
                    {
                        newSingleQuery
                        .AddArgument(x => x.ArgumentSubjectQuery  = SingleQuery.CreateQuery.AddProperty(ObjectHelper.CreatedInfoPropName),
                                     x => x.ArgumentValueConstant = modificationInfo.ToString());
                    }

                    result.Add(newSingleQuery);
                }
            }

            foreach (var methodNode in addMethodNodes)
            {
                foreach (var queryNode in singleQuery.NodesList)
                {
                    SingleQuery newSingleQuery = null;
                    if (queryNode == methodNode)
                    {
                        var id =
                            methodNode.Arguments.Where(
                                x => x.ArgumentSubjectQuery.NodesList.Last.Value.Name == ObjectHelper.IdPropName)
                            .Select(x => x.ArgumentValueConstant)
                            .SingleOrDefault();

                        // Somehow Id is empty or absent...
                        if (id == null)
                        {
                            continue;
                        }

                        newSingleQuery = singleQuery.MakeCopyUntil(queryNode, false);

                        var pivotData = methodNode.PivotData;
                        newSingleQuery.AddCollection(pivotData.PivotDefinition.Type.ToString())
                        .SetPivot(pivotData.PivotDefinition.Type, pivotData.MainValue, pivotData.SecondaryValues.ToArray());

                        newSingleQuery.AddCriteriaGroup(CriteriaAppendType.And)
                        .AddCriteria(SingleQuery.CreateQuery.AddProperty(ObjectHelper.IdPropName), CriteriaComparator.Eq, id);

                        newSingleQuery.AddMethod(QueryMethodType.Set)
                        .AddArgument(x => x.ArgumentSubjectQuery  = SingleQuery.CreateQuery.AddProperty(ObjectHelper.CreatedInfoPropName),
                                     x => x.ArgumentValueConstant = modificationInfo.ToString());

                        result.Add(newSingleQuery);
                        break;
                    }

                    newSingleQuery = singleQuery.MakeCopyUntil(queryNode);
                    newSingleQuery.AddMethod(QueryMethodType.Set)
                    .AddArgument(x => x.ArgumentSubjectQuery  = SingleQuery.CreateQuery.AddProperty(ObjectHelper.UpdatedInfoPropName),
                                 x => x.ArgumentValueConstant = modificationInfo.ToString());

                    if (isTransactionCreation)
                    {
                        newSingleQuery
                        .AddArgument(x => x.ArgumentSubjectQuery  = SingleQuery.CreateQuery.AddProperty(ObjectHelper.CreatedInfoPropName),
                                     x => x.ArgumentValueConstant = modificationInfo.ToString());
                    }

                    result.Add(newSingleQuery);
                }
            }

            return(result);
        }