Esempio n. 1
0
        protected bool CanProcessLocally(HttpContextBase context, string filePath, out IVirtualFileWriter virtualFileWriter)
        {
            //First check if there's any virtual file providers that can handle this
            var writer = FileWriters.GetVirtualWriterForFile(filePath);

            if (writer == null)
            {
                var ext = Path.GetExtension(filePath);
                writer = FileWriters.GetVirtualWriterForExtension(ext);
            }
            if (writer != null)
            {
                virtualFileWriter = writer;
                return(writer.FileProvider.FileExists(filePath));
            }

            //can process if it exists locally
            virtualFileWriter = null;
            return(File.Exists(context.Server.MapPath(filePath)));
        }
        /// <summary>
        /// This will check if there's a file writer for the file extension of the file path and if that file physically exists in the website
        /// </summary>
        /// <param name="context"></param>
        /// <param name="filePath"></param>
        /// <param name="virtualFileWriter"></param>
        /// <returns></returns>
        protected bool CanProcessLocally(HttpContextBase context, string filePath, out IVirtualFileWriter virtualFileWriter)
        {
            //First check if there's any virtual file providers that can handle this
            var writer = FileWriters.GetVirtualWriterForFile(filePath);

            if (writer == null)
            {
                if (!PathHelper.TryGetFileExtension(filePath, out var ext))
                {
                    virtualFileWriter = null;
                    return(false);
                }
                writer = FileWriters.GetVirtualWriterForExtension(ext);
            }
            if (writer != null)
            {
                virtualFileWriter = writer;
                try
                {
                    return(writer.FileProvider.FileExists(filePath));
                }
                catch (Exception)
                {
                    return(false);
                }
            }

            //can process if it exists locally
            virtualFileWriter = null;

            if (!PathHelper.TryMapPath(filePath, context, out var mappedPath))
            {
                return(false);
            }

            return(File.Exists(mappedPath));
        }