Exemple #1
0
        public int Begin(NSIndexSet aIndices, object aSource, NSPasteboard aPasteboard)
        {
            // build list of indices to be dragged
            List <int> indices = new List <int>();

            uint index = aIndices.FirstIndex;

            while (index != FoundationFramework.NSNotFound)
            {
                indices.Add((int)index);
                index = aIndices.IndexGreaterThanIndex(index);
            }

            // set the current data to be dragged
            DragDropManager.Current = iController.DragBegin(indices, aSource);

            // add a token to the pasteboard
            PasteboardViewDragData token = new PasteboardViewDragData();
            NSData tokenData             = NSKeyedArchiver.ArchivedDataWithRootObject(token);

            token.Release();

            aPasteboard.DeclareTypesOwner(NSArray.ArrayWithObject(PasteboardViewDragData.PboardType), null);
            aPasteboard.SetDataForType(tokenData, PasteboardViewDragData.PboardType);

            return(indices.Count);
        }
        public bool TableViewWriteToPasteboard(NSTableView aTableView, NSIndexSet aRows, NSPasteboard aPasteboard)
        {
            Console.WriteLine("TableViewWriteToPasteboard::" + aRows.Count);

            iDraggedBookmarks = new List <Bookmark>();

            uint index = aRows.FirstIndex;

            while (index != FoundationFramework.NSNotFound)
            {
                iDraggedBookmarks.Add(iBookmarks[(int)index].CastAs <BookmarkData>().Bookmark);
                index = aRows.IndexGreaterThanIndex(index);
            }


            // add a token to the pasteboard
            PasteboardViewDragDataBookmarks token = new PasteboardViewDragDataBookmarks();
            NSData tokenData = NSKeyedArchiver.ArchivedDataWithRootObject(token);

            token.Release();

            aPasteboard.DeclareTypesOwner(NSArray.ArrayWithObject(PasteboardViewDragDataBookmarks.PboardType), null);
            aPasteboard.SetDataForType(tokenData, PasteboardViewDragDataBookmarks.PboardType);
            iDragging = true;
            return(true);
        }
Exemple #3
0
        public void GetUnarchivedObject_TypeWrappers()
        {
            TestRuntime.AssertXcodeVersion(10, 0);

            NSDictionary <NSString, NSString> testValues = new NSDictionary <NSString, NSString> ((NSString)"1", (NSString)"a");

#if NET
            NSData data = NSKeyedArchiver.GetArchivedData(testValues, true, out NSError error);
#else
            NSData data = NSKeyedArchiver.ArchivedDataWithRootObject(testValues, true, out NSError error);
#endif
            Assert.IsNull(error);

            Type     dictionaryType  = typeof(NSDictionary <NSString, NSString>);
            Class    dictionaryClass = new Class(dictionaryType);
            NSObject o = NSKeyedUnarchiver.GetUnarchivedObject(dictionaryClass, data, out error);
            Assert.IsNotNull(o);
            Assert.IsNull(error, "GetUnarchivedObject - Class");

            o = NSKeyedUnarchiver.GetUnarchivedObject(new NSSet <Class> (new Class [] { dictionaryClass }), data, out error);
            Assert.IsNotNull(o);
            Assert.IsNull(error, "GetUnarchivedObject - NSSet<Class>");

            o = NSKeyedUnarchiver.GetUnarchivedObject(dictionaryType, data, out error);
            Assert.IsNotNull(o);
            Assert.IsNull(error, "GetUnarchivedObject - Type");

            o = NSKeyedUnarchiver.GetUnarchivedObject(new Type [] { dictionaryType }, data, out error);
            Assert.IsNotNull(o);
            Assert.IsNull(error, "GetUnarchivedObject - Type []");
        }
Exemple #4
0
        // Overrides required for drag and drop

        public override bool WriteRows(NSTableView tableView, Foundation.NSIndexSet rowIndexes, NSPasteboard pboard)
        {
            NSData data = NSKeyedArchiver.ArchivedDataWithRootObject(rowIndexes);

            pboard.DeclareTypes(new string[] { DungeonToolsConstants.ECOUNTER_INITIATIVE_DRAG_DROP_TYPE }, this);
            pboard.SetDataForType(data, DungeonToolsConstants.ECOUNTER_INITIATIVE_DRAG_DROP_TYPE);
            return(true);
        }
            public override bool WriteRows(NSTableView tableView, NSIndexSet rowIndexes, NSPasteboard pboard)
            {
                var item = new NSPasteboardItem();

                item.SetDataForType(NSKeyedArchiver.ArchivedDataWithRootObject(rowIndexes), DataTypeName);
                pboard.WriteObjects(new[] { item });
                return(true);
            }
