From f6949f814e089c5987f446323c2b1e6ee66a7880 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Thu, 6 May 2021 16:56:39 -0500 Subject: [PATCH] RCB-593: Upgrade System.Net.Http. Examples cleanup. Travis/Jenkins channels. --- .travis.yml | 25 ++-- Jenkinsfile | 2 +- README.md | 7 +- rosette_api/packages.config | 2 +- rosette_apiExamples/README.md | 91 ++++++++++---- rosette_apiExamples/docker/Dockerfile | 16 --- rosette_apiExamples/docker/README.md | 16 --- rosette_apiExamples/docker/compile-and-run.sh | 118 ------------------ rosette_apiUnitTests/packages.config | 2 +- 9 files changed, 86 insertions(+), 193 deletions(-) delete mode 100644 rosette_apiExamples/docker/Dockerfile delete mode 100644 rosette_apiExamples/docker/README.md delete mode 100755 rosette_apiExamples/docker/compile-and-run.sh diff --git a/.travis.yml b/.travis.yml index e3a6a409..d1cf9907 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,9 @@ -language: csharp - -install: - - nuget restore rosette_api.sln - -script: - - xbuild /p:Configuration=Release rosette_api.sln - - mono ./packages/NUnit.Console.3.0.1/tools/nunit3-console.exe ./rosette_apiUnitTests/bin/Release/rosette_apiUnitTests.dll - -notifications: - slack: - rooms: - - secure: 4FRaTAAiYyeUvgw2RhmblgbNiJO4wmd34OBgWcwURjP9oVmFfSwR9r1LNCdUGxrPOghexSY2DjXIuvIrfTfi/xYbhHb3Kw7PEAyB8IuBMlKtY4NSFou62S2VhYpxyg58T+C7P2zi0eDnDE06pwTCoGPaimxMZQY91yQ0yPYDPVXbwe5SjEgamzlwGBxlS/0A6w1iCPHg27/iO2hXtdW3oLS2I0F/Q8Q95RBkX9hpg6yqHlTV7jRbSqvQ9OFBqk/tXMHQvhoPDGgCgQDuykJuaAYx7g9d0YL0eEYYOh9B/TJ/kNOwdRFBu5kuQ2/nFS5Z0S3Y3UIhdYjUmm9gSMnwIbYnrW22EqDJLoT9Zi3Gv7Prg/8/fSkWsof7BJTMSuXUqO1AxDGKIxFv9u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jKZgTujhqgzijJGzVPSL8//hafj0Ec2+iJZFo/DYMPqUpYDsiKxX53+SMz9/GN/PKVKsI7bzuaOm04xXktU0A76pVfaG0N/qFSVHI64SShACoUXRpTzyUbmksRgzk7FB162R+TH1soPsR3vPh8c2SSWC9msrDc4iljcBhSFTdjL68z+srjDPYMSoOcFXXFNP+dmL+Q0veL/E4e40e7CWIU1O3grOcEcCkaSoZVSpGduNnCst8h6MpgauPtrgwHk4zGMoSl+L6al+nFo/3h2dXeebrQ0tY/hRfZi4Q8xwqG9083TBqi71fTpoFZ7sNtrY4Kdtl5Oa2CFUo7lVn1JB9qQwSa0eai3Whv0RyRqqQe77aDUj0dfD2R3Q61rX5OF/f++W0XtNwHQubzmj8HD/cFneShIQsbl9KgYXoR6HiXcbBiNdmmZjSrzkPYh7vlsujYrz6Cg2msKybWJ/FfOz0tS1cjlCtiCMOTExN6tEF8YCp9l+s+5RLe61pgFPy4Snr9pEjuTS5DYliTyZMY2ZZC1clBQtgE8E2qCG1QSzqnqqiGxj2K4zmLPpB4y1XpW8e3yk= - +language: csharp +install: +- nuget restore rosette_api.sln +script: +- xbuild /p:Configuration=Release rosette_api.sln +- mono ./packages/NUnit.Console.3.0.1/tools/nunit3-console.exe ./rosette_apiUnitTests/bin/Release/rosette_apiUnitTests.dll +notifications: + slack: + secure: i8q0FGroh4HVOLtMHPvPSupJ9s7LQ7WDbI5VNBBH6C+wpmk3H1kmlAy7ZjlLXtc99QBKDu69gphQksZSzjvmvHUXiwt23faBsVKqOSb+QfdEajSNEEl8Ujkw38osd/tJdwPbABfM/RKKUx9E3NhK9WfsNUWZEDMnIdC4WoR9WvB8WltwKGwCpruQePp3MO8IltIfkajUTsabu5ezodjD1X6qojfD777g8ivLwJP/x9koIGIdfm2d1SKA+ywdgaZOZeAfCSe6ETLCfU6Wa4DHxe3COBwOM5fJ6C/aHPQn3tpbsfLGG5rsb+fNuyeMuhJUZi0/XOX3w4O3rQ502bvG1cSrfotbhldkeQKqIPW1vqpsF82/UFliKpGVAC0Y1h2DQ3YZWHEUqfsqPlZ3QuFrekesic3qUgO8TVTSLyzmhYbc8QHOQs8iXbbm3qoT+yTdkDvILubhXemZC8RXohsjbBPkRAMc8zcyR+gLN8mUrR6/gUzJ7JtMD9hoM+HLS7Vj0+iFJYwLNzrEFMebe54+fDcv/cKRwYQSI+UdABG2Dm31TK94NT6uCvY6rFC3PSU1at+ci23PgF41BzFLDK+9AWgsTgSspPUiyoMtI25BwBd0ryUUhqepKF9WJvX9jsJBopMd9Z60wVuIbUeRnOL4NMalNfu1FpcMH/s0K9c3+3M= diff --git a/Jenkinsfile b/Jenkinsfile index d9ed2205..71651567 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -26,5 +26,5 @@ def slack(boolean success) { def color = success ? "#00FF00" : "#FF0000" def status = success ? "SUCCESSFUL" : "FAILED" def message = status + ": Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})" - slackSend(color: color, channel: "#rapid", message: message) + slackSend(color: color, channel: "#p-n-c_jenkins", message: message) } \ No newline at end of file diff --git a/README.md b/README.md index a0303c5c..1ff91166 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ -[![Build Status](https://travis-ci.org/rosette-api/csharp.svg?branch=master)](https://travis-ci.org/rosette-api/csharp) [![NuGet version](https://badge.fury.io/nu/rosette_api.svg)](https://badge.fury.io/nu/rosette_api) + + +--- + +[![Build Status](https://travis-ci.org/rosette-api/csharp.svg?branch=master)](https://travis-ci.org/rosette-api/csharp) +[![NuGet version](https://badge.fury.io/nu/rosette_api.svg)](https://badge.fury.io/nu/rosette_api) ## Rosette API The Rosette Text Analytics Platform uses natural language processing, statistical modeling, and machine learning to diff --git a/rosette_api/packages.config b/rosette_api/packages.config index 9517ce02..078edfaf 100755 --- a/rosette_api/packages.config +++ b/rosette_api/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/rosette_apiExamples/README.md b/rosette_apiExamples/README.md index 6731bdb6..64966f53 100644 --- a/rosette_apiExamples/README.md +++ b/rosette_apiExamples/README.md @@ -1,35 +1,80 @@ -.Net(C#) Examples -============================= - -## Endpoint Examples ## +## Endpoint Examples These examples are scripts that can be run independently to demonstrate the Rosette API functionality. Each example file demonstrates one of the capabilities of the Rosette Platform. Each example, when run, prints its output to the console. -Here are some methods for running the examples. Each example will also accept an optional `--url` parameter for -overriding the default URL. +Each example will also accept an optional, alternate url parameter for overriding the default URL. A note on prerequisites. Rosette API only supports TLS 1.2 so ensure your toolchain also supports it. +Here are some methods for running the examples. + +#### Latest Version on NuGet with Docker +- Clone the repository. + ``` + git clone git@github.com:rosette-api/csharp.git + cd csharp + ``` +- Launch a `mono` container. + ``` + docker run -it -v $(pwd):/csharp mono:6 + ``` +- Install the package from NuGet + ``` + cd /csharp + nuget install rosette_api + ``` +- Copy the runtime binaries to the examples directory. + ``` + cp Newtonsoft.Json.10.0.2/lib/net45/Newtonsoft.Json.dll rosette_apiExamples/. + cp rosette_api.1.14.4/lib/net45/rosette_api.dll rosette_apiExamples/. + ``` +- Compile the example you'd like to execute. E.g. language.cs + ``` + cd rosette_apiExamples + csc language.cs /r:rosette_api.dll /r:System.Net.Http.dll /r:System.Web.Extensions.dll + ``` +- Run the compiled example against Rosette Cloud. In this example, your Cloud API key is stored in the environment variable `$API_KEY`. + ``` + mono language.exe $API_KEY + ``` -### Docker Mono image -- install Docker per your OS -- cd to the docker directory under the examples -- `[sudo] docker build -t basistech/mono:1.1 .` -- cd to the examples directory -- Run the example as `[sudo] docker run -e FILENAME=_example_.cs -e API_KEY=_your_api_key_ -v "full-path-to-examples-source:/source" basistech/mono:1.1`. This will compile and run the example using a Mono environment. If you would like to run against an alternate URL, add `-e ALT_URL=_alternate_url_` before the `-v`. +#### Latest Source with Docker +- Clone the repository. + ``` + git clone git@github.com:rosette-api/csharp.git + cd csharp + ``` +- Launch a `mono` container. + ``` + docker run -it -v $(pwd):/csharp mono:6 + ``` +- Build the package from source. + ``` + cd /csharp + nuget restore rosette_api.sln + xbuild /p:Configuration=Release rosette_api.sln + ``` +- _Optional:_ Run the Unit Tests. + ``` + mono ./packages/NUnit.Console.3.0.1/tools/nunit3-console.exe ./rosette_apiUnitTests/bin/Release/rosette_apiUnitTests.dll + ``` +- Copy the runtime binaries to the examples directory. + ``` + cp packages/Newtonsoft.Json.10.0.3/lib/net45/Newtonsoft.Json.dll rosette_apiExamples/. + cp rosette_api/bin/Release/rosette_api.dll rosette_apiExamples/. + ``` +- Compile the example you'd like to execute. E.g. language.cs + ``` + cd rosette_apiExamples + csc language.cs /r:rosette_api.dll /r:System.Net.Http.dll /r:System.Web.Extensions.dll + ``` +- Run the compiled example against Rosette Cloud. In this example, your Cloud API key is stored in the environment variable `$API_KEY`. + ``` + mono language.exe $API_KEY + ``` ### Visual Studio -- If you are using Visual Studio, you can use the Nuget Package Manager. Search for rosette_api in the Online Packages and install. -- If you are using Nuget Command line: `nuget install rosette_api` +- If you are using Visual Studio, you can use the Nuget Package Manager. Search for `rosette_api` in the Online Packages and install. You can now run your desired endpoint file to see it in action. - -### Command line -- `nuget install rosette_api` -- copy the rosette_api.lib to the same directory as your examples (found in rosette_api.*/) -- Compile the file using `csc _endpoint_.cs /r:rosette_api.dll /r:System.Net.Http.dll /r:System.Web.Extensions.dll`. This will output an .exe file with the _endpoint_ name. - -### Running the compiled example -- Run the file using `_endpoint_.exe your_api_key [alternate_url]` - diff --git a/rosette_apiExamples/docker/Dockerfile b/rosette_apiExamples/docker/Dockerfile deleted file mode 100644 index 6310315a..00000000 --- a/rosette_apiExamples/docker/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM mono -MAINTAINER Chris Park -ENV REFRESHED_AT 2016-01-29 - -RUN mkdir csharp-dev && mkdir csharp-dev/rosette_apiExamples -WORKDIR csharp-dev -RUN nuget install rosette_api && cp rosette_api.*/lib/net45/rosette_api.dll rosette_apiExamples -ENV ALT_URL "" -COPY compile-and-run.sh compile-and-run.sh - -RUN cat /etc/ssl/certs/* > ca-bundle.crt && cert-sync ca-bundle.crt && rm ca-bundle.crt - -VOLUME ["/source"] - -CMD ./compile-and-run.sh $API_KEY $FILENAME $ALT_URL - diff --git a/rosette_apiExamples/docker/README.md b/rosette_apiExamples/docker/README.md deleted file mode 100644 index e4f90b11..00000000 --- a/rosette_apiExamples/docker/README.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -# Mono Image for CSharp Examples ---- -### Summary -To simplify the running of the C# examples, the Dockerfile will build a Mono image and install the latest rosette-api library from NuGet. - -### Basic Usage -Build the docker image, e.g. `sudo docker build -t basistech/mono:1.1 .` - -Run an example as `sudo docker run -e FILENAME=source-file.cs -e API_KEY=api-key -v "path-to-example-source:/source" basistech/mono:1.1` - -To run all of the examples in a directory, from the source directory: - -`find -maxdepth 1 -name "*.cs" -print -exec sudo run -e FILENAME={} -e API_KEY=api-key -v "path-to-example-source:/source" basistech/mono:1.1 \;` - -To test against an alternate url, add `-e ALT_URL=alternate_url` before the `-v` diff --git a/rosette_apiExamples/docker/compile-and-run.sh b/rosette_apiExamples/docker/compile-and-run.sh deleted file mode 100755 index f84f71e2..00000000 --- a/rosette_apiExamples/docker/compile-and-run.sh +++ /dev/null @@ -1,118 +0,0 @@ -#!/bin/bash - -ping_url="https://api.rosette.com/rest/v1" -retcode=0 -errors=( "Exception" "processingFailure" "badRequest" "ParseError" "ValueError" "SyntaxError" "AttributeError" "ImportError" ) - -#------------------ Functions ---------------------------------------------------- - -#Gets called when the user doesn't provide any args -function HELP { - echo -e "\nusage: --API_KEY API_KEY [--FILENAME filename] [--ALT_URL altUrl]" - echo " API_KEY - Rosette API key (required)" - echo " FILENAME - C# source file" - echo " ALT_URL - Alternate service URL (optional)" - echo "Compiles and runs the source file using the published rosette-api from NuGet" - exit 1 -} - -if [ ! -z ${ALT_URL} ]; then - ping_url=${ALT_URL} -fi - -#Checks if Rosette API key is valid -function checkAPI() { - echo "Check API Key" - match=$(curl "${ping_url}/ping" -H "X-RosetteAPI-Key: ${API_KEY}" | grep -o "forbidden") - if [ ! -z $match ]; then - echo -e "\nInvalid Rosette API Key" - exit 1 - fi -} - -function cleanURL() { - echo "Clean URL" - # strip the trailing slash off of the alt_url if necessary - if [ ! -z "${ALT_URL}" ]; then - case ${ALT_URL} in - */) ALT_URL=${ALT_URL::-1} - echo "Slash detected" - ;; - esac - ping_url=${ALT_URL} - fi -} - -function validateURL() { - output_file=validate_url_out.log - http_status_code=$(curl -s -o "${output_file}" -w "%{http_code}" -H "X-RosetteAPI-Key: ${API_KEY}" "${ping_url}/ping") - if [ "${http_status_code}" != "200" ]; then - echo -e "\n${ping_url} server not responding. Output is:\n" - cat "${output_file}" - exit 1 - fi -} - -function runExample() { - result="" - echo -e "\n---------- ${1} start -------------" - executable=$(basename "${1}" .cs).exe - mcs ${1} -r:rosette_api.dll -r:System.Net.Http.dll -r:System.Web.Extensions.dll -out:$executable - result="$(mono $executable ${API_KEY} ${ALT_URL})" - echo "${result}" - echo "---------- ${1} end -------------" - for err in "${errors[@]}"; do - if [[ ${result} == *"${err}"* ]]; then - retcode=1 - fi - done -} - -#------------------ Functions End ------------------------------------------------ -#Gets API_KEY, FILENAME and ALT_URL if present -while getopts ":API_KEY:FILENAME:ALT_URL:GIT_USERNAME:VERSION" arg; do - case "${arg}" in - API_KEY) - API_KEY=${OPTARG} - ;; - ALT_URL) - ALT_URL=${OPTARG} - ;; - FILENAME) - FILENAME=${OPTARG} - ;; - esac -done - -cleanURL - -validateURL - -#Copy the mounted content in /source to current WORKDIR -cp -r -n /source/. . - -#Update libraries -nuget restore rosette_api.sln -cp packages/Newtonsoft*/lib/net45/Newtonsoft.Json.dll rosette_apiExamples - -#Run the examples -if [ ! -z ${API_KEY} ]; then - #Check API key and if succesful then build local rosette_api project - checkAPI - #Change to dir where examples will be run from - pushd rosette_apiExamples - if [ ! -z ${FILENAME} ]; then - echo -e "\nRunning example against: ${ping_url}\n" - runExample ${FILENAME} - else - echo -e "\nRunning examples against: ${ping_url}\n" - for file in *.cs; do - runExample ${file} - done - fi - popd -else - HELP -fi - -exit ${retcode} diff --git a/rosette_apiUnitTests/packages.config b/rosette_apiUnitTests/packages.config index 3f3475ec..29b78320 100644 --- a/rosette_apiUnitTests/packages.config +++ b/rosette_apiUnitTests/packages.config @@ -10,5 +10,5 @@ - + \ No newline at end of file