public IdentifiedData History(string resourceType, string id) { this.ThrowIfNotReady(); try { var handler = ResourceHandlerUtil.Current.GetResourceHandler(resourceType); if (handler != null) { String since = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["_since"]; Guid sinceGuid = since != null?Guid.Parse(since) : Guid.Empty; // Query var retVal = handler.Get(Guid.Parse(id), Guid.Empty) as IVersionedEntity; List <IVersionedEntity> histItm = new List <IVersionedEntity>() { retVal }; while (retVal.PreviousVersionKey.HasValue) { retVal = handler.Get(Guid.Parse(id), retVal.PreviousVersionKey.Value) as IVersionedEntity; if (retVal != null) { histItm.Add(retVal); } // Should we stop fetching? if (retVal?.VersionKey == sinceGuid) { break; } } // Lock the item return(BundleUtil.CreateBundle(histItm.OfType <IdentifiedData>(), histItm.Count, 0, false)); } else { throw new FileNotFoundException(resourceType); } } catch (Exception e) { var remoteEndpoint = OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; this.m_traceSource.TraceEvent(TraceEventType.Error, e.HResult, String.Format("{0} - {1}", remoteEndpoint?.Address, e.ToString())); throw; } }
public IdentifiedData Search(string resourceType) { this.ThrowIfNotReady(); try { var handler = ResourceHandlerUtil.Current.GetResourceHandler(resourceType); if (handler != null) { String offset = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["_offset"], count = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["_count"]; var query = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters.ToQuery(); // Modified on? if (WebOperationContext.Current.IncomingRequest.IfModifiedSince.HasValue) { query.Add("modifiedOn", ">" + WebOperationContext.Current.IncomingRequest.IfModifiedSince.Value.ToString("o")); } // No obsoletion time? if (typeof(BaseEntityData).IsAssignableFrom(handler.Type) && !query.ContainsKey("obsoletionTime")) { query.Add("obsoletionTime", "null"); } int totalResults = 0; // Lean mode var lean = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["_lean"]; bool parsedLean = false; bool.TryParse(lean, out parsedLean); var retVal = handler.Query(query, Int32.Parse(offset ?? "0"), Int32.Parse(count ?? "100"), out totalResults).Select(o => o.GetLocked()).ToList(); WebOperationContext.Current.OutgoingResponse.LastModified = retVal.OrderByDescending(o => o.ModifiedOn).FirstOrDefault()?.ModifiedOn.DateTime ?? DateTime.Now; // Last modification time and not modified conditions if ((WebOperationContext.Current.IncomingRequest.IfModifiedSince.HasValue || WebOperationContext.Current.IncomingRequest.IfNoneMatch != null) && totalResults == 0) { WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotModified; return(null); } else { if (query.ContainsKey("_all") || query.ContainsKey("_expand") || query.ContainsKey("_exclude")) { using (WaitThreadPool wtp = new WaitThreadPool()) { foreach (var itm in retVal) { wtp.QueueUserWorkItem((o) => { try { var i = o as IdentifiedData; ObjectExpander.ExpandProperties(i, query); ObjectExpander.ExcludeProperties(i, query); } catch (Exception e) { this.m_traceSource.TraceEvent(TraceEventType.Error, e.HResult, "Error setting properties: {0}", e); } }, itm); } wtp.WaitOne(); } } return(BundleUtil.CreateBundle(retVal, totalResults, Int32.Parse(offset ?? "0"), parsedLean)); } } else { throw new FileNotFoundException(resourceType); } } catch (Exception e) { var remoteEndpoint = OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; this.m_traceSource.TraceEvent(TraceEventType.Error, e.HResult, String.Format("{0} - {1}", remoteEndpoint?.Address, e.ToString())); throw; } }