vault a file from vb.net

rated by 0 users
This post has 7 Replies | 2 Followers

Top 150 Contributor
Posts 9
Points 20
gwilliams Posted: Fri, Oct 19 2007 9:50 AM

Insufficient relationship count (0) of Located relationships. At least 1 required.

 

I can't vault a file - can some one explain what I'm doing wrong?

 

Dim conn As IOM.HTTPServerConnection = New IOM.HTTPServerConnection

conn.innovator_server_url = "http://10.12.19.57/InnovatorServer/Server/InnovatorServer.aspx"

conn.http_username = "willig01"

conn.http_password = IOM.Innovator.ScalcMD5("12345678")

conn.http_database = "InnovatorSolutions"

conn.vault_server_url = "http://10.12.19.57/InnovatorServer/vault/VaultServer.aspx"

Dim inn As IOM.Innovator = New IOM.Innovator(conn)

Dim queryItem As IOM.Item = inn.newItem("User", "get")

queryItem.setAttribute("select", "login_name")

Dim qryRes As IOM.Item = queryItem.apply

System.Console.WriteLine("Number of Users: " & qryRes.getItemCount)

'Dim docItm As IOM.Item = inn.getItemByKeyedName("Document", "1234567")

'docItm.apply("edit")

'docItm.setProperty("Description", "Desc???")

Dim fileItm As IOM.Item = inn.newItem("File", "add")

fileItm.setFileName("C:\Gary\CMII\Legend.dwg")

'Dim relItm As IOM.Item = inn.newItem("Document File", "add")

'docItm.addRelationship(relItm)

'relItm.setRelatedItem(fileItm)

Dim Res As IOM.Item = fileItm.apply()

If Res.isError Then

Console.WriteLine(Res.getErrorDetail)

End If

conn.Close()

  • Filed under: ,
  • | Post Points: 20
Top 10 Contributor
Posts 149
Points 5,665

I had the same problem on a project last month.   The solution is quite easy.      Innovator uses a distributed/replicated vaulting model.   The File Item has a relationship to Vault item,  that allows you to specify which vault the file should be stored into.     A File can be Located in 1 or more Vaults,  but has to be in at least one Vault.    The error message indicates that at least one instance of the Located relationship is required.

here's what I usually do:

After connecting,  the first query I run is to request the Default Vault for the current user,  this confirms that the connection parameters are valid,  and gets the Vault ID that I need.  This also gets the URL to the Vault Server (you have this hard-coded in your sample).  

When you create the File item,  you also need to create a Located relationship underneath it to specify the vaulting meta-data.  Then do the Apply().  VB.NET sample follows:

        Dim ConnectTest As Item = inn.newItem("User", "get")
        ConnectTest.setAttribute("select", "default_vault")
        ConnectTest.setProperty("login_name", vUsername)
        Dim ConnectTestResult As Item
        ConnectTestResult = ConnectTest.apply()
        If ConnectTestResult.isError() Then
            MsgBox("Error: " & ConnectTestResult.getErrorDetail(), , "Publish2Innovator")
            MyConnection.Logout()
            Return
        End If
        vDefaultVault = ConnectTestResult.getProperty("default_vault")

