arnaucube
arnaucube/openEventsPlatformAppPublic Self-hosted repository
openEventsPlatformApp/plugins/cordova-plugin-device/src/wp/Device.cs
plugins/cordova-plugin-device/src/wp/Device.csRaw
 1/*  
 2    Licensed under the Apache License, Version 2.0 (the "License");
 3    you may not use this file except in compliance with the License.
 4    You may obtain a copy of the License at
 5    
 6    http://www.apache.org/licenses/LICENSE-2.0
 7    
 8    Unless required by applicable law or agreed to in writing, software
 9    distributed under the License is distributed on an "AS IS" BASIS,
10    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11    See the License for the specific language governing permissions and
12    limitations under the License.
13*/
14
15using Microsoft.Phone.Info;
16using System;
17using System.IO;
18using System.IO.IsolatedStorage;
19
20namespace WPCordovaClassLib.Cordova.Commands
21{
22    public class Device : BaseCommand
23    {
24        public void getDeviceInfo(string notused)
25        {
26            string res = String.Format("\"name\":\"{0}\",\"platform\":\"{1}\",\"uuid\":\"{2}\",\"version\":\"{3}\",\"model\":\"{4}\",\"manufacturer\":\"{5}\",\"isVirtual\":{6}",
27                                        DeviceStatus.DeviceName,
28                                        Environment.OSVersion.Platform.ToString(),
29                                        UUID,
30                                        Environment.OSVersion.Version.ToString(),
31                                        DeviceStatus.DeviceName,
32                                        DeviceStatus.DeviceManufacturer,
33                                        IsVirtual ? "true" : "false");
34            DispatchCommandResult(new PluginResult(PluginResult.Status.OK, "{" + res + "}"));
35        }
36
37
38        public bool IsVirtual
39        {
40            get 
41            {
42                return (Microsoft.Devices.Environment.DeviceType == Microsoft.Devices.DeviceType.Emulator);
43            }
44        }
45
46        public string UUID
47        {
48            get
49            {
50                object id;
51
52                UserExtendedProperties.TryGetValue("ANID", out id);
53                if (id != null)
54                {
55                    return id.ToString().Substring(2, 32);
56                }
57
58                UserExtendedProperties.TryGetValue("ANID2", out id);
59                if (id != null)
60                {
61                    return id.ToString();
62                }
63
64                string returnVal = "???unknown???";
65
66                using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication())
67                {
68                    try
69                    {
70                        IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream("DeviceID.txt", FileMode.Open, FileAccess.Read, appStorage);
71
72                        using (StreamReader reader = new StreamReader(fileStream))
73                        {
74                            returnVal = reader.ReadLine();
75                        }
76                    }
77                    catch (Exception /*ex*/)
78                    {
79
80                    }
81                }
82
83                return returnVal;
84            }
85        }
86    }
87}