Ejemplo n.º 1
0
 public string[] GetFiles(string path)
 {
     if (path == null)
     {
         throw new ArgumentNullException();
     }
     if (string.IsNullOrWhiteSpace(path))
     {
         throw new ArgumentException("Path is empty");
     }
     try
     {
         IAsyncOperation <IReadOnlyList <StorageFile> > filesAsync = NETFXCOREIOService.GetDirectoryForPath(path).GetFilesAsync();
         WindowsRuntimeSystemExtensions.AsTask <IReadOnlyList <StorageFile> >(filesAsync).Wait();
         IReadOnlyList <StorageFile> results = filesAsync.GetResults();
         List <string> list = new List <string>(Enumerable.Count <StorageFile>((IEnumerable <StorageFile>)results));
         foreach (StorageFile storageFile in (IEnumerable <StorageFile>)results)
         {
             list.Add(storageFile.Path);
         }
         return(list.ToArray());
     }
     catch (IOException ex)
     {
         System.Diagnostics.Debug.WriteLine("NETFXCOREIOService.GetFiles: " + ex.Message + "\n" + ex.StackTrace);
         throw;
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("NETFXCOREIOService.GetFiles: " + ex.Message + "\n" + ex.StackTrace);
         throw new IOException(ex.Message, ex);
     }
 }
Ejemplo n.º 2
0
        internal static StorageFolder GetFolderForPathOrURI(string path)
        {
            if (System.Uri.IsWellFormedUriString(path, UriKind.RelativeOrAbsolute))
            {
                return(NETFXCOREIOService.GetFolderForURI(path));
            }
            IAsyncOperation <StorageFolder> folderFromPathAsync = StorageFolder.GetFolderFromPathAsync(Path.GetDirectoryName(path));

            WindowsRuntimeSystemExtensions.AsTask <StorageFolder>(folderFromPathAsync).Wait();
            return(folderFromPathAsync.GetResults());
        }
Ejemplo n.º 3
0
 public bool FileExists(string path)
 {
     try
     {
         return(NETFXCOREIOService.GetFileForPathOrURI(path) != null);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 4
0
 public bool DirectoryExists(string path)
 {
     try
     {
         return(NETFXCOREIOService.GetDirectoryForPath(path) != null);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 5
0
 public void FileDelete(string path)
 {
     if (path == null)
     {
         throw new ArgumentNullException();
     }
     if (path.Trim() == "")
     {
         throw new ArgumentException();
     }
     try
     {
         WindowsRuntimeSystemExtensions.AsTask(NETFXCOREIOService.GetFileForPathOrURI(path).DeleteAsync())
         .Wait();
     }
     catch (Exception ex)
     {
         throw NETFXCOREIOService.GetRethrowException(ex);
     }
 }
Ejemplo n.º 6
0
        // Static constructor. Setup default values
        static HTTPManager()
        {
            MaxConnectionPerServer = 6;
            KeepAliveDefaultValue  = true;
            MaxPathLength          = 255;
            MaxConnectionIdleTime  = TimeSpan.FromSeconds(20);

#if !BESTHTTP_DISABLE_COOKIES
#if UNITY_WEBGL
            // Under webgl when IsCookiesEnabled is true, it will set the withCredentials flag for the XmlHTTPRequest
            //  and that's different from the default behavior.
            // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials
            IsCookiesEnabled = false;
#else
            IsCookiesEnabled = true;
#endif
#endif

            CookieJarSize         = 10 * 1024 * 1024;
            EnablePrivateBrowsing = false;
            ConnectTimeout        = TimeSpan.FromSeconds(20);
            RequestTimeout        = TimeSpan.FromSeconds(60);

            // Set the default logger mechanism
            logger = new BestHTTP.Logger.ThreadedLogger();

#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
            DefaultCertificateVerifyer  = null;
            UseAlternateSSLDefaultValue = true;
#endif

#if NETFX_CORE
            IOService = new PlatformSupport.FileSystem.NETFXCOREIOService();
#elif UNITY_WEBGL && !UNITY_EDITOR
            IOService = new PlatformSupport.FileSystem.WebGLIOService();
#else
            IOService = new PlatformSupport.FileSystem.DefaultIOService();
#endif
        }
Ejemplo n.º 7
0
        public void DirectoryCreate(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException();
            }
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentNullException("Path is empty");
            }
            StorageFolder folder = (StorageFolder)null;

            path = path.Replace('/', '\\');
            string         path1 = path;
            Stack <string> stack = new Stack <string>();

            do
            {
                try
                {
                    folder = NETFXCOREIOService.GetDirectoryForPath(path1);
                    break;
                }
                catch
                {
                    int length = path1.LastIndexOf('\\');
                    if (length < 0)
                    {
                        path1 = (string)null;
                    }
                    else
                    {
                        stack.Push(path1.Substring(length + 1));
                        path1 = path1.Substring(0, length);
                    }
                }
            }while (path1 != null);
            if (path1 == null)
            {
                System.Diagnostics.Debug.WriteLine("NETFXCOREIOService.DirectoryCreate: Could not find any part of the path: " + path);
                throw new IOException("Could not find any part of the path: " + path);
            }
            try
            {
                while (stack.Count > 0)
                {
                    string desiredName = stack.Pop();
                    if (string.IsNullOrWhiteSpace(desiredName) && stack.Count > 0)
                    {
                        throw new ArgumentNullException("Empty directory name in the path");
                    }
                    IAsyncOperation <StorageFolder> folderAsync = folder.CreateFolderAsync(desiredName);
                    WindowsRuntimeSystemExtensions.AsTask <StorageFolder>(folderAsync).Wait();
                    folder = folderAsync.GetResults();
                }
            }
            catch (IOException ex)
            {
                System.Diagnostics.Debug.WriteLine("NETFXCOREIOService.DirectoryCreate: " + ex.Message + "\n" + ex.StackTrace);
                throw;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("NETFXCOREIOService.DirectoryCreate: " + ex.Message + "\n" + ex.StackTrace);
                throw new IOException(ex.Message, ex);
            }
        }