This sample takes the username provided, and tries to connect, and if successful, returns the ID of the default vault for this user.  Next sample shows how to use this with the File item.

            Dim File As Item = MyItem.newItem("File", "add")
            File.setProperty("filename", filename)
            File.setProperty("actual_filename", pathname)
            File.setProperty("checkedout_path", pathname.Substring(0, pathname.LastIndexOf("\")))
            File.attachPhysicalFile(pathname, vDefaultVault)
I am using a different IOM function here,  that sets the filename and builds the Located relationship in one step.   You could also more explicitly just create the relationship under your File item:

           Dim fileItm As Item = inn.newItem("File", "add")
           Dim fileLocatedRel As Item = inn.newItem("Located", "add")
           fileItm.setFileName("C:\Gary\CMII\Legend.dwg")
           fileLocatedRel.setProperty("related_id",vDefaultVault)
           fileItm.addRelationship(fileLocatedRel)
           Dim Res As IOM.Item = fileItm.apply()

Let me know if this works.    NOTE:  there were some fixes in the IOM.DLL  (patch for the 8.1.1 publically released version).   Drop me an email if you want the updated IOM.   pschroer@aras.com

 

 


 

Peter Schroer Aras Corp pschroer@aras.com
Top 150 Contributor
Posts 9
Points 20
gwilliams replied on Fri, Oct 19 2007 2:28 PM

 

Thank you for the help. Files are going in the Vault now.

I have a problem viewing tif files though. The viewer loads I can see it - then I'm asked to install active x control ArasIG.cab and when I do I get a blank page.

 

  • | Post Points: 0
Top 150 Contributor
Posts 9
Points 20
gwilliams replied on Fri, Oct 19 2007 5:13 PM

 

I spoke to soon - the file never gets in the vault. It has a location path but the path is not there.

It is in the files form.

 

 

Dim conn As IOM.HTTPServerConnection = New IOM.HTTPServerConnection

conn.innovator_server_url = "http://10.12.19.57/InnovatorServer/Server/InnovatorServer.aspx"

conn.http_username = "admin"

conn.http_password = IOM.Innovator.ScalcMD5("innovator")

conn.http_database = "InnovatorSolutions"

Dim inn As IOM.Innovator = New IOM.Innovator(conn)

Dim ConnectTest As IOM.Item = inn.newItem("User", "get")

ConnectTest.setAttribute("select", "default_vault")

ConnectTest.setProperty("login_name", "admin")

Dim ConnectTestResult As IOM.Item

ConnectTestResult = ConnectTest.apply()

If ConnectTestResult.isError() Then

MsgBox("Error: " & ConnectTestResult.getErrorDetail(), , "Publish2Innovator")

'MyConnection.Logout()

Return

End If

Dim vDefaultVault As String = ConnectTestResult.getProperty("default_vault")

Dim docItm As IOM.Item = inn.newItem("Document", "add")

docItm.setProperty("item_number", "112")

'docItm.setProperty("Description", "Desc???")

Dim docRes As IOM.Item = docItm.apply()

If docRes.isError Then

Console.WriteLine(docRes.getErrorDetail)

End If

Dim EDdocItm As IOM.Item = inn.newItem("Document", "edit")

EDdocItm.setAttribute("where", "[DOCUMENT].ITEM_NUMBER='112' and [DOCUMENT].IS_CURRENT='1'")

EDdocItm.setProperty("Description", "Desc???")

Dim size As Long = File.OpenRead("C:\Gary\CMII\Legend.dwg").Length

Dim fileItm As IOM.Item = inn.newItem("File", "add")

Dim fileLocatedRel As IOM.Item = inn.newItem("Located", "add")

fileItm.setFileName("C:\Gary\CMII\Legend.dwg")

fileLocatedRel.setProperty("related_id", vDefaultVault)

fileItm.addRelationship(fileLocatedRel)

fileItm.setProperty("file_type", "F2B9580CB239419A8CB12A02E4FC6962")

fileItm.setProperty("file_size", size)

Dim Res As IOM.Item = fileItm.apply()

If Res.isError Then Console.WriteLine(Res.getErrorDetail)

Dim fileItm2 As IOM.Item = inn.getItemByKeyedName("File", "Legend.dwg")

Dim relItm As IOM.Item = inn.newItem("Document File", "add")

relItm.setRelatedItem(fileItm2)

EDdocItm.addRelationship(relItm)

fileItm2.unlockItem()

EDdocItm.unlockItem()

Dim EDdocRes As IOM.Item = EDdocItm.apply()

If EDdocRes.isError Then Console.WriteLine(EDdocRes.getErrorDetail)

conn.Close()

Top 10 Contributor
Posts 149
Points 5,665

You'll need the patched IOM.DLL -   the 8.1.1   released version works for everything but the file handling.  

There is a work around:    you can create the  SOAP and XML message yourself  (IOM is a developers convenience layer)  and this works just fine.   The underlying web service is working...  the IOM is just not handling the physical file hand-off to the Vault's web service.  

Customers on support contracts have access to the patched IOM.DLL,  drop me an email if you want to try it,  or we can show you the work around.   

Peter Schroer Aras Corp pschroer@aras.com
  • | Post Points: 0
Not Ranked
Posts 1
Points 0
bbrink replied on Mon, Nov 12 2007 1:50 PM
When will the patched IOM.DLL be availible to the public? I'm having the same problem, and I wish to use the IOM instead of writing the SOAP/XML stuff myself.
  • | Post Points: 0
Top 10 Contributor
Posts 149
Points 5,665

Version 8.2 release to subscribers is a couple weeks out. It's in the Test and Release process right now.      The "open" posting of the 8.2 code base will likely follow the customer release by several weeks. 

Drop me an email and let me know what you are working on. I'll see if I can help.   pschroer@aras.com

 

Peter Schroer Aras Corp pschroer@aras.com
  • | Post Points: 0
Top 50 Contributor
Posts 36
Points 475

In release 8.2 IOM API has gone through some cleanup during which we tried to achieve several goals:

- have a single implementation of IOM API (prior to 8.2 there were 3 different implementations: .NET, JavaScript and COM)

- remove or obsolete methods that did not belong to the API and all they did could be easily achieved by other means. For example, everything the method Item.getWorkflows() did was getting relationships of type “Workflow” of the item, which can be done by just calling Item.getRelationships( “Workflow”). Currently IOM API contains only methods that are required to build an AML request; send it to the server and parse server AML response; plus a small set of utility methods (like Innovator.ScalcMD5(), etc.). Everything else that does not meet the criteria was removed from the IOM API in release 8.2 or was declared obsolete (these methods are still there but you'll get compilation warnings if you use them) and would be removed from future releases of IOM.

- provide a consistent way of login to Innovator

- provide a simple and transparent mechanism of uploading files to vault

Here is a small C# example based on 8.2+ IOM API that demonstrates how to connect to Innovator server; create item of type "File"; attach a physical file to it and submit the item to Innovator (which will upload physical file to the vault server and create an item of type "File" in Innovator's database that references the physical file in vault):

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using Aras.IOM;

namespace ForumDemo

{

class Program

{

// Let's assume here that:

// args[0] - server url

// args[1] - db name

// args[2] - user name

// args[3] - user password

// args[4] - path to physical file

// args[5] - local directory for file checkout

// NOTE: for simplicity no checking for number of arguments, etc. is done here

static void Main(string[] args)

{

try

{

Innovator inn = Login(args[0], args[1], args[2], args[3]);

string file_id = CheckIn(inn, args[4]);

CheckOut(inn, file_id, args[5]);

Console.WriteLine("Done");

}

catch (Exception exc)

{

Console.WriteLine("ERROR: {0}", exc.Message);

}

}

internal static Innovator Login(string url, string db, string user, string password)

{

// First: create connection

// NOTE: it's assumed that password was passed from the command line as not encrypted.

HttpServerConnection connection = IomFactory.CreateHttpServerConnection( url, db, user, Innovator.ScalcMD5( password ) );

// Second: login using the connection

Item log_result = connection.Login();

if (log_result.isError())

{

throw new Exception(string.Format("Failed to login to Innovator '{0}': {1}", url, getErrorDescription(log_result)));

}

// Third: create instance of Innovator with the logged-in connection

return new Innovator(connection);

}

internal static string CheckIn(Innovator inn, string file_path)

{

Item fitem = inn.newItem("File", "add");

fitem.setProperty("filename", file_path.Substring(file_path.LastIndexOf(System.IO.Path.DirectorySeparatorChar)));

fitem.attachPhysicalFile(file_path);

Item checkin_result = fitem.apply();

if (checkin_result.isError())

{

throw new Exception(string.Format("Failed to check-in file '{0}': {1}", file_path, getErrorDescription(checkin_result)));

}

return fitem.getID();

}

internal static void CheckOut(Innovator inn, string file_id, string dir)

{

Item get_file_request = inn.newItem();

get_file_request.setType("File");

get_file_request.setAction("get");

get_file_request.setID(file_id);

Item file_item = get_file_request.apply();

Item checkout_result = file_item.checkout(dir);

if (checkout_result.isError())

throw new Exception(string.Format("Failed to check-out file with ID={0}: {1}", file_id, getErrorDescription(checkout_result)));

}

private static string getErrorDescription(Item error)

{

StringBuilder sb = new StringBuilder();

string ecode = error.getErrorCode();

if (ecode != null)

sb.Append(string.Format("\nErrorCode:\t{0}", ecode));

string estr = error.getErrorString();

if (estr != null)

sb.Append(string.Format("\nErrorMessage:\t{0}", estr));

string edtl = error.getErrorDetail();

if (edtl != null)

sb.Append(string.Format("\nErrorDetails:\t{0}", edtl));

return sb.ToString();

}

}

}

  • | Post Points: 0
Page 1 of 1 (8 items) | RSS