using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using IMiS.StorageConnector;
namespace ConsoleApplication1
{
class Program
{
/// <summary>
/// Store local file as object on IMiS/ARC Storage Server.
/// </summary>
/// <param name="host">
/// An IMiS/ARC Storage Server host.
/// </param>
/// <param name="port">
/// An IMiS/ARC Storage Server port.
/// </param>
/// <param name="profile">
/// An IMiS/ARC Storage Server profile.
/// </param>
/// <param name="fileName">
/// The file path of the local file to be stored.
/// </param>
/// <returns>
/// The IMiS/ARC Storage Server object identifier.
/// </returns>
static string StoreObjectToIMiSARC(string host, int port, string profile, string fileName)
{
string objectId = "";
// Get an instance of the IMiS/Storage Connector
StorageConnector sc = StorageConnector.Instance;
try
{
// Open storage on IMiS/ARC Storage Server
Storage stg = sc.OpenIMiSARCStorage(host, port);
try
{
// Store local file as an object on IMiS/ARC
// Remarks: when null or empty mime parameter
// is specified, IMiS/Storage Connector tries
// to resolve the MIME type from the file extension
objectId = stg.StoreObject(fileName, profile, null);
}
finally
{
// Close IMiS/ARC storage
stg.Close();
stg = null;
}
}
finally
{
// Release IMiS/Storage Connector instance
sc = null;
StorageConnector.FreeInstance();
}
return objectId;
}
static void Main(string[] args)
{
try
{
string host = args[0];
int port = Int32.Parse(args[1]);
string profile = args[2];
string fileName = args[3];
// Store local file as object on IMiS/ARC
string objectId = StoreObjectToIMiSARC(host, port, profile, fileName);
// Show object identifier
Console.Out.WriteLine("Object stored on IMiS/ARC Storage Server with Id = {0}", objectId);
}
catch (Exception ex)
{
// Show error message
Console.Out.WriteLine("ErrorMessage = {0}", ex.Message);
}
}
}
} |