Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

1. Added cast parameter to PluginResult + script callback via 'eval' …

…js function;

2. Camera Api work in progress.
  • Loading branch information...
commit f3cb136a6f38074dde652b82256088b132b75c6d 1 parent 156aaee
unknown authored Jesse committed
6 example/www/index.html
@@ -155,9 +155,9 @@
155 155 <li onclick="exec(successCallback, failureCallback,'Device','name');">Device Platform</li>
156 156 <li onclick="exec(successCallback, failureCallback,'Dummy','somemethod');">Unknown Service</li>
157 157 <li onclick="exec(successCallback, failureCallback,'Device','somemethod');">Unknown Method</li>
158   - <li onclick="exec(successCallback, failureCallback,'Capture','captureImage',{limit: 2});">captureImage</li>
159   - <li onclick="exec(successCallback, failureCallback,'Camera','getPicture');">ChoosePictureFromAlbom</li>
160   - <li onclick="exec(successCallback, failureCallback,'Capture','getFormatData',{filePath: 'somePath', mimeType: 'image/jpeg'});">getMediaData</li>
  158 + <li onclick="exec(successCallback, failureCallback,'Capture','captureImage',{limit: 2});">Capture.captureImage</li>
  159 + <li onclick="exec(successCallback, failureCallback,'Camera','getPicture',{ PictureSourceType: 1, DestinationType: 1});">Camera.getPicture</li>
  160 + <li onclick="exec(successCallback, failureCallback,'Capture','getFormatData',{fullPath: 'CapturedImagesCache\\CameraCapture-f3b7730b-ff17-46b7-809a-59c179d08fd8.jpg'});">Capture.getMediaData</li>
161 161 </ul>
162 162
163 163 <div id="divProperties" style="color:Orange;">Placeholder for app messages</div>
11 framework/PGView.xaml.cs
@@ -254,13 +254,20 @@ private void InvokeJSSCallback(String callbackId, PluginResult result)
254 254 throw new ArgumentNullException("result");
255 255 }
256 256
  257 + string callBackScript = result.ToCallbackString(callbackId, "commandResult", "commandError");
  258 +
  259 + // TODO: this is correct invokation method
  260 + //this.GapBrowser.InvokeScript("eval", new string[] {callBackScript });
  261 +
  262 +
  263 + /// But we temporary use this version because C#<->JS bridge is on fully ready
257 264 if (result.IsSuccess)
258 265 {
259   - this.GapBrowser.InvokeScript("commandResult", new string[] {callbackId, result.ToJSONString()});
  266 + this.GapBrowser.InvokeScript("commandResult", new string[] { callbackId, result.ToJSONString() });
260 267 }
261 268 else
262 269 {
263   - this.GapBrowser.InvokeScript("commandError", new string[] {callbackId, result.ToJSONString()});
  270 + this.GapBrowser.InvokeScript("commandError", new string[] { callbackId, result.ToJSONString() });
264 271 }
265 272 }
266 273 }
14 framework/PhoneGap/Commands/BaseCommand.cs
@@ -54,13 +54,13 @@ public object InvokeMethodNamed(string methodName, params object[] args)
54 54 // options.Add("limit",2);
55 55 // args[0] = options;
56 56 //}
57   - if (methodName.Equals("getFormatData"))
58   - {
59   - var options = new Dictionary<string, object>();
60   - options.Add("filePath", "CapturedImagesCache\\CameraCapture-3768793c-1c66-424a-9e55-a941cbc158610.jpg");
61   - options.Add("mimeType", "image/jpeg");
62   - args[0] = options;
63   - }
  57 + //if (methodName.Equals("getFormatData"))
  58 + //{
  59 + // var options = new Dictionary<string, object>();
  60 + // options.Add("filePath", "CapturedImagesCache\\CameraCapture-3768793c-1c66-424a-9e55-a941cbc158610.jpg");
  61 + // options.Add("mimeType", "image/jpeg");
  62 + // args[0] = options;
  63 + //}
64 64
65 65 return mInfo.Invoke(this, args);
66 66 // every function handles DispatchCommandResult by itself
250 framework/PhoneGap/Commands/Camera.cs
@@ -7,24 +7,262 @@
7 7 using System.Windows.Input;
8 8 using System.Windows.Media;
9 9 using System.Windows.Media.Animation;
10   -using System.Windows.Shapes;
11 10 using System.Collections.Generic;
12 11 using Microsoft.Phone.Tasks;
  12 +using System.Runtime.Serialization;
  13 +using System.IO;
  14 +using System.IO.IsolatedStorage;
