public ChatClient()
 {
     chatTranslation = ChatTranslations.Get();
     clientScope = new Scope<object>();
     clientScope.Add(ChatConstants.ChatUpdateLisener, this);
     _client = new WebSocketOODSSClient(ServerAddress, PortNumber, chatTranslation, clientScope);
 }
        public static async Task<MetaMetadataRepository> ReadDirectoryRecursively(MetaMetadataRepository mainRepo, String path, SimplTypesScope mmdTScope, SimplTypesScope metadataTScope)
        {
            Stack<string> stack = new Stack<string>();
            stack.Push(path);
            while(stack.Count > 0)
            {
                string dir = stack.Pop();
                Debug.WriteLine("Looking in : " + dir);
                //String[] files = Directory.GetFiles(dir, "*.xml");
                string[] files = await FundamentalPlatformSpecifics.Get().GetFilesFromDirectory(dir, ".xml");
                foreach (string file in files)
                {
                    MetaMetadataRepository thatRepo = await ReadRepository(file, mmdTScope, metadataTScope, mainRepo);
                    // if (thatRepo != null)
                    //    mainRepo.IntegrateRepository(thatRepo);

                    //string[] directories = Directory.GetDirectories(dir);
                    //                                           string[] directories = await FundamentalPlatformSpecifics.Get().GetDirectoriesFromDirectory(dir);
                    //                                           foreach (
                    //                                                    string innerDir in directories.Where(
                    //                                                                                          innerDir =>
                    //                                                                                            !innerDir.Contains(".svn")))
                    //                                                                                    stack.Push(innerDir);
                    //                                                                            });
                }
                
            }

            return mainRepo;
        }
 public static SimplTypesScope ComposeTranslations(Type[] newTranslations,
     int portNumber, IPAddress ipAddress, SimplTypesScope requestTranslationSpace, 
     String prefix = "server_base: ")
 {
     return SimplTypesScope.Get(prefix + ipAddress + ":" + portNumber, requestTranslationSpace,
                                newTranslations);
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        private static SimplTypesScope Lookup(String name)
        {
            SimplTypesScope result = null;

            allTranslationScopes.TryGetValue(name, out result);
            return(result);
        }
Exemple #5
0
        public static void Main(string[] args)
        {
            Book abook = new Book();
            //Here's an instance of our type to serialize

            abook.setAuthorName("Michael Feathers");
            abook.setBookID(1337);
            abook.setTitle("Working Effectively with Legacy Code");
            //
            //

            SimplTypesScope book_example_sts = new SimplTypesScope("book_example", typeof(Book));

                //Serialize to JSON
            String jsonResult = SimplTypesScope.Serialize(abook, StringFormat.Json);

                //Serialize to XML
            // (Just change the StringFormat parameter!)
            String xmlResult  = SimplTypesScope.Serialize(abook, StringFormat.Xml);

            Object result1 = book_example_sts.Deserialize(jsonResult, StringFormat.Json);
            Book r1 = (Book) result1;

            Object result2 = book_example_sts.Deserialize(xmlResult, StringFormat.Xml);
            Book r2 = (Book) result2;

            Console.WriteLine(jsonResult);

            Console.WriteLine(xmlResult);
            Console.ReadLine();
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <param name="inheritedSimplTypesScope"></param>
 public SimplTypesScope(String name, SimplTypesScope inheritedSimplTypesScope)
     : this(name)
 {
     AddTranslations(inheritedSimplTypesScope);
     SimplTypesScope[] _inheritedSimplTypesScopes = new SimplTypesScope[1];
     _inheritedSimplTypesScopes[0]   = inheritedSimplTypesScope;
     this._inheritedSimplTypesScopes = _inheritedSimplTypesScopes;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="name"></param>
 /// <param name="inheritedSimplTypesScope"></param>
 public SimplTypesScope(String name, SimplTypesScope inheritedSimplTypesScope)
     : this(name)
 {
     AddTranslations(inheritedSimplTypesScope);
     SimplTypesScope[] _inheritedSimplTypesScopes = new SimplTypesScope[1];
     _inheritedSimplTypesScopes[0] = inheritedSimplTypesScope;
     this._inheritedSimplTypesScopes = _inheritedSimplTypesScopes;
 }
 /// <summary>
 /// Creates an instance of an NIOServer of some flavor. Creates the backend using the information
 /// in the arguments.
 /// Registers itself as the MAIN_START_AND_STOPPABLE in the object registry.
 /// </summary>
 /// <param name="portNumber"></param>
 /// <param name="ipAddresses"></param>
 /// <param name="requestTranslationScope"></param>
 /// <param name="objectRegistry"></param>
 /// <param name="idleConnectionTimeout"></param>
 /// <param name="maxMessageLength"></param>
 protected AbstractServer(int portNumber, IPAddress[] ipAddresses,
     SimplTypesScope requestTranslationScope, Scope<object> objectRegistry, int idleConnectionTimeout=-1,
     int maxMessageLength=-1)
 {
     Console.WriteLine("setting up server...");
     TranslationScope = requestTranslationScope;
     ApplicationObjectScope = objectRegistry;
 }
 public TestServiceClient(string serviceAddress, int port)
 {
     _serviceAddress = serviceAddress;
     _port = port;
     _testTypesScope = TestClientTypesScope.Get();
     _clientScope = new Scope<object>();
     _clientScope.Add(TestServiceConstants.ServiceUpdateListener, this);
     _client = new WebSocketOODSSClient(_serviceAddress, _port, _testTypesScope, _clientScope);
 }
        public SemanticsSessionScope(SimplTypesScope metadataTranslationScope, string repoLocation, ParsedUri serviceUri,
            EventHandler<EventArgs> onCompleted)
            : base(metadataTranslationScope, repoLocation, onCompleted)
        {
            SemanticsSessionScope.Get = this;

            MetadataServiceUri = serviceUri;
            HttpClient = new HttpClient();
        }
        public BaseSessionManager(string sessionId, SimplTypesScope translationScope, Scope<object> applicationObjectScope, ServerProcessor frontend)
        {
            FrontEnd = frontend;
            SessionId = sessionId;
            TranslationScope = translationScope;

            LocalScope = GenerateContextScope(applicationObjectScope);
            LocalScope.Add(SessionObjects.SessionId, sessionId);
            LocalScope.Add(SessionObjects.ClientManager, this);
        }
        public static SimplTypesScope Get(string name, SimplTypesScope[] inheritedScopes, params Type[] translations)
        {
            SimplTypesScope result = null;

            if (!allTranslationScopes.TryGetValue(name, out result))
            {
                result = new SimplTypesScope(name, inheritedScopes, translations);
            }
            return(result);
        }
        // background working thread

        #endregion WebSocketComponent

        #region Constructor

        /// <summary>
        /// Initialze a websocket OODSS client object
        /// </summary>
        /// <param name="ipAddress">server's ip address</param>
        /// <param name="portNumber">server's port number</param>
        /// <param name="translationScope">TranslationScope for OODSS messages</param>
        /// <param name="objectRegistry">application object scope</param>
        public WebSocketOODSSClient(String ipAddress, int portNumber, SimplTypesScope translationScope,
                                    Scope<object> objectRegistry)
        {
            ObjectRegistry = objectRegistry;
            TranslationScope = translationScope;
            ObjectRegistry.Add(SessionObjects.SessionId, _sessionId);
            ServerAddress = ipAddress;
            PortNumber = portNumber;


            _pendingRequests = new ConcurrentDictionary<long, RequestQueueObject>();
            _requestQueue = new BlockingCollection<RequestQueueObject>(new ConcurrentQueue<RequestQueueObject>());
            _responseQueue = new BlockingCollection<ResponseQueueObject>(new ConcurrentQueue<ResponseQueueObject>());


        }
Exemple #14
0
        private bool ResolveScopeAnnotation(string scopeAnnotation)
        {
            SimplTypesScope scope = SimplTypesScope.Get(scopeAnnotation);

            if (scope != null)
            {
                List <ClassDescriptor> scopeClassDescriptors = scope.GetClassDescriptors();
                InitTagClassDescriptorsArrayList(scopeClassDescriptors.Count);
                foreach (ClassDescriptor classDescriptor in scopeClassDescriptors)
                {
                    String tagName = classDescriptor.TagName;
                    polymorphClassDescriptors.Put(tagName, classDescriptor);
                    polymorphClasses.Put(tagName, classDescriptor.DescribedClass);
                }
            }
            return(scope != null);
        }
        /// <summary>
        /// Initialize a websocket oodss server object
        /// </summary>
        /// <param name="serverTranslationScope">translationscope for the oodss messages</param>
        /// <param name="applicationObjectScope">server object scope</param>
        /// <param name="idleConnectionTimeout"></param>
        /// <param name="maxMessageSize"></param>
        public WebSocketOODSSServer(SimplTypesScope serverTranslationScope, Scope<object> applicationObjectScope,
			int idleConnectionTimeout=-1, int maxMessageSize=-1, int port=0)
            : base(port, Dns.GetHostAddresses(Dns.GetHostName()), serverTranslationScope, applicationObjectScope, 
            idleConnectionTimeout, maxMessageSize)
        {
            MaxMessageSize = maxMessageSize + NetworkConstants.MaxHttpHeaderLength;
            TranslationScope = serverTranslationScope;

            ApplicationObjectScope = applicationObjectScope;

            ApplicationObjectScope.Add(SessionObjects.SessionsMap, ClientSessionManagerMap);
            ApplicationObjectScope.Add(SessionObjects.WebSocketOODSSServer, this);

            _serverInstance = this;

            SetUpWebSocketServer(port);
        }
Exemple #16
0
        private bool ResolveScopeAttribute(string scopeAttributeValue)
        {
            SimplTypesScope scope = SimplTypesScope.Get(scopeAttributeValue);

            if (scope != null)
            {
                List <ClassDescriptor> scopeClassDescriptors = scope.ClassDescriptors;
                InitPolymorphicClassDescriptorsList(scopeClassDescriptors.Count);
                foreach (var scopeClassDescriptor in scopeClassDescriptors)
                {
                    polymorphClassDescriptors.Put(scopeClassDescriptor.TagName, scopeClassDescriptor);
                    polymorphClasses.Put(scopeClassDescriptor.TagName, scopeClassDescriptor.DescribedClass);
                    tlvClassDescriptors.Put(_tagName.GetHashCode(), scopeClassDescriptor);
                }
            }

            return(scope != null);
        }
        public MetadataServicesClient(SimplTypesScope metadatascope, SemanticsSessionScope semanticSessionScope, ParsedUri serviceUri, bool useWebSockets = false)
        {
            SimplTypesScope[] oodssAndMetadataScope = {metadatascope, DefaultServicesTranslations.Get()};

            _metadataTypeScope = SimplTypesScope.Get("MetadataServicesTranslationScope",
                                                        oodssAndMetadataScope,
                                                        typeof (MetadataRequest),
                                                        typeof (MetadataResponse),
                                                        typeof (SemanticServiceError)
                                                    );

            _serviceBaseUri = serviceUri;

            if (useWebSockets)
            {
                _metadataClient = new WebSocketOODSSClient("127.0.0.1", 2018, _metadataTypeScope, semanticSessionScope);
                _metadataClient.StartAsync();
            }
            
        }
Exemple #18
0
        public OODSSClient(String host, int port, SimplTypesScope simplTypesScope, Scope<object> objectRegistry)
        {
            _sendMesssageThread         = new Thread(SendMessageWorker);
            _receiveMesssageThread      = new Thread(ReceiveMessageWorker);
            _pendingRequests            = new ConcurrentDictionary<int, QueueObject>();
            _requestQueue               = new BlockingCollection<QueueObject>(new ConcurrentQueue<QueueObject>());

            Host                        = host;
            Port                        = port;
            ObjectRegistry              = objectRegistry;

            //Add the OODSS messages to the scope.
            simplTypesScope.AddTranslations(ServicesTranslationScope);

            SimplTypesScope             = simplTypesScope;
            
            var initState = new InitConnectionRequest();
            int uid = _uid;
            QueueObject q = new QueueObject(initState, uid, null);
            _requestQueue.Add(q);
        }
Exemple #19
0
        public void TestMethod1()
        {
            Book abook = new Book();
            //Here's an instance of our type to serialize

            abook.initBook();
            //
            //

            SimplTypesScope book_example_sts = new SimplTypesScope("book_example", typeof(Book));

            //Serialize to JSON
            String jsonResult = SimplTypesScope.Serialize(abook, StringFormat.Json);

            //Serialize to XML
            // (Just change the StringFormat parameter!)
            String xmlResult = SimplTypesScope.Serialize(abook, StringFormat.Xml);

            Object result1 = book_example_sts.Deserialize(jsonResult, StringFormat.Json);
            Book r1 = (Book)result1;

            Object result2 = book_example_sts.Deserialize(xmlResult, StringFormat.Xml);
            Book r2 = (Book)result2;

            Assert.IsTrue(result1.GetType().IsAssignableFrom(abook.GetType()));

            Assert.AreEqual(r1.getAuthor(), abook.getAuthor());
            Assert.AreEqual(r1.getBookID(), abook.getBookID());
            Assert.AreEqual(r1.getTitle(), abook.getTitle());

            Assert.AreEqual(r1.getAuthor(), "Michael Feathers");
            Assert.AreEqual(r1.getBookID(), 1337);
            Assert.AreEqual(r1.getTitle(), "Working Effectively with Legacy Code");

            Assert.AreEqual(r2.getAuthor(), abook.getAuthor());
            Assert.AreEqual(r2.getBookID(), abook.getBookID());
            Assert.AreEqual(r2.getTitle(), abook.getTitle());
        }
        public SimplTypesScope GetSubtractedSubset(string newName, Type superClassCriterion)
        {
            SimplTypesScope result = Lookup(newName);

            if (result == null)
            {
                result = Lookup(newName);
                if (result == null)
                {
                    result = new SimplTypesScope(newName);
                    AddTranslationScope(newName);
                    foreach (ClassDescriptor classDescriptor in EntriesByClassName.Values)
                    {
                        Type thatClass = classDescriptor.DescribedClass;
                        if (!superClassCriterion.GetTypeInfo().IsAssignableFrom(thatClass.GetTypeInfo()))
                        {
                            result.AddTranslation(thatClass);
                        }
                    }
                }
            }
            return(result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="inheritedSimplTypesScope"></param>
        public void AddTranslations(SimplTypesScope inheritedSimplTypesScope)
        {
            if (inheritedSimplTypesScope != null)
            {
                UpdateMapWithValues(inheritedSimplTypesScope.EntriesByClassSimpleName, EntriesByClassSimpleName, "classSimpleName");
                UpdateMapWithValues(inheritedSimplTypesScope.EntriesByClassName, EntriesByClassName, "className");
                UpdateMapWithValues(inheritedSimplTypesScope.EntriesByTag, EntriesByTag, "tagName");

                Dictionary <string, Type> inheritedNameSpaceClassesByURN = inheritedSimplTypesScope.nameSpaceClassesByURN;
                if (inheritedNameSpaceClassesByURN != null)
                {
                    foreach (String urn in inheritedNameSpaceClassesByURN.Keys)
                    {
                        Type valueToAdd = null;

                        if (inheritedNameSpaceClassesByURN.TryGetValue(urn, out valueToAdd))
                        {
                            nameSpaceClassesByURN.Add(urn, valueToAdd);
                        }
                    }
                }
            }
        }
 internal override bool GetClassAndBindDescriptors(SimplTypesScope metadataTScope)
 {
     return GetChildComposite().GetClassAndBindDescriptors(metadataTScope);
 }
 protected internal override MetadataClassDescriptor BindMetadataClassDescriptor(SimplTypesScope metadataTScope)
 {
     MetaMetadataCompositeField childComposite = GetChildComposite();
     if (childComposite != null)
     return childComposite.BindMetadataClassDescriptor(metadataTScope);
     return null;
 }
 public SimplTypesScope GetSubtractedSubset(string newName, Type superClassCriterion)
 {
     SimplTypesScope result = Lookup(newName);
     if (result == null)
     {
         result = Lookup(newName);
         if (result == null)
         {
             result = new SimplTypesScope(newName);
             AddTranslationScope(newName);
             foreach (ClassDescriptor classDescriptor in EntriesByClassName.Values)
             {
                 Type thatClass = classDescriptor.DescribedClass;
                 if (!superClassCriterion.GetTypeInfo().IsAssignableFrom(thatClass.GetTypeInfo()))
                     result.AddTranslation(thatClass);
             }
         }
     }
     return result;
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inheritedSimplTypesScope"></param>
        public void AddTranslations(SimplTypesScope inheritedSimplTypesScope)
        {
            if (inheritedSimplTypesScope != null)
            {
                UpdateMapWithValues(inheritedSimplTypesScope.EntriesByClassSimpleName, EntriesByClassSimpleName, "classSimpleName");
                UpdateMapWithValues(inheritedSimplTypesScope.EntriesByClassName, EntriesByClassName, "className");
                UpdateMapWithValues(inheritedSimplTypesScope.EntriesByTag, EntriesByTag, "tagName");

                Dictionary<string, Type> inheritedNameSpaceClassesByURN = inheritedSimplTypesScope.nameSpaceClassesByURN;
                if (inheritedNameSpaceClassesByURN != null)
                {
                    foreach (String urn in inheritedNameSpaceClassesByURN.Keys)
                    {
                        Type valueToAdd = null;

                        if (inheritedNameSpaceClassesByURN.TryGetValue(urn, out valueToAdd))
                            nameSpaceClassesByURN.Add(urn, valueToAdd);
                    }
                }
            }
        }
 public static SimplTypesScope Get(string name, SimplTypesScope[] inheritedScopes, params Type[] translations)
 {
     SimplTypesScope result = null;
     if (!allTranslationScopes.TryGetValue(name, out result))
     {
         result = new SimplTypesScope(name, inheritedScopes, translations);
     }
     return result;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="name"></param>
 /// <param name="inheritedSimplTypesScope"></param>
 /// <param name="translation"></param>
 public SimplTypesScope(String name, SimplTypesScope inheritedSimplTypesScope, Type translation)
     : this(name, inheritedSimplTypesScope)
 {
     AddTranslation(translation);
     AddTranslationScope(name);
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="inheritedSimplTypesScope"></param>
        /// <param name="translations"></param>
        private SimplTypesScope(String name, SimplTypesScope inheritedSimplTypesScope, Type[] translations)
            : this(name, inheritedSimplTypesScope)
        {

            AddTranslations(translations);
            AddTranslationScope(name);
        }
 public SemanticsGlobalScope(SimplTypesScope metadataTranslationScope, string repoLocation, EventHandler<EventArgs> onCompleted) : base(metadataTranslationScope, repoLocation, onCompleted)
 {
     _globalDocumentCollection = new SemanticsGlobalCollection<Document>();
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="_inheritedSimplTypesScopes"></param>
        /// <param name="translations"></param>
        public SimplTypesScope(String name, SimplTypesScope[] _inheritedSimplTypesScopes, Type[] translations)
            : this(name, _inheritedSimplTypesScopes)
        {   
	        AddTranslations(translations);

            AddTranslationScope(name);
        }
 protected override void CustomizeFieldDescriptor(SimplTypesScope metadataTScope, MetadataFieldDescriptorProxy fdProxy)
 {
     base.CustomizeFieldDescriptor(metadataTScope, fdProxy);
     fdProxy.SetCollectionOrMapTagName(ChildTag);
     fdProxy.SetWrapped(!NoWrap);
 }
 protected abstract BaseSessionManager GenerateContextManager(string seesionId,
                                                              SimplTypesScope translationScope,
                                                              Scope<Object> globalScope);
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <param name="inheritedSimplTypesScope"></param>
 /// <param name="translations"></param>
 private SimplTypesScope(String name, SimplTypesScope inheritedSimplTypesScope, Type[] translations)
     : this(name, inheritedSimplTypesScope)
 {
     AddTranslations(translations);
     AddTranslationScope(name);
 }
 public static SimplTypesScope ComposeTranslations(int portNumber, IPAddress ipAddress, 
     SimplTypesScope requestTranslationSpace)
 {
     return ComposeTranslations(_ourTranslation, portNumber, ipAddress, requestTranslationSpace);
 }
 protected AbstractServer(int portNumber, IPAddress ipAddress, SimplTypesScope requestTranslationSpace,
         Scope<object> objectRegistry, int idleConnectionTimeout, int maxMessageLength)
     : this(portNumber, new[]{ipAddress}, requestTranslationSpace, 
         objectRegistry, idleConnectionTimeout, maxMessageLength)
 {
 }
        public void SimplPolymorphicCompositeFollowsTagNameConventions()
        {
            // case A: We have an ITC in the polymorphic class

            // Create the object
            var ourObjCaseA = new InternalPolymorphicCompositeTestClass(4, true);

            // Make sure that we created it correctly
            Assert.IsTrue(ourObjCaseA.polyMorph.GetType().Equals(typeof(InternalTestClass)), "Type should be internalTestClass");

            // Create the sts
            var ourSTS = new SimplTypesScope("CompositeWithPolymorph", new[] { typeof(InternalTestClass), typeof(InternalCompositeTestClass), typeof(InternalPolymorphicCompositeTestClass) });

            // Serialize it, get the XML representation, parse it
            var resultStream = TestMethods.TestSerialization(ourObjCaseA, Format.Xml);
            string xmlString = resultStream.StringData;
            XElement xe = XElement.Parse(xmlString);

            // polyMorph => poly_morph. And we should expect that element in our serialized representation.
            Assert.IsTrue(xe.Elements("poly_morph").Any(), "Should have an XML composite element \"poly_morph\"");

            // Okay, let's do case B, an Internal Composite inside. ;D
            var ourObjCaseB = new InternalPolymorphicCompositeTestClass(5, false);

            // Yes, I know this could probably be a seperate method. Just putting it here beacuse it fit in the moment.
            // Feel free to refactor if it tickles your fancy as such.

            // Serialize it, get the XML representation, parse it
            var resultStreamCaseB = TestMethods.TestSerialization(ourObjCaseB, Format.Xml);
            string xmlStringCaseB =  resultStreamCaseB.StringData;
            XElement xeCaseB = XElement.Parse(xmlStringCaseB);

            // polyMorph => poly_morph. And we should expect that element in our serialized representation.
            Assert.IsTrue(xeCaseB.Elements("poly_morph").Any(), "Should have an XML composite element \"poly_morph\"");

            // We'll defer these tests to the end; if we have a failure earlier we'll end up getting a deserialized null
            // because we fail hard if we don't serialize the type name correctly.
            TestMethods.TestSimplObject(ourObjCaseA, ourSTS);
            TestMethods.TestSimplObject(ourObjCaseB, ourSTS);
        }
 public WebSocketClientSessionManager(string sessionId, SimplTypesScope translationScope, Scope<object> applicationObjectScope, ServerProcessor frontend)
     : base(sessionId, translationScope , applicationObjectScope, frontend)
 {
 }
 public async static Task<SemanticsSessionScope> InitAsync(SimplTypesScope metadataTranslationScope, string repoLocation, ParsedUri serviceUri)
 {
     var scope = await Task.Run(() => new SemanticsSessionScope(metadataTranslationScope, repoLocation, serviceUri, null));
     return scope;
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <param name="inheritedSimplTypesScope"></param>
 /// <param name="translation"></param>
 public SimplTypesScope(String name, SimplTypesScope inheritedSimplTypesScope, Type translation)
     : this(name, inheritedSimplTypesScope)
 {
     AddTranslation(translation);
     AddTranslationScope(name);
 }