Exemple #6
0
        async partial void SaveExperience()
        {
            var worldMap = await _sceneView.Session.GetCurrentWorldMapAsync();

            if (worldMap != null)
            {
                try
                {
                    // Add a snapshot image indicating where the map was captured.
                    var snapshotAnchor = SnapshotAnchor.Create(_sceneView);

                    if (snapshotAnchor != null)
                    {
                        var imageView = UIImage.LoadFromData(snapshotAnchor.ImageData);
                        _snapShotThumbnail.Hidden = false;
                        _snapShotThumbnail.Image  = imageView;
                        worldMap.Anchors          = worldMap.Anchors.Append(snapshotAnchor).ToArray();
                        Debug.WriteLine("Screenshot saved");
                    }
                    else
                    {
                        Debug.WriteLine("Snapshot anchor is null");
                    }
                }
                catch
                {
                    Debug.WriteLine("Can't take screenshot");
                    throw;
                }

                var data = NSKeyedArchiver.ArchivedDataWithRootObject(worldMap, true, out var err);

                if (err != null)
                {
                    Debug.WriteLine(err);
                    return;
                }

                try
                {
                    File.WriteAllBytes(MapSaveURL, data.ToArray());
                    DispatchQueue.MainQueue.DispatchAsync(() =>
                    {
                        _loadButton.Hidden  = false;
                        _loadButton.Enabled = true;
                    });
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Can't save map: {ex.Message}");
                }
            }
            else
            {
                Debug.WriteLine("Can't get current world map");
            }
        }
Exemple #7
0
        //
        // Save support:
        //    Override one of GetAsData, GetAsFileWrapper, or WriteToUrl.
        //

        // This method should store the contents of the document using the given typeName
        // on the return NSData value.
        public override NSData GetAsData(string documentType, out NSError outError)
        {
            outError = null;
            // End editing
            tableView.Window.EndEditingFor(null);

            // Create an NSData object from the cars array
            return(NSKeyedArchiver.ArchivedDataWithRootObject(Cars));
        }
Exemple #8
0
        public void AddWidgetTrackingEvent(WidgetTrackingEvent e)
        {
            var currentEvents = (NSMutableArray)getTrackableEvents(widgetInstalledKey).MutableCopy();

            currentEvents.Add(e);

            userDefaults[siriTrackingEventsKey] = NSKeyedArchiver.ArchivedDataWithRootObject(currentEvents);
            userDefaults.Synchronize();
        }
        private void SaveDocumentInDevice(DocumentArchive doc)
        {
            this.DocumentsDownloadedList.Add(doc);

            // Archiver document object
            NSData encodedObject = NSKeyedArchiver.ArchivedDataWithRootObject(this.DocumentsDownloadedList);

            NSUserDefaults.StandardUserDefaults.SetValueForKey(encodedObject, DocumentSavedKey);
            NSUserDefaults.StandardUserDefaults.Synchronize();
        }
Exemple #10
0
        private NSDataItem(IMimeItem item)
        {
            var nsObject = item.Value.ToNSObject();

            if (nsObject != null)
            {
                NSUti         = item.ToNsUti();
                KeyedArchiver = NSKeyedArchiver.ArchivedDataWithRootObject(nsObject);
            }
        }
