Пример #1
0
        public static string GetSignature(this MethodDefinition methodDefinition, MapDelegate map = null)
        {
            var sb = new StringBuilder();

            sb.AppendMappedFullName(methodDefinition.ReturnType, map);
            sb.Append(" ");

            sb.Append("(");
            if (methodDefinition.HasParameters)
            {
                for (var i = 0; i < methodDefinition.Parameters.Count; i++)
                {
                    var parameterType = methodDefinition.Parameters[i].ParameterType;

                    if (i > 0)
                    {
                        sb.Append(",");
                    }

                    if (parameterType is SentinelType)
                    {
                        sb.Append("...,");
                    }

                    sb.AppendMappedFullName(parameterType, map);
                }
            }

            sb.Append(")");

            return(sb.ToString());
        }
Пример #2
0
 public void Map(MapDelegate funct)
 {
     for (int i = 0; i < _table.Length; i++)
     {
         _table[i] = funct(_table[i]);
     }
 }
        public override void MovedToWindow()
        {
            base.MovedToWindow();

            if (mapDelegate == null)
            {
                mapDelegate = new MapDelegate(Control);
            }

            if (clusterManager == null)
            {
                var iconGenerator = new GMUDefaultClusterIconGenerator();
                var algorithm     = new GMUNonHierarchicalDistanceBasedAlgorithm();
                var renderer      = new GMUDefaultClusterRenderer(Control, iconGenerator)
                {
                    WeakDelegate = mapDelegate
                };
                clusterManager = new GMUClusterManager(Control, algorithm, renderer);
                clusterManager.SetDelegate(mapDelegate, mapDelegate);

                SubscribeToMarkers();

                Element.SetMapReady(DateTime.UtcNow.Ticks);
            }
        }
Пример #4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Set up the cluster manager with default icon generator and renderer.
            var iconGenerator = new GMUDefaultClusterIconGenerator();
            var algorithm     = new GMUNonHierarchicalDistanceBasedAlgorithm();
            var renderer      = new GMUDefaultClusterRenderer(mapView: mapView, iconGenerator: iconGenerator);

            clusterManager = new GMUClusterManager(mapView: mapView, algorithm: algorithm, renderer: renderer);

            // Generate and add random items to the cluster manager.
            generateClusterItems();

            // Call cluster() after items have been added to perform the clustering and rendering on map.
            clusterManager.Cluster();

            // Register self to listen to both GMUClusterManagerDelegate and GMSMapViewDelegate events.
            var mapDelegate = new MapDelegate();

            clusterManager.SetDelegate(this, mapDelegate: mapDelegate);

            UIBarButtonItem removeButton = new UIBarButtonItem("Remove", UIBarButtonItemStyle.Plain, this, new ObjCRuntime.Selector("removeClusterManager"));

            NavigationItem.RightBarButtonItems = new UIBarButtonItem[] { removeButton };
        }
Пример #5
0
        /// <summary>
        /// Defines the View's <see cref="Couchbase.Lite.MapDelegate"/>
        /// and <see cref="Couchbase.Lite.ReduceDelegate"/>.
        /// </summary>
        /// <remarks>
        /// Defines a view's functions.
        /// The view's definition is given as a class that conforms to the Mapper or
        /// Reducer interface (or null to delete the view). The body of the block
        /// should call the 'emit' object (passed in as a paramter) for every key/value pair
        /// it wants to write to the view.
        /// Since the function itself is obviously not stored in the database (only a unique
        /// string idenfitying it), you must re-define the view on every launch of the app!
        /// If the database needs to rebuild the view but the function hasn't been defined yet,
        /// it will fail and the view will be empty, causing weird problems later on.
        /// It is very important that this block be a law-abiding map function! As in other
        /// languages, it must be a "pure" function, with no side effects, that always emits
        /// the same values given the same input document. That means that it should not access
        /// or change any external state; be careful, since callbacks make that so easy that you
        /// might do it inadvertently!  The callback may be called on any thread, or on
        /// multiple threads simultaneously. This won't be a problem if the code is "pure" as
        /// described above, since it will as a consequence also be thread-safe.
        /// </remarks>
        /// <returns>
        /// <c>true</c> if the <see cref="Couchbase.Lite.MapDelegate"/>
        /// and <see cref="Couchbase.Lite.ReduceDelegate"/> were set, otherwise <c>false</c>.
        /// If the values provided are identical to the values that are already set,
        /// then the values will not be updated and <c>false</c> will be returned.
        /// In addition, if <c>true</c> is returned, the index was deleted and
        /// will be rebuilt on the next <see cref="Couchbase.Lite.Query"/> execution.
        /// </returns>
        /// <param name="map">The <see cref="Couchbase.Lite.MapDelegate"/> to set.</param>
        /// <param name="reduce">The <see cref="Couchbase.Lite.ReduceDelegate"/> to set.</param>
        /// <param name="version">
        /// The key of the property value to return. The value of this parameter must change
        /// when the <see cref="Couchbase.Lite.MapDelegate"/> and/or <see cref="Couchbase.Lite.ReduceDelegate"/>
        /// are changed in a way that will cause them to produce different results.
        /// </param>
        public Boolean SetMapReduce(MapDelegate map, ReduceDelegate reduce, String version)
        {
            System.Diagnostics.Debug.Assert(map != null);
            System.Diagnostics.Debug.Assert(version != null); // String.Empty is valid.

            Map    = map;
            Reduce = reduce;

            if (!Database.Open())
            {
                return(false);
            }
            // Update the version column in the database. This is a little weird looking
            // because we want to
            // avoid modifying the database if the version didn't change, and because the
            // row might not exist yet.
            var storageEngine = this.Database.StorageEngine;

            // Older Android doesnt have reliable insert or ignore, will to 2 step
            // FIXME review need for change to execSQL, manual call to changes()
            var    sql    = "SELECT name, version FROM views WHERE name=?"; // TODO: Convert to ADO params.
            var    args   = new [] { Name };
            Cursor cursor = null;

            try
            {
                cursor = storageEngine.RawQuery(sql, args);

                if (!cursor.MoveToNext())
                {
                    // no such record, so insert
                    var insertValues = new ContentValues();
                    insertValues["name"]    = Name;
                    insertValues["version"] = version;
                    storageEngine.Insert("views", null, insertValues);
                    return(true);
                }

                var updateValues = new ContentValues();
                updateValues["version"]      = version;
                updateValues["lastSequence"] = 0;

                var whereArgs    = new [] { Name, version };
                var rowsAffected = storageEngine.Update("views", updateValues, "name=? AND version!=?", whereArgs);

                return(rowsAffected > 0);
            }
            catch (SQLException e)
            {
                Log.E(Database.Tag, "Error setting map block", e);
                return(false);
            }
            finally
            {
                if (cursor != null)
                {
                    cursor.Close();
                }
            }
        }
