コード例 #1
0
        private static byte[] ToByteArray(DetectionResult result)
        {
            var bf = new BinaryFormatter();

            using (var ms = new MemoryStream())
            {
                bf.Serialize(ms, result);
                return(ms.ToArray());
            }
        }
コード例 #2
0
        private static Task <string> SaveAsync(DetectionResult result)
        {
            try
            {
                var type =
                    result.Type == 0
                                        ? "iPhone detected!"
                                        : result.Type == 1
                                                ? "Android detected!"
                                                : "User-agent doesn't look like a phone. Don't cheat ;)";

                var client  = new RestClient($"http://{FN_ADDRESS}:8080/t/fndotnet/save");
                var request = new RestRequest(Method.POST);
                request.AddJsonBody(result);

                var response = client.Post(request);
                return(Task.FromResult(type));
            }
            catch (Exception ex)
            {
                return(Task.FromResult(ex.ToString()));
            }
        }