Exemple #11
0
        public override bool WriteRows(NSTableView tableView, NSIndexSet rowIndexes, NSPasteboard pboard)
        {
            // Copy the row numbers to the pasteboard.
            NSData zNSIndexSetData = NSKeyedArchiver.ArchivedDataWithRootObject(rowIndexes);

            string[] typeArray = { "NSStringPboardType" };
            pboard.DeclareTypes(typeArray, this);
            pboard.SetDataForType(zNSIndexSetData, "NSStringPboardType");
            return(true);
        }
        /// <summary>
        /// Stores the provided video codec setting into the store.
        /// If the provided video codec is not part of the available video codecs
        /// the store operation will not be executed and NO will be returned.
        /// </summary>
        /// <param name="videoCodec">video codec settings the string to be stored.</param>
        /// <returns>YES/NO depending on success.</returns>
        public bool StoreVideoCodecSetting(RTCVideoCodecInfo videoCodec)
        {
            if (!AvailableVideoCodecs.Contains(videoCodec))
            {
                return(false);
            }
            var codecData = NSKeyedArchiver.ArchivedDataWithRootObject(videoCodec);

            _settingStore.VideoCodec = codecData;
            return(true);
        }
        // First, cleans out the internal identifier structures, then saves
        // the `accessoryToCharacteristicIdentifiers` map and `accessoryIdentifiers` array into `NSUserDefaults`.
        // This method should be called whenever a change is made to the internal structures.
        void Save()
        {
            RemoveUnusedIdentifiers();

            var userDefaults = NSUserDefaults.StandardUserDefaults;

            NSDictionary nativeMap = Convert(accessoryToCharacteristicIdentifiers);
            var          mapData   = NSKeyedArchiver.ArchivedDataWithRootObject(nativeMap);

            userDefaults [accessoryToCharacteristicIdentifierMappingKey] = mapData;
        }
 public NSObject GetPasteboardPropertyListForType(string type)
 {
     if (type == _pasteboardItemName)
     {
         return(NSKeyedArchiver.ArchivedDataWithRootObject(this));
     }
     else
     {
         return(null);
     }
 }
        //Save stored scores to file
        public void writeStoredScore()
        {
            NSError err;
            NSData  archivedScore = NSKeyedArchiver.ArchivedDataWithRootObject(storedScores);

            archivedScore.Save(this.storedScoresFilename, NSDataWritingOptions.FileProtectionNone, out err);
            if (err != null)
            {
                Console.WriteLine("Error when saving stored scores.");
            }
        }
Exemple #16
0
        //
        // Save support:
        //    Override one of GetAsData, GetAsFileWrapper, or WriteToUrl.
        //

        // This method should store the contents of the document using the given typeName
        // on the return NSData value.
        public override NSData GetAsData(string documentType, out NSError outError)
        {
            outError = null;
            // End editing
            tableView.Window.EndEditingFor(null);

            // Create an NSData object from the employees array
            return(NSKeyedArchiver.ArchivedDataWithRootObject(Employees));

            // Default template code
//			outError = NSError.FromDomain(NSError.OsStatusErrorDomain, -4);
//			return null;
        }
 // Saves the OIDAuthState to NSUSerDefaults.
 private void SaveState()
 {
     // for production usage consider using the OS Keychain instead
     if (AuthState != null)
     {
         var archivedAuthState = NSKeyedArchiver.ArchivedDataWithRootObject(AuthState);
         NSUserDefaults.StandardUserDefaults[kAppAuthExampleAuthStateKey] = archivedAuthState;
     }
     else
     {
         NSUserDefaults.StandardUserDefaults.RemoveObject(kAppAuthExampleAuthStateKey);
     }
     NSUserDefaults.StandardUserDefaults.Synchronize();
 }
Exemple #18
0
        //
        // Save support:
        //    Override one of GetAsData, GetAsFileWrapper, or WriteToUrl.
        //

        // This method should store the contents of the document using the given typeName
        // on the return NSData value.
        public override NSData GetAsData(string documentType, out NSError outError)
        {
            outError = null;
            NSMutableArray array = new NSMutableArray();

            foreach (Oval o in Ovals)
            {
                array.Add(o);
            }

            // Create an NSData object from the employees array
            NSData data = NSKeyedArchiver.ArchivedDataWithRootObject(array);

            return(data);
        }
Exemple #19
0
        public virtual NSObject GetPasteboardPropertyListForType(string type)
        {
            // Take action based on the requested type
            switch (type)
            {
            case "com.xamarin.image-info":
                return(NSKeyedArchiver.ArchivedDataWithRootObject(this));

            case "public.text":
                return(new NSString(string.Format("{0}.{1}", Name, ImageType)));
            }

            // Failure, return null
            return(null);
        }