Пример #6
0
    // Start is called before the first frame update
    void Start()
    {
        _luaEnv.DoString(_luaScript);
        LogTool.Log($"luaA={_luaEnv.Global.Get<int>("a")}");
        LogTool.Log($"luaB={_luaEnv.Global.Get<string>("b")}");
        LogTool.Log($"luaC={_luaEnv.Global.Get<bool>("c")}");
        LogTool.Log($"luaD={_luaEnv.Global.Get<float>("d")}");
        //映射到class 值拷贝 发生修改互相不同步
        LogTool.Log("lua ValueClass1=", _luaEnv.Global.Get <ValueClass1>("valueClass1"));
        //映射到接扣 引用拷贝
        ILuaMap1 luaMap1 = _luaEnv.Global.Get <ILuaMap1>("valueClass1");

        LogTool.Log("lua映射到接口 调用方法 结果=", luaMap1.add(luaMap1.f1, luaMap1.f2));
        luaMap1.f2 = 9;
        _luaEnv.DoString("print(valueClass1.f2)");
        List <string> list = _luaEnv.Global.Get <List <string> >("byValueListTable");

        for (int i = 0; i < list.Count; i++)
        {
            LogTool.Log($"{i}=", list[i]);
        }
        Dictionary <string, int> dict = _luaEnv.Global.Get <Dictionary <string, int> >("byValueDictTable");

        LogTool.Log("dict.lenght=" + dict.Count);
        for (int i = 0; i < dict.Count; i++)
        {
            LogTool.Log($"{i}=", dict.ElementAt(i));
        }
        _luaEnv.DoString("byValueDictTable['one']=3");
        dict = _luaEnv.Global.Get <Dictionary <string, int> >("byValueDictTable");
        for (int i = 0; i < dict.Count; i++)
        {
            LogTool.Log($"{i}=", dict.ElementAt(i));
        }
        LuaTable luaTable = _luaEnv.Global.Get <LuaTable>("valueClass1");//映射到luaTable by ref

        LogTool.Log("f2=", luaTable.Get <int>("f2"));
//映射到delegate
        //lua多返回值的映射 从左到右填充
        MapDelegate mapDelegate = _luaEnv.Global.Get <MapDelegate>("map2Delegate");
        ValueClass1 c;
        string      result = mapDelegate(10, true, out c);

        LogTool.Log("result=" + result + "c=" + c);
        //系统委托的映射
        Action action = _luaEnv.Global.Get <Action>("action");

        action();
//映射到LuaFunction
        LuaFunction luaFunction = _luaEnv.Global.Get <LuaFunction>("action");

        luaFunction.Call();
        luaFunction = _luaEnv.Global.Get <LuaFunction>("map2Delegate");
        ValueClass1 valueClass1 = null;

        object [] a = luaFunction.Call(1, false, valueClass1);
        LogTool.Log("a=" + a[0] + "c=" + c);
    }
Пример #7
0
        //*** JavaScript View ***//

        private Couchbase.Lite.View CompileView(Database db, string viewName, JObject viewProps)
        {
            JToken language;

            if (!viewProps.TryGetValue("language", out language))
            {
                language = "javascript";
            }
            JToken mapSource;

            if (!viewProps.TryGetValue("map", out mapSource))
            {
                return(null);
            }

            IViewCompiler viewCompiler = Couchbase.Lite.View.Compiler;
            IViewCompiler test         = new JSViewCompilerCopy();

            Couchbase.Lite.View.Compiler = test;
            MapDelegate mapBlock = Couchbase.Lite.View.Compiler.CompileMap(mapSource.Value <string>(), language.Value <string>());

            if (mapBlock == null)
            {
                return(null);
            }

            string mapID = db.Name + ":" + viewName + ":" + mapSource.Value <string>().GetHashCode();

            JToken         reduceSource = null;
            ReduceDelegate reduceBlock  = null;

            if (viewProps.TryGetValue("reduce", out reduceSource))
            {
                // Couchbase.Lite.View.compiler est null et Couchbase.Lite.Listener.JSViewCompiler est inaccessible (même avec la reflection)

                reduceBlock = Couchbase.Lite.View.Compiler.CompileReduce(reduceSource.Value <string>(), language.Value <string>());
                if (reduceBlock == null)
                {
                    return(null);
                }
                mapID += ":" + reduceSource.Value <string>().GetHashCode();
            }

            Couchbase.Lite.View view = db.GetView(viewName);
            view.SetMapReduce(mapBlock, reduceBlock, mapID);
            JToken collation = null;

            if (viewProps.TryGetValue("collation", out collation))
            {
                if ("raw".Equals((String)collation))
                {
                    // ???
                }
            }

            return(view);
        }
