public static int ReadObject(ExecutionContext context, object[] values, out object[] inlineParameters) { inlineParameters = EmptyParameters; if (values.Length < 1 || values.Length > 4) { context.Error.WriteLine("Invalid syntax: ReadObject NodePath [TypedStream [Index]]"); return(-1); } string path = values[0].ToString(); Type type = null; uint index = 0; // We first get type. if (values.Length > 1) { type = Type.GetType(values[1].ToString()); if (type == null) { context.Error.WriteLine("Type '{0}' not resolved.", values[1].ToString()); return(-1); } } if (values.Length > 2) { if (values[2] is uint) { index = (uint)values[2]; } else if (values[3] is int) { index = (uint)((int)values[2]); } else if (!uint.TryParse(values[2].ToString(), out index)) { context.Error.WriteLine("The index is not a number: {0}", values[2].ToString()); return(-1); } } Node <object> node = context.ShellApp.WorkingDirectory.Find(path); if (node == null) { context.Error.WriteLine("Path '{0}' does not exist", path); return(-1); } TypedStream <object> typedStream = null; try { if (type == null) { typedStream = node.OpenForReading(); } else { typedStream = node.Open(type, OpenMode.Read); } if (typedStream == null) { context.Error.WriteLine("Typed stream '{0}' does not exist on path '{1}'", type, path); return(-1); } // We write it. inlineParameters = new object[] { typedStream.Read(index) }; } finally { if (typedStream != null) { typedStream.Dispose(); } } return(1); }
static List <Selectable> FindInternal <Selectable, T>(List <Selectable> result, Node <object> table, IQueryExpression <Selectable, T> expression) { TypedStream <T> typedStream = table.Open <T>(OpenMode.Read); if (typedStream == null) { throw new TypedStreamNotFoundException( string.Format("Typed stream of type {0} not found in '{1}'", typeof(T), table.Path)); } // We first obtain index table. IndexTable index2 = table.IndexTable; StreamIndexTable index = index2 != null ? index2[typeof(T)] : null; QueryFilter filter = expression.Filter; // We make sure it is disposed correcly. using (typedStream) { uint[] locations = typedStream.ObjectLocations; for (int i = 0; i < locations.Length; i++) { // We have object's location. uint primary = locations[i]; T processingObject = default(T); // 1) We now filter all objects, first by index. if ((filter & QueryFilter.Index) != 0) { Dictionary <string, object> indexData = StreamIndexTable.IndexOfObject <T>(index, typedStream, primary, out processingObject); // We now process through filter. if (!expression.IsSatisfied(primary, indexData)) { continue; } } // 2) Now we try the alternative filtering, by object. if ((filter & QueryFilter.Object) != 0) { // Force object loading, if not already by indexing. if (!object.ReferenceEquals(processingObject, null)) { processingObject = typedStream.Read(primary); } // We now process it. if (!expression.IsSatisfied(processingObject)) { continue; } } // 3) We now select it. result.Add(expression.Select(processingObject)); } } // 4) After all object are loaded, we sort them if ((filter & QueryFilter.Sort) != 0) { expression.Sort(result); } return(result); }