示例#1
0
        private void OnObjectConnected(ObjectConnectedPayload data)
        {
            Debug.Assert(this.client.CheckAccess());

            OpenOperation operation;
            ObjectPayload objectPayload = data.ObjectPayload;

            if (this.pendingOpenOperations.TryGetValue(objectPayload.Name, out operation))
            {
                // This will occur when a client has called OpenObject for an object
                // We must verify that the object the user
                // is registering for is of the same type on the server as on the client
                if (objectPayload.Type != operation.Entry.Type.AssemblyQualifiedName)
                {
                    throw new Exception("The type of the object on the client does not match with the server");
                }
                this.pendingOpenOperations.Remove(objectPayload.Name);

                // Update all the properties on the local copy of the object
                operation.Entry.Update(objectPayload);
                operation.Entry.IsConnected = true;
                this.Add(operation.Entry);

                if (operation.Callback != null)
                {
                    // If callback was provided, call the opened callback
                    operation.Callback(new ObjectConnectedEventArgs(operation.Entry.Object, objectPayload.Name, data.Created));
                }
            }
            else
            {
                Debug.Assert(false, "Received ObjectConnected payload for object we did not open");
            }
        }
示例#2
0
        /// <summary>
        /// Return
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="exception"></param>
        /// <param name="isRecreate"></param>
        public void Recycle(ObjectPayload <SqlConnection> obj, Exception exception, bool isRecreate = false)
        {
            if (exception is SqlException)
            {
                if (obj.Value.Ping() == false)
                {
                    SetUnavailable(exception);
                }
            }

            base.Recycle(obj, isRecreate);
        }
示例#3
0
 /// <summary>
 /// Updates the local copy of any object based upon the contents of an ObjectPayload. This codepath
 /// is exercised when an existing named object is opened and the actual contents of the object are
 /// pushed down to the client which needs to then update the local object
 /// </summary>
 /// <param name="payload"></param>
 internal void Update(ObjectPayload payload)
 {
     try
     {
         this.IgnoreChanges = true;
         this.Id            = payload.Id;
         UpdateProperties(this.Object, payload);
     }
     finally
     {
         this.IgnoreChanges = false;
     }
 }
示例#4
0
        /// <summary>
        /// Constructor used for Incoming Objects
        /// </summary>
        /// <param name="client"></param>
        public ObjectEntry(SharedObjectsClient client, ObjectPayload payload)
        {
            this.client        = client;
            this.IgnoreChanges = true;

            this.Object     = this.GenerateSharedObject(payload);
            this.Name       = payload.Name;
            this.Id         = payload.Id;
            this.Attributes = payload.Attributes;
            this.IsDynamic  = payload.IsDynamic;
            this.Properties = new SharedPropertyDictionary(payload.SharedProperties);
            this.Parents    = new Dictionary <Guid, ParentEntry>();
            this.Type       = Type.GetType(payload.Type);
        }
示例#5
0
        private INotifyPropertyChanged GenerateSharedObject(ObjectPayload data)
        {
            ManualResetEvent       waitInit     = new ManualResetEvent(false);
            INotifyPropertyChanged sharedObject = null;

            // Create the object on the Dispatcher thread
            this.client.RunOnDispatcher(() =>
            {
                sharedObject = ConstructSharedType(data.Type);
                UpdateProperties(sharedObject, data);
                waitInit.Set();
            });

            waitInit.WaitOne();
            return(sharedObject);
        }
示例#6
0
        private void OnObjectPayload(ObjectPayload data)
        {
            Debug.Assert(this.client.CheckAccess());

            // Check if this is a locally pending object creation
            if (data.ClientId == this.client.ClientId)
            {
                // Nothing
                return;
            }
            else
            {
                // Create object from payload. Object will be set to IgnoreChanges
                ObjectEntry entry = new ObjectEntry(this.client, data);
                entry.IsConnected = true;
                this.Add(entry);
                entry.IgnoreChanges = false;
            }
        }