Пример #8
0
 /// <summary>
 /// Adds a global mapping function which will be executed for every property of the processed entities.
 /// The result of the <paramref name="mappingFunc"/> will be used to evaluate the value to be assigned to the processed property.
 /// </summary>
 /// <param name="mappingFunc">The mapping function</param>
 /// <returns></returns>
 public Config AddMapping(MapDelegate <object> mappingFunc)
 {
     if (GlobalMappings == null)
     {
         GlobalMappings = new List <MapDelegate <object> >();
     }
     GlobalMappings.Add(mappingFunc);
     return(this);
 }
        private void SetMapView()
        {
            var mapDelegate = new MapDelegate();
            var camera      = CameraPosition.FromCamera(cameraLatitude, cameraLongitude, 4);

            mapView          = MapView.FromCamera(CGRect.Empty, camera);
            mapView.Delegate = mapDelegate;
            View             = mapView;
        }
Пример #10
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                var mapModel = (Map)e.OldElement;
                MessagingCenter.Unsubscribe <Map, MapSpan>(this, MoveMessageName);
                ((ObservableCollection <Pin>)mapModel.Pins).CollectionChanged -= OnCollectionChanged;
            }

            if (e.NewElement != null)
            {
                var mapModel = (Map)e.NewElement;

                if (Control == null)
                {
                    MKMapView mapView = null;
#if __MOBILE__
                    if (FormsMaps.IsiOs9OrNewer)
                    {
                        // See if we've got an MKMapView available in the pool; if so, use it
                        mapView = MapPool.Get();
                    }
#endif
                    if (mapView == null)
                    {
                        // If this is iOS 8 or lower, or if there weren't any MKMapViews in the pool,
                        // create a new one
                        mapView = new MKMapView(RectangleF.Empty);
                    }

                    SetNativeControl(mapView);

                    var mkMapView   = (MKMapView)Control;
                    var mapDelegate = new MapDelegate(mapModel);
                    mkMapView.GetViewForAnnotation = mapDelegate.GetViewForAnnotation;
                    mkMapView.RegionChanged       += MkMapViewOnRegionChanged;
                }

                MessagingCenter.Subscribe <Map, MapSpan>(this, MoveMessageName, (s, a) => MoveToRegion(a), mapModel);
                if (mapModel.LastMoveToRegion != null)
                {
                    MoveToRegion(mapModel.LastMoveToRegion, false);
                }

                UpdateMapType();
                UpdateIsShowingUser();
                UpdateHasScrollEnabled();
                UpdateHasZoomEnabled();

                ((ObservableCollection <Pin>)mapModel.Pins).CollectionChanged += OnCollectionChanged;

                OnCollectionChanged(((Map)Element).Pins, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }
        }
Пример #11
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);
            if (isLoaded)
            {
                nativeMap.RemoveOverlays(nativeMap.Overlays);
            }

            if (e.NewElement == null)
            {
                return;
            }
            if (e.OldElement != null)
            {
                nativeMap = Control as MKMapView;
            }
            element            = Element as ExtendedMap;
            mapDelegate        = new MapDelegate();
            nativeMap          = Control as MKMapView;
            nativeMap.Delegate = null;
            nativeMap.Delegate = mapDelegate;

            var formsMap = (ExtendedMap)e.NewElement;

            CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[element.RouteCoordinates.Count];

            int    index     = 0;
            int    idCounter = 1;
            string icon      = "";

            icon = element.ImageSource;
            foreach (var circle in element.Circles)
            {
                var annot = new CustomAnnotation(new CLLocationCoordinate2D(circle.Position.Latitude, circle.Position.Longitude), element.CustomPins.FirstOrDefault().Label, "", false, icon);
                annot.Id = idCounter++;
                nativeMap.AddAnnotation(annot);
                //pinCollection.Add(annot.Id, item);
                annotations.Add(annot);
                var circleOverlay = MKCircle.Circle(new CLLocationCoordinate2D(circle.Position.Latitude, circle.Position.Longitude), circle.Radius);
                nativeMap.AddOverlay(circleOverlay);
            }

            foreach (var position in element.RouteCoordinates)
            {
                var annot = new CustomAnnotation(new CLLocationCoordinate2D(position.Latitude, position.Longitude), element.CustomPins.FirstOrDefault().Label, "", false, icon);
                annot.Id = idCounter++;
                nativeMap.AddAnnotation(annot);
                //pinCollection.Add(annot.Id, item);
                annotations.Add(annot);
                coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                index++;
            }
            var routeOverlay = MKPolyline.FromCoordinates(coords);

            nativeMap.AddOverlay(routeOverlay);
        }
Пример #12
0
        public static ListPoolList <T> Map <F>(ICollection <F> mapFrom, MapDelegate <T, F> mapFunc)
        {
            var a = Get();

            foreach (var item in mapFrom)
            {
                a.Add(mapFunc(item));
            }
            return(a);
        }
    protected override void OnElementChanged(ElementChangedEventArgs<View> e)
    {
      base.OnElementChanged(e);

      var mapDelegate = new MapDelegate();
      mapDelegate.MapTapped += MapDelegateOnMapTapped;
	_nativeMapView.Delegate = null;
      _nativeMapView.Delegate = mapDelegate;

      _customMap.CustomPins.CollectionChanged += HandleCollectionChanged;
    }
