private void HandleOwnerGetRequest(IContainerOwner containerOwner, HttpContext context, string contentPath) { if (context.Request.Url.Host == "localhost" && (contentPath.Contains("oipcms/") || contentPath.Contains("wwwsite/"))) { HandleFileSystemGetRequest(containerOwner, context, contentPath); return; } CloudBlob blob = StorageSupport.GetOwnerBlobReference(containerOwner, contentPath); var response = context.Response; // Read blob content to response. response.Clear(); try { blob.FetchAttributes(); response.ContentType = blob.Properties.ContentType; response.Headers.Add("ETag", blob.Properties.ETag); blob.DownloadToStream(response.OutputStream); } catch (StorageClientException scEx) { if (scEx.ErrorCode == StorageErrorCode.BlobNotFound || scEx.ErrorCode == StorageErrorCode.ResourceNotFound || scEx.ErrorCode == StorageErrorCode.BadRequest) { response.Write("Blob not found or bad request: " + blob.Name + " (original path: " + context.Request.Path + ")"); response.StatusCode = (int)scEx.StatusCode; } else { response.Write("Error code: " + scEx.ErrorCode.ToString() + Environment.NewLine); response.Write(scEx.ToString()); response.StatusCode = (int)scEx.StatusCode; } } catch (Exception ex) { response.Write(ex.ToString()); } response.End(); }
private void HandleOwnerGetRequest(IContainerOwner containerOwner, HttpContext context, string contentPath) { //CloudBlob blob = StorageSupport.GetOwnerBlobReference(containerOwner, contentPath); // Read blob content to response. context.Response.Clear(); try { string contentType = StorageSupport.GetMimeType(Path.GetExtension(contentPath)); context.Response.ContentType = contentType; string prefixStrippedContent = contentPath; //contentPath.Substring(AuthDeveloperPrefixLen + GuidIDLen + 1); string fileName = Path.Combine(DeveloperWebRootFolder, prefixStrippedContent); //blob.FetchAttributes(); var matches = defaultViewRegex.Matches(contentPath); if (matches.Count > 0) { var match = matches[0]; string informationObjectType = match.Groups["typename"].Value; string objectID = match.Groups["id"].Value; Type objectType = typeof(IInformationObject).Assembly.GetType(informationObjectType); MethodInfo retrieveFromDefaultLocation = objectType.GetMethod("RetrieveFromDefaultLocation"); IInformationObject iObject = (IInformationObject)retrieveFromDefaultLocation.Invoke(null, new object[] { objectID, containerOwner }); string templateName = DefaultViewSupport.GetDefaultStaticTemplateName(iObject); foreach (string groupTemplateDirectory in DefaultViewSupport.FixedGroupSiteLocations) { string filesystemDirectory = Path.Combine(DeveloperWebRootFolder, groupTemplateDirectory); string templateFileName = Path.Combine(filesystemDirectory, templateName); string templateContent; try { templateContent = GetTemplateContent(templateFileName); } catch { continue; } string blobDirectory = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(contentPath)), groupTemplateDirectory); string templateBlobPath = Path.Combine(blobDirectory, templateName).Replace("\\", "/"); var templateBlob = StorageSupport.UploadOwnerBlobText(containerOwner, templateBlobPath, templateContent, StorageSupport. InformationType_WebTemplateValue); } var blob = DefaultViewSupport.CreateDefaultViewRelativeToRequester(contentPath, iObject, containerOwner); blob.DownloadToStream(context.Response.OutputStream); } else { string templateContent = GetTemplateContent(fileName); if (templateContent != null) { string templateBlobPath = Path.Combine("template", contentPath).Replace("\\", "/"); var templateBlob = StorageSupport.UploadOwnerBlobText(containerOwner, templateBlobPath, templateContent, StorageSupport. InformationType_WebTemplateValue); var targetBlob = StorageSupport.GetOwnerBlobReference(containerOwner, contentPath); RenderWebSupport.RenderTemplateWithContentToBlob(templateBlob, targetBlob); targetBlob.DownloadToStream(context.Response.OutputStream); //List<RenderWebSupport.ContentItem> contentRoots = new List<RenderWebSupport.ContentItem>(); //string rendered = RenderWebSupport.RenderTemplateWithContentRoots(fixedContent, contentRoots); //RenderWebSupport.Ren //context.Response.Output.Write(rendered); } else { if (File.Exists(fileName)) { var fileStream = File.OpenRead(fileName); fileStream.CopyTo(context.Response.OutputStream); fileStream.Close(); } else { var targetBlob = StorageSupport.GetOwnerBlobReference(containerOwner, contentPath); targetBlob.DownloadToStream(context.Response.OutputStream); } } } } catch (Exception ex) { context.Response.Write(ex.ToString()); } context.Response.End(); }