Exemple #1
0
        static void Main(string[] args)
        {
            TimeProvider timeProvider = new TimeProvider();

            TimeManager.Instance     = new TimeManager(timeProvider);
            LogManager.RuntimeLogger = new ConsoleLogger();

            GameManager.Instance         = new GameManager();
            GameResources.Instance       = new GameResources("C:\\Users\\Dmitry\\Documents\\GitHub\\TileEngineSfml\\TileEngineSfmlCs\\TileEngineSfmlCs\\Resources");
            MapContainerManager.Instance = new MapContainerManager();
            TypeManager.Instance         = new TypeManager();
            SoundManager.Instance        = new SoundManager();

            IMapContainer container = MapContainerManager.Instance.GetMapContainer("C:\\Users\\Dmitry\\Downloads\\_DELETE\\MapExample");
            Scene         scene     = Scene.CreateFromMap(container, "main.scene");

            //Scene scene = new Scene(50, 50);
            UdpNetworkServer server = new UdpNetworkServer(25565);

            GameManager.Instance.StartGame(scene, server);

            Console.WriteLine("TileEngine server started!");

            Stopwatch stopwatch = new Stopwatch();

            while (true)
            {
                stopwatch.Reset();
                stopwatch.Start();
                timeProvider.SendTimeSignal();
                stopwatch.Stop();
                timeProvider.DeltaTime  = stopwatch.ElapsedMilliseconds / 1000f;
                timeProvider.TotalTime += timeProvider.DeltaTime;
            }
        }
Exemple #2
0
        /// <summary>
        /// A Message receive callback delegate that prints the SDT content
        /// of received messages.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="args"></param>
        public void PrintReceivedMessage(Object source, MessageEventArgs args)
        {
            IMessage      message   = args.Message;
            ISDTContainer container = SDTUtils.GetContainer(message);
            StringBuilder sb        = new StringBuilder();

            if (container is IMapContainer)
            {
                IMapContainer map = (IMapContainer)container;
                sb.Append("map={");
                while (map.HasNext())
                {
                    KeyValuePair <string, ISDTField> entry = map.GetNext();
                    sb.Append(string.Format("\n\tkey={0} value={1}", entry.Key, entry.Value.Value.ToString()));
                }
                sb.Append("}\n");
            }
            else if (container is IStreamContainer)
            {
                IStreamContainer stream = (IStreamContainer)container;
                sb.Append("stream={");
                while (stream.HasNext())
                {
                    ISDTField entry = stream.GetNext();
                    sb.Append(string.Format("\n\tvalue={0}", entry.Value.ToString()));
                }
                sb.Append("}\n");
            }
            SampleUtils.HandleMessageEvent(source, args);
            Console.WriteLine(sb.ToString());
        }
Exemple #3
0
 public List <TOut> To <TOut>(IMapContainer map)
 {
     if (SourceCollection == null)
     {
         return(new List <TOut>());
     }
     return((from i in SourceCollection select MapContextHelper.Map <T, TOut>(i, map)).ToList());
 }
 public IDictionary <TOutKey, TOutValue> To <TOutKey, TOutValue>(IMapContainer map)
 {
     if (SourceCollection == null)
     {
         return(new Dictionary <TOutKey, TOutValue>());
     }
     return(SourceCollection.ToDictionary(item => MapContextHelper.Map <TKey, TOutKey>(item.Key), item => MapContextHelper.Map <TValue, TOutValue>(item.Value, map)));
 }
        internal static TOutItem Map <TInn, TOutItem>(TInn source, IMapContainer map, TOutItem target = default(TOutItem))
        {
            var rule = map.GetRule <TInn, TOutItem>();

            return((TOutItem)Resolver.Activate <ITypeConverter>(rule.BasicType)
                   .Initialize(rule)
                   .Convert(source, target));
        }
Exemple #6
0
        private static void ConvertAppHeaders(IDictionary <string, object> appHeaders, IMessage solaceMsg)
        {
            IMapContainer map = solaceMsg.CreateUserPropertyMap();

            foreach (string key in appHeaders.Keys)
            {
                object val = appHeaders[key];
                WriteCustomHeader(key, val, map);
            }
        }
