public void NotifyElementRemoved(ITrackableJSObject jsObj, string collectionPropName, int position)
 {
     jsObj.IsTracked.MustBeTrue();
     this.ExecuteScriptFunction("CommonAPI.NotifyElementRemoved", new object[]
     {
         this.EscapeString(jsObj.TrackingCode),
         this.EscapeString(collectionPropName),
         this.EscapeJSObjectValue(position)
     });
 }
 private string CallJSConstructor(ITrackableJSObject trackable)
 {
     return(string.Concat(new string[]
     {
         "(CommonAPI.CreateViewObject(require('",
         trackable.ModulePath,
         "').",
         trackable.ConstructorFunction,
         ", ",
         this.EscapeJSObject(trackable.ToJavascriptObject()),
         "))"
     }));
 }
 public void NotifyPropertyChanged(ITrackableJSObject jsObj, string propName, object propValue)
 {
     if (!jsObj.IsTracked)
     {
         this.TrackObject(jsObj);
     }
     this.ExecuteScriptFunction("CommonAPI.NotifyPropertyChanged", new object[]
     {
         this.EscapeString(jsObj.TrackingCode),
         this.EscapeString(propName),
         this.EscapeJSObjectValue(propValue)
     });
 }
        public string EscapeJSObject(IJSObject o)
        {
            ITrackableJSObject trackableJSObject = o as ITrackableJSObject;

            if (trackableJSObject != null)
            {
                if (trackableJSObject.IsTracked)
                {
                    return("CommonAPI.GetTrackedObject(" + JavascriptSerializer.Serialize(trackableJSObject.TrackingCode) + ")");
                }
                if (trackableJSObject.ConstructorFunction != null)
                {
                    return(this.CallJSConstructor(trackableJSObject));
                }
            }
            return(JavascriptSerializer.Serialize(o.ToJavascriptObject()));
        }
        public void TrackObject(ITrackableJSObject obj)
        {
            this.ExecuteScriptFunction("CommonAPI.TrackObject", new object[]
            {
                this.EscapeJSObject(obj)
            });
            this.trackedObjects[obj.TrackingCode] = new WeakReference(obj);
            obj.IsTracked = true;
            int num2;

            lock (this)
            {
                int num = this.trackCounts;
                this.trackCounts = num + 1;
                num2             = num;
            }
            if (num2 > TRACKS_BEFORE_GC)
            {
                this.GC_TrackedObjects();
            }
        }
Ejemplo n.º 6
0
        public static NotifyCollectionChangedEventHandler CreateOnCollectionChangedHandler(IBindableJSContextProvider jsCtx, ITrackableJSObject jsObj, string collectionPropName)
        {
            return(delegate(object sender, NotifyCollectionChangedEventArgs e)
            {
                switch (e.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    jsCtx.NotifyElementAdded(jsObj, collectionPropName, e.NewStartingIndex, e.NewItems[0]);
                    return;

                case NotifyCollectionChangedAction.Remove:
                    jsCtx.NotifyElementRemoved(jsObj, collectionPropName, e.OldStartingIndex);
                    return;

                case NotifyCollectionChangedAction.Replace:
                    jsCtx.NotifyElementReplaced(jsObj, collectionPropName, e.OldStartingIndex, e.NewItems[0]);
                    return;

                case NotifyCollectionChangedAction.Move:
                    jsCtx.NotifyElementMoved(jsObj, collectionPropName, e.OldStartingIndex, e.NewStartingIndex);
                    return;

                case NotifyCollectionChangedAction.Reset:
                    jsCtx.NotifyPropertyChanged(jsObj, collectionPropName, new IJSObject[0]);
                    return;

                default:
                    throw new InvalidOperationException("Unexpected type of collection update");
                }
            });
        }