Пример #1
0
        /// <summary>
        /// Delete the directory with the given path.
        /// </summary>
        public static void Delete(string path, bool recursive)
        {
            var file = new JFile(path);

            if (file.IsDirectory())
            {
                if (recursive)
                {
                    var children = file.List();
                    foreach (var child in children)
                    {
                        var childFile = new JFile(child);
                        if (childFile.IsFile())
                        {
                            childFile.Delete();
                        }
                        if (childFile.IsDirectory())
                        {
                            Delete(child, recursive);
                        }
                    }
                }
                file.Delete();
            }
        }
Пример #2
0
        /// <summary>
        /// Gets the file name part (without extension) of the specified path.
        /// </summary>
        public static string GetFileNameWithoutExtension(string path)
        {
            var name  = new JFile(path).GetName();
            var index = GetExtensionIndex(name);

            return((index >= 0) ? name.JavaSubstring(0, index) : name);
        }
Пример #3
0
        /// <summary>
        /// Create a unique named zero-byte length temporary file on disk and returns it's path.
        /// </summary>
        public static string GetTempFileName()
        {
            var rndName = GetRandomFileName();
            var index   = rndName.IndexOf('.');

            return(JFile.CreateTempFile(rndName.JavaSubstring(0, index), rndName.JavaSubstring(index)).GetAbsolutePath());
        }
Пример #4
0
        public void testWriteAllText1()
        {
            var path = JFile.CreateTempFile("dot42.TestFile-WriteAllText1", "txt");

            File.WriteAllText(path.AbsolutePath, "Hello world");
            AssertTrue(path.Exists());
            path.Delete();
            AssertFalse(path.Exists());
        }
Пример #5
0
        /// <summary>
        /// Delete the directory with the given path.
        /// </summary>
        public static void Delete(string path)
        {
            var file = new JFile(path);

            if (file.IsDirectory())
            {
                file.Delete();
            }
        }
Пример #6
0
        public void test1()
        {
            var path = JFile.CreateTempFile("dot42.TestXLoad-1", "txt");

            File.WriteAllText(path, "<root></root>");
            var doc = XDocument.Load(path);

            path.Delete();
            AssertNotNull(doc);
            AssertNotNull(doc.Root);
        }
Пример #7
0
        public void testWriteAllText2()
        {
            const string Data = "Hello worldAllText2";
            var          path = JFile.CreateTempFile("dot42.TestFile-WriteAllText2", "txt");

            File.WriteAllText(path.AbsolutePath, Data);
            AssertTrue(path.Exists());
            var content = File.ReadAllText(path.AbsolutePath);

            path.Delete();
            AssertEquals(content, Data);
        }
Пример #8
0
        public void test2()
        {
            var path = JFile.CreateTempFile("dot42.TestXLoad-2", "txt");

            File.WriteAllText(path, "<root></root>");
            using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                var doc = XDocument.Load(stream);
                AssertNotNull(doc);
                AssertNotNull(doc.Root);
            }
            path.Delete();
        }
Пример #9
0
        public void test3()
        {
            var path = JFile.CreateTempFile("dot42.TestXLoad-3", "txt");

            File.WriteAllText(path, "<?xml version=\"1.0\" encoding=\"utf-8\"?><Version xmlns=\"urn:Dot42:TodoApi:1.0\">v1_0</Version>");
            using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                var doc = XDocument.Load(stream);
                AssertNotNull("doc should not be null", doc);
                AssertNotNull("doc.Root should not be null", doc.Root);
                AssertTrue("doc.Root.Name.LocalName != 'Version'", doc.Root.Name.LocalName == "Version");
                AssertTrue("doc.Root.Value != 'v1_0' but:" + doc.Root.Value, doc.Root.Value == "v1_0");
            }
            path.Delete();
        }
Пример #10
0
        public void testWriteAllBytes1()
        {
            var data = new byte[] { 1, 2, 3, 4 };
            var path = JFile.CreateTempFile("dot42.TestFile-WriteAllBytes1", "txt");

            File.WriteAllBytes(path.AbsolutePath, data);
            AssertTrue(path.Exists());
            var readData = File.ReadAllBytes(path.AbsolutePath);

            path.Delete();
            AssertFalse(path.Exists());
            AssertEquals(data.Length, readData.Length);
            for (var i = 0; i < data.Length; i++)
            {
                AssertEquals(data[i], readData[i]);
            }
        }
Пример #11
0
 /// <summary>
 /// Delete the directory with the given path.
 /// </summary>
 public static void Delete(string path, bool recursive)
 {
     var file = new JFile(path);
     if (file.IsDirectory())
     {
         if (recursive)
         {
             var children = file.List();
             foreach (var child in children)
             {
                 var childFile = new JFile(child);
                 if (childFile.IsFile()) childFile.Delete();
                 if (childFile.IsDirectory()) Delete(child, recursive);
             }
         }
         file.Delete();
     }
 }