Exemple #7
0
 public static void SaveToMap(Scene scene, IMapContainer map, string scenePath)
 {
     map.DeleteEntry(scenePath);
     using (Stream mapXmlStream = map.CreateEntry(scenePath).OpenStream())
     {
         SerializeScene(scene, mapXmlStream);
         mapXmlStream.Flush();
         mapXmlStream.Close();
     }
 }
        private void CreateMapContainer(string path)
        {
            _tileEngineMap?.Dispose();
            if (MapContainerManager.Instance == null)
            {
                MapContainerManager.Instance = new MapContainerManager();
            }

            _tileEngineMap = MapContainerManager.Instance.GetMapContainer(path);
        }
Exemple #9
0
        void IMapBuilder <T> .BuildMaps(IMapContainer <T> map)
        {
            MapBuilderUtility.QualifyName(ref _name, map.Namespace);

            var elementMap = new ElementContainerMap <T>(_name, _required, map.GetType().Name);

            ((IElementMapContainer <T>)map).AddElementMap(_name, elementMap);

            // build children
            builders.ForEach(b => b.BuildMaps(elementMap));
        }
Exemple #10
0
        private static void BuildHeaderMap(IMessage msg, IDictionary <string, object> outHeaders)
        {
            IMapContainer headers = msg.UserPropertyMap;

            if (headers == null)
            {
                return;
            }

            while (headers.HasNext())
            {
                KeyValuePair <string, ISDTField> kv = headers.GetNext();
                string key = kv.Key;
                outHeaders[key] = kv.Value.Value;
            }
            headers.Close();
        }
Exemple #11
0
 void IMapBuilder <TObj> .BuildMaps(IMapContainer <TObj> map)
 {
     if (map is IAttributeMapContainer <TObj> && isAttribute)
     {
         AttributeMap <TObj, TProperty> attributeMap;
         attributeMap = new AttributeMap <TObj, TProperty>(_name, _required, _defaultValue, _writeDefault);
         ((IAttributeMapContainer <TObj>)map).AddAttributeMap(_name, attributeMap);
         attributeMap.Property  = _simpleMemberMap.GetProperty();
         attributeMap.Converter = _simpleMemberMap.GetConverter();
     }
     else if (map is IAttributeMapContainer <TObj> && isAttributeGroup)
     {
         var attributeGroupMap = new AttributeGroupMap <TObj, TProperty>(_name, _groupDefaultValue, _groupHasDefault);
         ((IAttributeMapContainer <TObj>)map).AddAttributeMap(_name, attributeGroupMap);
         attributeGroupMap.Property     = _attributeGroupMap.GetProperty();
         attributeGroupMap.GroupTypeMap = _attributeGroupMap.GetGroupTypeMap();
     }
     else if (map is IElementMapContainer <TObj> && isElement)
     {
         MapBuilderUtility.QualifyName(ref _name, map.Namespace);
         var elementMap = new ElementMap <TObj, TProperty>(_name, _required);
         ((IElementMapContainer <TObj>)map).AddElementMap(_name, elementMap);
         elementMap.Property        = _classMemberMap.GetProperty();
         elementMap.ClassMapFactory = _classMemberMap.GetClassMapFactory();
     }
     else if (map is IElementMapContainer <TObj> && isSimpleElement)
     {
         MapBuilderUtility.QualifyName(ref _name, map.Namespace);
         var simpleElementMap = new SimpleElementMap <TObj, TProperty>(_name, _required);
         ((IElementMapContainer <TObj>)map).AddElementMap(_name, simpleElementMap);
         simpleElementMap.Property        = _simpleMemberMap.GetProperty();
         simpleElementMap.ClassMapFactory = () => new SimpleElementClassMap <TProperty>(_simpleMemberMap.GetConverter());
     }
     else if (map is IElementContentContainer <TObj> && isContent)
     {
         var contentMap = new ContentMap <TObj, TProperty>();
         ((IElementContentContainer <TObj>)map).SetElementContentMap(contentMap);
         contentMap.Property  = _simpleMemberMap.GetProperty();
         contentMap.Converter = _simpleMemberMap.GetConverter();
     }
     else
     {
         var prop = new Property <TObj, TProperty>(_property, null);
         throw new MappingException("Error mapping ({0}).{1}: a property must be mapped to either an attribute, an element, or element conent.", prop.GetTypeName(), prop.GetName());
     }
 }