13 15
14 16 namespace WP7GapClassLib.PhoneGap.Commands
15 17 {
16 18 public class Camera : BaseCommand
17 19 {
  20 +
  21 + /// <summary>
  22 + /// Return base64 encoded string
  23 + /// </summary>
  24 + private const int DATA_URL = 0;
  25 +
  26 + /// <summary>
  27 + /// Return file uri
  28 + /// </summary>
  29 + private const int FILE_URI = 1;
  30 +
  31 + /// <summary>
  32 + /// Choose image from picture library
  33 + /// </summary>
  34 + private const int PHOTOLIBRARY = 0;
  35 +
  36 + /// <summary>
  37 + /// Take picture from camera
  38 + /// </summary>
  39 +
  40 + private const int CAMERA = 1;
  41 +
  42 + /// <summary>
  43 + /// Choose image from picture library
  44 + /// </summary>
  45 + private const int SAVEDPHOTOALBUM = 2;
  46 +
  47 + /// <summary>
  48 + /// Take a picture of type JPEG
  49 + /// </summary>
  50 + private const int JPEG = 0;
  51 +
  52 + /// <summary>
  53 + /// Take a picture of type PNG
  54 + /// </summary>
  55 + private const int PNG = 1;
  56 +
  57 + /// <summary>
  58 + /// Desired width of the image
  59 + /// </summary>
  60 + private int targetWidth;
  61 +
  62 + /// <summary>
  63 + /// desired height of the image
  64 + /// </summary>
  65 + private int targetHeight;
  66 +
  67 +
  68 + /// <summary>
  69 + /// Folder to store captured images
  70 + /// </summary>
  71 + private string isoFolder = "CapturedImagesCache";
  72 +
  73 + /// <summary>
  74 + /// Represents captureImage action options.
  75 + /// </summary>
  76 + [DataContract]
  77 + public class CameraOptions
  78 + {
  79 + /// <summary>
  80 + /// Source to getPicture from.
  81 + /// </summary>
  82 + [DataMember]
  83 + public int PictureSourceType { get; set; }
  84 +
  85 + /// <summary>
  86 + /// Format of image that returned from getPicture.
  87 + /// </summary>
  88 + [DataMember]
  89 + public int DestinationType { get; set; }
  90 +
  91 + /// <summary>
  92 + /// Encoding of image returned from getPicture.
  93 + /// </summary>
  94 + [DataMember]
  95 + public int EncodingType { get; set; }
  96 +
  97 + public static CameraOptions Default
  98 + {
  99 + get { return new CameraOptions() { PictureSourceType = CAMERA, DestinationType = DATA_URL, EncodingType = JPEG}; }
  100 + }
  101 +
  102 + }
  103 +
  104 + /// <summary>
  105 + /// Used to open photo library
  106 + /// </summary>
  107 + PhotoChooserTask photoChooserTask;
  108 +
  109 + /// <summary>
  110 + /// Used to open camera application
  111 + /// </summary>
  112 + CameraCaptureTask cameraTask;
  113 +
  114 + /// <summary>
  115 + /// Camera options
  116 + /// </summary>
  117 + CameraOptions cameraOptions;
  118 +
18 119 public void getPicture(string options)
19 120 {
20   - var photoChooserTask = new PhotoChooserTask();
21   - photoChooserTask.Completed += onComplited;
22   - photoChooserTask.Show();
  121 + try
  122 + {
  123 + this.cameraOptions = String.IsNullOrEmpty(options) ?
  124 + CameraOptions.Default : JSON.JsonHelper.Deserialize<CameraOptions>(options);
  125 +
  126 + }
  127 + catch (Exception ex)
  128 + {
  129 + this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, ex.Message));
  130 + return;
  131 + }
  132 +
  133 + //TODO Check if all the options are acceptable
  134 +
  135 +
  136 + if (cameraOptions.PictureSourceType == CAMERA)
  137 + {
  138 + cameraTask = new CameraCaptureTask();
  139 + cameraTask.Completed += onComplited;
  140 + cameraTask.Show();
  141 + }
  142 + else
  143 + {
  144 + if ((cameraOptions.PictureSourceType == PHOTOLIBRARY) || (cameraOptions.PictureSourceType == SAVEDPHOTOALBUM))
  145 + {
  146 + photoChooserTask = new PhotoChooserTask();
  147 + photoChooserTask.Completed += onComplited;
  148 + photoChooserTask.Show();
  149 + }
  150 + else
  151 + {
  152 + DispatchCommandResult(new PluginResult(PluginResult.Status.NO_RESULT));
  153 + }
  154 + }
  155 +
23 156 }
24 157
25 158 public void onComplited(object sender,PhotoResult e) {
26   - string name = e.OriginalFileName;
27   - DispatchCommandResult();
  159 + if (e.Error != null)
  160 + {
  161 + DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR));
  162 + return;
  163 + }
  164 +
  165 + switch (e.TaskResult)
  166 + {
  167 + case TaskResult.OK:
  168 + try
  169 + {
  170 + string imageData = string.Empty;
  171 +
  172 + if(cameraOptions.PictureSourceType == CAMERA)
  173 + {
  174 + if (cameraOptions.DestinationType == DATA_URL)
  175 + {
  176 + imageData = getBase64(e.ChosenPhoto);
  177 + }
  178 + else
  179 + {
  180 + byte[] imageBytes = new byte[e.ChosenPhoto.Length];
  181 + e.ChosenPhoto.Read(imageBytes, 0, imageBytes.Length);
  182 + imageData = this.SaveImageToLocalStorage(Path.GetFileName(e.OriginalFileName), isoFolder, imageBytes);
  183 + }
  184 + }
  185 + else
  186 + {
  187 + if (cameraOptions.DestinationType == DATA_URL)
  188 + {
  189 + imageData = getBase64(e.ChosenPhoto);
  190 + }
  191 + else
  192 + {
  193 + //TODO Set default value or return base64 or something else
  194 + }
  195 + }
  196 +
  197 + DispatchCommandResult(new PluginResult(PluginResult.Status.OK,imageData));
  198 +
  199 + }
  200 + catch (Exception ex)
  201 + {
  202 + DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Error retrieving image."));
  203 + }
  204 + break;
  205 +
  206 + case TaskResult.Cancel:
  207 + DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR,"Selection cancelled."));
  208 + break;
  209 +
  210 + default:
  211 + DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR,"Selection did not complete!"));
  212 + break;
  213 + }
  214 + }
  215 +
  216 +
  217 + /// <summary>
  218 + /// Creates base64 string from binary file
  219 + /// </summary>
  220 + /// <param name="stream"></param>
  221 + /// <returns></returns>
  222 + private string getBase64(Stream stream) {
  223 + int streamLength = (int)stream.Length;
  224 + byte[] fileData = new byte[streamLength + 1];
  225 + stream.Read(fileData, 0, streamLength);
  226 + stream.Close();
  227 + return Convert.ToBase64String(fileData);
  228 + }
  229 +
  230 +
  231 + /// <summary>
  232 + /// Saves captured image in isolated storage
  233 + /// </summary>
  234 + /// <param name="imageFileName">image file name</param>
  235 + /// <param name="imageFolder">folder to store images</param>
  236 + /// <returns>Image path</returns>
  237 + private string SaveImageToLocalStorage(string imageFileName, string imageFolder, byte[] imageBytes)
  238 + {
  239 + if (imageBytes == null)
  240 + {
  241 + throw new ArgumentNullException("imageBytes");
  242 + }
  243 + try
  244 + {
  245 + var isoFile = IsolatedStorageFile.GetUserStoreForApplication();
  246 +
  247 + if (!isoFile.DirectoryExists(imageFolder))
  248 + {
  249 + isoFile.CreateDirectory(imageFolder);
  250 + }
  251 + string filePath = System.IO.Path.Combine(imageFolder, imageFileName);
  252 +
  253 + using (var stream = isoFile.CreateFile(filePath))
  254 + {
  255 + stream.Write(imageBytes, 0, imageBytes.Length);
  256 + }
  257 +
  258 + return filePath;
  259 + }
  260 + catch (Exception e)
  261 + {
  262 + //TODO: log or do something else
  263 + throw;
  264 + }
28 265 }
  266 +
