public void Can_create_CKAsset()
    {
        var url   = NSURL.URLWithString("file:///readme.txt");
        var asset = new CKAsset(url);

        Assert.Equals(asset.FileURL, url);
    }
Beispiel #2
0
        // Creates an Image from a UIImage (photo was taken from camera or photo library)
        public Image(UIImage image)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }

            CGImage rawImage = image.CGImage;

            using (CGImage cropped = Crop(rawImage)) {
                // Resizes image to be 1500 x 1500 px and saves it to a temporary file
                UIImage fullImage = Resize(cropped, image.CurrentScale, image.Orientation, new CGSize(1500, 1500));
                var     fullUrl   = SaveToTmp(fullImage, "toUploadFull.tmp");

                // Resizes thumbnail to be 200 x 200 px and then saves to different temp file
                UIImage thumbImage = Resize(cropped, image.CurrentScale, image.Orientation, new CGSize(200, 200));
                var     thumbURL   = SaveToTmp(thumbImage, "toUploadThumb.tmp");

                // Creates Image record type with two assets, full sized image and thumbnail sized image
                CKRecord newImageRecord = new CKRecord(RecordType);
                newImageRecord [FullsizeKey]  = new CKAsset(fullUrl);
                newImageRecord [ThumbnailKey] = new CKAsset(thumbURL);

                // Calls designated initalizer, this is a new image so it is not on the server
                Init(newImageRecord, false);
            }
        }
		public async Task<CKRecord> UploadAssetAsync (NSUrl assetUrl)
		{
			var assetRecord = new CKRecord (PhotoAssetRecordType);
			var photo = new CKAsset (assetUrl);
			assetRecord [PhotoAssetField] = photo;

			return await publicDatabase.SaveRecordAsync (assetRecord);
		}
Beispiel #4
0
        public async Task <CKRecord> UploadAssetAsync(NSUrl assetUrl)
        {
            var assetRecord = new CKRecord(PhotoAssetRecordType);
            var photo       = new CKAsset(assetUrl);

            assetRecord [PhotoAssetField] = photo;

            return(await publicDatabase.SaveRecordAsync(assetRecord));
        }
Beispiel #5
0
    public void Can_set_and_retrieve_asset_by_key()
    {
        var record   = new CKRecord("record_type");
        var asset    = new CKAsset(NSURL.URLWithString("file:///someasset.bytes"));
        var assetKey = "asset_key";

        record.SetAsset(asset, assetKey);

        Assert.AreEqual(record.AssetForKey(assetKey), asset);
    }
		public async override Task<Results> Run ()
		{
			string recordName, zoneName;
			if (!TryGetString ("recordName", out recordName) || !TryGetString ("zoneName", out zoneName))
				throw new InvalidProgramException ();

			var container = CKContainer.DefaultContainer;
			var privateDB = container.PrivateCloudDatabase;

			var recordType = "Items";

			CKRecord record;
			if (string.IsNullOrWhiteSpace(zoneName)) {
				record = string.IsNullOrWhiteSpace (recordName)
						? new CKRecord (recordType)
						: new CKRecord (recordType, new CKRecordID (recordName));
			} else {
				var zoneID = new CKRecordZoneID (zoneName, CKContainer.OwnerDefaultName);
				record = string.IsNullOrWhiteSpace (recordName)
						? new CKRecord (recordType, zoneID)
						: new CKRecord (recordType, new CKRecordID (recordName, zoneID));
			}

			string name;
			if (TryGetString ("name", out name))
				record ["name"] = (NSString)name;

			CLLocation location;
			if (TryGetLocation("location", out location))
				record ["location"] = location;

			NSUrl url;
			if (TryGetUrl ("asset", out url))
				record ["asset"] = new CKAsset (url);

			try {
				CKRecord rec = await privateDB.SaveRecordAsync (record);
				return ProcessResult (rec);
			} catch (NSErrorException ex) {
				// In this case we are trying to overwrite an existing record so let's fetch it and modify it.
				if (ex.Error.Code == 14) {
					var rec = await privateDB.FetchRecordAsync (record.Id);
					if (rec != null) {
						foreach (var key in record.AllKeys ())
							rec [key] = record [key];
						rec = await privateDB.SaveRecordAsync (rec);
						return ProcessResult (rec);
					}
				}
				throw ex;
			}
		}
    private void OnRecordSaved(CKRecord record, NSError error)
    {
        if (error != null)
        {
            Debug.LogError(error.LocalizedDescription);
        }
        else
        {
            Debug.Log(string.Format("Record saved with name: {0}", record.RecordID.RecordName));
            // Once saved, the FileURL may (but may not) point to a URL with the
            // asset contents. It may still point to the local filesys
            // See: https://developer.apple.com/documentation/cloudkit/ckasset/1515050-fileurl?language=objc

            CKAsset asset = record.AssetForKey("MyAsset");
            Debug.Log("Asset data is now at: " + asset.FileURL.AbsoluteString);
            StartCoroutine(GetRequest(asset.FileURL.AbsoluteString));
        }
    }