示例#7
0
        /// <summary>
        /// Update the properties of the target object with the contents of the ObjectPayload
        /// </summary>
        /// <param name="target"></param>
        /// <param name="data"></param>
        private void UpdateProperties(INotifyPropertyChanged target, ObjectPayload data)
        {
            this.client.VerifyAccess();

            Type targetType = target.GetType();

            IJsObject jsDictionary = target as IJsObject;

            if (jsDictionary != null)
            {
                // In case of JsObservableDictionary, we want to treat the properties in this payload as items of the dictionary
                foreach (SharedProperty sharedProp in data.SharedProperties.Values)
                {
                    jsDictionary[sharedProp.Name] = Json.ReadObject(DynamicTypeMapping.Instance.GetTypeFromValue(sharedProp.PropertyType), sharedProp.Value);
                }
            }
            else
            {
                foreach (SharedProperty sharedProp in data.SharedProperties.Values)
                {
                    Json.AssignProperty(target, sharedProp.Name, sharedProp.Value);
                }
            }
        }
示例#8
0
 /// <summary>
 /// Updates the local copy of any object based upon the contents of an ObjectPayload. This codepath
 /// is exercised when an existing named object is opened and the actual contents of the object are
 /// pushed down to the client which needs to then update the local object
 /// </summary>
 /// <param name="payload"></param>
 internal void Update(ObjectPayload payload)
 {
     try
     {
         this.IgnoreChanges = true;
         this.Id = payload.Id;
         UpdateProperties(this.Object, payload);
     }
     finally
     {
         this.IgnoreChanges = false;
     }
 }
示例#9
0
        /// <summary>
        /// Update the properties of the target object with the contents of the ObjectPayload
        /// </summary>
        /// <param name="target"></param>
        /// <param name="data"></param>
        private void UpdateProperties(INotifyPropertyChanged target, ObjectPayload data)
        {
            this.client.VerifyAccess();

            Type targetType = target.GetType();

            IJsObject jsDictionary = target as IJsObject;
            if (jsDictionary != null)
            {
                // In case of JsObservableDictionary, we want to treat the properties in this payload as items of the dictionary
                foreach (SharedProperty sharedProp in data.SharedProperties.Values)
                {
                    jsDictionary[sharedProp.Name] = Json.ReadObject(DynamicTypeMapping.Instance.GetTypeFromValue(sharedProp.PropertyType), sharedProp.Value);
                }
            }
            else
            {
                foreach (SharedProperty sharedProp in data.SharedProperties.Values)
                {
                    Json.AssignProperty(target, sharedProp.Name, sharedProp.Value);
                }
            }
        }
示例#10
0
        private INotifyPropertyChanged GenerateSharedObject(ObjectPayload data)
        {
            ManualResetEvent waitInit = new ManualResetEvent(false);
            INotifyPropertyChanged sharedObject = null;

            // Create the object on the Dispatcher thread
            this.client.RunOnDispatcher(() =>
            {
                sharedObject = ConstructSharedType(data.Type);
                UpdateProperties(sharedObject, data);
                waitInit.Set();
            });

            waitInit.WaitOne();
            return sharedObject;
        }
示例#11
0
        /// <summary>
        /// Constructor used for Incoming Objects
        /// </summary>
        /// <param name="client"></param>
        public ObjectEntry(SharedObjectsClient client, ObjectPayload payload)
        {
            this.client = client;
            this.IgnoreChanges = true;

            this.Object = this.GenerateSharedObject(payload);
            this.Name = payload.Name;
            this.Id = payload.Id;
            this.Attributes = payload.Attributes;
            this.IsDynamic = payload.IsDynamic;
            this.Properties = new SharedPropertyDictionary(payload.SharedProperties);
            this.Parents = new Dictionary<Guid, ParentEntry>();
            this.Type = Type.GetType(payload.Type);
        }
示例#12
0
 /// <summary>
 /// Return connection
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="connectionString"></param>
 /// <typeparam name="TConn"></typeparam>
 public static void Return <TConn>(ObjectPayload <TConn> obj, string connectionString)
     where TConn : IDbConnection
 {
     Pools.Get <TConn>(connectionString).Recycle(obj);
 }