29 267 }
30 268 }
84 framework/PhoneGap/Commands/Capture.cs
@@ -45,6 +45,23 @@ public static CaptureImageOptions Default
45 45 }
46 46
47 47 /// <summary>
  48 + /// Represents getFormatData action options.
  49 + /// </summary>
  50 + [DataContract]
  51 + public class MediaFormatOptions
  52 + {
  53 + /// <summary>
  54 + /// The maximum number of images the device user can capture in a single capture operation. The value must be greater than or equal to 1 (defaults to 1).
  55 + /// </summary>
  56 + [DataMember]
  57 + public string fullPath { get; set; }
  58 +
  59 + [DataMember]
  60 + public string type { get; set; }
  61 +
  62 + }
  63 +
  64 + /// <summary>
48 65 /// Stores image info
49 66 /// </summary>
50 67 [DataContract]
@@ -70,8 +87,7 @@ public MediaFile(string filePath, Picture image)
70 87 {
71 88 this.filePath = filePath;
72 89 this.fileName = System.IO.Path.GetFileName(this.filePath);
73   - // TODO find internal func
74   - this.type = "image/jpeg";
  90 + this.type = MimeTypeMapper.GetMimeType(fileName);
75 91 this.size = image.GetImage().Length;
76 92 this.lastModifiedDate = image.Date.ToString();
77 93
@@ -166,32 +182,41 @@ public void captureImage(string options)
166 182 /// Retrieves the format information of the media file.
167 183 /// </summary>
168 184 /// <param name="options"></param>
169   - public void getFormatData(Dictionary<string, object> options)
  185 + public void getFormatData(string options)
170 186 {
171   -
  187 + if(String.IsNullOrEmpty(options)){
  188 + this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
  189 + return;
  190 + }
  191 +
172 192 try
173   - {
174   - string filePath = string.Empty;
175   - string mimeType = string.Empty;
176   -
177   - if (options.ContainsKey("filePath"))
  193 + {
  194 + MediaFormatOptions mediaFormatOptions;
  195 + try
178 196 {
179   - filePath = (string)options["filePath"];
  197 + mediaFormatOptions = JSON.JsonHelper.Deserialize<MediaFormatOptions>(options);
  198 + }
  199 + catch (Exception ex)
  200 + {
  201 + this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, ex.Message));
  202 + return;
180 203 }
181 204
182   - if (options.ContainsKey("mimeType"))
  205 + if (string.IsNullOrEmpty(mediaFormatOptions.fullPath))
183 206 {
184   - mimeType = (string)options["mimeType"];
  207 + DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
185 208 }
186 209
187   - if (string.IsNullOrEmpty(filePath) || string.IsNullOrEmpty(mimeType))
  210 + string mimeType = mediaFormatOptions.type;
  211 +
  212 + if (string.IsNullOrEmpty(mimeType))
188 213 {
189   - DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR));
  214 + mimeType = MimeTypeMapper.GetMimeType(mediaFormatOptions.fullPath);
190 215 }
191 216
192   - if (mimeType.Equals("image/jpeg") || filePath.EndsWith(".jpeg"))
  217 + if (mimeType.Equals("image/jpeg"))
