/// <summary> /// This method prepares the binary body for output from the content. /// </summary> /// <param name="context">The current context.</param> /// <param name="content">The content to be prepared.</param> /// <returns>Returns a ResourceManagerMessageFragmentBody object with the binary representation of the content.</returns> protected virtual ResourceManagerMessageFragmentBody PrepareBodyOutput(ResourceManagerContext context, BinaryContent content) { ResourceManagerMessageFragmentBody body = context.GetObjectPool<ResourceManagerMessageFragmentBody>().Get(); byte[] blob = content.ToArray(); switch (context.Request.Data.RequestPreferredCompression) { case "gzip": using (MemoryStream ms = new MemoryStream()) { using (Stream gz = new GZipStream(ms, CompressionMode.Compress, true)) { gz.Write(blob, 0, blob.Length); gz.Close(); } ms.Position = 0; body.Load(ms); } body.ContentEncoding = "gzip"; break; case "deflate": using (MemoryStream ms = new MemoryStream()) { using (Stream gz = new DeflateStream(ms, CompressionMode.Compress, true)) { gz.Write(blob, 0, blob.Length); gz.Close(); } ms.Position = 0; body.Load(ms); } body.ContentEncoding = "deflate"; break; default: body.Load(blob, 0, blob.Length); break; } blob = null; if (content.MimeType == null || content.MimeType == "") { if (context.Request.Settings.OutputColl.Count > 0) body.ContentType = context.Request.Settings.OutputColl[0].OutputMIMEType; else body.ContentType = "application/octet-stream"; } else body.ContentType = content.MimeType; return body; }
public override bool RequestValidate(ResourceManagerContext context) { Guid? cid = context.Request.ETagFlushID; if (cid.HasValue && context.ContextSettings.ETagCacheFlush(cid.Value)) { context.Response.Status = CH.HTTPCodes.OK_200; } else context.Response.Status = CH.HTTPCodes.NotFound_404; return false; }
public static async Task SeedEssentialDataAsync ( ResourceManagerContext context, UserManager <Worker> userManager, RoleManager <IdentityRole> roleManager, string adminPassword ) { await SeedRolesAsync(roleManager); await CreateAdmin(userManager, adminPassword); await context.SaveChangesAsync(); }
/// <summary> /// This method determines whether the entity has not been modified, and if so /// simply instructs the calling party that that is the case. /// </summary> /// <param name="context">The current context.</param> /// <returns>Returns false if the output logic should not be processed.</returns> public override bool RequestValidate(ResourceManagerContext context) { //Check whether the request has an ETag. string ETag = context.Request.Data.RequestIfNoneMatch; context.CheckChangeState("OutputSelector"); if (ETag == null || ETag == "") return true; try { Guid vid = new Guid(ETag.Trim(new char[] { '"' })); Guid? cid; DateTime? expiry; Type contentType; if (!context.ContextSettings.ETagValidate(vid, out cid, out expiry, out contentType)) return true; if (expiry.HasValue && expiry.Value > DateTime.Now) { context.Request.Data.ResponseHeaderAdd("Expires", CH.ConvertToRFC1123DateString(expiry.Value)); //set the cache control to public as we want these resources to be as cached as possible. context.Request.Data.ResponseHeaderAdd("Cache-control", "public"); } else if (!RevalidateAndUpdateETag(context, vid, cid.Value, contentType)) //OK, check the CDS to see if the content has changed. { context.Request.Data.ResponseHeaderAdd("X-debug", "cachehit revalidate fail"); return true; } else context.Request.Data.ResponseHeaderAdd("Cache-control", "must-revalidate"); context.Request.Data.ResponseHeaderAdd("ETag", ETag); context.Response.Status = CH.HTTPCodes.NotModified_304; context.Response.Substatus = "Not Modified"; return false; } catch (Exception ex) { context.Request.Data.ResponseHeaderAdd("X-debug", "cachehit exception"); return true; } }
/// <summary> /// This is the initialize state. This method does nothing. /// </summary> /// <param name="context">The current context.</param> public override void Initialize(ResourceManagerContext context) { string subCommand = ""; if (context.Data.DestinationAddress.SubCommand is string) subCommand =(string)context.Data.DestinationAddress.SubCommand; switch (subCommand) { case "ETagFlush": context.CheckChangeState("ETagCacheFlush"); break; default: context.CheckChangeState("OutputSelector"); break; } }
/// <summary> /// This method selects the appropriate node and creates a Body content. /// </summary> /// <param name="context">The current context.</param> public override void OutputPrepare(ResourceManagerContext context) { BinaryContent content = null; try { Uri resource = new Uri(context.Request.Settings.OutputColl[0].Output); GuidHolder holder; lock (syncLockCache) { byte[] blob; if (!mInternalResourceCache.ContainsKey(resource)) { blob = RH.ResourceLoadFromUri(resource); holder = new GuidHolder(Guid.NewGuid(), Guid.NewGuid(), blob); mInternalResourceCache.Add(resource, holder); } else holder = mInternalResourceCache[resource]; } content = context.GetObjectPool<BinaryContent>().Get(); content.Load(); content.Data = holder.blob; //content.Load(holder.blob, 0, holder.blob.Length); content.IDContent = holder.ID; content.IDVersion = holder.Version; string statusBody; context.Response.Body = PrepareBody(context, content, out statusBody); context.Response.Status = statusBody; } catch (Exception ex) { context.Response.Body = null; context.Response.Status = CH.HTTPCodes.InternalServerError_500; context.Response.Substatus = ex.Message; } finally { if (content != null && content.ObjectPoolCanReturn) content.ObjectPoolReturn(); content = null; } }
/// <summary> /// This method selects the appropriate node and creates a Body content. /// </summary> /// <param name="context">The current context.</param> public override void OutputPrepare(ResourceManagerContext context) { Content content = null; try { string refType = "name";// context.Request.Data.VariableGet("resourcetype"); string refValue = context.Request.Data.VariableGet("resourcevalue"); Type entityType = RH.CreateTypeFromString(context.Request.Settings.OutputColl[0].Output); string status; throw new NotImplementedException(); //= context.CDSHelper.Execute(entityType, // CDSData.Get(CDSAction.Read, refType, refValue) // , out content); if (status == CH.HTTPCodes.OK_200 && content is BinaryContent) { string statusBody; context.Response.Body = PrepareBody(context, (BinaryContent)content, out statusBody); context.Response.Status = statusBody; } else { context.Response.Body = null; context.Response.Status = CH.HTTPCodes.NotFound_404; } } catch (Exception ex) { context.Response.Body = null; context.Response.Status = CH.HTTPCodes.InternalServerError_500; context.Response.Substatus = ex.Message; } finally { if (content != null && content.ObjectPoolCanReturn) content.ObjectPoolReturn(); content = null; } }
/// <summary> /// This method selects the appropriate output style. /// </summary> /// <param name="context">The current context.</param> public override void OutputSelect(ResourceManagerContext context) { string id = context.Request.Settings.OutputColl[0].OutputType; switch (id) { case "file": context.CheckChangeState("RS_OutputFile"); break; case "resource": context.CheckChangeState("RS_OutputResource"); break; case "cds": context.CheckChangeState("RS_OutputCDS"); break; //case "app": // context.CheckChangeState("RS_OutputAPP"); // break; default: throw new InvalidOutputCCException(@"Output format """ + id + @""" not recognised."); } }
public virtual bool RequestValidate(ResourceManagerContext context) { throw new NotImplementedException("ContentCompilerState->RequestValidate is not implemented: " + this.ToString()); }
public override void OutputComplete(ResourceManagerContext context) { //Do nothing }
public WorkerRepository(ResourceManagerContext context) : base(context) { }
public SupplierRepository(ResourceManagerContext context) : base(context) { }
public SafetyClassRepository(ResourceManagerContext context) : base(context) { }
public DistrictRepository(ResourceManagerContext context) : base(context) { }
public BaseRepository(ResourceManagerContext context) { this.Context = context; }
/// <summary> /// This method prepares the HTTP body based on the browser content encoding settings. /// </summary> /// <param name="context">The current compile context.</param> /// <param name="blob">The UTF-8 formatted byte array.</param> /// <returns>Returns a ContentCompilerMessageFragmentBody object containing the prepared output binary data.</returns> protected virtual ResourceManagerMessageFragmentBody PrepareBody( ResourceManagerContext context, BinaryContent content, out string status) { DateTime? expiry = null; string cacheControl = context.Request.Data.RequestHeaderGet("Cache-Control"); bool allowNotModified = cacheControl == null || cacheControl.ToLowerInvariant() != "no-cache"; int? expiryIns = content.CacheExpiry; ResourceManagerMessageFragmentBody body = null; string eTag = content.IDVersion.ToString("N").ToUpperInvariant(); string eTagValidate = context.Request.Data.RequestIfNoneMatch.Trim(new char[]{'"',' '}); if ((content.CacheOptions & ContentCacheOptions.Cacheable)>0) expiry = DateTime.Now.AddSeconds(expiryIns.Value); context.ContextSettings.ETagAdd(content.IDVersion, content.IDContent, expiry, content.GetType(), expiryIns); //Next check whether we have an etag in the request, and whether it matches the content. if (!allowNotModified || eTagValidate == "" || eTag != eTagValidate) { //Ok, get the body. body = PrepareBodyOutput(context, content); body.ETag = string.Format(@"""{0}""", eTag); if (expiry.HasValue) body.Expires = CH.ConvertToRFC1123DateString(expiry.Value); status = CH.HTTPCodes.OK_200; } else { if (expiry.HasValue) context.Request.Data.ResponseHeaderAdd("Expires", CH.ConvertToRFC1123DateString(expiry.Value)); context.Request.Data.ResponseHeaderAdd("ETag", string.Format(@"""{0}""", eTag)); status = CH.HTTPCodes.NotModified_304; } if (expiry.HasValue) context.Request.Data.ResponseHeaderAdd("Cache-control", "public"); else if ((content.CacheOptions & ContentCacheOptions.VersionCheck) > 0) context.Request.Data.ResponseHeaderAdd("Cache-control", "must-revalidate"); return body; }
public OrderStatusRepository(ResourceManagerContext context) : base(context) { }
public InventoryGivingStatusRepository(ResourceManagerContext context) : base(context) { }
public InventoryRepository(ResourceManagerContext context) : base(context) { }
public MeasuringUnitRepository(ResourceManagerContext context) : base(context) { }
public OrderItemRepository(ResourceManagerContext context) : base(context) { }
public ResourceSubCategoryRepository(ResourceManagerContext context) : base(context) { }
public virtual void Finish(ResourceManagerContext context) { throw new NotImplementedException("ContentCompilerState->Finalize is not implemented " + this.ToString()); }
public EcologyClassRepository(ResourceManagerContext context) : base(context) { }
public virtual void OutputComplete(ResourceManagerContext context) { throw new NotImplementedException("ContentCompilerState->OutputPrepare is not implemented: " + this.ToString()); }
/// <summary> /// This method revalidates the etag versionID values with the Content Data Store. /// This method also resets the content expiry time, or removes the ETag from the cache if the version is invalid. /// </summary> /// <param name="context">The current context.</param> /// <param name="vidIn">The Etag version ID.</param> /// <param name="cidIn">The content ID.</param> /// <param name="contentType">The content type.</param> /// <returns>Returns true if the ETag is valid.</returns> protected virtual bool RevalidateAndUpdateETag(ResourceManagerContext context, Guid vidIn, Guid cidIn, Type contentType) { Guid? cid, vid; throw new NotImplementedException(); string status; //= context.CDSHelper.Execute(contentType, // CDSData.Get(CDSAction.VersionCheck, cidIn, null), out cid, out vid); if (status != CH.HTTPCodes.OK_200) return false; bool success = vidIn == vid; if (success) context.ContextSettings.ETagExpiryReset(vidIn); else context.ContextSettings.ETagCacheFlush(cidIn); return success; }
public CityRepository(ResourceManagerContext context) : base(context) { }
public WarehouseRepository(ResourceManagerContext context) : base(context) { }
public override void Finish(ResourceManagerContext context) { }