Пример #14
0
        public static OUT[] Map <IN, OUT>(IList <IN> list, MapDelegate <IN, OUT> map)
        {
            OUT[] result = new OUT[list.Count];

            int index = 0;

            foreach (IN element in list)
            {
                result[index++] = map(element);
            }
            return(result);
        }
Пример #15
0
        public static ArrayPoolArray <T> Map <F>(ICollection <F> mapFrom, MapDelegate <T, F> mapFunc)
        {
            var a = Get(mapFrom.Count);
            var i = 0;

            foreach (var item in mapFrom)
            {
                a.array[i] = mapFunc(item);
                i++;
            }
            return(a);
        }
Пример #16
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);

            var mapDelegate = new MapDelegate();

            mapDelegate.MapTapped  += MapDelegateOnMapTapped;
            _nativeMapView.Delegate = null;
            _nativeMapView.Delegate = mapDelegate;

            _customMap.CustomPins.CollectionChanged += HandleCollectionChanged;
        }
Пример #17
0
        internal Status Compile(IDictionary <string, object> viewProps, string language)
        {
            language = language ?? "javascript";
            string mapSource = viewProps.Get("map") as string;

            if (mapSource == null)
            {
                return(new Status(StatusCode.NotFound));
            }

            MapDelegate mapDelegate = Compiler.CompileMap(mapSource, language);

            if (mapDelegate == null)
            {
                Log.To.View.W(TAG, "{0} could not compile {1} map fn: {2}", Name, language,
                              new SecureLogString(mapSource, LogMessageSensitivity.PotentiallyInsecure));
                return(new Status(StatusCode.CallbackError));
            }

            string         reduceSource   = viewProps.Get("reduce") as string;
            ReduceDelegate reduceDelegate = null;

            if (reduceSource != null)
            {
                reduceDelegate = Compiler.CompileReduce(reduceSource, language);
                if (reduceDelegate == null)
                {
                    Log.To.View.W(TAG, "{0} could not compile {1} reduce fn: {2}", Name, language,
                                  new SecureLogString(reduceSource, LogMessageSensitivity.PotentiallyInsecure));
                    return(new Status(StatusCode.CallbackError));
                }
            }

            string version = Misc.HexSHA1Digest(Manager.GetObjectMapper().WriteValueAsBytes(viewProps));

            SetMapReduce(mapDelegate, reduceDelegate, version);
            DocumentType = viewProps.GetCast <string>("documentType");

            var options = viewProps.Get("options").AsDictionary <string, object>();

            Collation = ViewCollation.Unicode;
            if (options != null && options.ContainsKey("collation"))
            {
                string collation = options["collation"] as string;
                if (collation.ToLower().Equals("raw"))
                {
                    Collation = ViewCollation.Raw;
                }
            }

            return(new Status(StatusCode.Ok));
        }
Пример #18
0
        private void SetClusterManager()
        {
            mapDelegate = new MapDelegate(mapView);
            var iconGenerator = IconGeneratorWithImages();
            var algorithm     = new GMUNonHierarchicalDistanceBasedAlgorithm();
            var renderer      = new GMUDefaultClusterRenderer(mapView, iconGenerator)
            {
                WeakDelegate = mapDelegate
            };

            clusterManager = new GMUClusterManager(mapView, algorithm, renderer);
            clusterManager.SetDelegate(mapDelegate, mapDelegate);
            GenerateClusterItem();
            clusterManager.Cluster();
        }
 public override void ViewDidLoad ()
 {
     base.ViewDidLoad ();
     
     _md = new MapDelegate ();
     map.Delegate = _md;
    
     map.AddAnnotation (new RestaurantAnnotation[] { 
         new RestaurantAnnotation ("Mike's Pizza", "Gourmet Pizza Kitchen", new CLLocationCoordinate2D (41.86337816, -72.56874647), RestaurantKind.Pizza), 
         new RestaurantAnnotation ("Barb's Seafod", "Best Seafood in New England", new CLLocationCoordinate2D (41.96337816, -72.96874647), RestaurantKind.Seafood),
         new RestaurantAnnotation ("John's Pizza", "Deep Dish Style", new CLLocationCoordinate2D (41.45537816, -72.76874647), RestaurantKind.Pizza)});
    
     AddOverlays ();
     
     map.MapType = MKMapType.Hybrid;
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            _md          = new MapDelegate();
            map.Delegate = _md;

            map.AddAnnotation(new RestaurantAnnotation[] {
                new RestaurantAnnotation("Mike's Pizza", "Gourmet Pizza Kitchen", new CLLocationCoordinate2D(41.86337816, -72.56874647), RestaurantKind.Pizza),
                new RestaurantAnnotation("Barb's Seafod", "Best Seafood in New England", new CLLocationCoordinate2D(41.96337816, -72.96874647), RestaurantKind.Seafood),
                new RestaurantAnnotation("John's Pizza", "Deep Dish Style", new CLLocationCoordinate2D(41.45537816, -72.76874647), RestaurantKind.Pizza)
            });

            AddOverlays();

            map.MapType = MKMapType.Hybrid;
        }
Пример #21
0
        private void InitMap()
        {
            MapView = new MKMapView(View.Bounds);
            MapView.AutoresizingMask  = UIViewAutoresizing.FlexibleDimensions;
            MapView.ShowsUserLocation = true;
            LocationManager.RequestWhenInUseAuthorization();

            View.AddSubview(MapView);

            View.SendSubviewToBack(MapView);
            var mapDel = new MapDelegate();

            mapDel.FoodMarkerSelected += OnFoodMarkerSelected;
            MapView.Delegate           = mapDel;
            MapView.UserLocation.Title = "";
            RegisterToMapView();
        }
