public ChunkStringBuilder(string value)
 {
     this.m_sbs = new List <StringBuilder>();
     if (value != null)
     {
         if (value.Length <= 20000)
         {
             this.m_sb = ChunkStringBuilder.CreateStringBuilder();
             this.m_sb.Append(value);
             this.m_sbs.Add(this.m_sb);
             return;
         }
         for (int i = 0; i < value.Length; i += 20000)
         {
             int num = 20000;
             if (i + num > value.Length)
             {
                 num = value.Length - i;
             }
             this.m_sb = ChunkStringBuilder.CreateStringBuilder();
             this.m_sb.Append(value, i, num);
             this.m_sbs.Add(this.m_sb);
         }
     }
 }
 private void ExecuteQueryToServer(ChunkStringBuilder sb)
 {
     this.m_context.FireExecutingWebRequestEvent(new WebRequestEventArgs(this.RequestExecutor));
     this.RequestExecutor.RequestContentType = "text/xml";
     if (this.m_context.AuthenticationMode == ClientAuthenticationMode.Default)
     {
         this.RequestExecutor.RequestHeaders["X-RequestForceAuthentication"] = "true";
     }
     ClientRequest.ExecuteQueryMimeInfo executeQueryMimeInfo = null;
     if (this.SerializationContext.Streams != null && this.SerializationContext.Streams.Count > 0)
     {
         executeQueryMimeInfo = new ClientRequest.ExecuteQueryMimeInfo();
         this.RequestExecutor.RequestContentType = executeQueryMimeInfo.ContentType;
     }
     Stream requestStream = this.RequestExecutor.GetRequestStream();
     if (executeQueryMimeInfo != null)
     {
         this.WriteMimeStream(executeQueryMimeInfo, sb, requestStream);
     }
     else
     {
         sb.WriteContentAsUTF8(requestStream);
     }
     requestStream.Flush();
     //Edited for .NET Core
     //requestStream.Close();
     requestStream.Dispose();
     this.RequestExecutor.Execute();
     this.ProcessResponse();
 }
 internal override void Invalidate()
 {
     this.m_parameters           = null;
     this.m_sb                   = null;
     this.m_serializationContext = null;
     base.IsValid                = false;
 }
 private void CreateNewBufferIfNecessary()
 {
     if (this.m_sb.Length >= 20000)
     {
         this.m_sb = ChunkStringBuilder.CreateStringBuilder();
         this.m_sbs.Add(this.m_sb);
     }
 }
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         this.m_chunkStringBuilder = null;
     }
     base.Dispose(disposing);
 }
 public ChunkStringReader(ChunkStringBuilder s)
 {
     if (s == null)
     {
         throw new ArgumentNullException("s");
     }
     this.m_chunkStringBuilder = s;
 }
Exemple #7
0
 public ChunkStringWriter(ChunkStringBuilder sb, IFormatProvider formatProvider) : base(formatProvider)
 {
     if (sb == null)
     {
         throw new ArgumentNullException("sb");
     }
     this.m_sb     = sb;
     this.m_isOpen = true;
 }
 internal void ExecuteQuery()
 {
     if (this.m_requestStatus != ClientRequestStatus.Active)
     {
         throw new ClientRequestException(Resources.GetString("RequestHasBeenExecuted"));
     }
     this.m_requestStatus = ClientRequestStatus.InProgress;
     ChunkStringBuilder sb = this.BuildQuery();
     this.CleanupQuery();
     this.ExecuteQueryToServer(sb);
 }
        public ObjectPathConstructor(ClientRuntimeContext context, string typeId, object[] parameters) : base(context, null, true)
        {
            ClientAction.CheckActionParametersInContext(context, parameters);
            this.m_typeId               = typeId;
            this.m_parameters           = parameters;
            this.m_serializationContext = new SerializationContext(context);
            this.m_sb = new ChunkStringBuilder();
            XmlWriter xmlWriter = this.m_sb.CreateXmlWriter();

            this.WriteToXmlPrivate(xmlWriter, this.m_serializationContext);
            xmlWriter.Dispose();// Close();
            this.m_parameters = null;
        }
        public ObjectPathMethod(ClientRuntimeContext context, ObjectPath parent, string methodName, object[] parameters) : base(context, parent, true)
        {
            ClientAction.CheckActionParametersInContext(context, parameters);
            this.m_methodName           = methodName;
            this.m_parameters           = parameters;
            this.m_serializationContext = new SerializationContext(context);
            this.m_sb = new ChunkStringBuilder();
            XmlWriter xmlWriter = this.m_sb.CreateXmlWriter();

            this.WriteToXmlPrivate(xmlWriter, this.m_serializationContext);
            xmlWriter.Dispose();// Close();
            this.m_parameters = null;
        }