Exemple #20
0
 private void CompressMap(ARWorldMap map, Action <NSData, NSError> closure)
 {
     DispatchQueue.DefaultGlobalQueue.DispatchAsync(() =>
     {
         var data = NSKeyedArchiver.ArchivedDataWithRootObject(map, true, out NSError error);
         if (error == null)
         {
             closure(data, null);
         }
         else
         {
             // archiving failed
             closure(null, error);
         }
     });
 }
        public override NSObject ContentsForType(string typeName, out NSError outError)
        {
            outError = null;
            NSData serializedList = NSKeyedArchiver.ArchivedDataWithRootObject(List);

            if (serializedList != null)
            {
                return(serializedList);
            }

            outError = new NSError(NSError.CocoaErrorDomain, (int)NSCocoaError.FileReadUnknown, new NSDictionary(
                                       NSError.LocalizedDescriptionKey, "Could not save file",
                                       NSError.LocalizedFailureReasonErrorKey, "An unexpected error occured"
                                       ));

            return(null);
        }
        public Task <OfflinePack> DownloadMap(OfflinePackRegion formsRegion, Dictionary <string, string> packInfo, IOfflineStorageDelegate downloadDelegate = null)
        {
            this.downloadDelegate = downloadDelegate;
            var tsc    = new TaskCompletionSource <OfflinePack>();
            var region = new MGLTilePyramidOfflineRegion(
                new NSUrl(formsRegion.StyleURL),
                new MGLCoordinateBounds()
            {
                sw = TypeConverter.FromPositionToCoordinate(formsRegion.Bounds.SouthWest),
                ne = TypeConverter.FromPositionToCoordinate(formsRegion.Bounds.NorthEast)
            },
                formsRegion.MinimumZoomLevel,
                formsRegion.MaximumZoomLevel);
            NSData context = null;

            if (packInfo != null)
            {
                var keys   = new List <NSString>();
                var values = new List <NSString>();
                foreach (string key in packInfo.Keys)
                {
                    keys.Add((NSString)key);
                    values.Add((NSString)packInfo[key]);
                }
                var userInfo = NSDictionary.FromObjectsAndKeys(keys.ToArray(), values.ToArray());
                context = NSKeyedArchiver.ArchivedDataWithRootObject(userInfo);
            }

            MGLOfflineStorage.SharedOfflineStorage().AddPackForRegion(region, context, (pack, error) =>
            {
                if (error != null)
                {
                    System.Diagnostics.Debug.WriteLine("Couldn't create offline pack: " + error.LocalizedFailureReason);
                    tsc.TrySetResult(null);
                }
                else
                {
                    pack.Resume();
                    var formsPack = pack.ToFormsPack();
                    tempPacks.Add(pack.GetNativeHash(), formsPack);
                    tsc.TrySetResult(formsPack);
                }
            });

            return(tsc.Task);
        }
Exemple #23
0
 // Writes the data to `NSUserDefaults`
 protected void WriteData()
 {
     UserDefaultsAccessQueue.DispatchAsync(() =>
     {
         try
         {
             NSData encodedData             = NSKeyedArchiver.ArchivedDataWithRootObject(ManagedDataBackingInstance);
             IgnoreLocalUserDefaultsChanges = true;
             UserDefaults.SetValueForKey(encodedData, (NSString)StorageDescriptor.Key);
             IgnoreLocalUserDefaultsChanges = false;
             NotifyClientsDataChanged();
         }
         catch (Exception e)
         {
             throw new Exception($"Could not save data. Reason: {e.Message}");
         }
     });
 }
Exemple #24
0
        public static void ClassInitialize()
        {
            // Create a Defaults dictionary
            NSMutableDictionary defaultValues = new NSMutableDictionary();

            // Archive the color object
            NSData colorAsData = NSKeyedArchiver.ArchivedDataWithRootObject(NSColor.White);

            // Put defaults in the dictionary
            defaultValues.SetValueForKey(colorAsData, DefaultStrings.RMTableBgColorKey);
            defaultValues.SetValueForKey(NSNumber.FromBoolean(true), DefaultStrings.RMEmptyDocKey);

            // Register the dictionary of defaults
            NSUserDefaults.StandardUserDefaults.RegisterDefaults(defaultValues);
            Console.WriteLine("Registered defaults: {0}", defaultValues);

            sFirstLaunch = true;
        }