Пример #22
0
        private void InitializeMapView()
        {
            if (ViewModel.OrgEvent != null &&
                ViewModel.OrgEvent.Venues != null)
            {
                if (!_isMapViewInitialized)
                {
                    VenuesMapView.RemoveAnnotations(VenuesMapView.Annotations);

                    if (!(VenuesMapView.WeakDelegate is MapDelegate))
                    {
                        var mapDelegate = new MapDelegate
                        {
                            SelectAnnotationCommand = ViewModel.SelectVenueOnMapCommand,
                            ShowDetailsCommand      = ViewModel.NavigateVenueCommand
                        };
                        VenuesMapView.Delegate = mapDelegate;
                    }

                    var annotations = ViewModel.OrgEvent.Venues
                                      .SelectMany(v => v.Info.Addresses
                                                  .Select(a => new VenueAnnotation(v, a))).ToArray();
                    var coordinates = MapUtil.GetAnnotationsCoordinates(annotations);

                    VenuesMapView.SetRegion(MapUtil.CoordinateRegionForCoordinates(coordinates, MapMargin), false);
                    VenuesMapView.AddAnnotations(annotations);

                    if (ViewModel.SelectedVenueOnMap != null)
                    {
                        SelectVenueMapAnnotation(ViewModel.SelectedVenueOnMap);
                    }

                    _isMapViewInitialized = true;
                }
            }
            else
            {
                VenuesMapView.RemoveAnnotations(VenuesMapView.Annotations);
                _isMapViewInitialized = false;
            }
        }
        private void SetupMap()
        {

            //Init Map wiht Camera
            var camera = new CameraPosition(new CLLocationCoordinate2D(36.069082, -94.155976), 15, 30, 0);
            _mapView = MapView.FromCamera(RectangleF.Empty, camera);
            _mapView.MyLocationEnabled = true;

            //Add button to zoom to location
            _mapView.Settings.MyLocationButton = true;

            _mapView.MyLocationEnabled = true;
            _mapView.MapType = MapViewType.Hybrid;
            _mapView.Settings.SetAllGesturesEnabled(true);

            //Init MapDelegate
            _mapDelegate = new MapDelegate(_mapView);
            _mapView.Delegate = _mapDelegate;

            View = _mapView;
        }
Пример #24
0
        private void SetupMap()
        {
            //Init Map wiht Camera
            var camera = new CameraPosition(new CLLocationCoordinate2D(36.069082, -94.155976), 15, 30, 0);

            _mapView = MapView.FromCamera(RectangleF.Empty, camera);
            _mapView.MyLocationEnabled = true;

            //Add button to zoom to location
            _mapView.Settings.MyLocationButton = true;

            _mapView.MyLocationEnabled = true;
            _mapView.MapType           = MapViewType.Hybrid;
            _mapView.Settings.SetAllGesturesEnabled(true);

            //Init MapDelegate
            _mapDelegate      = new MapDelegate(_mapView);
            _mapView.Delegate = _mapDelegate;

            View = _mapView;
        }
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (disposing)
            {
                markerSubscription.Clear();

                clusterManager?.Dispose();
                mapDelegate?.Dispose();

                clusterManager = null;
                mapDelegate    = null;

                foreach (var item in renderedMarkers)
                {
                    item.Value.Dispose();
                }

                renderedMarkers.Clear();
            }
        }
Пример #26
0
        public void TestViewUpdateIndexWithLiveQuery()
        {
            var         view     = database.GetView("TestViewUpdateWithLiveQuery");
            MapDelegate mapBlock = (document, emitter) => emitter(document["name"], null);

            view.SetMap(mapBlock, "1.0");

            var rowCountAlwaysOne = true;
            var liveQuery         = view.CreateQuery().ToLiveQuery();

            liveQuery.Changed += (sender, e) =>
            {
                var count = e.Rows.Count;
                if (count > 0)
                {
                    rowCountAlwaysOne = rowCountAlwaysOne && (count == 1);
                }
            };

            liveQuery.Start();

            var properties = new Dictionary <string, object>();

            properties.Put("name", "test");
            var doc = database.CreateDocument();
            var rev = doc.PutProperties(properties);

            for (var i = 0; i < 50; i++)
            {
                rev = rev.CreateRevision(properties);
            }

            // Sleep to ensure that the LiveQuery is done all of its async operations.
            Thread.Sleep(5000);

            liveQuery.Stop();

            Assert.IsTrue(rowCountAlwaysOne);
        }
