Touchgui/plugins/org.apache.cordova.device/src/wp/Device.cs

Thu, 04 Jun 2015 14:50:33 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 04 Jun 2015 14:50:33 +0200
changeset 0
e8ccd40d0ef6
permissions
-rw-r--r--

Genesis of lecture sources for Droidcon Berlin 2015 in Postbahnhof.

     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
     6 	http://www.apache.org/licenses/LICENSE-2.0
     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 */
    15 using System;
    16 using System.Net;
    17 using System.Windows;
    18 using System.Windows.Controls;
    19 using System.Windows.Documents;
    20 using System.Windows.Ink;
    21 using System.Windows.Input;
    22 using System.Windows.Media;
    23 using System.Windows.Media.Animation;
    24 using System.Windows.Shapes;
    25 using Microsoft.Phone.Info;
    26 using System.IO.IsolatedStorage;
    27 using System.Windows.Resources;
    28 using System.IO;
    29 using System.Diagnostics;
    31 namespace WPCordovaClassLib.Cordova.Commands
    32 {
    33     public class Device : BaseCommand
    34     {
    35         public void getDeviceInfo(string notused)
    36         {
    38             string res = String.Format("\"name\":\"{0}\",\"platform\":\"{1}\",\"uuid\":\"{2}\",\"version\":\"{3}\",\"model\":\"{4}\"",
    39                                         this.name,
    40                                         this.platform,
    41                                         this.uuid,
    42                                         this.version,
    43                                         this.model);
    45             res = "{" + res + "}";
    46             //Debug.WriteLine("Result::" + res);
    47             DispatchCommandResult(new PluginResult(PluginResult.Status.OK, res));
    48         }
    50         public string model
    51         {
    52             get
    53             {
    54                 return DeviceStatus.DeviceName;
    55                 //return String.Format("{0},{1},{2}", DeviceStatus.DeviceManufacturer, DeviceStatus.DeviceHardwareVersion, DeviceStatus.DeviceFirmwareVersion); 
    56             }
    57         }
    59         public string name
    60         {
    61             get
    62             {
    63                 return DeviceStatus.DeviceName;
    65             }
    66         }
    68         public string platform
    69         {
    70             get
    71             {
    72                 return Environment.OSVersion.Platform.ToString();
    73             }
    74         }
    76         public string uuid
    77         {
    78             get
    79             {
    80                 string returnVal = "";
    81                 object id;
    82                 UserExtendedProperties.TryGetValue("ANID", out id);
    84                 if (id != null)
    85                 {
    86                     returnVal = id.ToString().Substring(2, 32);
    87                 }
    88                 else
    89                 {
    90                     returnVal = "???unknown???";
    92                     using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication())
    93                     {
    94                         try
    95                         {
    96                             IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream("DeviceID.txt", FileMode.Open, FileAccess.Read, appStorage);
    98                             using (StreamReader reader = new StreamReader(fileStream))
    99                             {
   100                                 returnVal = reader.ReadLine();
   101                             }
   102                         }
   103                         catch (Exception /*ex*/)
   104                         {
   106                         }
   107                     }
   108                 }
   110                 return returnVal;
   111             }
   112         }
   114         public string version
   115         {
   116             get
   117             {
   118                 return Environment.OSVersion.Version.ToString();
   119             }
   120         }
   122     }
   123 }

mercurial