Exemple #25
0
        public static IBinaryMessage Compose(NSEvent nsEvent)
        {
            return(BinaryMessage.Compose(Name, writer =>
            {
                try
                {
                    var data = NSKeyedArchiver.ArchivedDataWithRootObject(nsEvent);
                    var managedData = new byte[data.Length];
                    Marshal.Copy(data.Bytes, managedData, 0, (int)data.Length);

                    writer.Write((int)data.Length);
                    writer.Write(managedData);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }));
        }
Exemple #26
0
        public void StoreUbiquityIdentityToken()
        {
            NSUserDefaults defaults = NSUserDefaults.StandardUserDefaults;
            var            token    = NSFileManager.DefaultManager.UbiquityIdentityToken;

            if (token != null)
            {
                // the account has changed
                NSData ubiquityIdentityTokenArchive = NSKeyedArchiver.ArchivedDataWithRootObject(token);
                defaults [StoredUbiquityIdentityTokenKey] = ubiquityIdentityTokenArchive;
            }
            else
            {
                // the is no signed-in account
                defaults.RemoveObject(StoredUbiquityIdentityTokenKey);
            }

            defaults.Synchronize();
        }
        // GetWorldMap
        partial void shareSession(RoundedButton sender)
        {
            this.sceneView.Session.GetCurrentWorldMap((worldMap, error) =>
            {
                if (worldMap != null)
                {
                    var data = NSKeyedArchiver.ArchivedDataWithRootObject(worldMap, true, out NSError archivError);
                    if (archivError != null)
                    {
                        throw new Exception("can't encode map");
                    }

                    this.multipeerSession.SendToAllPeers(data);
                }
                else if (error != null)
                {
                    Console.WriteLine($"Error: {error.LocalizedDescription}");
                }
            });
        }
        partial void handleSceneTap(UITapGestureRecognizer sender)
        {
            // Hit test to find a place for a virtual object.
            var types         = ARHitTestResultType.ExistingPlaneUsingGeometry | ARHitTestResultType.EstimatedHorizontalPlane;
            var hitTestResult = this.sceneView.HitTest(sender.LocationInView(this.sceneView), types).FirstOrDefault();

            if (hitTestResult != null)
            {
                // Place an anchor for a virtual character. The model appears in renderer(_:didAdd:for:).
                var anchor = new ARAnchor("panda", hitTestResult.WorldTransform);
                this.sceneView.Session.AddAnchor(anchor);

                // Send the anchor info to peers, so they can place the same content.
                var data = NSKeyedArchiver.ArchivedDataWithRootObject(anchor, true, out NSError error);
                if (error != null)
                {
                    throw new Exception("can't encode anchor");
                }

                this.multipeerSession.SendToAllPeers(data);
            }
        }
Exemple #29
0
        //
        // Save support:
        //    Override one of GetAsData, GetAsFileWrapper, or WriteToUrl.
        //

        // This method should store the contents of the document using the given typeName
        // on the return NSData value.
        public override NSData GetAsData(string typeName, out NSError outError)
        {
            outError = null;
            // End editing
            tableView.Window.EndEditingFor(null);

            NSMutableArray array = new NSMutableArray();

            foreach (Person p in Employees)
            {
                array.Add(p);
            }

            // Create an NSData object from the employees array
            NSData data = NSKeyedArchiver.ArchivedDataWithRootObject(array);

            return(data);

            // Default template code
//			outError = NSError.FromDomain(NSError.OsStatusErrorDomain, -4);
//			return null;
        }
Exemple #30
0
        /// <summary>
        /// Generate a dictionary containing a time stamp and a random color data.
        /// </summary>
        private static NSDictionary <NSString, NSObject> GetTimedColor()
        {
            var random = new Random();
            var red    = (float)random.NextDouble();
            var green  = (float)random.NextDouble();
            var blue   = (float)random.NextDouble();

            var randomColor = UIColor.FromRGBA(red, green, blue, 1f);

            var data = NSKeyedArchiver.ArchivedDataWithRootObject(randomColor, false, out NSError error);

            if (data == null || error != null)
            {
                throw new Exception("Failed to archive a UIColor!");
            }

            var dateFormatter = new NSDateFormatter {
                TimeStyle = NSDateFormatterStyle.Medium
            };
            var timeString = dateFormatter.StringFor(new NSDate());

            return(NSDictionary <NSString, NSObject> .FromObjectsAndKeys(new NSObject[] { new NSString(timeString), data },
                                                                         new NSString[] { PayloadKey.TimeStamp, PayloadKey.ColorData }));
        }