Пример #27
0
        /// <summary>
        /// Defines the View's <see cref="Couchbase.Lite.MapDelegate"/>
        /// and <see cref="Couchbase.Lite.ReduceDelegate"/>.
        /// </summary>
        /// <remarks>
        /// Defines a view's functions.
        /// The view's definition is given as a class that conforms to the Mapper or
        /// Reducer interface (or null to delete the view). The body of the block
        /// should call the 'emit' object (passed in as a paramter) for every key/value pair
        /// it wants to write to the view.
        /// Since the function itself is obviously not stored in the database (only a unique
        /// string idenfitying it), you must re-define the view on every launch of the app!
        /// If the database needs to rebuild the view but the function hasn't been defined yet,
        /// it will fail and the view will be empty, causing weird problems later on.
        /// It is very important that this block be a law-abiding map function! As in other
        /// languages, it must be a "pure" function, with no side effects, that always emits
        /// the same values given the same input document. That means that it should not access
        /// or change any external state; be careful, since callbacks make that so easy that you
        /// might do it inadvertently!  The callback may be called on any thread, or on
        /// multiple threads simultaneously. This won't be a problem if the code is "pure" as
        /// described above, since it will as a consequence also be thread-safe.
        /// </remarks>
        /// <returns>
        /// <c>true</c> if the <see cref="Couchbase.Lite.MapDelegate"/>
        /// and <see cref="Couchbase.Lite.ReduceDelegate"/> were set, otherwise <c>false</c>.
        /// If the values provided are identical to the values that are already set,
        /// then the values will not be updated and <c>false</c> will be returned.
        /// In addition, if <c>true</c> is returned, the index was deleted and
        /// will be rebuilt on the next <see cref="Couchbase.Lite.Query"/> execution.
        /// </returns>
        /// <param name="map">The <see cref="Couchbase.Lite.MapDelegate"/> to set.</param>
        /// <param name="reduce">The <see cref="Couchbase.Lite.ReduceDelegate"/> to set.</param>
        /// <param name="version">
        /// The key of the property value to return. The value of this parameter must change
        /// when the <see cref="Couchbase.Lite.MapDelegate"/> and/or <see cref="Couchbase.Lite.ReduceDelegate"/>
        /// are changed in a way that will cause them to produce different results.
        /// </param>
        public bool SetMapReduce(MapDelegate map, ReduceDelegate reduce, string version)
        {
            System.Diagnostics.Debug.Assert(map != null);
            System.Diagnostics.Debug.Assert(version != null); // String.Empty is valid.

            var changed = version != MapVersion;
            var shared  = Database.Shared;

            shared.SetValue("map", Name, Database.Name, map);
            shared.SetValue("mapVersion", Name, Database.Name, version);
            shared.SetValue("reduce", Name, Database.Name, reduce);

            if (changed)
            {
                Storage.SetVersion(version);
                if (_changed != null)
                {
                    _changed(this, null);
                }
            }

            return(changed);
        }
        void InitializeCouchbaseSummaryView()
        {
            var view = Database.GetView("Done");

            var mapBlock = new MapDelegate((doc, emit) =>
            {
                object date;
                doc.TryGetValue(CreationDatePropertyName, out date);

                object checkedOff;
                doc.TryGetValue(CheckboxPropertyName, out checkedOff);

                if (date != null)
                {
                    emit(new[] { checkedOff, date }, null);
                }
            });


            var reduceBlock = new ReduceDelegate((keys, values, rereduce) =>
            {
                var key = keys.Sum(data =>
                                   1 - (int)(((JArray)data)[0])
                                   );

                var result = new Dictionary <string, string>
                {
                    { "Label", "Items Remaining" },
                    { "Count", key.ToString() }
                };

                return(result);
            });

            view.SetMapReduce(mapBlock, reduceBlock, "1.1");
        }
        View InitializeCouchbaseView()
        {
            var view = Database.GetView(DefaultViewName);

            var mapBlock = new MapDelegate((doc, emit) =>
            {
                object date;
                doc.TryGetValue(CreationDatePropertyName, out date);

                object deleted;
                doc.TryGetValue(DeletedKey, out deleted);

                if (date != null && deleted == null)
                {
                    emit(date, doc);
                }
            });

            view.SetMap(mapBlock, "1.1");

            var validationBlock = new ValidateDelegate((revision, context) =>
            {
                if (revision.IsDeletion)
                {
                    return(true);
                }

                object date;
                revision.Properties.TryGetValue(CreationDatePropertyName, out date);
                return(date != null);
            });

            Database.SetValidation(CreationDatePropertyName, validationBlock);

            return(view);
        }
Пример #30
0
        public void InitMap(float zoomLevel
                            , bool zoom       = false
                            , bool compass    = true
                            , bool mapToolbar = true)
        {
            if (_controller.GetType() == typeof(MapView))
            {
                _mapDelegate = new MapDelegate(_controller as MapView);
            }
            else if (_controller.GetType() == typeof(ModeZoneFirstView))
            {
                _mapDelegate = new MapDelegate(_controller as ModeZoneFirstView);
            }
            else if (_controller.GetType() == typeof(MapHistoricView))
            {
                _mapDelegate = new MapDelegate(_controller as MapHistoricView);
            }
            else if (_controller.GetType() == typeof(MapAllSeekiosView))
            {
                _mapDelegate = new MapDelegate(_controller as MapAllSeekiosView);
            }

            MapViewControl.Delegate = _mapDelegate;
        }
    void InitializeCouchbaseSummaryView ()
    {
            var view = Database.GetExistingView("Done") ?? Database.GetView ("Done");
                
            var mapBlock = new MapDelegate ((doc, emit) => 
                {
                    object date;
                    doc.TryGetValue (CreationDatePropertyName, out date);

                    object checkedOff;
                    doc.TryGetValue ("check", out checkedOff);

                    if (date != null) {
                       emit (new[] { checkedOff, date }, null);
                    }
                });

        
            var reduceBlock = new ReduceDelegate ((keys, values, rereduce) => 
                {
                    var key = keys.Sum(data => 
                        1 - (int)(((JArray)data)[0])
                    );

                    var result = new Dictionary<string,string>
                    {
                        {"Label", "Items Remaining"},
                        {"Count", key.ToString ()}
                    };

                    return result;
                });

        view.SetMapReduce (mapBlock, reduceBlock, "1.1");
    }
