You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2013/01/23 01:22:04 UTC
[1/16] wp7 commit: consolidation of commands with wp8
consolidation of commands with wp8
Project: http://git-wip-us.apache.org/repos/asf/cordova-wp7/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp7/commit/2ff76c6d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp7/tree/2ff76c6d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp7/diff/2ff76c6d
Branch: refs/heads/master
Commit: 2ff76c6dd112b92b5ecdee3160e99d0603ffce11
Parents: 8043c07
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Tue Jan 15 15:52:01 2013 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Tue Jan 15 15:52:01 2013 -0800
----------------------------------------------------------------------
.../standalone/cordovalib/Commands/Contacts.cs | 20 +++--
templates/standalone/cordovalib/Commands/Device.cs | 5 +-
templates/standalone/cordovalib/Commands/File.cs | 60 ++++++++++++++-
.../standalone/cordovalib/Commands/FileTransfer.cs | 5 +-
.../cordovalib/Commands/ImageExifHelper.cs | 2 +-
.../standalone/cordovalib/Commands/Notification.cs | 1 -
6 files changed, 77 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/2ff76c6d/templates/standalone/cordovalib/Commands/Contacts.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/Commands/Contacts.cs b/templates/standalone/cordovalib/Commands/Contacts.cs
index df9c67e..af78942 100644
--- a/templates/standalone/cordovalib/Commands/Contacts.cs
+++ b/templates/standalone/cordovalib/Commands/Contacts.cs
@@ -176,7 +176,7 @@ namespace WPCordovaClassLib.Cordova.Commands
string[] args = JSON.JsonHelper.Deserialize<string[]>(jsonContact);
- JSONContact contact = JSON.JsonHelper.Deserialize<JSONContact>(args[0]) ;
+ JSONContact contact = JSON.JsonHelper.Deserialize<JSONContact>(args[0]);
SaveContactTask contactTask = new SaveContactTask();
@@ -344,7 +344,7 @@ namespace WPCordovaClassLib.Cordova.Commands
deviceContacts.SearchAsync(displayName, FilterKind.DisplayName, task);
});
-
+
}
else if (e.TaskResult == TaskResult.Cancel)
@@ -611,16 +611,22 @@ namespace WPCordovaClassLib.Cordova.Commands
"\"honorificPrefix\":\"{4}\"," +
"\"honorificSuffix\":\"{5}\"";
- retVal = string.Format(formatStr,
- con.CompleteName.FirstName, // TODO:
+ if (con.CompleteName != null)
+ {
+ retVal = string.Format(formatStr,
+ con.CompleteName.FirstName + " " + con.CompleteName.LastName, // TODO: does this need suffix? middlename?
con.CompleteName.LastName,
con.CompleteName.FirstName,
con.CompleteName.MiddleName,
con.CompleteName.Title,
con.CompleteName.Suffix);
+ }
+ else
+ {
+ retVal = string.Format(formatStr,"","","","","","");
+ }
return "{" + retVal + "}";
-
}
private string FormatJSONContact(Contact con, string[] fields)
@@ -641,7 +647,7 @@ namespace WPCordovaClassLib.Cordova.Commands
string jsonContact = String.Format(contactFormatStr,
con.GetHashCode(),
con.DisplayName,
- con.CompleteName.Nickname,
+ con.CompleteName != null ? con.CompleteName.Nickname : "",
FormatJSONPhoneNumbers(con),
FormatJSONEmails(con),
FormatJSONAddresses(con),
@@ -652,7 +658,7 @@ namespace WPCordovaClassLib.Cordova.Commands
//Debug.WriteLine("jsonContact = " + jsonContact);
// JSON requires new line characters be escaped
- return "{" + jsonContact.Replace("\n", "\\n") +"}";
+ return "{" + jsonContact.Replace("\n", "\\n") + "}";
}
}
}
http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/2ff76c6d/templates/standalone/cordovalib/Commands/Device.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/Commands/Device.cs b/templates/standalone/cordovalib/Commands/Device.cs
index ffeacb4..e23b6f9 100644
--- a/templates/standalone/cordovalib/Commands/Device.cs
+++ b/templates/standalone/cordovalib/Commands/Device.cs
@@ -43,6 +43,8 @@ namespace WPCordovaClassLib.Cordova.Commands
this.version,
this.model);
+
+
res = "{" + res + "}";
//Debug.WriteLine("Result::" + res);
DispatchCommandResult(new PluginResult(PluginResult.Status.OK, res));
@@ -53,15 +55,16 @@ namespace WPCordovaClassLib.Cordova.Commands
get
{
return DeviceStatus.DeviceName;
+ //return String.Format("{0},{1},{2}", DeviceStatus.DeviceManufacturer, DeviceStatus.DeviceHardwareVersion, DeviceStatus.DeviceFirmwareVersion);
}
}
-
public string name
{
get
{
return DeviceStatus.DeviceName;
+
}
}
http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/2ff76c6d/templates/standalone/cordovalib/Commands/File.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/Commands/File.cs b/templates/standalone/cordovalib/Commands/File.cs
index 91d85d6..0a0efa1 100644
--- a/templates/standalone/cordovalib/Commands/File.cs
+++ b/templates/standalone/cordovalib/Commands/File.cs
@@ -348,11 +348,11 @@ namespace WPCordovaClassLib.Cordova.Commands
try
{
- this.FullPath = filePath;// new Uri(filePath).LocalPath;
+ this.FullPath = filePath.Replace('\\', '/'); // new Uri(filePath).LocalPath;
}
catch (Exception)
{
-
+ this.FullPath = filePath;
}
}
}
@@ -627,6 +627,53 @@ namespace WPCordovaClassLib.Cordova.Commands
}
}
+ /// <summary>
+ /// Reads application resource as a text
+ /// </summary>
+ /// <param name="options">Path to a resource</param>
+ public void readResourceAsText(string options)
+ {
+ string pathToResource;
+ try
+ {
+ string[] optStrings = JSON.JsonHelper.Deserialize<string[]>(options);
+ pathToResource = optStrings[0];
+ }
+ catch (Exception)
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+ return;
+ }
+
+ try
+ {
+ if (pathToResource.StartsWith("/"))
+ {
+ pathToResource = pathToResource.Remove(0, 1);
+ }
+
+ var resource = System.Windows.Application.GetResourceStream(new Uri(pathToResource, UriKind.Relative));
+
+ if (resource == null)
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, NOT_FOUND_ERR));
+ return;
+ }
+
+ string text;
+ StreamReader streamReader = new StreamReader(resource.Stream);
+ text = streamReader.ReadToEnd();
+
+ DispatchCommandResult(new PluginResult(PluginResult.Status.OK, text));
+ }
+ catch (Exception ex)
+ {
+ if (!this.HandleException(ex))
+ {
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, NOT_READABLE_ERR));
+ }
+ }
+ }
public void truncate(string options)
{
@@ -1226,6 +1273,12 @@ namespace WPCordovaClassLib.Cordova.Commands
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, INVALID_MODIFICATION_ERR));
return;
}
+ else if (isoFile.DirectoryExists(newPath))
+ {
+ // there is already a folder with the same name, operation is not allowed
+ DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, INVALID_MODIFICATION_ERR));
+ return;
+ }
else if (isoFile.FileExists(newPath))
{ // remove destination file if exists, in other case there will be exception
isoFile.DeleteFile(newPath);
@@ -1348,7 +1401,6 @@ namespace WPCordovaClassLib.Cordova.Commands
}
}
- // TODO: this is NOT working, object is not valid ...
private void GetFileOrDirectory(string options, bool getDirectory)
{
FileOptions fOptions = new FileOptions();
@@ -1406,8 +1458,10 @@ namespace WPCordovaClassLib.Cordova.Commands
return;
}
+
// need to make sure the parent exists
// it is an error to create a directory whose immediate parent does not yet exist
+ // see issue: https://issues.apache.org/jira/browse/CB-339
string[] pathParts = path.Split('/');
string builtPath = pathParts[0];
for (int n = 1; n < pathParts.Length - 1; n++)
http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/2ff76c6d/templates/standalone/cordovalib/Commands/FileTransfer.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/Commands/FileTransfer.cs b/templates/standalone/cordovalib/Commands/FileTransfer.cs
index f2a83a1..e585895 100644
--- a/templates/standalone/cordovalib/Commands/FileTransfer.cs
+++ b/templates/standalone/cordovalib/Commands/FileTransfer.cs
@@ -251,9 +251,8 @@ namespace WPCordovaClassLib.Cordova.Commands
{
try
{
- String obj = JSON.JsonHelper.Deserialize<String[]>(options)[0];
-
- uploadOptions = JSON.JsonHelper.Deserialize<UploadOptions>(obj);
+ string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
+ uploadOptions = JSON.JsonHelper.Deserialize<UploadOptions>(args[0]);
}
catch (Exception)
{
http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/2ff76c6d/templates/standalone/cordovalib/Commands/ImageExifHelper.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/Commands/ImageExifHelper.cs b/templates/standalone/cordovalib/Commands/ImageExifHelper.cs
index ec78201..68ddf87 100644
--- a/templates/standalone/cordovalib/Commands/ImageExifHelper.cs
+++ b/templates/standalone/cordovalib/Commands/ImageExifHelper.cs
@@ -135,7 +135,7 @@ namespace WPCordovaClassLib.Cordova.Commands
// Get the data length
ushort dLen = BitConverter.ToUInt16(reader.ReadBytes(2), 0);
// skip along
- reader.BaseStream.Seek(dLen - 2, SeekOrigin.Current);
+ reader.ReadBytes(dLen - 2);
start = reader.ReadByte();
index = reader.ReadByte();
}
http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/2ff76c6d/templates/standalone/cordovalib/Commands/Notification.cs
----------------------------------------------------------------------
diff --git a/templates/standalone/cordovalib/Commands/Notification.cs b/templates/standalone/cordovalib/Commands/Notification.cs
index eeae341..0caca97 100644
--- a/templates/standalone/cordovalib/Commands/Notification.cs
+++ b/templates/standalone/cordovalib/Commands/Notification.cs
@@ -22,7 +22,6 @@ using System.Windows.Resources;
using Microsoft.Phone.Controls;
using Microsoft.Xna.Framework.Audio;
using WPCordovaClassLib.Cordova.UI;
-using System.Diagnostics;
namespace WPCordovaClassLib.Cordova.Commands
{