Пример #1
0
            public override WebResourceResponse ShouldInterceptRequest(WebView p0, string url)
            {
                if (url.Contains("/static/"))
                {
                    var filePath      = url.Substring(url.LastIndexOf("/static/"), (url.Length - url.LastIndexOf("/static/")));
                    var extensionName = filePath.Substring(filePath.LastIndexOf(".") + 1, (filePath.Length - filePath.LastIndexOf(".") - 1));
                    if (!File.Exists(DeviceInfo.HtmlFolder + filePath))
                    {
                        Task.Run(() =>
                        {
                            new HtmlFileManage().DownloadFile(HybridCommon.Config.HtmlServerHost + filePath, DeviceInfo.HtmlFolder + filePath);
                        });
                    }
                    else
                    {
                        var fileStream = File.OpenRead(DeviceInfo.HtmlFolder + filePath);
                        var result     = new WebResourceResponse();
                        result.Encoding = "UTF-8";
                        result.MimeType = MimeHelper.GetMime(extensionName);
                        result.Data     = fileStream;
                        return(result);
                    }
                }
                else if (url.Contains("/index.html#/Empty/"))
                {
                    var filePath = "/index.html";
                    if (!File.Exists(DeviceInfo.HtmlFolder + filePath))
                    {
                        Task.Run(() =>
                        {
                            new HtmlFileManage().DownloadFile(HybridCommon.Config.HtmlServerHost + filePath,
                                                              DeviceInfo.HtmlFolder + filePath);
                        });
                    }
                    else
                    {
                        var fileStream = File.OpenRead(DeviceInfo.HtmlFolder + filePath);
                        var result     = new WebResourceResponse();
                        result.Encoding = "UTF-8";
                        result.MimeType = MimeHelper.GetMime("html");
                        result.Data     = fileStream;
                        return(result);
                    }
                }

                //if (url.Contains(DeviceInfo.HtmlFolder))
                //{

                //    url = url.Replace(DeviceInfo.HtmlFolder, "@");
                //    url = url.Substring(url.IndexOf("@")+1, url.Length - url.IndexOf("@")-1);
                //    url = HybridCommon.Config.HtmlServerHost + url;
                //}

                return(base.ShouldInterceptRequest(p0, url));
            }
        public bool TryGetProfileImageFilePath(int userId, ProfileImageSize profileImageSize, out string path, out string fileMime)
        {
            var userHasProfileImage = HasUserProfileImage(userId);

            if (userHasProfileImage)
            {
                path     = AppFileManager.GetUserProfileImagePath(userId, profileImageSize);
                fileMime = MimeHelper.GetMime(Path.GetExtension(path));
                return(true);
            }

            path     = null;
            fileMime = null;
            return(false);
        }
Пример #3
0
        /// <summary>
        /// 根据指定的文件名上传文件
        /// </summary>
        /// <param name="bucket"></param>
        /// <param name="key"></param>
        /// <param name="filePathName"></param>
        /// <returns></returns>
        public async Task <OssResult <PutObjectResult> > PutObjectByFileNameAsync(BucketInfo bucket, string key,
                                                                                  string filePathName)
        {
            using (var stream = File.OpenRead(filePathName))
            {
                var file = new RequestContent()
                {
                    ContentType   = RequestContentType.Stream,
                    StreamContent = stream,
                    MimeType      = MimeHelper.GetMime(filePathName)
                };

                return(await PutObjectAsync(bucket, key, file));
            }
        }
Пример #4
0
        /// <summary>
        /// 根据指定的文件名上传文件
        /// </summary>
        /// <param name="bucket"></param>
        /// <param name="key"></param>
        /// <param name="filePathName"></param>
        /// <returns></returns>
        public async Task <OssResult <PutObjectResult> > PutObjectByFileNameAsync(BucketInfo bucket, string key,
                                                                                  string filePathName, ObjectMetadata meta = null, IDictionary <string, string> extraHeaders = null)
        {
            using (var stream = File.OpenRead(filePathName))
            {
                var file = new RequestContent()
                {
                    ContentType   = RequestContentType.Stream,
                    StreamContent = stream,
                    MimeType      = MimeHelper.GetMime(filePathName),
                    Metadata      = meta
                };

                return(await PutObjectAsync(bucket, key, file, extraHeaders));
            }
        }
 public void GetOriginalProfileImageFilePath(int userId, out string path, out string fileMime)
 {
     path     = AppFileManager.GetUserProfileImagePath(userId, ProfileImageSize.Original);
     fileMime = MimeHelper.GetMime(Path.GetExtension(path));
 }