Exemple #12
0
        public static Scene CreateFromMap(IMapContainer map, string scenePath)
        {
            var entry = map.GetEntry(scenePath);

            if (entry == null)
            {
                LogManager.EditorLogger.LogError("[Scene] main.scene not found!");
                return(null);
            }
            using (Stream mapXmlStream = entry.OpenStream())
            {
                if (mapXmlStream == null)
                {
                    return(null);
                }
                return(DeserializeScene(mapXmlStream));
            }
        }
Exemple #13
0
        /*
         * Recursive map printer for displaying a map to the user.
         */
        public static string dumpMap(IMapContainer m, int indent)
        {
            string pad = getSpaces(indent);
            string ret = pad + "(Dumping map)\n";
            KeyValuePair <string, ISDTField> e;

            while ((e = m.GetNext()).Key != null)
            {
                ret += pad + string.Format("{0} : [Type={1}, Val={2}]\n", e.Key, e.Value.Type, e.Value.Value);
                if (e.Value.Type == SDTFieldType.MAP)
                {
                    ret += dumpMap((IMapContainer)e.Value.Value, indent + 4);
                }
                else if (e.Value.Type == SDTFieldType.STREAM)
                {
                    ret += dumpStream((IStreamContainer)e.Value.Value, indent + 4);
                }
            }
            m.Rewind();
            return(ret);
        }
Exemple #14
0
        void IMapBuilder <TObj> .BuildMaps(IMapContainer <TObj> map)
        {
            MapBuilderUtility.QualifyName(ref _name, map.Namespace);

            if (isSimple)
            {
                var collectionMap = new SimpleElementCollectionMap <TObj, TProperty>(_name, _required);
                collectionMap.ClassMapFactory = () => new SimpleElementClassMap <TProperty>(_simpleMemberMap.GetConverter());
                collectionMap.Collection      = _simpleMemberMap.GetCollection();
                ((IElementMapContainer <TObj>)map).AddElementMap(_name, collectionMap);
            }
            else if (isClassMap)
            {
                var collectionMap = new ElementCollectionMap <TObj, TProperty>(_name, _required);
                collectionMap.Collection      = _classMemberMap.GetCollection();
                collectionMap.ClassMapFactory = _classMemberMap.GetClassMapFactory();
                ((IElementMapContainer <TObj>)map).AddElementMap(_name, collectionMap);
            }
            else
            {
                var coll = new Collection <TObj, TProperty>(_collection, null);
                throw new MappingException("Error mapping ({0}).{1}: a collection must be mapped to either an an element or simple element.", coll.GetTypeName(), coll.GetName());
            }
        }
Exemple #15
0
 public DictionaryMapper(IMapContainer parent)
 {
     Parent = parent;
 }
