What do you need to import with the “using” statement in C# to be able to work with SQL?

For Microsoft


using System.Data;
using System.Data.SqlClient;

System.Data includes the DataReader, DataAdapter, Connetions, Commands and so on (from ADO.NET).

For Oracle


using System.Data;
using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.Types;

Run the nvidia-smi command.

Get the name/model of your NVidia card, then find it on this page: https://developer.nvidia.com/cuda-gpus

So below, you can see my GeForce GTX 950 has a computer power of 5.0:

The reason for checking this was from a blog on Medium regarding TensorFlow. It said:
Check for compatibility of your graphics card. The latest environment, called “CUDA Toolkit 9”, requires a compute capability of 3 or higher.

PyTorch is a machine learning package for Python. This code sample will test if it access to your Graphical Processing Unit (GPU) to use “CUDA

from __future__ import print_function
import torch

x = torch.rand(5, 3)
print(x)

if not torch.cuda.is_available():
   print ("Cuda is available")
   device_id = torch.cuda.current_device()
   gpu_properties = torch.cuda.get_device_properties(device_id)
   print("Found %d GPUs available. Using GPU %d (%s) of compute capability %d.%d with "
          "%.1fGb total memory.\n" % 
          (torch.cuda.device_count(),
          device_id,
          gpu_properties.name,
          gpu_properties.major,
          gpu_properties.minor,
          gpu_properties.total_memory / 1e9))
else:    
   print ("Cuda is not available")

CUDA® is a parallel computing platform and programming model developed by NVIDIA for general computing on graphical processing units (GPUs). With CUDA, developers are able to dramatically speed up computing applications by harnessing the power of GPUs.

In GPU-accelerated applications, the sequential part of the workload runs on the CPU – which is optimized for single-threaded performance – while the compute intensive portion of the application runs on thousands of GPU cores in parallel. When using CUDA, developers program in popular languages such as C, C++, Fortran, Python and MATLAB and express parallelism through extensions in the form of a few basic keywords.

C:\Program Files\NVIDIA Corporation\NVSMI>nvidia-smi

Sun Nov 24 13:35:47 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 441.22 Driver Version: 441.22 CUDA Version: 10.2 |
|-------------------------------+----------------------+----------------------+
| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 950M WDDM | 00000000:01:00.0 Off | N/A |
| N/A 60C P0 N/A / N/A | 141MiB / 4096MiB | 0% Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 2664 C+G ...iles (x86)\Opera\64.0.3417.92\opera.exe N/A |
| 0 10684 C+G ...hell.Experiences.TextInput.InputApp.exe N/A |
| 0 14500 C+G ...osoft.LockApp_cw5n1h2txyewy\LockApp.exe N/A |
| 0 15348 C+G ...iles\TechSmith\Snagit 2019\Snagit32.exe N/A |
| 0 15408 C+G ...vernote\Evernote\EvernoteSubprocess.exe N/A |
| 0 16448 C+G ...\TechSmith\Snagit 2019\SnagitEditor.exe N/A |
+-----------------------------------------------------------------------------+

Some machine learning tools that require GPU require a certain level of capability:
For more info, see https://www.tenforums.com/tutorials/136634-determine-nvidia-graphics-display-driver-version-installed-windows.html

Use the Oracle PL/SQL “Extract” function to extract the Year, Month, Day into separate columns for sorting/grouping:

select 
   EXTRACT(YEAR FROM Creation_Date) as Year, 
   EXTRACT(MONTH FROM Creation_Date) as Month, 
   EXTRACT(DAY FROM Creation_Date) as Day, 
   Creation_Date 
from PO.PO_HEADERS_INTERFACE  POI

Date fields in Oracle hold the time, but by default, the time is not displayed.

Below is a sample of how to format the date with time:

   TO_CHAR(CREATION_DATE, 'YYYY-MM-DD HH24:MI:SS') as CREATION_DATE

Example:

select Creation_Date, TO_CHAR(CREATION_DATE, 'YYYY-MM-DD HH24:MI:SS') as CREATION_DATE_Fmt 
from PO.PO_HEADERS_ALL
where Creation_Date is not null 
order by Creation_Date desc 

Notice how the time does not appear by default in the first field displayed:

