Get ArcGIS for Server System folder from SOI

1414
7
Jump to solution
09-11-2016 11:14 PM
JoseSousa
Esri Contributor

Hi,

How can I obtain the ArcGIS for Server System Folder from within a Server Object Interceptor (SOI)?

The folder I am looking for is:

C:\arcgisserver\directories\arcgissystem

I need to get access to the arcgisuploads folder and would like to do that dynamically by asking ArcGIS for Server what is the configured location of the arcgissystem folder.

Can you share this information? 

Cheers,

Jose

1 Solution

Accepted Solutions
nicogis
MVP Frequent Contributor
var se4 = this.ServerEnvironment as IServerEnvironmentEx;
                    var dirInfos = se4.GetServerDirectoryInfos();
                    dirInfos.Reset();
                    object dirInfo = dirInfos.Next();
                    while (dirInfo != null)
                    {
                        var dinfo2 = dirInfo as IServerDirectoryInfo2;
                        if (null != dinfo2 && dinfo2.Type == esriServerDirectoryType.esriSDTypeSystem)
                        {
                            string pathSystem = dinfo2.Path;
                            break;
                        }
 
                        dirInfo = dirInfos.Next();
                    }

View solution in original post

7 Replies
nicogis
MVP Frequent Contributor
var se4 = this.ServerEnvironment as IServerEnvironmentEx;
                    var dirInfos = se4.GetServerDirectoryInfos();
                    dirInfos.Reset();
                    object dirInfo = dirInfos.Next();
                    while (dirInfo != null)
                    {
                        var dinfo2 = dirInfo as IServerDirectoryInfo2;
                        if (null != dinfo2 && dinfo2.Type == esriServerDirectoryType.esriSDTypeSystem)
                        {
                            string pathSystem = dinfo2.Path;
                            break;
                        }
 
                        dirInfo = dirInfos.Next();
                    }
JoseSousa
Esri Contributor

Hi Domenico,

Thanks for sharing. Much appreciated.

The line below causes a COM error:

object dirInfo = dirInfos.Next();

The error is:

{"Unable to cast COM object of type 'System.__ComObject' to interface type 'ESRI.ArcGIS.Server.IServerDirectoryInfo'.

This operation failed because the QueryInterface on the COM component for the interface with IID '{CF180145-BCFE-4D6F-AC53-3B9E127AF840}'

failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."}

Have you tried this in ArcGIS for Server 10.4.1? The account running is an admin of course. I wonder if Esri changed this in 10.4.1?

The dirInfos.Count works though ...

Cheers,

Jose

0 Kudos
nicogis
MVP Frequent Contributor

Hi Jose, I have tried and in 10.4.1 I have same error. Peraphs it's a bug.

In fact if you see code sample Esri (Watermark) in sdk 10.4.1  I see comment '//interop problem' and try/catch ....

try
                {
                    //interop problem?
                    var se4 = _restSOIHelper.ServerEnvironment as IServerEnvironmentEx;
                    var dirInfos = se4.GetServerDirectoryInfos();
                    dirInfos.Reset();
                    object dirInfo = dirInfos.Next();
                    while (dirInfo != null)
                    {
                        var dinfo2 = dirInfo as IServerDirectoryInfo2;
                        if (null != dinfo2 && dinfo2.Type == esriServerDirectoryType.esriSDTypeOutput)
                        {
                            _outputDirectory = dinfo2.Path;
                            break;
                        }
                        dirInfo = dirInfos.Next();
                    }
                }
                catch (Exception ignore)
                {
                    _outputDirectory = string.Empty;
                }

                _outputDirectory = _outputDirectory.Trim();
                if (string.IsNullOrEmpty(_outputDirectory))
                {
                    _serverLog.LogMessage(ServerLogger.msgType.error, _soiName + ".init()", 500, "OutputDirectory is empty or missing. Reset to default.");
                    _outputDirectory = "C:\\arcgisserver\\directories\\arcgisoutput";
                }
0 Kudos
JoseSousa
Esri Contributor

Hi Domenico,

Thanks for coming back to me.

I will accept your initial response as Correct and wait for Esri Inc. to fix the issue.

Cheers,

Jose

0 Kudos
MaximilianGlas
Esri Contributor

Actual Version 10.6, and this problem is still not fixed.

0 Kudos
by Anonymous User
Not applicable

Uploads directory located on Drive installed location C:\arcgisserver\directories\arcgissystem\arcgisuploads

0 Kudos
RebeccaStrauch__GISP
MVP Esteemed Contributor

If you decide that you would like to see an option in python, or can use this to convert.... 

I'm doing something similar in python to find the physical path for the arcgisinput directory which is on my D: drive.  I get it by reading the info from the arcgisinput.json file located in the default C:\arcgisserver\config-store\serverdirs folder.  You should be able to do the same from the arcgisuploads.json file.  But sorry, only have it for arcpy/python.

In general, in python..

import sys
import os
import json
from pprint import pprint  # prints json pairs in readable format
import arcpy

server = "machinename"
serverPath = (r"\\{0}\c$\arcgisserver".format(server))

configInDir = os.path.join(serverPath, "config-store", "serverdirs", "arcgisinput.json")

# from arcgisinput.json file, determines the physical path of the services folder
with open(configInDir) as data_file:
     data = json.load(data_file)   #if issue in python 3.x, look at json.loads as option
     PhyPath = data['physicalPath']
     RelPath = (os.path.splitdrive(PhyPath)[1])
     #servicesDir = (r"{0}{1}".format(uncpath, RelPath))
     pprint(data)  # For debugging, to print out the .ini info

...you would have to update and test for the uploads file and convert it for your use.