internal ClientRequest(ClientRequestContext context) { this.m_context = context; this.m_actions = new List<Action>(); this.m_actionResultHandler = new Dictionary<int, IResultHandler>(); this.m_referencedObjectPaths = new Dictionary<int, ObjectPath>(); this.m_flags = ClientRequestFlags.None; this.m_traceInfos = new Dictionary<int, string>(); }
internal static void ValidateContext(ClientRequestContext context, ClientObject obj) { if (obj != null && obj.Context != context) { throw CreateRuntimeError( ErrorCodes.GeneralException, _GetResourceString(ResourceStrings.InvalidObjectPath), null); } }
public static ObjectPath _CreateGlobalObjectObjectPath(ClientRequestContext context) { ObjectPathInfo objectPathInfo = new ObjectPathInfo() { Id = context._NextId(), ObjectPathType = ObjectPathType.GlobalObject, Name = "" }; return(new ObjectPath(objectPathInfo, null, false /*isCollection*/, false /*isInvalidAfterRequest*/)); }
public static ObjectPath _CreateNewObjectObjectPath(ClientRequestContext context, string typeName, bool isCollection) { ObjectPathInfo objectPathInfo = new ObjectPathInfo() { Id = context._NextId(), ObjectPathType = ObjectPathType.NewObject, Name = typeName }; return(new ObjectPath(objectPathInfo, null, isCollection, false /*isInvalidAfterRequest*/)); }
public static ObjectPath _CreatePropertyObjectPath(ClientRequestContext context, ClientObject parent, string propertyName, bool isCollection, bool isInvalidAfterRequest) { ObjectPathInfo objectPathInfo = new ObjectPathInfo() { Id = context._NextId(), ObjectPathType = ObjectPathType.Property, Name = propertyName, ParentObjectPathId = parent._ObjectPath.ObjectPathInfo.Id, }; return(new ObjectPath(objectPathInfo, parent._ObjectPath, isCollection, isInvalidAfterRequest)); }
public static ObjectPath _CreateIndexerObjectPathUsingParentPath(ClientRequestContext context, ObjectPath parentObjectPath, object[] args) { ObjectPathInfo objectPathInfo = new ObjectPathInfo() { Id = context._NextId(), ObjectPathType = ObjectPathType.Indexer, Name = "", ParentObjectPathId = parentObjectPath.ObjectPathInfo.Id, ArgumentInfo = new ArgumentInfo() }; objectPathInfo.ArgumentInfo.Arguments = args; return(new ObjectPath(objectPathInfo, parentObjectPath, false /*isCollection*/, false /*isInvalidAfterRequest*/)); }
internal static Action CreateTraceAction(ClientRequestContext context, string message) { ActionInfo actionInfo = new ActionInfo() { Id = context._NextId(), ActionType = ActionType.Trace, Name = "Trace", ObjectPathId = 0 }; Action ret = new Action(actionInfo, false); context._PendingRequest.AddAction(ret); context._PendingRequest.AddTrace(actionInfo.Id, message); return(ret); }
public ClientObject(ClientRequestContext context, ObjectPath objectPath) { Utility.CheckArgumentNull(context, "context"); this.m_context = context; this.m_objectPath = objectPath; if (this.m_objectPath != null) { // If object is being created during a normal API flow (and NOT as part of processing load results), // create an instantiation action and call keepReference, if applicable if (!context.ProcessingResult) { ActionFactory.CreateInstantiateAction(context, this); } } this.m_loadedPropertyNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase); }
internal static Action CreateInstantiateAction(ClientRequestContext context, ClientObject obj) { Utility.ValidateObjectPath(obj); ActionInfo actionInfo = new ActionInfo() { Id = context._NextId(), ActionType = ActionType.Instantiate, Name = "", ObjectPathId = obj._ObjectPath.ObjectPathInfo.Id }; var ret = new Action(actionInfo, false); context._PendingRequest.AddAction(ret); context._PendingRequest.AddReferencedObjectPath(obj._ObjectPath); context._PendingRequest.AddActionResultHandler(ret, new InstantiateActionResultHandler(obj)); return(ret); }
public static ObjectPath _CreateMethodObjectPath(ClientRequestContext context, ClientObject parent, string methodName, OperationType operationType, object[] args, bool isCollection, bool isInvalidAfterRequest) { ObjectPathInfo objectPathInfo = new ObjectPathInfo() { Id = context._NextId(), ObjectPathType = ObjectPathType.Method, Name = methodName, ParentObjectPathId = parent._ObjectPath.ObjectPathInfo.Id, ArgumentInfo = new ArgumentInfo() }; List <ObjectPath> argumentObjectPaths = Utility.SetMethodArguments(context, objectPathInfo.ArgumentInfo, args); ObjectPath ret = new ObjectPath(objectPathInfo, parent._ObjectPath, isCollection, isInvalidAfterRequest); ret.ArgumentObjectPaths = argumentObjectPaths; ret.IsWriteOperation = (operationType != OperationType.Read); return(ret); }
internal static Action CreateQueryAction(ClientRequestContext context, ClientObject parent, QueryInfo queryOption) { Utility.ValidateObjectPath(parent); ActionInfo actionInfo = new ActionInfo() { Id = context._NextId(), ActionType = ActionType.Query, Name = "", ObjectPathId = parent._ObjectPath.ObjectPathInfo.Id, }; actionInfo.QueryInfo = queryOption; Action ret = new Action(actionInfo, false); context._PendingRequest.AddAction(ret); context._PendingRequest.AddReferencedObjectPath(parent._ObjectPath); return(ret); }
internal static List <ObjectPath> SetMethodArguments(ClientRequestContext context, ArgumentInfo argumentInfo, object[] args) { if (args == null) { return(null); } var referencedObjectPaths = new List <ObjectPath>(); List <object> referencedObjectPathIds = new List <object>(); bool hasOne = Utility.CollectObjectPathInfos(context, args, referencedObjectPaths, referencedObjectPathIds); argumentInfo.Arguments = args; if (hasOne) { argumentInfo.ReferencedObjectPathIds = referencedObjectPathIds.ToArray(); return(referencedObjectPaths); } return(null); }
private static bool CollectObjectPathInfos( ClientRequestContext context, object[] args, List <ObjectPath> referencedObjectPaths, List <object> referencedObjectPathIds) { bool hasOne = false; for (int i = 0; i < args.Length; i++) { if (args[i] is ClientObject) { ClientObject clientObject = (ClientObject)args[i]; Utility.ValidateContext(context, clientObject); args[i] = clientObject._ObjectPath.ObjectPathInfo.Id; referencedObjectPathIds.Add(clientObject._ObjectPath.ObjectPathInfo.Id); referencedObjectPaths.Add(clientObject._ObjectPath); hasOne = true; } else if (args[i] != null && args[i].GetType().IsArray) { var childArrayObjectPathIds = new List <object>(); var childArrayHasOne = Utility.CollectObjectPathInfos(context, (object[])args[i], referencedObjectPaths, childArrayObjectPathIds); if (childArrayHasOne) { referencedObjectPathIds.Add(childArrayObjectPathIds.ToArray()); hasOne = true; } else { referencedObjectPathIds.Add(0); } } else { referencedObjectPathIds.Add(0); } } return(hasOne); }
public static ObjectPath _CreateChildItemObjectPathUsingGetItemAt(ClientRequestContext context, ClientObject parent, JToken childItem, int index) { JToken indexFromServer = childItem[Constants.Index]; if (!Utility._IsNullOrUndefined(indexFromServer)) { index = indexFromServer.Value <int>(); } ObjectPathInfo objectPathInfo = new ObjectPathInfo() { Id = context._NextId(), ObjectPathType = ObjectPathType.Method, Name = Constants.GetItemAt, ParentObjectPathId = parent._ObjectPath.ObjectPathInfo.Id, ArgumentInfo = new ArgumentInfo() }; objectPathInfo.ArgumentInfo.Arguments = new object[] { index }; return(new ObjectPath(objectPathInfo, parent._ObjectPath, false /*isCollection*/, false /*isInvalidAfterRequest*/)); }
public static ObjectPath _CreateChildItemObjectPathUsingIndexer(ClientRequestContext context, ClientObject parent, JToken childItem) { var id = childItem[Constants.Id]; if (Utility._IsNullOrUndefined(id)) { id = childItem[Constants.IdPrivate]; } ObjectPathInfo objectPathInfo = new ObjectPathInfo() { Id = context._NextId(), ObjectPathType = ObjectPathType.Indexer, Name = "", ParentObjectPathId = parent._ObjectPath.ObjectPathInfo.Id, ArgumentInfo = new ArgumentInfo() }; objectPathInfo.ArgumentInfo.Arguments = new object[] { id }; return(new ObjectPath(objectPathInfo, parent._ObjectPath, false /*isCollection*/, false /*isInvalidAfterRequest*/)); }
public static Action _CreateMethodAction(ClientRequestContext context, ClientObject parent, string methodName, OperationType operationType, object[] args) { Utility.ValidateObjectPath(parent); ActionInfo actionInfo = new ActionInfo() { Id = context._NextId(), ActionType = ActionType.Method, Name = methodName, ObjectPathId = parent._ObjectPath.ObjectPathInfo.Id, ArgumentInfo = new ArgumentInfo() }; var referencedArgumentObjectPaths = Utility.SetMethodArguments(context, actionInfo.ArgumentInfo, args); Utility.ValidateReferencedObjectPaths(referencedArgumentObjectPaths); bool isWriteOperation = operationType != OperationType.Read; var ret = new Action(actionInfo, isWriteOperation); context._PendingRequest.AddAction(ret); context._PendingRequest.AddReferencedObjectPath(parent._ObjectPath); context._PendingRequest.AddReferencedObjectPaths(referencedArgumentObjectPaths); return(ret); }
public static Action _CreateSetPropertyAction(ClientRequestContext context, ClientObject parent, string propertyName, object value) { Utility.ValidateObjectPath(parent); ActionInfo actionInfo = new ActionInfo() { Id = context._NextId(), ActionType = ActionType.SetProperty, Name = propertyName, ObjectPathId = parent._ObjectPath.ObjectPathInfo.Id, ArgumentInfo = new ArgumentInfo() }; object[] args = new object[] { value }; var referencedArgumentObjectPaths = Utility.SetMethodArguments(context, actionInfo.ArgumentInfo, args); Utility.ValidateReferencedObjectPaths(referencedArgumentObjectPaths); var ret = new Action(actionInfo, true); context._PendingRequest.AddAction(ret); context._PendingRequest.AddReferencedObjectPath(parent._ObjectPath); context._PendingRequest.AddReferencedObjectPaths(referencedArgumentObjectPaths); return(ret); }
internal TrackedObjects(ClientRequestContext context) { this.m_context = context; }
public static ObjectPath _CreateChildItemObjectPathUsingIndexerOrGetItemAt(bool hasIndexerMethod, ClientRequestContext context, ClientObject parent, JToken childItem, int index) { var id = childItem[Constants.Id]; if (Utility._IsNullOrUndefined(id)) { id = childItem[Constants.IdPrivate]; } if (hasIndexerMethod && !Utility._IsNullOrUndefined(id)) { return(ObjectPathFactory._CreateChildItemObjectPathUsingIndexer(context, parent, childItem)); } else { return(ObjectPathFactory._CreateChildItemObjectPathUsingGetItemAt(context, parent, childItem, index)); } }