コード例 #1
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);
			}
		}
コード例 #2
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);
            }
        }
コード例 #3
0
		public Task<IFile> CreateFile (string path, byte[] contents)
		{
			var tcs = new TaskCompletionSource<IFile> ();

			var f = new CloudFile (path, documentsUrl);

			if (contents != null) {
				Task.Factory.StartNew (() => {
					var c = new NSFileCoordinator (filePresenterOrNil: null);
					NSError coordErr;
					c.CoordinateWrite (f.LocalUrl, NSFileCoordinatorWritingOptions.ForReplacing, out coordErr, newUrl => {

						var newPath = newUrl.Path;

//						Console.WriteLine ("CLOUD WRITE TO " + newUrl + "    from: " + f.LocalUrl + "    at: " + newPath);

						var dir = Path.GetDirectoryName (newPath);
						if (!string.IsNullOrEmpty (dir) && dir != "/" && !Directory.Exists (dir)) {
							Directory.CreateDirectory (dir);
						}

						try {
							File.WriteAllBytes (newPath, contents);
							tcs.SetResult (f);							
						} catch (Exception ex) {
							tcs.SetException (ex);
						}
					});
					if (coordErr != null) {
						tcs.SetException (new Exception ("Could not coordinate iCloud write for CreateFile: " + coordErr.DebugDescription));
					}
				});
			} else {
				tcs.SetResult (f);
			}

			return tcs.Task;
		}