/// <summary>
        /// Begins to get an ObjectSecurity object that encapsulates the access control list (ACL) entries for a specified object 
        /// </summary>
        /// <param name="obj">The object whose AccessControl information you want to retrieve</param>
        /// <param name="asyncCallback">The user-defined delegate that is called when the asynchronous operation has completed.</param>
        /// <param name="asyncState">The user-defined object that qualifies or contains information about an asynchronous operation.</param>
        /// <returns>An IAsyncResult that represents the asynchronous operation.</returns>
        public IAsyncResult BeginGetAccessControl(object obj, AsyncCallback asyncCallback, object asyncState)
        {
            ISharedObjectEntry entry;
            bool isContainer = false;

            if (obj == this)
            {
                // Get the (ACL)s for the root namespace
                entry = this;
                isContainer = true;
            }
            else
            {
                if (obj is SharedCollection)
                {
                    var collection = obj as SharedCollection;
                    CollectionEntry collectionEntry;
                    if (!this.CollectionsManager.TryGetValue(collection.Name, out collectionEntry))
                    {
                        throw new ArgumentException("obj is not being tracked by this client", "obj");
                    }
                    entry = collectionEntry;
                    isContainer = true;
                }
                else
                {
                    ObjectEntry objectEntry;
                    this.ObjectsManager.TryGetValue(obj as INotifyPropertyChanged, out objectEntry);
                    entry = objectEntry;
                }
            }

            // Client has previously cached the value, return it immediately
            if (entry.ObjectSecurity != null)
            {
                var result = new AsyncResult<SharedObjectSecurity>(asyncCallback, 0);
                result.SetAsCompleted(entry.ObjectSecurity, true);
                return result;
            }

            var security = new SharedObjectSecurity(entry.Name, entry.Id, isContainer, new ETag(Guid.Empty));
            SharedObjectSecurityPayload payload = new SharedObjectSecurityPayload(PayloadAction.Get, security, this.ClientId);

            var getResult = new SharedAsyncResult<SharedObjectSecurity>(asyncCallback, payload.PayloadId);

            this.EnqueueAsyncResult(getResult, payload.PayloadId);

            this.SendPublishEvent(payload);

            return getResult;
        }
        /// <summary>
        /// Begins to get an ObjectSecurity object that encapsulates the access control list (ACL) entries for a specified object
        /// </summary>
        /// <param name="obj">The object whose AccessControl information you want to retrieve</param>
        /// <param name="asyncCallback">The user-defined delegate that is called when the asynchronous operation has completed.</param>
        /// <param name="asyncState">The user-defined object that qualifies or contains information about an asynchronous operation.</param>
        /// <returns>An IAsyncResult that represents the asynchronous operation.</returns>
        public IAsyncResult BeginGetAccessControl(object obj, AsyncCallback asyncCallback, object asyncState)
        {
            ISharedObjectEntry entry;
            bool isContainer = false;

            if (obj == this)
            {
                // Get the (ACL)s for the root namespace
                entry       = this;
                isContainer = true;
            }
            else
            {
                if (obj is SharedCollection)
                {
                    var             collection = obj as SharedCollection;
                    CollectionEntry collectionEntry;
                    if (!this.CollectionsManager.TryGetValue(collection.Name, out collectionEntry))
                    {
                        throw new ArgumentException("obj is not being tracked by this client", "obj");
                    }
                    entry       = collectionEntry;
                    isContainer = true;
                }
                else
                {
                    ObjectEntry objectEntry;
                    this.ObjectsManager.TryGetValue(obj as INotifyPropertyChanged, out objectEntry);
                    entry = objectEntry;
                }
            }

            // Client has previously cached the value, return it immediately
            if (entry.ObjectSecurity != null)
            {
                var result = new AsyncResult <SharedObjectSecurity>(asyncCallback, 0);
                result.SetAsCompleted(entry.ObjectSecurity, true);
                return(result);
            }

            var security = new SharedObjectSecurity(entry.Name, entry.Id, isContainer, new ETag(Guid.Empty));
            SharedObjectSecurityPayload payload = new SharedObjectSecurityPayload(PayloadAction.Get, security, this.ClientId);

            var getResult = new SharedAsyncResult <SharedObjectSecurity>(asyncCallback, payload.PayloadId);

            this.EnqueueAsyncResult(getResult, payload.PayloadId);

            this.SendPublishEvent(payload);

            return(getResult);
        }
        public void SetAccessControl(SharedObjectSecurity objectSecurity)
        {
            var payload = new SharedObjectSecurityPayload(PayloadAction.Set, objectSecurity, this.ClientId);

            // Update the locally cached copy of the security object, if the change fails the actual security
            // information will be sent down
            ISharedObjectEntry sharedObjectEntry = GetObjectEntry(payload);

            Debug.Assert(sharedObjectEntry != null);
            sharedObjectEntry.ObjectSecurity = objectSecurity;

            this.activeAsyncOperations[payload.PayloadId] = null;

            this.SendPublishEvent(payload);
        }
Ejemplo n.º 4
0
 public SharedObjectSecurityPayload(PayloadAction securityAction, SharedObjectSecurity sharedObjectSecurity, Guid clientId, ushort payloadId)
     : base(clientId, payloadId)
 {
     this.SecurityAction = securityAction;
     this.SharedObjectSecurity = sharedObjectSecurity;
 }
        public void SetAccessControl(SharedObjectSecurity objectSecurity)
        {
            var payload = new SharedObjectSecurityPayload(PayloadAction.Set, objectSecurity, this.ClientId);

            // Update the locally cached copy of the security object, if the change fails the actual security 
            // information will be sent down
            ISharedObjectEntry sharedObjectEntry = GetObjectEntry(payload);
            Debug.Assert(sharedObjectEntry != null);
            sharedObjectEntry.ObjectSecurity = objectSecurity;

            this.activeAsyncOperations[payload.PayloadId] = null;

            this.SendPublishEvent(payload);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }