Beispiel #1
0
 public void OnBeforeSerialize()
 {
     // #if UNITY_EDITOR
     // Event e = Event.current;
     // if(e != null && e.type != UnityEngine.EventType.Used &&
     //  (e.type == UnityEngine.EventType.Repaint ||
     //  e.type == UnityEngine.EventType.MouseDrag ||
     //  e.type == UnityEngine.EventType.Layout ||
     //  e.type == UnityEngine.EventType.ScrollWheel)) {
     //  return;
     // }
     // #endif
     _odinSerializedData = SerializerUtility.Serialize(value, out listReference);
     _serializedData     = null;
 }
Beispiel #2
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral deferral = taskInstance.GetDeferral();

            try
            {
                Geolocator  geolocator = new Geolocator();
                Geoposition position   = await geolocator.GetGeopositionAsync();

                //////////////////////////////////////////////////////////////////////////
#if DEBUG
                XmlDocument toastXml          = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
                XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
                toastTextElements[0].AppendChild(toastXml.CreateTextNode(position.Coordinate.Point.Position.Latitude + "|" + position.Coordinate.Point.Position.Longitude));
                ToastNotification toastNotification = new ToastNotification(toastXml);
                ToastNotificationManager.CreateToastNotifier().Show(toastNotification);
#endif
                //////////////////////////////////////////////////////////////////////////

                ApplicationDataContainer settings = ApplicationData.Current.LocalSettings;
                LimitedQueue <GPSInfo>   queue;
                if (settings.Values.ContainsKey("Queue") == true)
                {
                    string queueString = (string)settings.Values["Queue"];
                    queue = SerializerUtility.Deserialize <LimitedQueue <GPSInfo> >(queueString);
                }
                else
                {
                    queue = new LimitedQueue <GPSInfo>(20);
                }

                queue.Push(new GPSInfo()
                {
                    Latitude = position.Coordinate.Point.Position.Latitude, Longitude = position.Coordinate.Point.Position.Longitude, PositionSource = position.Coordinate.PositionSource.ToString()
                });

                try
                {
                    string deviceUniqueId = UniqueIdUtility.GetUniqueId();

                    GPSInfo[] gpsInfoList     = queue.Retrive();
                    string    gpsInfoListJson = SerializerUtility.Serialize <GPSInfo[]>(gpsInfoList);

                    KeyValuePair <string, string>[] postData = new KeyValuePair <string, string> [2];
                    postData[0] = new KeyValuePair <string, string>("deviceUniqueId", deviceUniqueId);
                    postData[1] = new KeyValuePair <string, string>("gpsInfoList", gpsInfoListJson);

                    await HttpUtility.GetHttpResponse(ConfigUtility.GetValue("SendPositionAPI"), postData);

                    queue.Clear();
                }
                finally
                {
                    string queueString = SerializerUtility.Serialize <LimitedQueue <GPSInfo> >(queue);
                    settings.Values["Queue"] = queueString;
                }
            }
            catch (Exception ex)
            {
            }

            deferral.Complete();
        }