193 218 {
194   - WriteableBitmap image = ExtractImageFromLocalStorage(filePath);
  219 + WriteableBitmap image = ExtractImageFromLocalStorage(mediaFormatOptions.fullPath);
195 220
196 221 if (image == null)
197 222 {
@@ -206,8 +231,6 @@ public void getFormatData(Dictionary<string, object> options)
206 231 {
207 232 DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR));
208 233 }
209   -
210   -
211 234 }
212 235 catch (Exception e)
213 236 {
@@ -259,32 +282,41 @@ private void cameraTask_Completed(object sender, PhotoResult e)
259 282 }
260 283 else
261 284 {
262   - DispatchCommandResult(new PluginResult(PluginResult.Status.OK, files));
  285 + DispatchCommandResult(new PluginResult(PluginResult.Status.OK, files, "navigator.device.capture._castMediaFile"));
263 286 files.Clear();
264 287 }
265 288 }
266 289 catch(Exception ex)
267 290 {
268   - DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR));
  291 + DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR,"Error capturing image."));
269 292 }
270 293 break;
271 294
272 295 case TaskResult.Cancel:
273 296 if (files.Count > 0)
274 297 {
275   - // User canceled operation, but some images were made
276   - DispatchCommandResult(new PluginResult(PluginResult.Status.OK, files));
  298 + // User canceled operation, but some images were made
  299 + DispatchCommandResult(new PluginResult(PluginResult.Status.OK, files, "navigator.device.capture._castMediaFile"));
277 300 files.Clear();
278 301 }
279 302 else
280 303 {
281   - DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR));
  304 + DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Canceled."));
