コード例 #1
0
        public async Task <IActionResult> GetResource(
            [FromRoute, Required] string type,
            [FromRoute, Required] string path,
            [FromHeader(Name = "If-None-Match")] string etag)
        {
            if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(type))
            {
                Logger.LogTrace("Not Found: No Path Specified!");
                return(FormattedNotFound("No Path specified!"));
            }

            //Known Types:
            var knownTypes = new[] { "files", "images" };

            if (!knownTypes.Contains(type, StringComparer.CurrentCultureIgnoreCase))
            {
                Logger.LogTrace("Unknown Type specified!");
                return(FormattedNotFound("Unknown Type specified!"));
            }

            Uri uri = null;

            try
            {
                var uriStr = "smartdevices://resources/" + type + "/" + path;
                uri = new Uri(uriStr);
            }
            catch (UriFormatException e)
            {
                Logger.LogError(e, $"Bad Request: Could not parse Path: {type}/{path}");
                return(FormattedBadRequest("Could not parse Path"));
            }

            var ret = await _resourceModel.GetResource(uri);

            var resourceInfo = ret.Item1;
            var stream       = ret.Item2;

            if (resourceInfo == null)
            {
                Logger.LogError("Not Found: Could not found requested Resource");
                return(FormattedNotFound("Could not found requested Resource"));
            }

            if (resourceInfo.ETag.Equals(etag))
            {
                return(FormattedNotModified());
            }

            SetCacheControlHeadersToNoCache();
            Response.Headers.Add("Content-Disposition", $"inline; filename=\"{resourceInfo.Name}\"");
            Response.Headers.Add("Content-Type", resourceInfo.ContentType.ToString());
            Response.Headers.Add("Content-Length", resourceInfo.Size.ToString());
            Response.Headers.Add("ETag", resourceInfo.ETag);

            return(new FileStreamResult(stream, resourceInfo.ContentType.ToString()));
        }
コード例 #2
0
 public void Update()
 {
     DGR.ItemsSource             = null;
     CB_People.ItemsSource       = null;
     CB_ReportPeople.ItemsSource = null;
     using (var db = new ResourceModel())
     {
         DGR.ItemsSource             = db.GetResource();
         CB_People.ItemsSource       = db.GetPeople();
         CB_ReportPeople.ItemsSource = db.GetPeople();
     }
 }