Ejemplo n.º 1
0
 /// <summary>
 ///     Message deserialization an initiation of handling methods.
 /// </summary>
 /// <param name="serializedData">Message string containing data.</param>
 private void GetData(string serializedData)
 {
     // don't need to handle empty messages
     if (string.IsNullOrEmpty(serializedData))
     {
         return;
     }
     try
     {
         // convert package string into stub
         NetworkPackageStub stub = JsonConvert.DeserializeObject <NetworkPackageStub>(serializedData);
         // check if calltype belongs to a known message type
         Type type;
         if (!m_PackageTypes.TryGetValue(stub.call, out type))
         {
             AciLog.LogFormat(LogType.Error, GetType().ToString(), "Can't handle NetworkPackage with calltype \"{0}\".", stub.call);
             return;
         }
         // deserialize into package instance
         INetworkPackage package = JsonConvert.DeserializeObject(serializedData, type) as INetworkPackage;
         // call handler mathods
         UnityMainThreadDispatcher.Instance().Enqueue(() => m_PackageRegistry.Handle(package));
     }
     catch (Exception e)
     {
         AciLog.LogException(e);
     }
 }
Ejemplo n.º 2
0
        // Initialization function to restore values from serialized object
        private void Intialize()
        {
            foreach (LocalizationData data in baseLocalization)
            {
                AddLocalizationData(data);
            }
            foreach (LocalizationData data in loadedData)
            {
                if (data.languageIETF == _currentLocalization)
                {
                    currentLocalizationData = data;
                    if (eventBroker != null)
                    {
                        eventBroker.Invoke(new LocalizationChangedArgs()
                        {
                            ietf            = _currentLocalization,
                            localeDecorator = currentLocalizationData.languageDescriptor
                        });
                    }
                }
            }

            if (currentLocalizationData == null)
            {
                AciLog.LogFormat(LogType.Error, "LocalizationManager", "Target language \"{0}\" could not be loaded from persivously serialzed values. Please check if the correct files are set on the LocalizationManager instance.", _currentLocalization);
                _currentLocalization = null;
            }

            initialized = true;
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Async network listener loop.
        /// </summary>
        /// <param name="token"><see cref="CancellationToken"/> that is used to interrupt listening process.</param>
        /// <returns></returns>
        private async Task ReceiveData(CancellationToken token)
        {
            using (UdpClient client = new UdpClient(port))
            {
                AciLog.LogFormat(LogType.Log, GetType().ToString(), "Starting to receive data on port {0}.", port);
                while (!token.IsCancellationRequested)
                {
                    UdpReceiveResult result = await client.ReceiveAsync();

                    string data = Encoding.UTF8.GetString(result.Buffer);
                    GetData(data);
                }
                AciLog.Log(GetType().ToString(), "Stopped listening for new data.");
            }
            m_Running = false;
        }