Exemple #16
0
 public TypeMapper(IMapContainer parent)
 {
     Parent = parent;
 }
        /// <summary>
        /// The main function in the sample.
        /// </summary>
        /// <param name="args"></param>
        public override void SampleCall(string[] args)
        {
            #region Parse Arguments
            ArgParser cmdLineParser = new ArgParser();
            if (!cmdLineParser.Parse(args))
            {
                // parse failed
                PrintUsage(INVALID_ARGUMENTS_ERROR);
                return;
            }
            cmdLineParser.Config.DeliveryMode = MessageDeliveryMode.Persistent;
            cmdLineParser.Config.DestMode     = DestMode.QUEUE;
            #endregion

            #region Initialize properties from command line
            // Initialize the properties
            ContextProperties contextProps = new ContextProperties();
            SessionProperties sessionProps = SampleUtils.NewSessionPropertiesFromConfig(cmdLineParser.Config);
            #endregion

            // Define IContext and ISession
            IContext context = null;
            ISession session = null;
            IFlow    flow    = null;
            try
            {
                InitContext(cmdLineParser.LogLevel);
                Console.WriteLine("About to create the context ...");
                context = ContextFactory.Instance.CreateContext(contextProps, null);
                Console.WriteLine("Context successfully created. ");

                Console.WriteLine("About to create the session ...");
                session = context.CreateSession(sessionProps, SampleUtils.HandleMessageEvent, SampleUtils.HandleSessionEvent);
                Console.WriteLine("Session successfully created.");

                Console.WriteLine("About to connect the session ...");
                if (session.Connect() == ReturnCode.SOLCLIENT_OK)
                {
                    Console.WriteLine("Session successfully connected");
                    Console.WriteLine(GetRouterInfo(session));
                }
                if (!session.IsCapable(CapabilityType.SELECTOR))
                {
                    Console.WriteLine(string.Format("Capability '{0}' is required to run this sample",
                                                    CapabilityType.SELECTOR));
                    return;
                }
                if (!session.IsCapable(CapabilityType.SUB_FLOW_GUARANTEED) || !(session.IsCapable(CapabilityType.TEMP_ENDPOINT)))
                {
                    Console.WriteLine(string.Format("Capabilities '{0}'  and {1} are required to run this sample",
                                                    CapabilityType.SUB_FLOW_GUARANTEED,
                                                    CapabilityType.TEMP_ENDPOINT));
                    return;
                }

                // The creation of the Queue object. Temporary destinations must be
                // acquired from a connected session, as they require knowledge
                // about the connected appliance.
                IQueue queue = session.CreateTemporaryQueue();

                // The creation of a flow. A FlowReceiver is acquired for consuming
                // messages from a specified endpoint.
                //
                // The selector "pasta = 'rotini' OR pasta = 'farfalle'" is used to
                // select only messages matching those pasta types in their user
                // property map.
                FlowProperties flowProps = new FlowProperties();
                flowProps.FlowStartState = true;  // created in a started state;
                flowProps.Selector       = "pasta = 'rotini' OR pasta = 'farfalle'";
                flow = session.CreateFlow(flowProps, queue, null, SampleUtils.HandleMessageEvent, SampleUtils.HandleFlowEvent);

                // Now publish a number of messages to queue, the user should only get the ones with 'rotini' or 'farfalle'.
                // Note that this uses SDT and custom header properties, which could impact performance.
                IMessage message = SampleUtils.CreateMessage(cmdLineParser.Config, session);
                message.Destination = queue;
                string[] pastas = new string[] { "macaroni", "fettuccini", "farfalle", "fiori", "rotini", "penne" };
                for (int i = 0; i < pastas.Length; i++)
                {
                    IMapContainer userProps = message.CreateUserPropertyMap();
                    userProps.AddString("pasta", pastas[i]);
                    if (session.Send(message) == ReturnCode.SOLCLIENT_OK)
                    {
                        Console.WriteLine(String.Format("- Sent {0}", pastas[i]));
                    }
                }
                Console.WriteLine(string.Format("\nDone\n Sleeping for {0} secs before exiting. Expecting 2 messages to match the selector ", Timeout / 1000));
                Thread.Sleep(Timeout);
            }
            catch (Exception ex)
            {
                PrintException(ex);
            }
            finally
            {
                if (flow != null)
                {
                    flow.Dispose();
                }
                if (session != null)
                {
                    session.Dispose();
                }
                if (context != null)
                {
                    context.Dispose();
                }
                // Must cleanup after.
                CleanupContext();
            }
        }
Exemple #18
0
 public TypeMapper(IMapContainer parent)
 {
     Parent = parent;
 }
Exemple #19
0
 public ListMapper(IMapContainer parent)
 {
     Parent = parent;
 }
Exemple #20
0
 private static void WriteCustomHeader(string key, object val, IMapContainer map)
 {
     if (val is string)
     {
         map.AddString(key, val as string);
     }
     else if (val is Int16 || val is short)
     {
         map.AddInt16(key, (short)val);
     }
     else if (val is Int32 || val is int)
     {
         map.AddInt32(key, (int)val);
     }
     else if (val is Int64 || val is long)
     {
         map.AddInt64(key, (long)val);
     }
     else if (val is bool)
     {
         map.AddBool(key, (bool)val);
     }
     else if (val is float)
     {
         map.AddFloat(key, (float)val);
     }
     else if (val is double)
     {
         map.AddDouble(key, (double)val);
     }
     else if (val is UInt16 || val is ushort)
     {
         map.AddUInt16(key, (short)val);
     }
     else if (val is UInt32 || val is uint)
     {
         map.AddUInt32(key, (uint)val);
     }
     else if (val is UInt64 || val is ulong)
     {
         map.AddUInt64(key, (long)val);
     }
     else if (val is byte)
     {
         map.AddUInt8(key, (byte)val);
     }
     else if (val is sbyte)
     {
         map.AddInt8(key, (sbyte)val);
     }
     else if (val is byte[])
     {
         map.AddByteArray(key, (byte[])val);
     }
     else if (val is char)
     {
         map.AddChar(key, (char)val);
     }
     else
     {
         throw new MessagingException("Unsupported app header type" + val.GetType());
     }
 }