282 305 }
283 306 break;
284   - }
285   -
286   -
287 307
  308 + default:
  309 + if (files.Count > 0)
  310 + {
  311 + DispatchCommandResult(new PluginResult(PluginResult.Status.OK, files, "navigator.device.capture._castMediaFile"));
  312 + files.Clear();
  313 + }
  314 + else
  315 + {
  316 + DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Did not complete!"));
  317 + }
  318 + break;
  319 + }
288 320 }
289 321
290 322 /// <summary>
76 framework/PhoneGap/Commands/MimeTypeMapper.cs
... ... @@ -0,0 +1,76 @@
  1 +using System;
  2 +using System.Net;
  3 +using System.Windows;
  4 +using System.Windows.Controls;
  5 +using System.Windows.Documents;
  6 +using System.Windows.Ink;
  7 +using System.Windows.Input;
  8 +using System.Windows.Media;
  9 +using System.Windows.Media.Animation;
  10 +using System.Collections.Generic;
  11 +using System.IO;
  12 +
  13 +namespace WP7GapClassLib.PhoneGap.Commands
  14 +{
  15 + /// <summary>
  16 + /// Represents map to getting mime type by file extention
  17 + /// </summary>
  18 + public static class MimeTypeMapper
  19 + {
  20 + /// <summary>
  21 + /// Stores mime type for all necessary extension
  22 + /// </summary>
  23 + private static readonly Dictionary<string, string> MIMETypesDictionary = new Dictionary<string, string>
  24 + {
  25 + {"avi", "video/x-msvideo"},
  26 + {"bmp", "image/bmp"},
  27 + {"gif", "image/gif"},
  28 + {"jpe", "image/jpeg"},
  29 + {"jpeg", "image/jpeg"},
  30 + {"jpg", "image/jpeg"},
  31 + {"mov", "video/quicktime"},
  32 + {"mp2", "audio/mpeg"},
  33 + {"mp3", "audio/mpeg"},
  34 + {"mp4", "video/mp4"},
  35 + {"mpe", "video/mpeg"},
  36 + {"mpeg", "video/mpeg"},
  37 + {"mpg", "video/mpeg"},
  38 + {"mpga", "audio/mpeg"},
  39 + {"pbm", "image/x-portable-bitmap"},
  40 + {"pct", "image/pict"},
  41 + {"pgm", "image/x-portable-graymap"},
  42 + {"pic", "image/pict"},
  43 + {"pict", "image/pict"},
  44 + {"png", "image/png"},
  45 + {"pnm", "image/x-portable-anymap"},
  46 + {"pnt", "image/x-macpaint"},
  47 + {"pntg", "image/x-macpaint"},
  48 + {"ppm", "image/x-portable-pixmap"},
  49 + {"qt", "video/quicktime"},
  50 + {"ra", "audio/x-pn-realaudio"},
  51 + {"ram", "audio/x-pn-realaudio"},
  52 + {"ras", "image/x-cmu-raster"},
  53 + {"rgb", "image/x-rgb"},
  54 + {"snd", "audio/basic"},
  55 + {"tif", "image/tiff"},
  56 + {"tiff", "image/tiff"},
  57 + {"wav", "audio/x-wav"},
  58 + {"wbmp", "image/vnd.wap.wbmp"},
  59 +
  60 + };
  61 + /// <summary>
  62 + /// Gets mime type by file extension
  63 + /// </summary>
  64 + /// <param name="fileName">file name to extract extension</param>
  65 + /// <returns>mime type</returns>
  66 + public static string GetMimeType(string fileName)
  67 + {
  68 + if (MIMETypesDictionary.ContainsKey(Path.GetExtension(fileName).Remove(0, 1)))
  69 + {
  70 + return MIMETypesDictionary[Path.GetExtension(fileName).Remove(0, 1)];
  71 + }
  72 + // For unknown type it is allowed to use 'application/octet-stream' - http://stackoverflow.com/questions/1176022/unknown-file-type-mime
  73 + return "application/octet-stream";
  74 + }
  75 + }
  76 +}
3  framework/PhoneGap/PhoneGapCommandCall.cs
@@ -8,6 +8,7 @@
8 8 using System.Windows.Media;
9 9 using System.Windows.Media.Animation;
10 10 using System.Windows.Shapes;
  11 +using System.Linq;