Beispiel #8
0
		// Creates an Image from a UIImage (photo was taken from camera or photo library)
		public Image (UIImage image)
		{
			if (image == null)
				throw new ArgumentNullException ("image");

			CGImage rawImage = image.CGImage;
			using (CGImage cropped = Crop (rawImage)) {
				// Resizes image to be 1500 x 1500 px and saves it to a temporary file
				UIImage fullImage = Resize (cropped, image.CurrentScale, image.Orientation, new CGSize (1500, 1500));
				var fullUrl = SaveToTmp (fullImage, "toUploadFull.tmp");

				// Resizes thumbnail to be 200 x 200 px and then saves to different temp file
				UIImage thumbImage = Resize (cropped, image.CurrentScale, image.Orientation, new CGSize (200, 200));
				var thumbURL = SaveToTmp (thumbImage, "toUploadThumb.tmp");

				// Creates Image record type with two assets, full sized image and thumbnail sized image
				CKRecord newImageRecord = new CKRecord (RecordType);
				newImageRecord [FullsizeKey] = new CKAsset (fullUrl);
				newImageRecord [ThumbnailKey] = new CKAsset (thumbURL);

				// Calls designated initalizer, this is a new image so it is not on the server
				Init (newImageRecord, false);
			}
		}
        public async override Task <Results> Run()
        {
            string recordName, zoneName;

            if (!TryGetString("recordName", out recordName) || !TryGetString("zoneName", out zoneName))
            {
                throw new InvalidProgramException();
            }

            var container = CKContainer.DefaultContainer;
            var privateDB = container.PrivateCloudDatabase;

            var recordType = "Items";

            CKRecord record;

            if (string.IsNullOrWhiteSpace(zoneName))
            {
                record = string.IsNullOrWhiteSpace(recordName)
                                                ? new CKRecord(recordType)
                                                : new CKRecord(recordType, new CKRecordID(recordName));
            }
            else
            {
                var zoneID = new CKRecordZoneID(zoneName, CKContainer.OwnerDefaultName);
                record = string.IsNullOrWhiteSpace(recordName)
                                                ? new CKRecord(recordType, zoneID)
                                                : new CKRecord(recordType, new CKRecordID(recordName, zoneID));
            }

            string name;

            if (TryGetString("name", out name))
            {
                record ["name"] = (NSString)name;
            }

            CLLocation location;

            if (TryGetLocation("location", out location))
            {
                record ["location"] = location;
            }

            NSUrl url;

            if (TryGetUrl("asset", out url))
            {
                record ["asset"] = new CKAsset(url);
            }

            try {
                CKRecord rec = await privateDB.SaveRecordAsync(record);

                return(ProcessResult(rec));
            } catch (NSErrorException ex) {
                // In this case we are trying to overwrite an existing record so let's fetch it and modify it.
                if (ex.Error.Code == 14)
                {
                    var rec = await privateDB.FetchRecordAsync(record.Id);

                    if (rec != null)
                    {
                        foreach (var key in record.AllKeys())
                        {
                            rec [key] = record [key];
                        }
                        rec = await privateDB.SaveRecordAsync(rec);

                        return(ProcessResult(rec));
                    }
                }
                throw ex;
            }
        }