Exemple #21
0
 public TOut To <TOut>(IMapContainer map)
 {
     return(To(default(TOut), map));
 }
Exemple #22
0
        /// <summary>
        /// The main function in the sample.
        /// </summary>
        /// <param name="args"></param>
        public override void SampleCall(string[] args)
        {
            #region Parse Arguments
            ArgParser cmdLineParser = new ArgParser();
            if (!cmdLineParser.Parse(args))
            {
                // parse failed
                PrintUsage(INVALID_ARGUMENTS_ERROR);
                return;
            }
            #endregion

            #region Initialize properties from command line
            // Initialize the properties.
            ContextProperties contextProps = new ContextProperties();
            SessionProperties sessionProps = SampleUtils.NewSessionPropertiesFromConfig(cmdLineParser.Config);
            #endregion

            // Define IContext and ISession and ITopic.
            IContext context = null;
            ISession session = null;
            ITopic   topic   = null;
            try
            {
                InitContext(cmdLineParser.LogLevel);
                Console.WriteLine("About to create the Context ...");
                context = ContextFactory.Instance.CreateContext(contextProps, null);
                Console.WriteLine("Context successfully created. ");

                Console.WriteLine("About to create the Session ...");
                session = context.CreateSession(sessionProps,
                                                PrintReceivedMessage,
                                                SampleUtils.HandleSessionEvent);
                Console.WriteLine("Session successfully created.");

                Console.WriteLine("About to connect the Session ...");
                if (session.Connect() == ReturnCode.SOLCLIENT_OK)
                {
                    Console.WriteLine("Session successfully connected");
                    Console.WriteLine(GetRouterInfo(session));
                }

                topic = ContextFactory.Instance.CreateTopic(SampleUtils.SAMPLE_TOPIC);

                Console.WriteLine("About to subscribe to topic " + SampleUtils.SAMPLE_TOPIC);
                if (session.Subscribe(topic, true) == ReturnCode.SOLCLIENT_OK)
                {
                    Console.WriteLine("Successfully added topic subscription");
                }

                // Create the message independent stream.
                IStreamContainer stream = SDTUtils.CreateStream(1024);

                // Populate the stream.
                stream.AddDouble(3.141592654);
                stream.AddString("message");

                // Create the message-independent map.
                IMapContainer map = SDTUtils.CreateMap(1024);

                // Add a well known integer to the map.
                map.AddInt32("mersenne", 43112609);

                // Create the message.
                IMessage message = ContextFactory.Instance.CreateMessage();

                // Set the message delivery options.
                message.DeliveryMode = MessageDeliveryMode.Direct;
                message.Destination  = topic;

                int numMsgsToSend = 10;
                Console.WriteLine(string.Format("About to send {0} messages ...", numMsgsToSend));
                for (int i = 0; i < numMsgsToSend; i++)
                {
                    // Overwrite the "message" field, set the container, and send.
                    map.DeleteField("message");
                    map.AddString("message", "message" + (i + 1));
                    // Set the user property map to the map.
                    message.UserPropertyMap = map;
                    SDTUtils.SetSDTContainer(message, stream);
                    session.Send(message);
                }

                // Dispose of the map, stream, and message.
                map.Dispose();
                stream.Dispose();
                message.Dispose();

                Thread.Sleep(500); // wait for 0.5 seconds
                Console.WriteLine("\nDone");
            }
            catch (Exception ex)
            {
                PrintException(ex);
            }
            finally
            {
                if (session != null)
                {
                    if (topic != null)
                    {
                        session.Unsubscribe(topic, true);
                    }
                    session.Dispose();
                }
                if (context != null)
                {
                    context.Dispose();
                }
                // Must cleanup after.
                CleanupContext();
            }
        }
Exemple #23
0
 public TOut To <TOut>(TOut target, IMapContainer map)
 {
     return(MapContextHelper.Map(Source, map, target));
 }