11 12
12 13 namespace WP7GapClassLib.PhoneGap
13 14 {
@@ -44,7 +45,7 @@ public static PhoneGapCommandCall Parse(string commandStr)
44 45 commandCallParameters.Service = split[0];
45 46 commandCallParameters.Action = split[1];
46 47 commandCallParameters.CallbackId = split[2];
47   - commandCallParameters.Args = split.Length > 3 ? split[3] : String.Empty;
  48 + commandCallParameters.Args = split.Length <= 3 ? String.Empty : String.Join("/", split.Skip(3));
48 49
49 50 return commandCallParameters;
50 51 }
55 framework/PhoneGap/PluginResult.cs
@@ -8,6 +8,7 @@
8 8 using System.Windows.Media;
9 9 using System.Windows.Media.Animation;
10 10 using System.Windows.Shapes;
  11 +using System.Text;
11 12
12 13 namespace WP7GapClassLib.PhoneGap
13 14 {
@@ -52,7 +53,9 @@ public enum Status :int
52 53
53 54 public Status Result {get; private set;}
54 55 public string Message {get; private set;}
55   - public bool KeepCallback { get; set; }
  56 + public String Cast { get; private set; }
  57 +
  58 + public bool KeepCallback { get; set; }
56 59
57 60 /// <summary>
58 61 /// Whether command succeded or not
@@ -69,25 +72,63 @@ public bool IsSuccess
69 72 /// Creates new instance of the PluginResult class.
70 73 /// </summary>
71 74 /// <param name="status">Execution result</param>
72   - public PluginResult(Status status)
73   - : this(status, PluginResult.StatusMessages[(int)status])
  75 + public PluginResult(Status status)
  76 + : this(status, PluginResult.StatusMessages[(int)status])
74 77 {
75   - }
  78 + }
  79 +
  80 + /// <summary>
  81 + /// Creates new instance of the PluginResult class.
  82 + /// </summary>
  83 + /// <param name="status">Execution result</param>
  84 + /// <param name="message">The message</param>
  85 + public PluginResult(Status status, object message)
  86 + : this(status, message, null)
  87 + {
  88 + }
76 89
77 90 /// <summary>
78 91 /// Creates new instance of the PluginResult class.
79 92 /// </summary>
80 93 /// <param name="status">Execution result</param>
81   - /// <param name="callBackArgs">Callback parameters</param>
82   - public PluginResult(Status status, object message)
  94 + /// <param name="message">The message</param>
  95 + /// <param name="cast">The cast parameter</param>
  96 + public PluginResult(Status status, object message, string cast)
83 97 {
84 98 this.Result = status;
85 99 this.Message = JSON.JsonHelper.Serialize(message);
  100 + this.Cast = cast;
86 101 }
87 102
88 103 public string ToJSONString()
89 104 {
90   - return "{status:" + (int)this.Result + ",message:" + this.Message + ",keepCallback:" + this.KeepCallback + "}";
  105 +
  106 + return "'{status:" + (int)this.Result + ",message:" + this.Message + ",keepCallback:" + this.KeepCallback + "}'";
  107 +
  108 + }
  109 +
  110 + public string ToCallbackString(string callbackId, string successCallback, string errorCallback)
  111 + {
  112 + //return String.Format("{0}('{1}',{2});", successCallback, callbackId, this.ToJSONString());
  113 +
  114 + if (this.IsSuccess)
  115 + {
  116 + StringBuilder buf = new StringBuilder("");
  117 + if (this.Cast != null)
  118 + {
  119 + buf.Append("var temp = " + this.Cast + "(" + this.ToJSONString() + ");\n");
  120 + buf.Append(String.Format("{0}('{1}',temp);", successCallback, callbackId));
  121 + }
  122 + else
  123 + {
  124 + buf.Append(String.Format("{0}('{1}',{2});", successCallback, callbackId, this.ToJSONString()));
  125 + }
  126 + return buf.ToString();
  127 + }
  128 + else
  129 + {
  130 + return String.Format("{0}('{1}',{2});", errorCallback, callbackId, this.ToJSONString());
  131 + }
91 132 }
92 133
93 134 public override String ToString()
1  framework/WP7GapClassLib.csproj
@@ -60,6 +60,7 @@
60 60 </ItemGroup>
61 61 <ItemGroup>
62 62 <Compile Include="PhoneGap\JSON\JsonHelper.cs" />
  63 + <Compile Include="PhoneGap\Commands\MimeTypeMapper.cs" />
63 64 <Compile Include="PhoneGap\PhoneGapCommandCall.cs" />
64 65 <Compile Include="PhoneGap\CommandFactory.cs" />
65 66 <Compile Include="PhoneGap\Commands\Accelerometer.cs" />

0 comments on commit f3cb136

Please sign in to comment.
Something went wrong with that request. Please try again.