Пример #32
0
        void setupScannedView()
        {
            viewScanned = db.GetView ("scanned-by-employee");

            var mapBlock = new MapDelegate ((doc, emit) =>
                {
                    object name;
                    doc.TryGetValue ("employee", out name);

                    object quantity;
                    doc.TryGetValue ("quantity", out quantity);
                    string q = quantity.ToString ();
                    int quant;
                    var ok = Int32.TryParse(q, out quant);

                    if (ok && name != null)
                        emit (name, quant);
                });

            viewScanned.SetMapReduce (mapBlock, Couchbase.Lite.Views.BuiltinReduceFunctions.Sum, "1.1");
        }
Пример #33
0
 /// <summary>
 /// Defines the <see cref="Couchbase.Lite.View"/>'s <see cref="Couchbase.Lite.MapDelegate"/> and sets
 /// its <see cref="Couchbase.Lite.ReduceDelegate"/> to null.
 /// </summary>
 /// <returns>
 /// True if the <see cref="Couchbase.Lite.MapDelegate"/> was set, otherwise false. If the values provided are
 /// identical to the values that are already set, then the values will not be updated and false will be returned.
 /// In addition, if true is returned, the index was deleted and will be rebuilt on the next
 /// <see cref="Couchbase.Lite.Query"/> execution.
 /// </returns>
 /// <param name="mapDelegate">The <see cref="Couchbase.Lite.MapDelegate"/> to set</param>
 /// <param name="version">
 /// The key of the property value to return. The value of this parameter must change when
 /// the <see cref="Couchbase.Lite.MapDelegate"/> is changed in a way that will cause it to
 /// produce different results.
 /// </param>
 public Boolean SetMap(MapDelegate mapDelegate, string version)
 {
     return(SetMapReduce(mapDelegate, null, version));
 }
 public ReadOnlyListDecorator( IList innerList, MapDelegate mapDelegate )
 {
     _innerList = innerList;
     _mapDelegate = mapDelegate;
 }
Пример #35
0
 /// <summary>Defines the <see cref="Couchbase.Lite.View"/>'s <see cref="Couchbase.Lite.MapDelegate"/> and sets 
 /// its <see cref="Couchbase.Lite.ReduceDelegate"/> to null.</summary>
 /// <returns>
 /// True if the <see cref="Couchbase.Lite.MapDelegate"/> was set, otherwise false.  If the values provided are 
 /// identical to the values that are already set, then the values will not be updated and false will be returned.  
 /// In addition, if true is returned, the index was deleted and will be rebuilt on the next 
 /// <see cref="Couchbase.Lite.Query"/> execution.
 /// </returns>
 public Boolean SetMap(MapDelegate mapDelegate, String version) {
     return SetMapReduce(mapDelegate, null, version);
 }
    View InitializeCouchbaseView ()
    {
        var view = Database.GetView (DefaultViewName);

        var mapBlock = new MapDelegate ((doc, emit) => 
        {
            object date;
            doc.TryGetValue (CreationDatePropertyName, out date);

            object deleted;
            doc.TryGetValue (DeletedKey, out deleted);

            if (date != null && deleted == null)
                emit (date, doc);
        });

        view.SetMap (mapBlock, "1.1");

        var validationBlock = new ValidateDelegate ((revision, context) =>
                {
                    if (revision.IsDeletion)
                        return true;

                    object date;
                    revision.Properties.TryGetValue (CreationDatePropertyName, out date);
                    return (date != null);
                });

        Database.SetValidation(CreationDatePropertyName, validationBlock);

        return view;
    }
Пример #37
0
 public ReadOnlyListDecorator(IList innerList, MapDelegate mapDelegate)
 {
     _innerList   = innerList;
     _mapDelegate = mapDelegate;
 }
Пример #38
0
 /// <summary>Constructor</summary>
 internal Query(Database database, MapDelegate mapFunction)
     : this(database, database.MakeAnonymousView())
 {
     TemporaryView = true;
     View.SetMap(mapFunction, string.Empty);
 }
Пример #39
0
        void setupSoldView()
        {
            viewSold = db.GetView ("sold-by-employee");

            var mapBlock = new MapDelegate ((doc, emit) =>
                {
                    object type;
                    doc.TryGetValue ("type", out type);
                    if (type != null) {
                        string t = type.ToString ();
                        if (t == "sale") {
                            object name;
                            doc.TryGetValue ("employee", out name);

                            object quantity;
                            doc.TryGetValue ("quantity", out quantity);
                            string q = quantity.ToString ();
                            int quant;
                            var ok = Int32.TryParse(q, out quant);

                            object price;
                            doc.TryGetValue ("price", out price);
                            string ps = price.ToString ();
                            Single pnum;
                            var ok2 = Single.TryParse(ps, out pnum);

                            if (ok && ok2 && name != null)
                                emit (name, quant * pnum);
                        }
                    }
                });

            viewSold.SetMapReduce (mapBlock, Couchbase.Lite.Views.BuiltinReduceFunctions.Sum, "1.3");
        }