Here’s a sample of how I GAC and UnGAC DLLs from Powershell. I think I got this on StackOverflow, but don’t have the link handy now.
(GAC, of course, refers to the .NET Global Assembly Cache. All BizTalk artificats and C# programs must be in the GAC to be called from a BizTalk orchestration).


function GacDll ($dllpath)
{
    Write-Host " "  # blank line 
    if (!(Test-Path $dllpath)) 
       {

          Write-Host "`n dllpath not found: $dllpath  `n`n" 
          exit
       }
    [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")            
    $publish = New-Object System.EnterpriseServices.Internal.Publish            
    $publish.GacInstall($dllpath)
    Write-Host "Published to GAC: $dllpath" 

}

function unGacDLL ($dllpath) 
{
    if (!(Test-Path $dllpath)) 
       {

          Write-Host "`n dllpath not found: $dllpath  `n`n" 
          exit
       }
    [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")            
    $publish = New-Object System.EnterpriseServices.Internal.Publish            
    $publish.GacRemove($dllpath) 
    Write-Host "Removed from GAC: $dllpath" 
  
}

cls

$dllpath1 = "c:\VSTS\ABC.Oracle\ABC.OracleDB.Helpers\ABC.OracleDB.Helpers\bin\Debug\ABC.OracleDatabase.Helpers.dll"
UnGacDll $dllPath1 

$dllpath2 = "c:\VSTS\ABC.BizTalkNonDB.Helpers\ABC.BizTalkNonDB.Helpers\bin\Debug\ABC.BizTalkNonDB.Helpers.dll"
GacDll $dllPath2 
 
$date = Get-Date -Format "yyyy-MM-dd hh:mm:ss"
Write-Host "`nDate/Time Completed: $date "

Error in the Execution Result

Response:
{
  "errorType": "Runtime.ImportModuleError",
  "errorMessage": "Error: Cannot find module 'decode-verify-jwt'",

Response:
{
  "errorType": "Runtime.ImportModuleError",
  "errorMessage": "Error: Cannot find module 'decode-verify-jwt'",

and also the following text appears:

    
   Lambda can't find the file decode-verify-jwt.js. Make sure that your handler upholds the format: file-name.method.

Solution

I uploaded the file by using a zip. I zipped the parent directory, so my starting module was not in the root directory, but one level under that.

So there are two ways to fix it:
1) Include the parent directory on the “Handler”.
example parentDirectoryName/decode-verify-jwt.handler

2) Rebuild your zip without the parent directory and upload the zip again.

Overall, it’s a mismatch between the handler and the code in your directory structure.

I needed to implement RawString functionality to be able to read a non-XML file into an orchestration. Scott Colestock had a great article on this on his TraceOfThought blog, but when I needed it the other day, it had been hacked (hopefully only temporary).

1. Deploy the C# code towards the bottom of this log; it is not a pipeline, so can be added to new class to an existing C# helper library you might have, or you can put it in its own assembly.

2. Add a reference to this C# Assembly in your orchestration.

3. In your orchestration, create a multipart message type. It will have only one part, but that will be the RawString class from the code below.

4. In the orchestration, create a nessage of type System.Xml.XmlDocument, and assign this to your cativating receive. But wait Neal, I thought you said we wanted to receive a non-XML message. Trust me, this will work.

5. In the orchestration, add a Message Assignment shape and code similar to below:

//convert the message received to a new message with a multiple-part-type of RawString 
msg_rcv_RawString.MessagePart_1 = msg_XML_Doc; 

6. At this point, you can access the message as a string, for example:

varText = msg_rcv_RawString.MessagePart_1.ToString();

Voila – you have now have the text of the file in a variable called varText. You can then parse it, or do whatever you want with it.

The code below needs to be in a C# helper class that you can access within your orchestration. (Obviously give it a strong name and GAC it.) I can’t remember which site I got this code from, but I think it’s out there on several.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.IO;
using Microsoft.XLANGs.BaseTypes;

namespace REI.BizTalkNonDB.Helpers
{

    public abstract class BaseFormatter : IFormatter
    {
        public virtual SerializationBinder Binder
        {
            get { throw new NotSupportedException(); }
            set { throw new NotSupportedException(); }
        }

        public virtual StreamingContext Context
        {
            get { throw new NotSupportedException(); }
            set { throw new NotSupportedException(); }
        }

        public virtual ISurrogateSelector SurrogateSelector
        {
            get { throw new NotSupportedException(); }
            set { throw new NotSupportedException(); }
        }

        public abstract void Serialize(Stream stm, object obj);
        public abstract object Deserialize(Stream stm);
    }


    public class RawStringFormatter : BaseFormatter
    {
        public override void Serialize(Stream s, object o)
        {
            RawString rs = (RawString)o;
            byte[] ba = rs.ToByteArray();
            s.Write(ba, 0, ba.Length);
        }

        public override object Deserialize(Stream stm)
        {
            StreamReader sr = new StreamReader(stm, true);
            string s = sr.ReadToEnd();
            return new RawString(s);
        }
    }

    [CustomFormatter(typeof(RawStringFormatter))]
    [Serializable]
    public class RawString
    {
        [XmlIgnore]
        string _val;

        public RawString(string s)
        {
            if (null == s)
                throw new ArgumentNullException();
            _val = s;
        }

        public RawString()
        {
        }

        public byte[] ToByteArray()
        {
            return Encoding.UTF8.GetBytes(_val);
        }

        public override string ToString()
        {
            return _val;
        }
    }


}

My goal here was to send myself an email of all new files received from vendors. This is assuming the files are not picked up and processed by BizTalk automatically. If that were the case, you might be able to point the folders to your archive directories and still achieve the same results.

In my particular case, we have a production serer exposed to our vendors. They send us test files, and I have to manually copy them and process them on our test server. At this time, we don’t have any access from one server to the other. So the email alert will trigger me to go process the files, rather than waiting for an email from the vendor.

#
#      Name: Neal Walters
#      Date: 2019/07/29 
#
#   Purpose: Send email with all any new test files received. 
#            Files are received on Prod server that is exposed to outside world. 
#            We have to manually copy these files to our test system and process them. 
#
#

cls

$minutes = $args[0]

#allow this to be run 
if ($minutes -eq $null)
   {
     $minutes = 60
   }
   

$filterDate = (Get-Date).AddDays(-6) 
Write-Host "filterDate=$filterDate" 

$folderMask = "c:\BizTalk\Vendors\*\AS2FilesReceived\*.*"
#-Exclude "*997*.*"
$files = Get-ChildItem -Path $folderMask -File | Where-Object {$_.CreationTime -gt (Get-Date).AddMinutes($minutes)} | Sort-Object FullName
Write-Host "Number of Matching AS2 Files = $($files.Count)" 

$folderMask = "f:\SFTPFiles\*\*Test\From*To*\*.*"
$FTPfiles = Get-ChildItem -Path $folderMask -File | Where-Object {$_.CreationTime -gt (Get-Date).AddMinutes($minutes)} | Sort-Object FullName
Write-Host "Number of Matching SFTP Files = $($FTPfiles.Count)" 


$fileCount = 0 
$HTMLmessage = "<Table border=1>"

foreach ($file in $files) 
{
     $fileCount = $fileCount + 1 
     Write-Host "$fileCount $($file.FullName) $($file.CreationTime)`n" 
     $HTMLmessage = $HTMLMessage + "<tr><td>$fileCount $($file.FullName)</td><td> $($file.CreationTime)</td></tr>`n" 

}

foreach ($file in $FTPfiles) 
{
     $fileCount = $fileCount + 1 
     Write-Host "$fileCount $($file.FullName) $($file.CreationTime)`n" 
     $HTMLmessage = $HTMLMessage + "<tr><td>$fileCount $($file.FullName)</td><td> $($file.CreationTime)</td></tr>`n" 

}

$HTMLmessage = $HTMLMessage + "</Table>"

#[string[]] $toEmails = "nwalters@rogent.com", "bshaw@rogent.com" # List of toEmails to email your report to (separate by comma) or use a distribution list 
[string[]] $toEmails = "nwalters@rogent.com" # List of toEmails to email your report to (separate by comma) or use a distribution list 

$smtpServer = "smtp.rogent.com" 
$fromemail = "noreplyFilesReceived@rogent.com"
$emailSubject = "BizTalk EDI Files Received"

if ($fileCount -gt 0)
{
   send-mailmessage -from $fromemail -to $toEmails -subject $emailSubject  -BodyAsHTML -body $HTMLmessage -priority High -smtpServer $smtpServer
   $traceDateTime = get-date
   Write-Host "$traceDateTime Email sent to: $toEmails (size in bytes=$($HTMLmessage.length))" 
}