Пример #12
0
 private Java.Io.File[] GetEntries(string path)
 {
     var dir = new Java.Io.File(path);
     if (dir.Exists() && dir.IsDirectory())
     {
         var entries = dir.ListFiles();
         if (entries != null)
         {
             var list = entries.OrderBy(x => x.Name).ToList();
             if (path != startPath)
             {
                 var parent = dir.ParentFile;
                 if (parent != null)
                 {
                     list.Insert(0, parent);
                 }
             }
             return list.ToArray();
         }
     }
     return new Java.Io.File[0];
 }
Пример #13
0
        private Java.Io.File[] GetEntries(string path)
        {
            var dir = new Java.Io.File(path);

            if (dir.Exists() && dir.IsDirectory())
            {
                var entries = dir.ListFiles();
                if (entries != null)
                {
                    var list = entries.OrderBy(x => x.Name).ToList();
                    if (path != startPath)
                    {
                        var parent = dir.ParentFile;
                        if (parent != null)
                        {
                            list.Insert(0, parent);
                        }
                    }
                    return(list.ToArray());
                }
            }
            return(new Java.Io.File[0]);
        }
Пример #14
0
        /// <summary>
        /// Initialize activity
        /// </summary>
        protected override void OnCreate(Bundle savedInstance)
        {
            base.OnCreate(savedInstance);

            try
            {
                var        httpCacheDir  = new Java.Io.File(GetCacheDir(), "http");
                const long httpCacheSize = 10 * 1024 * 1024; // 10 MB
                HttpResponseCache.Install(httpCacheDir, httpCacheSize);
            }
            catch (IOException ex)
            {
                Log.E(Tag, "HTTP response cache installation failed. " + ex.Message + " " + ex.StackTrace);
            }

            SetContentView(R.Layouts.MainLayout);
            _fixtureList = FindViewById <ListView>(R.Ids.fixtureList);

            _fixturesArray = _fixtures.ToArray();
            _adapter       = new ArrayAdapter <Fixture>(this, Android.R.Layout.Simple_list_item_1, _fixturesArray);
            _fixtureList.SetAdapter(_adapter);

            GetFixturesAsync();
        }
Пример #15
0
 /// <summary>
 /// Gets the file name part (without extension) of the specified path.
 /// </summary>
 public static string GetFileNameWithoutExtension(string path)
 {
     var name = new JFile(path).GetName();
     var index = GetExtensionIndex(name);
     return (index >= 0) ? name.JavaSubstring(0, index) : name;
 }
Пример #16
0
 /// <summary>
 /// Delete the directory with the given path.
 /// </summary>
 public static void Delete(string path)
 {
     var file = new JFile(path);
     if (file.IsDirectory())
         file.Delete();
 }
        /// <summary>
        /// Initialize activity
        /// </summary>
        protected override void OnCreate(Bundle savedInstance)
        {
            base.OnCreate(savedInstance);

            try
            {
                var httpCacheDir = new Java.Io.File(GetCacheDir(), "http");
                const long httpCacheSize = 10 * 1024 * 1024; // 10 MB
                HttpResponseCache.Install(httpCacheDir, httpCacheSize);
            }
            catch (IOException ex)
            {
                Log.E(Tag, "HTTP response cache installation failed. " + ex.Message + " " + ex.StackTrace);
            }

            SetContentView(R.Layouts.MainLayout);
            _fixtureList = FindViewById<ListView>(R.Ids.fixtureList);

            _fixturesArray = _fixtures.ToArray();
            _adapter = new ArrayAdapter<Fixture>(this, Android.R.Layout.Simple_list_item_1, _fixturesArray);
            _fixtureList.SetAdapter(_adapter);

            GetFixturesAsync();
        }
Пример #18
0
 public static /*DirectoryInfo*/ void CreateDirectory(string path)
 {
     var file      = new JFile(path);
     var isCreated = file.Mkdirs();
 }
Пример #19
0
        /// <summary>
        /// Does a directory with given path exist on the filesystem?
        /// </summary>
        public static bool Exists(string path)
        {
            var file = new JFile(path);

            return(file.IsDirectory() && file.Exists());
        }
Пример #20
0
 /// <summary>
 /// Does a directory with given path exist on the filesystem?
 /// </summary>
 public static bool Exists(string path)
 {
     var file = new JFile(path);
     return file.IsDirectory() && file.Exists();
 }
Пример #21
0
 public static /*DirectoryInfo*/ void CreateDirectory(string path)
 {
     var file = new JFile(path);
     var isCreated = file.Mkdirs();
 }