Ejemplo n.º 1
0
 public Task <IFile> CreateFile(string path, byte[] contents)
 {
     return(Task.Run <IFile> (() => {
         var r = new DeviceFile(path, documentsPath);
         if (contents != null)
         {
             Directory.CreateDirectory(Path.GetDirectoryName(r.LocalPath));
             File.WriteAllBytes(r.LocalPath, contents);
         }
         return r;
     }));
 }
Ejemplo n.º 2
0
 public Task <IFile> CreateFile(string path, byte[] contents)
 {
     return(Task.Run <IFile> (() => {
         var r = new DeviceFile(path, documentsPath);
         if (contents != null)
         {
             var dir = Path.GetDirectoryName(r.LocalPath);
             if (!Directory.Exists(dir))
             {
                 if (File.Exists(dir))
                 {
                     File.Delete(dir);
                 }
                 Directory.CreateDirectory(dir);
             }
             File.WriteAllBytes(r.LocalPath, contents);
         }
         return r;
     }));
 }
Ejemplo n.º 3
0
        void ReadQueryResults()
        {
            var fm = new NSFileManager();

            var deadIndex = new HashSet <string> (fileIndex.Keys);
            var newList   = new List <CloudFile> ();
            var newIndex  = new Dictionary <string, IFile> ();

//			Console.WriteLine ("-------------- Received iCloud");

            foreach (var item in query.Results)
            {
                var cf = new CloudFile(item, documentsUrl);

                var key = cf.Path;

                if (deadIndex.Contains(key))
                {
                    deadIndex.Remove(key);
                }
                else
                {
                    newList.Add(cf);
                }
                newIndex[key] = cf;

                //
                // Add a "file" for directories
                //
                var dir = Path.GetDirectoryName(cf.Path);
                if (!string.IsNullOrEmpty(dir) && !newIndex.ContainsKey(dir))
                {
                    newIndex [dir] = new DeviceFile(dir, documentsUrl.Path);
                }


//				Console.WriteLine (cf);
            }

            foreach (var f in newList)
            {
                if (!f.IsDownloaded)
                {
                    NSError error;
                    fm.StartDownloadingUbiquitous(f.LocalUrl, out error);
                }
            }

            fileIndex = newIndex;

            IsSyncing = false;

            if (firstQueryResult != null)
            {
                var t = firstQueryResult;
                firstQueryResult = null;
                t.SetResult(null);
            }

            var ev = FilesChanged;

            if (ev != null)
            {
                ev(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 4
0
#pragma warning restore 67

        public Task <IFile> GetFile(string path)
        {
            var file = new DeviceFile(path, documentsPath);

            return(Task.FromResult <IFile> (file));
        }
Ejemplo n.º 5
0
		void ReadQueryResults ()
		{
			var fm = new NSFileManager ();

			var deadIndex = new HashSet<string> (fileIndex.Keys);
			var newList = new List<CloudFile> ();
			var newIndex = new Dictionary<string, IFile> ();

//			Console.WriteLine ("-------------- Received iCloud");

			foreach (var item in query.Results) {

				var cf = new CloudFile (item, documentsUrl);

				var key = cf.Path;

				if (deadIndex.Contains (key)) {
					deadIndex.Remove (key);
				}
				else {
					newList.Add (cf);
				}
				newIndex[key] = cf;

				//
				// Add a "file" for directories
				//
				var dir = Path.GetDirectoryName (cf.Path);
				if (!string.IsNullOrEmpty (dir) && !newIndex.ContainsKey (dir))
					newIndex [dir] = new DeviceFile (dir, documentsUrl.Path);


//				Console.WriteLine (cf);
			}

			foreach (var f in newList) {
				if (!f.IsDownloaded) {
					NSError error;
					fm.StartDownloadingUbiquitous (f.LocalUrl, out error);
				}
			}

			fileIndex = newIndex;

			IsSyncing = false;

			if (firstQueryResult != null) {
				var t = firstQueryResult;
				firstQueryResult = null;
				t.SetResult (null);
			}

			var ev = FilesChanged;
			if (ev != null) {
				ev (this, EventArgs.Empty);
			}
		}
Ejemplo n.º 6
0
		public Task<IFile> GetFile (string path)
		{
			var file = new DeviceFile (path, documentsPath);
			return Task.FromResult<IFile> (file);
		}
Ejemplo n.º 7
0
		public Task<IFile> CreateFile (string path, byte[] contents)
		{
			return Task.Run<IFile> (() => {
				var r = new DeviceFile (path, documentsPath);
				if (contents != null) {
					Directory.CreateDirectory (Path.GetDirectoryName (r.LocalPath));
					File.WriteAllBytes (r.LocalPath, contents);
				}
				return r;
			});
		}