| Back | Main view

Storing objects on IMiS/ARC with IMiS/Storage Connector .NET

Product:IMiS/Storage Connector .NET
Release:1.1.1007
Date:11/23/2010

Case: This article will demonstrate how to use IMiS/Storage Connector .NET interface to store a file on a local file system as an object on IMiS/ARC Storage Server.

Description:

Storing an object on IMiS/ARC Storage Server with IMiS/Storage Connector is done with the following steps:
1. get an instance of the StorageConnector class
2. open a storage on IMiS/ARC Storage Server specified by the hostname and port
3. use the StoreObject method of the Storage class to store a local file as an object on the IMiS/ARC Storage Server.

Notes:
The sample C# code provided is a Console Application project created in Visual Studio 2005 with a reference to an IMiS/Storage Connector assembly.
The Console Application gets the IMiS/ARC Storage Server host, port and profile, and an local file path through the command line arguments.


C#
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);
      }
    }
  }
}
 

Related Documents:

Database 'IMiS Knowledge database', View 'All Documents', Document 'Retrieving objects from IMiS/ARC with IMiS/Storage Connector .NET' Retrieving objects from IMiS/ARC with IMiS/Storage Connector .NET

| Back | Main view