public void Load <T>(T clientObject, params Expression <Func <T, object> >[] retrievals) where T : ClientObject { if (clientObject == null) { throw new ArgumentNullException("clientObject"); } ClientAction.CheckActionParameterInContext(this, clientObject); DataRetrieval.Load <T>(clientObject, retrievals); }
internal void AddQuery(ClientAction query) { if (this.m_requestStatus != ClientRequestStatus.Active) { throw new InvalidOperationException(Resources.GetString("RequestHasBeenExecuted")); } this.m_queries.Add(query); this.m_lastAction = query; }
internal static void CheckActionParametersInContext(ClientRuntimeContext context, object[] values) { if (context != null && values != null && values.Length > 0) { for (int i = 0; i < values.Length; i++) { ClientAction.CheckActionParameterInContext(context, values[i]); } } }
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; }
public IEnumerable <T> LoadQuery <T>(ClientObjectCollection <T> clientObjects) where T : ClientObject { if (clientObjects == null) { throw new ArgumentNullException("clientObjects"); } ClientAction.CheckActionParameterInContext(this, clientObjects); ClientQueryableResult <T> clientQueryableResult = new ClientQueryableResult <T>(); ClientQueryInternal clientQueryInternal = new ClientQueryInternal(clientObjects, null, false, null); clientQueryInternal.ChildItemQuery.SelectAllProperties(); clientObjects.Context.AddQueryIdAndResultObject(clientQueryInternal.Id, clientQueryableResult); clientObjects.Context.AddQuery(clientQueryInternal); return(clientQueryableResult); }
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; }
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 IDisposable StartFinally() { if (this.m_executionScope == null || this.m_executionScope.Disposed || this.m_tryScope == null || !this.m_tryScope.Disposed || (this.m_catchScope != null && !this.m_catchScope.Disposed) || this.m_finallyScope != null) { throw ExceptionHandlingScope.CreateInvalidUsageException(); } ClientAction lastAction = this.m_context.PendingRequest.LastAction; if (lastAction == null || !(lastAction is ClientActionExecutionScopeEnd)) { throw ExceptionHandlingScope.CreateInvalidUsageException(); } if (((ClientActionExecutionScopeEnd)lastAction).Scope.Name != "TryScope" && ((ClientActionExecutionScopeEnd)lastAction).Scope.Name != "CatchScope") { throw ExceptionHandlingScope.CreateInvalidUsageException(); } this.m_finallyScope = new ExecutionScope(this.m_context, "FinallyScope", null); return(this.m_finallyScope); }
private void ExceptionHandlingScopeDisposingCallback() { if (this.m_tryScope != null) { if (this.m_catchScope == null && this.m_finallyScope == null) { throw ExceptionHandlingScope.CreateInvalidUsageException(); } ClientAction lastAction = this.m_context.PendingRequest.LastAction; if (lastAction == null || !(lastAction is ClientActionExecutionScopeEnd)) { throw ExceptionHandlingScope.CreateInvalidUsageException(); } ClientActionExecutionScopeEnd clientActionExecutionScopeEnd = (ClientActionExecutionScopeEnd)lastAction; if (clientActionExecutionScopeEnd.Scope.Name != "CatchScope" && clientActionExecutionScopeEnd.Scope.Name != "FinallyScope") { throw ExceptionHandlingScope.CreateInvalidUsageException(); } } }
public IEnumerable <T> LoadQuery <T>(IQueryable <T> clientObjects) where T : ClientObject { if (clientObjects == null) { throw new ArgumentNullException("clientObjects"); } ClientAction.CheckActionParameterInContext(this, clientObjects); ClientObjectCollection <T> clientObjectCollection = clientObjects as ClientObjectCollection <T>; if (clientObjectCollection != null) { return(this.LoadQuery <T>(clientObjectCollection)); } ClientQueryable <T> clientQueryable = clientObjects as ClientQueryable <T>; if (clientQueryable != null) { return(DataRetrieval.Retrieve <T>(clientQueryable)); } throw new NotSupportedException(); }
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; }
public static void WriteValueToXmlElement(XmlWriter writer, object objValue, SerializationContext serializationContext) { if (writer == null) { throw new ArgumentNullException("writer"); } if (serializationContext == null) { throw new ArgumentNullException("serializationContext"); } if (objValue == null) { writer.WriteAttributeString("Type", "Null"); return; } if (!(objValue is ClientObject)) { if (objValue is ClientValueObject) { ClientValueObject clientValueObject = (ClientValueObject)objValue; writer.WriteAttributeString("TypeId", clientValueObject.TypeId); if (!clientValueObject.CustomWriteToXml(writer, serializationContext)) { clientValueObject.WriteToXml(writer, serializationContext); return; } } else { if (objValue is Stream) { Stream stream = (Stream)objValue; writer.WriteAttributeString("Type", "Binary"); writer.WriteStartElement(MtomGlobals.XopIncludeLocalName); string text = "http://sharepoint.microsoft.com/" + serializationContext.Context.NextSequenceId.ToString(CultureInfo.InvariantCulture); serializationContext.AddStream(new StreamInfo(text, stream)); writer.WriteAttributeString(MtomGlobals.XopIncludeHrefLocalName, "cid:" + text); writer.WriteEndElement(); return; } DataConvert.WriteValueHandler writeValueHandler = null; if (DataConvert.s_writeValueHandlers.TryGetValue(objValue.GetType(), out writeValueHandler)) { writer.WriteAttributeString("Type", DataConvert.s_writeValueTypeNames[objValue.GetType()]); writeValueHandler(writer, objValue); return; } if (objValue.GetType().IsArray) { writer.WriteAttributeString("Type", "Array"); //Edited for .NET Core //using (IEnumerator enumerator = ((Array)objValue).GetEnumerator()) IEnumerator enumerator = ((Array)objValue).GetEnumerator(); { while (enumerator.MoveNext()) { object current = enumerator.Current; writer.WriteStartElement("Object"); DataConvert.WriteValueToXmlElement(writer, current, serializationContext); writer.WriteEndElement(); } return; } } if (objValue is IDictionary) { writer.WriteAttributeString("Type", "Dictionary"); IDictionary dictionary = objValue as IDictionary; IDictionaryEnumerator enumerator2 = dictionary.GetEnumerator(); while (enumerator2.MoveNext()) { object value = enumerator2.Value; if (DataConvert.CouldSerializeDictionaryEntry(value) && enumerator2.Key is string) { writer.WriteStartElement("Property"); writer.WriteAttributeString("Name", (string)enumerator2.Key); DataConvert.WriteValueToXmlElement(writer, enumerator2.Value, serializationContext); writer.WriteEndElement(); } } return; } //Edited for .NET Core //if (typeof(IEnumerable).IsAssignableFrom(objValue.GetType()) && ExpressionUtility.GetElementType(objValue.GetType()) != null) if (typeof(IEnumerable).GetTypeInfo().IsAssignableFrom(objValue.GetType()) && ExpressionUtility.GetElementType(objValue.GetType()) != null) { writer.WriteAttributeString("Type", "Array"); //Edited for .NET Core //using (IEnumerator enumerator3 = ((IEnumerable)objValue).GetEnumerator()) IEnumerator enumerator3 = ((IEnumerable)objValue).GetEnumerator(); { while (enumerator3.MoveNext()) { object current2 = enumerator3.Current; writer.WriteStartElement("Object"); DataConvert.WriteValueToXmlElement(writer, current2, serializationContext); writer.WriteEndElement(); } return; } } Type type = objValue.GetType(); //Edited for .NET Core //if (type.IsEnum) if (type.GetTypeInfo().IsEnum) { writer.WriteAttributeString("Type", "Enum"); DataConvert.s_writeValueEnum(writer, objValue); return; } writer.WriteAttributeString("Type", "Unspecified"); writer.WriteString(objValue.ToString()); } return; } ClientObject clientObject = (ClientObject)objValue; if (clientObject.Path == null) { throw new ClientRequestException(Resources.GetString("NoObjectPathAssociatedWithObject")); } ClientAction.CheckActionParameterInContext(serializationContext.Context, clientObject); writer.WriteAttributeString("ObjectPathId", clientObject.Path.Id.ToString(CultureInfo.InvariantCulture)); serializationContext.AddClientObject(clientObject); }
public T CastTo <T>(ClientObject obj) where T : ClientObject { if (obj == null) { throw new ArgumentNullException("obj"); } ClientAction.CheckActionParameterInContext(this, obj); Type typeFromHandle = typeof(T); //Edited for .NET Core //if (!typeof(ClientObject).IsAssignableFrom(typeFromHandle)) if (!typeof(ClientObject).GetTypeInfo().IsAssignableFrom(typeFromHandle)) { throw new ArgumentException(); } if (obj.Context != this) { throw new InvalidOperationException(); } T t; //Edited for .NET Core //if (typeFromHandle.IsAssignableFrom(obj.GetType())) if (typeFromHandle.GetTypeInfo().IsAssignableFrom(obj.GetType())) { t = (T)((object)Activator.CreateInstance(typeFromHandle, new object[] { this, obj.Path })); t.SetObjectDataFrom(obj); return(t); } //Edited for .NET Core //if (obj.ObjectData.AssociatedObject != null && typeFromHandle.IsAssignableFrom(obj.ObjectData.AssociatedObject.GetType())) if (obj.ObjectData.AssociatedObject != null && typeFromHandle.GetTypeInfo().IsAssignableFrom(obj.ObjectData.AssociatedObject.GetType())) { t = (T)((object)Activator.CreateInstance(typeFromHandle, new object[] { this, obj.Path })); t.SetObjectDataFrom(obj); return(t); } //Edited for .NET Core //if (!obj.GetType().IsAssignableFrom(typeFromHandle)) if (!obj.GetType().GetTypeInfo().IsAssignableFrom(typeFromHandle)) { throw ClientUtility.CreateArgumentException("type"); } //Edited for .NET Core //if (obj.ObjectData.AssociatedObject != null && !obj.ObjectData.AssociatedObject.GetType().IsAssignableFrom(typeFromHandle)) if (obj.ObjectData.AssociatedObject != null && !obj.ObjectData.AssociatedObject.GetType().GetTypeInfo().IsAssignableFrom(typeFromHandle)) { throw ClientUtility.CreateArgumentException("type"); } t = (T)((object)Activator.CreateInstance(typeFromHandle, new object[] { this, obj.Path })); t.SetObjectDataFrom(obj); object obj2; if (obj.ObjectData.AssociatedObject == null) { obj2 = obj; } else { obj2 = obj.ObjectData.AssociatedObject; } if (obj2 != null) { List <string> list = new List <string>(); Dictionary <string, object> queryIdToObjectMap = this.PendingRequest.QueryIdToObjectMap; foreach (KeyValuePair <string, object> current in queryIdToObjectMap) { if (object.ReferenceEquals(current.Value, obj2)) { list.Add(current.Key); } } foreach (string current2 in list) { queryIdToObjectMap[current2] = t; } obj.ObjectData.AssociatedObject = t; } return(t); }