Exemple #11
0
 internal ClientQueryInternal ChildItemFilterExpression(ChunkStringBuilder childItemFilterExpression)
 {
     if (!this.m_isChildItemQuery)
     {
         throw new InvalidOperationException();
     }
     if (childItemFilterExpression == null)
     {
         throw new ArgumentOutOfRangeException("childItemFilterExpression");
     }
     if (this.m_childItemFilterSb != null)
     {
         throw new InvalidQueryExpressionException();
     }
     this.m_childItemFilterSb = childItemFilterExpression;
     return(this);
 }
        public ClientActionSetStaticProperty(ClientRuntimeContext context, string typeId, string propName, object propValue) : base(context, null, propName)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            ClientAction.CheckActionParameterInContext(context, propValue);
            this.m_typeId               = typeId;
            this.m_propValue            = propValue;
            this.m_serializationContext = new SerializationContext(context);
            this.m_sb = new ChunkStringBuilder();
            XmlWriter xmlWriter = this.m_sb.CreateXmlWriter();

            this.WriteToXmlPrivate(xmlWriter, this.m_serializationContext);
            xmlWriter.Dispose();// Close();
            this.m_propValue = null;
        }
Exemple #13
0
        public ClientActionInvokeStaticMethod(ClientRuntimeContext context, string typeId, string methodName, object[] parameters) : base(context, null, methodName)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            ClientAction.CheckActionParametersInContext(context, parameters);
            this.m_typeId               = typeId;
            this.m_parameters           = parameters;
            this.m_serializationContext = new SerializationContext(context);
            this.m_sb = new ChunkStringBuilder();
            XmlWriter xmlWriter = this.m_sb.CreateXmlWriter();

            this.WriteToXmlPrivate(xmlWriter, this.m_serializationContext);
            xmlWriter.Dispose();// Close();
            this.m_parameters = null;
        }
        public ClientActionSetProperty(ClientObject obj, string propName, object propValue) : base(ClientRuntimeContext.GetContextFromClientObject(obj), (obj == null) ? null : obj.Path, propName)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            if (obj.Path == null || !obj.Path.IsValid)
            {
                throw new ClientRequestException(Resources.GetString("NoObjectPathAssociatedWithObject"));
            }
            ClientAction.CheckActionParameterInContext(obj.Context, propValue);
            this.m_propName             = propName;
            this.m_propValue            = propValue;
            this.m_serializationContext = new SerializationContext(obj.Context);
            this.m_sb = new ChunkStringBuilder();
            XmlWriter xmlWriter = this.m_sb.CreateXmlWriter();

            this.WriteToXmlPrivate(xmlWriter, this.m_serializationContext);
            xmlWriter.Dispose();//.Close();
            this.m_propValue = null;
        }
        public ClientActionInvokeMethod(ClientObject obj, string methodName, object[] parameters) : base(ClientRuntimeContext.GetContextFromClientObject(obj), (obj == null) ? null : obj.Path, methodName)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            ClientAction.CheckActionParametersInContext(obj.Context, parameters);
            this.m_parameters = parameters;
            if (obj.Path == null || !obj.Path.IsValid)
            {
                throw new ClientRequestException(Resources.GetString("NoObjectPathAssociatedWithObject"));
            }
            this.m_version = obj.ObjectData.Version;
            this.m_serializationContext = new SerializationContext(obj.Context);
            this.m_sb = new ChunkStringBuilder();
            XmlWriter xmlWriter = this.m_sb.CreateXmlWriter();

            this.WriteToXmlPrivate(xmlWriter, this.m_serializationContext);
            xmlWriter.Dispose();// Close();
            this.m_parameters = null;
        }
 private void WriteMimeStream(ClientRequest.ExecuteQueryMimeInfo mimeInfo, ChunkStringBuilder sb, Stream requestStream)
 {
     MimeWriter mimeWriter = new MimeWriter(requestStream, mimeInfo.Boundary);
     mimeWriter.StartPart();
     mimeWriter.WriteHeader(MimeGlobals.ContentIDHeader, mimeInfo.MainPartCid);
     mimeWriter.WriteHeader(MimeGlobals.ContentTransferEncodingHeader, "8bit");
     mimeWriter.WriteHeader(MimeGlobals.ContentTypeHeader, "application/xop+xml;charset=utf-8;type=\"application/xml\"");
     mimeWriter.WriteHeader(MimeGlobals.ContentLengthHeader, sb.Length.ToString(CultureInfo.InvariantCulture));
     sb.WriteContentAsUTF8(mimeWriter.GetContentStream());
     foreach (StreamInfo current in this.SerializationContext.Streams)
     {
         mimeWriter.StartPart();
         mimeWriter.WriteHeader(MimeGlobals.ContentIDHeader, "<" + current.Id + ">");
         mimeWriter.WriteHeader(MimeGlobals.ContentTransferEncodingHeader, "binary");
         mimeWriter.WriteHeader(MimeGlobals.ContentTypeHeader, "application/octet-stream");
         mimeWriter.WriteHeader(MimeGlobals.ContentLengthHeader, current.Stream.Length.ToString(CultureInfo.InvariantCulture));
         Stream contentStream = mimeWriter.GetContentStream();
         ChunkStreamBuilder.CopyStream(current.Stream, contentStream);
         //Edited for .NET Core
         current.Stream.Dispose();//.Close();
     }
     mimeWriter.Close();
 }
 public ChunkStringBuilder()
 {
     this.m_sbs = new List <StringBuilder>();
     this.m_sb  = ChunkStringBuilder.CreateStringBuilder();
     this.m_sbs.Add(this.m_sb);
 }
 private ChunkStringBuilder BuildQuery()
 {
     SerializationContext serializationContext = this.SerializationContext;
     ChunkStringBuilder chunkStringBuilder = new ChunkStringBuilder();
     XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
     xmlWriterSettings.OmitXmlDeclaration = true;
     xmlWriterSettings.NewLineHandling = NewLineHandling.Entitize;
     XmlWriter xmlWriter = XmlWriter.Create(chunkStringBuilder.CreateTextWriter(CultureInfo.InvariantCulture), xmlWriterSettings);
     xmlWriter.WriteStartElement("Request", "http://schemas.microsoft.com/sharepoint/clientquery/2009");
     xmlWriter.WriteAttributeString("AddExpandoFieldTypeSuffix", "true");
     xmlWriter.WriteAttributeString("SchemaVersion", this.Context.RequestSchemaVersion.ToString());
     xmlWriter.WriteAttributeString("LibraryVersion", "16.0.0.0");
     if (!string.IsNullOrEmpty(this.m_context.ApplicationName))
     {
         xmlWriter.WriteAttributeString("ApplicationName", this.m_context.ApplicationName);
     }
     xmlWriter.WriteStartElement("Actions");
     Stack<ExecutionScope> stack = new Stack<ExecutionScope>();
     foreach (ClientAction current in this.m_queries)
     {
         if (current is ClientActionExecutionScopeStart)
         {
             ClientActionExecutionScopeStart clientActionExecutionScopeStart = (ClientActionExecutionScopeStart)current;
             clientActionExecutionScopeStart.Scope.WriteStart(xmlWriter, serializationContext);
             stack.Push(clientActionExecutionScopeStart.Scope);
         }
         else if (current is ClientActionExecutionScopeEnd)
         {
             ClientActionExecutionScopeEnd clientActionExecutionScopeEnd = (ClientActionExecutionScopeEnd)current;
             if (stack.Count == 0 || stack.Pop() != clientActionExecutionScopeEnd.Scope)
             {
                 throw ExceptionHandlingScope.CreateInvalidUsageException();
             }
             clientActionExecutionScopeEnd.Scope.WriteEnd(xmlWriter, serializationContext);
         }
         else
         {
             current.WriteToXml(xmlWriter, serializationContext);
         }
     }
     if (stack.Count > 0)
     {
         throw ExceptionHandlingScope.CreateInvalidUsageException();
     }
     xmlWriter.WriteEndElement();
     xmlWriter.WriteStartElement("ObjectPaths");
     Dictionary<long, ObjectPath> dictionary = new Dictionary<long, ObjectPath>();
     while (true)
     {
         List<long> list = new List<long>();
         foreach (long current2 in serializationContext.Paths.Keys)
         {
             if (!dictionary.ContainsKey(current2))
             {
                 list.Add(current2);
             }
         }
         if (list.Count == 0)
         {
             break;
         }
         for (int i = 0; i < list.Count; i++)
         {
             ObjectPath objectPath = this.m_context.ObjectPaths[list[i]];
             objectPath.WriteToXml(xmlWriter, serializationContext);
             dictionary[list[i]] = objectPath;
         }
     }
     xmlWriter.WriteEndElement();
     xmlWriter.WriteEndElement();
     xmlWriter.Flush();
     return chunkStringBuilder;
 }
 public UTF8ReadonlyStream(ChunkStringBuilder sb)
 {
     this.m_chunkStringBuilder = sb;
 }
        private static ClientQueryInternal ProcessClientQueryableMethodCallQueryExpression(
            ClientQueryInternal rootQuery, ClientObject rootClientObject,
            MethodCallExpression exp, bool leaf,
            DataRetrieval.QueryProcessInfo queryInfo, DataRetrieval.QueryMethodAggregator aggregator)
        {
            //Edited for .NET Core
            string name;

            if ((name = exp.Method.Name) != null)
            {
                //Edited for .NET Core
                // This was bugged when reflecting the source, wo it needs checking
                var newDictionary = new Dictionary <string, int>(8)
                {
                    {
                        "Where",
                        0
                    },
                    {
                        "OrderBy",
                        1
                    },
                    {
                        "OrderByDescending",
                        2
                    },
                    {
                        "ThenBy",
                        3
                    },
                    {
                        "ThenByDescending",
                        4
                    },
                    {
                        "Select",
                        5
                    },
                    {
                        "Take",
                        6
                    },
                    {
                        "OfType",
                        7
                    }
                };
                int num;
                if (newDictionary.TryGetValue(name, out num))
                {
                    ClientQueryInternal result;
                    switch (num)
                    {
                    case 0:
                    case 1:
                    case 2:
                    case 3:
                    case 4:
                    {
                        ClientQueryInternal clientQueryInternal = DataRetrieval.ProcessQueryExpression(rootQuery, rootClientObject, exp.Arguments[0], leaf, queryInfo, aggregator);
                        string name2;
                        if ((name2 = exp.Method.Name) != null)
                        {
                            if (!(name2 == "Where"))
                            {
                                if (!(name2 == "OrderBy"))
                                {
                                    if (name2 == "OrderByDescending")
                                    {
                                        aggregator.OrderByDescending++;
                                    }
                                }
                                else
                                {
                                    aggregator.OrderBy++;
                                }
                            }
                            else
                            {
                                aggregator.Where++;
                            }
                        }
                        Expression       expression       = ExpressionUtility.StripQuotes(exp.Arguments[1]);
                        LambdaExpression lambdaExpression = expression as LambdaExpression;
                        if (lambdaExpression == null)
                        {
                            throw DataRetrieval.CreateInvalidQueryExpressionException(exp);
                        }
                        ChunkStringBuilder chunkStringBuilder = new ChunkStringBuilder();
                        XmlWriter          xmlWriter          = chunkStringBuilder.CreateXmlWriter();
                        string             name3;
                        if ((name3 = exp.Method.Name) != null)
                        {
                            if (!(name3 == "Where"))
                            {
                                if (!(name3 == "OrderBy"))
                                {
                                    if (!(name3 == "OrderByDescending"))
                                    {
                                        if (!(name3 == "ThenBy"))
                                        {
                                            if (!(name3 == "ThenByDescending"))
                                            {
                                                goto IL_224;
                                            }
                                            xmlWriter.WriteStartElement("ThenByDescending");
                                        }
                                        else
                                        {
                                            xmlWriter.WriteStartElement("ThenBy");
                                        }
                                    }
                                    else
                                    {
                                        xmlWriter.WriteStartElement("OrderByDescending");
                                    }
                                }
                                else
                                {
                                    xmlWriter.WriteStartElement("OrderBy");
                                }
                            }
                            else
                            {
                                xmlWriter.WriteStartElement("Where");
                            }
                            ClientQueryInternal.WriteFilterExpressionToXml(xmlWriter, clientQueryInternal.ChildItemQuery.ChildItemExpressionSerializationContext, lambdaExpression);
                            xmlWriter.WriteStartElement("Object");
                            ChunkStringBuilder chunkStringBuilder2 = null;
                            if (queryInfo.Expression.TryGetValue(clientQueryInternal.ChildItemQuery, out chunkStringBuilder2))
                            {
                                chunkStringBuilder2.WriteContentAsRawXml(xmlWriter);
                            }
                            else
                            {
                                xmlWriter.WriteStartElement("QueryableObject");
                                xmlWriter.WriteEndElement();
                            }
                            xmlWriter.WriteEndElement();
                            xmlWriter.WriteEndElement();
                            xmlWriter.Dispose();
                            queryInfo.Expression[clientQueryInternal.ChildItemQuery] = chunkStringBuilder;
                            result = clientQueryInternal;
                            break;
                        }
IL_224:
                        throw DataRetrieval.CreateInvalidQueryExpressionException(exp);
                    }

                    case 5:
                    {
                        DataRetrieval.CheckSelectExpression(exp);
                        ClientQueryInternal clientQueryInternal2 = DataRetrieval.ProcessQueryExpression(rootQuery, rootClientObject, exp.Arguments[0], leaf, queryInfo, aggregator);
                        aggregator.Select++;
                        result = clientQueryInternal2;
                        queryInfo.BySelect[clientQueryInternal2.ChildItemQuery.Id] = clientQueryInternal2.ChildItemQuery;
                        break;
                    }

                    case 6:
                    {
                        ClientQueryInternal clientQueryInternal3 = DataRetrieval.ProcessQueryExpression(rootQuery, rootClientObject, exp.Arguments[0], leaf, queryInfo, aggregator);
                        aggregator.Take++;
                        Expression expression2 = exp.Arguments[1];
                        expression2 = ExpressionEvaluator.PartialEvaluate(expression2, new Func <Expression, bool>(DataRetrieval.ExpectConstantExpression_CanExpressionBeEvaluated));
                        if (expression2.NodeType != ExpressionType.Constant || expression2.Type != typeof(int))
                        {
                            throw DataRetrieval.CreateInvalidQueryExpressionException(exp);
                        }
                        ConstantExpression constantExpression = (ConstantExpression)expression2;
                        int num2 = (int)constantExpression.Value;
                        if (num2 < 0)
                        {
                            throw DataRetrieval.CreateInvalidQueryExpressionException(exp);
                        }
                        ChunkStringBuilder chunkStringBuilder3 = new ChunkStringBuilder();
                        XmlWriter          xmlWriter2          = chunkStringBuilder3.CreateXmlWriter();
                        xmlWriter2.WriteStartElement("Take");
                        xmlWriter2.WriteAttributeString("Count", num2.ToString(CultureInfo.InvariantCulture));
                        ChunkStringBuilder chunkStringBuilder4 = null;
                        if (queryInfo.Expression.TryGetValue(clientQueryInternal3.ChildItemQuery, out chunkStringBuilder4))
                        {
                            chunkStringBuilder4.WriteContentAsRawXml(xmlWriter2);
                        }
                        else
                        {
                            xmlWriter2.WriteStartElement("QueryableObject");
                            xmlWriter2.WriteEndElement();
                        }
                        xmlWriter2.WriteEndElement();
                        xmlWriter2.Dispose();
                        queryInfo.Expression[clientQueryInternal3.ChildItemQuery] = chunkStringBuilder3;
                        result = clientQueryInternal3;
                        break;
                    }

                    case 7:
                    {
                        ClientQueryInternal clientQueryInternal4 = DataRetrieval.ProcessQueryExpression(rootQuery, rootClientObject, exp.Arguments[0], leaf, queryInfo, aggregator);
                        if (!exp.Method.IsGenericMethod || exp.Method.ContainsGenericParameters)
                        {
                            throw new InvalidQueryExpressionException(Resources.GetString("NotSupportedQueryExpressionWithExpressionValue", new object[]
                                {
                                    exp.ToString()
                                }));
                        }
                        Type[] genericArguments = exp.Method.GetGenericArguments();
                        if (genericArguments == null || genericArguments.Length != 1)
                        {
                            throw new InvalidQueryExpressionException(Resources.GetString("NotSupportedQueryExpressionWithExpressionValue", new object[]
                                {
                                    exp.ToString()
                                }));
                        }
                        string value  = null;
                        string value2 = null;
                        DataConvert.GetTypeNameOrTypeId(genericArguments[0], out value, out value2);
                        if (string.IsNullOrEmpty(value) && string.IsNullOrEmpty(value2))
                        {
                            throw new InvalidQueryExpressionException(Resources.GetString("NotSupportedQueryExpressionWithExpressionValue", new object[]
                                {
                                    exp.ToString()
                                }));
                        }
                        ChunkStringBuilder chunkStringBuilder5 = new ChunkStringBuilder();
                        XmlWriter          xmlWriter3          = chunkStringBuilder5.CreateXmlWriter();
                        xmlWriter3.WriteStartElement("OfType");
                        if (!string.IsNullOrEmpty(value))
                        {
                            xmlWriter3.WriteAttributeString("Type", value);
                        }
                        else
                        {
                            xmlWriter3.WriteAttributeString("TypeId", value2);
                        }
                        ChunkStringBuilder chunkStringBuilder6 = null;
                        if (queryInfo.Expression.TryGetValue(clientQueryInternal4.ChildItemQuery, out chunkStringBuilder6))
                        {
                            chunkStringBuilder6.WriteContentAsRawXml(xmlWriter3);
                        }
                        else
                        {
                            xmlWriter3.WriteStartElement("QueryableObject");
                            xmlWriter3.WriteEndElement();
                        }
                        xmlWriter3.WriteEndElement();
                        xmlWriter3.Dispose();
                        queryInfo.Expression[clientQueryInternal4.ChildItemQuery] = chunkStringBuilder5;
                        result = clientQueryInternal4;
                        break;
                    }

                    default:
                        goto IL_5B7;
                    }
                    return(result);
                }
            }
IL_5B7:
            throw DataRetrieval.CreateInvalidQueryExpressionException(exp);
        }