Forum Discussion

FrankDK's avatar
FrankDK
Contributor
2 years ago

Smart Connector with access to SMB Fileshare

Anyone aware if the Smart Connector solution supports a way to access a SMB fileshare on the clients network? Use case is that client uses a file-share for flat-file exchange
  • Ryan_Berry's avatar
    5 months ago

    MZ ,

    I have a working example for you -- have to do some tricks to convert the file to base64 encoded string to pass it over but it works.

     

    public object Main(SessionInfo si, BRGlobals globals, object api, ExtenderArgs args)
    {
    try
    {
    string fileName = BRApi.Utilities.GetFileShareFolder(si, FileShareFolderTypes.ApplicationOutgoing, null) + "\\test5mb.txt";
    //string fileName = BRApi.Utilities.GetFileShareFolder(si, FileShareFolderTypes.ApplicationOutgoing, null) + "\\hw_25000.csv";
    BRApi.ErrorLog.LogMessage(si, "Reading File: " + fileName);
    byte[] fileBytes = System.IO.File.ReadAllBytes(fileName);
    string base64String = Convert.ToBase64String(fileBytes);
     
    if (fileBytes != null && !String.IsNullOrEmpty(base64String))
    {
       object[] functionParams = new object[1] {base64String};
       RemoteRequestResultDto objResult = BRApi.Utilities.ExecRemoteGatewayBusinessRule(si, "TestFileRead", functionParams, "ryantestconnection2", "WriteFile");
       
       if (objResult.RemoteResultStatus == RemoteMessageResultType.Success)
       {
        BRApi.ErrorLog.LogMessage(si, "Successfully Submitted File - Result: " + objResult?.ObjectResultValue?.ToString());
       }
       else
       {
          if (objResult.RemoteException != null)
      {
      BRApi.ErrorLog.LogMessage(si, "Remote Exception: " + objResult.RemoteException.Message);
      }
      else
      {
      BRApi.ErrorLog.LogMessage(si, "Unknown Failure");
      }
       }
    }
    else
    {
    BRApi.ErrorLog.LogMessage(si, "Missing File Bytes");
    }
    return null;
    }
    catch (Exception ex)
    {
    throw ErrorHandler.LogWrite(si, new XFException(si, ex));
    }
    }
     
    And the corresponding remote BR TestFileRead with the WriteFile method:
    namespace OneStream.BusinessRule.SmartIntegrationFunction.TestFileRead
    {
    public class MainClass
    {
     
    public bool WriteFile(string inboundData)
    {
     
    byte[] buffer = Convert.FromBase64String(inboundData);
    string fname = @"c:\temp\hwtemp.txt";
    System.IO.File.WriteAllBytes(fname,buffer);
    return true;
    }
     
    }