30. September 2009 10:54
// create necessary automations
IF (ISCLEAR(Decoding)) THEN
IF NOT (CREATE(Decoding, TRUE, FALSE)) THEN
ERROR(txtAutomationInstanciationErr, 'Decoding');
IF (ISCLEAR(Encoding)) THEN
IF NOT (CREATE(Encoding, TRUE, TRUE)) THEN
ERROR(txtAutomationInstanciationErr, 'Encoding');
// open file via automation and store in base64String
// what happens on error in 'Encoding.encodeFile'?
base64String.ADDTEXT(Encoding.encodeFile(sourceFile));
// Decode the base64 encoded file into the tmpFile
ErrorCode := Decoding.decodeToFile(base64String, targetFile);
namespace DropZone.Automations
{
[Guid("B1E4786B-F32E-481c-AF6C-4004D6E67864")]
public interface IDecoding
{
[DispId(1)]
int decodeToFile(StringBuilder base64String, string filename);
}
/// <summary>
///
/// </summary>
[ClassInterface(ClassInterfaceType.None)]
[Guid("2FB58F9C-9E3B-48b0-8841-4B105D434E67")]
public class Base64Decoding : IDecoding
{
/// <summary>
///
/// </summary>
/// <param name="base64String"></param>
/// <param name="filename"></param>
/// <returns></returns>
public int decodeToFile(StringBuilder base64String, string filename)
{
try
{
System.IO.Directory.CreateDirectory(filename.Substring(0,filename.LastIndexOf('\\')));
System.IO.File.WriteAllBytes(filename, Convert.FromBase64String(base64String.ToString()));
return 0;
}
#region ExceptionHandling
[...]
#endregion
}
}
}
30. September 2009 11:20
30. September 2009 11:41
9. Oktober 2009 11:04
public string decode(Object base64String, string filename)
{
try
{
System.IO.Directory.CreateDirectory(filename.Substring(0, filename.LastIndexOf('\\')));
System.IO.File.WriteAllBytes(filename, Convert.FromBase64String(base64String as String));
return "SUCCESS";
}
catch (Exception exc)
{
return exc.ToString();
}