Пример #40
0
        /// <summary>Defines a view's functions.</summary>
        /// <remarks>
        /// Defines a view's functions.
        /// The view's definition is given as a class that conforms to the Mapper or
        /// Reducer interface (or null to delete the view). The body of the block
        /// should call the 'emit' object (passed in as a paramter) for every key/value pair
        /// it wants to write to the view.
        /// Since the function itself is obviously not stored in the database (only a unique
        /// string idenfitying it), you must re-define the view on every launch of the app!
        /// If the database needs to rebuild the view but the function hasn't been defined yet,
        /// it will fail and the view will be empty, causing weird problems later on.
        /// It is very important that this block be a law-abiding map function! As in other
        /// languages, it must be a "pure" function, with no side effects, that always emits
        /// the same values given the same input document. That means that it should not access
        /// or change any external state; be careful, since callbacks make that so easy that you
        /// might do it inadvertently!  The callback may be called on any thread, or on
        /// multiple threads simultaneously. This won't be a problem if the code is "pure" as
        /// described above, since it will as a consequence also be thread-safe.
        /// </remarks>
        public Boolean SetMapReduce(MapDelegate map, ReduceDelegate reduce, String version) { 
            System.Diagnostics.Debug.Assert((map != null));
            System.Diagnostics.Debug.Assert(!String.IsNullOrWhiteSpace(version));

            Map = map;
            Reduce = reduce;

            if (!Database.Open())
            {
                return false;
            }
            // Update the version column in the database. This is a little weird looking
            // because we want to
            // avoid modifying the database if the version didn't change, and because the
            // row might not exist yet.
            var storageEngine = this.Database.StorageEngine;

            // Older Android doesnt have reliable insert or ignore, will to 2 step
            // FIXME review need for change to execSQL, manual call to changes()
            var sql = "SELECT name, version FROM views WHERE name=@"; // TODO: Convert to ADO params.
            var args = new [] { Name };
            Cursor cursor = null;

            try
            {
                cursor = storageEngine.RawQuery(sql, args);

                if (!cursor.MoveToNext())
                {
                    // no such record, so insert
                    var insertValues = new ContentValues();
                    insertValues["name"] = Name;
                    insertValues["version"] = version;
                    storageEngine.Insert("views", null, insertValues);
                    return true;
                }

                var updateValues = new ContentValues();
                updateValues["version"] = version;
                updateValues["lastSequence"] = 0;

                var whereArgs = new [] { Name, version };
                var rowsAffected = storageEngine.Update("views", updateValues, "name=@ AND version!=@", whereArgs);

                return (rowsAffected > 0);
            }
            catch (SQLException e)
            {
                Log.E(Database.Tag, "Error setting map block", e);
                return false;
            }
            finally
            {
                if (cursor != null)
                {
                    cursor.Close();
                }
            }
        }
Пример #41
0
 /// <summary>Constructor</summary>
 internal Query(Database database, MapDelegate mapFunction)
 : this(database, database.MakeAnonymousView())
 {
     TemporaryView = true;
     View.SetMap(mapFunction, string.Empty);
 }
Пример #42
0
 /// <summary>
 /// Creates a one-shot query with the given map function. This is equivalent to creating an
 /// anonymous View and then deleting it immediately after querying it. It may be useful during
 /// development, but in general this is inefficient if this map will be used more than once,
 /// because the entire view has to be regenerated from scratch every time.
 /// </summary>
 /// <returns>The query.</returns>
 /// <param name="map">Map.</param>
 internal Query SlowQuery(MapDelegate map) 
 {
     return new Query(this, map);
 }
Пример #43
0
        /// <summary>
        /// Defines the View's <see cref="Couchbase.Lite.MapDelegate"/> 
        /// and <see cref="Couchbase.Lite.ReduceDelegate"/>.
        /// </summary>
        /// <remarks>
        /// Defines a view's functions.
        /// The view's definition is given as a class that conforms to the Mapper or
        /// Reducer interface (or null to delete the view). The body of the block
        /// should call the 'emit' object (passed in as a paramter) for every key/value pair
        /// it wants to write to the view.
        /// Since the function itself is obviously not stored in the database (only a unique
        /// string idenfitying it), you must re-define the view on every launch of the app!
        /// If the database needs to rebuild the view but the function hasn't been defined yet,
        /// it will fail and the view will be empty, causing weird problems later on.
        /// It is very important that this block be a law-abiding map function! As in other
        /// languages, it must be a "pure" function, with no side effects, that always emits
        /// the same values given the same input document. That means that it should not access
        /// or change any external state; be careful, since callbacks make that so easy that you
        /// might do it inadvertently!  The callback may be called on any thread, or on
        /// multiple threads simultaneously. This won't be a problem if the code is "pure" as
        /// described above, since it will as a consequence also be thread-safe.
        /// </remarks>
        /// <returns>
        /// <c>true</c> if the <see cref="Couchbase.Lite.MapDelegate"/> 
        /// and <see cref="Couchbase.Lite.ReduceDelegate"/> were set, otherwise <c>false</c>.
        /// If the values provided are identical to the values that are already set, 
        /// then the values will not be updated and <c>false</c> will be returned. 
        /// In addition, if <c>true</c> is returned, the index was deleted and 
        /// will be rebuilt on the next <see cref="Couchbase.Lite.Query"/> execution.
        /// </returns>
        /// <param name="map">The <see cref="Couchbase.Lite.MapDelegate"/> to set.</param>
        /// <param name="reduce">The <see cref="Couchbase.Lite.ReduceDelegate"/> to set.</param>
        /// <param name="version">
        /// The key of the property value to return. The value of this parameter must change 
        /// when the <see cref="Couchbase.Lite.MapDelegate"/> and/or <see cref="Couchbase.Lite.ReduceDelegate"/> 
        /// are changed in a way that will cause them to produce different results.
        /// </param>
        public bool SetMapReduce(MapDelegate map, ReduceDelegate reduce, string version) { 
            System.Diagnostics.Debug.Assert(map != null);
            System.Diagnostics.Debug.Assert(version != null); // String.Empty is valid.

            var changed = version != MapVersion;
            var shared = Database.Shared;
            shared.SetValue("map", Name, Database.Name, map);
            shared.SetValue("mapVersion", Name, Database.Name, version);
            shared.SetValue("reduce", Name, Database.Name, reduce);

            if (changed) {
                Storage.SetVersion(version);
                if (_changed != null) {
                    _changed(this, null);
                }
            }

            return changed;
        }