示例#13
0
        public EventLinkPage()
        {
            var text = new Div()
            {
                Text = "Server Address:"
            };
            var textbox = new Input()
            {
                Value = "elipc:4040"
            };
            var div = new Div();

            div.Add(text);
            div.Add(textbox);
            Browser.Document.Body.Add(div);

            // Conventional DOM interaction
            var jsonButton = new Button {
                InnerHtml = "Test JSON..."
            };

            jsonButton.Click += e =>
            {
                MemoryStream    st  = new MemoryStream();
                PrincipalObject obj = new PrincipalObject()
                {
                    Sid = "sa", Id = "eli"
                };
                Console.WriteLine(obj);

                JsonPayloadWriter w = new JsonPayloadWriter(st);
                var pl = new ObjectPayload(Guid.NewGuid(), obj, Guid.NewGuid(), "ObjectName");
                Console.WriteLine(pl);
                w.Write(string.Empty, pl);
                StreamReader sr     = new StreamReader(st);
                string       output = sr.ReadToEnd();
                Console.WriteLine(output);
                return;



                //DUMMY TEST
                //string jsont = "{ \"ChannelName\": \"test\" }";
                //JsonPayloadReader jsr = new JsonPayloadReader(jsont);
                //Console.WriteLine(jsr.ReadString("ChannelName"));

                string ns             = "namespace1";
                string subscriptionId = "1234";
                Guid   clientId       = Guid.NewGuid();
                Guid   parentId       = Guid.NewGuid();
                Guid   objectId       = Guid.NewGuid();

                Payload payload = new ClientConnectPayload(subscriptionId, clientId, ns, NamespaceLifetime.ServerInstance);
                ETag    eTag    = new ETag(clientId, 2);
                string  json    = WriteToJson(payload);
                Console.WriteLine("WROTE: {0}", json);

                JsonPayloadReader jsonReader = new JsonPayloadReader(json);
                var payloadResult            = jsonReader.ReadObject <Payload>(string.Empty, Payload.CreateInstance);
                Console.WriteLine("READ OBJECT: {0}", payloadResult);

                EventSet[] events = new EventSet[]
                {
                    new EventSet {
                        Sequence = 0, ChannelName = "test", Payloads = new Payload[] { new ClientConnectPayload(subscriptionId, clientId, ns, NamespaceLifetime.ConnectedOnly) }
                    }
                };

                json = WriteToJson(events);
                Console.WriteLine(json);

                MemoryStream ms = new MemoryStream();
                StreamWriter sw = new StreamWriter(ms);
                sw.Write(json);
                sw.Flush();

                var eventsResult = EventSet.CreateEventSetsFromStream(ms, PayloadFormat.JSON);
                Console.WriteLine(eventsResult);

                var principal = new PrincipalObject()
                {
                    Id = "Eli", Sid = "sa"
                };
                var es = new EventSet {
                    Sequence = 0, ChannelName = "test", Payloads = new Payload[] { new ClientConnectPayload(subscriptionId, clientId, ns, NamespaceLifetime.ConnectedOnly, principal) }
                };

                json = WriteToJson(es);
                Console.Write(json);

                return;
            };
            Browser.Document.Body.Add(jsonButton);

            var soButton = new Button {
                InnerHtml = "Subscribe Shared Objects Client"
            };

            soButton.Click += e =>
            {
                var guid = Guid.NewGuid();
                var txt  = textbox.Value;

                string path = string.Format("http://{0}/{1}", txt, guid.ToString());

                SharedObjectsClient soc       = new SharedObjectsClient(path, NamespaceLifetime.ConnectedOnly);
                PrincipalObject     principal = new PrincipalObject()
                {
                    Id = "ClientA", Sid = "sa"
                };
                soc.PrincipalObject = principal;

                soc.Connect();
                Console.WriteLine("Connecting to:{0}", path);
                soc.Connected += (s, ec) =>
                {
                    Console.WriteLine("CONNECTED TO SHARED OBJECTS SERVER");
                };
            };
            Browser.Document.Body.Add(soButton);

            // Conventional DOM interaction
            var subButton = new Button {
                InnerHtml = "Subscribe..."
            };

            subButton.Click += e =>
            {
                Console.WriteLine("Subscribing...");

                Uri uri = new Uri("http://elipc:4040/");
                this.client = new EventLinkClient(uri, "3bb04637-af98-40e9-ad65-64fb2668a0d2", (s, ex) =>
                {
                    Console.WriteLine(string.Format("Error state:{0} exception:{1}", s, ex));
                });
                this.client.Subscribe("99ca2aff-538e-49f2-a71c-79b7720e3f21ClientControl", EventLinkEventsReceived, this.OnSubscriptionInitialized);
                return;

                //this.Channel = new EventLinkChannel(new Uri("http://elipc:4040/"), "nameSpace", (c1, c2) =>
                //{
                //    Write("Error state changed");
                //});

                //this.Channel.SubscriptionInitialized += OnIncomingChannelsInitialized;
                //this.Channel.EventsReceived += OnIncomingChannelsDataReceived;
                //string name = Channels.GetClientName(Guid.NewGuid());
                //this.Channel.SubscribeAsync(name);

                //Uri uri = new Uri("http://elipc:4040/");
                //this.client = new EventLinkClient(uri, "f148dc15-ad26-484e-9f74-8d0655e8fc0d", (s, ex) =>
                //{
                //    Console.WriteLine(string.Format("Error state:{0} exception:{1}", s, ex));
                //});
                //this.client.Subscribe("81dddf4c-f84c-414f-9f04-99f926fc8c68ClientControl", EventLinkEventsReceived, () => this.OnSubscriptionInitialized());
            };
            Browser.Document.Body.Add(subButton);

            // Conventional DOM interaction
            var secButton = new Button {
                InnerHtml = "Test Security..."
            };

            secButton.Click += e =>
            {
                Console.WriteLine("sec");

                //var el = new EventLinkClient(new Uri("http://localhost:4040/"), "partitionA", (c) =>
                //{
                //    Write("EventLinkClient Connected");
                //});

                //var att = new SharedAttributes();
                //Write(att);

                //var client = new SharedObjectsClient("http://www.cnn.com/namespaceName");
                //Write(client);

                //client.Connect();

                Guid g = Guid.NewGuid();
                Console.WriteLine(g);

                Guid g2 = Guid.Empty;
                Console.WriteLine(g2);

                ETag e2 = new ETag(Guid.Empty);
                Console.WriteLine(e2);

                SharedObjectSecurity s = new SharedObjectSecurity("Security", false, new ETag(Guid.Empty));
                s.AddAccessRule(new SharedObjectAccessRule("Idenity", ObjectRights.ChangePermissions, System.Security.AccessControl.InheritanceFlags.ContainerInherit, System.Security.AccessControl.AccessControlType.Allow));
                Console.WriteLine(s);

                PrincipalObject p = new PrincipalObject()
                {
                    Id = "Hello", Sid = "Sid"
                };
                Console.WriteLine(p);

                SharedEntryMap <SampleEntry> map = new SharedEntryMap <SampleEntry>();
                Console.WriteLine(map);

                var attr = new SharedAttributes();
                Console.WriteLine(attr);

                var ep = new ObjectExpirationPolicy("timespan", TimeSpan.FromDays(1), TimeSpan.FromMilliseconds(100));
                Console.WriteLine(ep);

                var v = new ProtocolVersion(1, 0);
                Console.WriteLine(v);

                //var tp = new TracePayload("Message", Guid.Empty);
                //Write(tp);



                //ObjectDeletedPayload p2 = new ObjectDeletedPayload(Guid.Empty, Guid.NewGuid());
                //Write(p2);

                ////WAIT FOR SAHRED PROEPRPT
                ////ClientConnectPayload c = new ClientConnectPayload("sub", Guid.Empty, "namespace");
                ////Write(c);



                //var principalObject = new PrincipalObject() { Id = "Eli", Sid = "sa" };
                ////                var principal = new ObjectPayload(Guid.NewGuid(), principalObject, Guid.NewGuid(), "NamedObject");

                //var sharedProps = new Dictionary<short, SharedProperty>();
                //Write(sharedProps);

                ////TODO THIS IS BROKEN
                ////var spd = new SharedPropertyDictionary();
                ////Write(spd);

                //var puo = new PropertyUpdateOperation();
                //Write(puo);



                //JavascriptHttpStream str = new JavascriptHttpStream(null);
                //BinaryReader br = new BinaryReader(str);
                //BinaryWriter bw = new BinaryWriter(str);
                //BinaryReader br = new BinaryReader(null);
                //BinaryWriter bw = new BinaryWriter(null);
            };
            //Browser.Document.Body.Add(secButton);

            // Conventional DOM interaction
            var linqButton = new Button {
                InnerHtml = "Test Linq..."
            };

            linqButton.Click += e =>
            {
                int value = "abc".Select(a => a - 'a').Sum();
                Console.WriteLine(value);

                value = "abcdefg".Select(a => a - 'a').Sum();
                Console.WriteLine(value);
            };

            //Browser.Document.Body.Add(linqButton);
        }