string replacement malfunction in WebApi .Net Core 3.1 - asp.net-core-3.1

I have an Asp.Net Core 3.1 WebApi project running on Windows servers that is doing string replacement
var newLine = "\n";
var nextLine = "\u0085";
var str = "|\r\n| - |\r\u0085|";
var newStr = str.Replace(nextLine, newLine);
locally - I am getting this:
{"str":"|\r\n| - |\r\u0085|","newStr":"|\r\n| - |\r\n|"}
remotely - I am getting this:
{"str":"|\r\n| - |\r\u0085|","newStr":"|\r\n| - |\r |"}
What could be the cause?

Related

Mirth String Handling

I'm using the code below to try and strip the file extension off the incoming file and replace it with "ACK";
Can't use .lastIndexOf as it's not available in Rhino.
var _filename = String(sourceMap.get('originalFilename'));
pos = -1;
var search = ".";
for(var i = 0; i < _filename.length - search.length; i++) {
if (_filename.substr(i, search.length) == search) {
pos = i;
}
}
logger.info('_pos:' + _pos);
Every time I get a pos value of -1
i.e. Last full stop position not found.
BUT if I hardcode the filename in as "2020049.259317052.HC.P.F3M147-G" it works perfectly.
Is it something to do with the sourceMap.get('originalFilename') supplying a non-string or different
character set ?
This was tested on mirth 3.5. Rhino does, in fact, have String.prototype.lastIndexOf for all mirth versions going back to at least mirth 3.0. You were correctly converting the java string from the sourceMap to a javascript string, however, it is not necessary in this case.
Java strings share String.prototype methods as long as there is not a conflict in method name. Java strings themselves have a lastIndexOf method, so that is the one being called in my answer. The java string is able to then borrow the slice method from javascript seamlessly. The javascript method returns a javascript string.
If for some reason the filename starts with a . and doesn't contain any others, this won't leave you with a blank filename.
var filename = $('originalFilename');
var index = filename.lastIndexOf('.');
if (index > 0) filename = filename.slice(0, index);
logger.info('filename: ' + filename);
That being said, I'm not sure why your original code wasn't working. When I replaced the first line with
var originalFilename = new java.lang.String('2020049.259317052.HC.P.F3M147-G');
var _filename = String(originalFilename);
It gave me the correct pos value of 22.
New Answer
After reviewing and testing what agermano said he is correct.
In your sample code you are setting pos = i but logging _pos
New answer var newFilename = _filename.slice(0, _filename.lastIndexOf('.'))
Older Answer
First, you are mixing JavaScript types and Java types.
var _filename = String(sourceMap.get('originalFilename'));
Instead, do
var _filename = '' + sourceMap.get('originalFilename');
This will cause a type conversion from Java String to JS string.
Secondly, there is an easier way to do what you are trying to do.
var _filenameArr = ('' + sourceMap.get('originalFilename')).split('.');
_filenameArr.pop() // throw away last item
var _filename = _filenameArr.join('.') // rejoin the array with out the last item
logger.info('_filename:' + _filename)

Unity 5.3 and .NET | AppendText & CreateText

Even though I have already changed the API Compatibility Level from .NET 2.0 Subset to .NET 2.0 in Edit->Project Settings->Player under Optimizations, upon upgrading to Unity 5.3.0 I am still getting the following two error messages:
`System.IO.File' does not contain a definition for `AppendText'
`System.IO.File' does not contain a definition for `CreateText'
They refer to the following code snippets:
using(StreamWriter writer = File.CreateText(saveFilePath))
{
string sLine = "time;joint;pos_x;pos_y;poz_z";
writer.WriteLine(sLine);
}
using(StreamWriter writer = File.AppendText(saveFilePath))
{
string sLine = string.Format("{0:F3};{1};{2:F3};{3:F3};{4:F3}", Time.time, (int)joint, jointPos.x, jointPos.y, jointPos.z);
writer.WriteLine(sLine);
}
How do I resolve this?
Are you tried this case?
using (var f = new StreamWriter("file path", true))
{
f.WriteLine("appended text");
f.Flush();
}

How to convert config/environment.js to CoffeeScript?

Using ember-cli version 0.2.3, I converted config/environment.js to config/environment.coffee.
The app is named frontend.
In the dist/frontend.js file, I see the following differences - note that instead of frontend, the prefix is undefined.
How to fix this?
Working:
define('frontend/config/environment', ['ember'], function(Ember) {
var prefix = 'frontend';
...
Not working:
define('undefined/config/environment', ['ember'], function(Ember) {
var prefix = 'undefined';
...

Entity Framework Stored Procedure with Multiple Record Set not accepting my parameter

I'm using Microsofts suggested solution for using Entity Framework to read multiple record sets from a stored procedure but added a small snippet to use parameters and it's not working. I've had a co-worker look at the code and tell me it looks like it should work so I thought I'd ask here.
Using the 4.5 framework is not an option. I'm stuck with 4.0 and etity framework 4.4.
App MyApp = (App)Application.Current;
EnterpriseEntities EE = new EnterpriseEntities();
EE.Database.Connection.ConnectionString = MyApp.EnterpriseEntityConnectionString;
var cmd = EE.Database.Connection.CreateCommand();
cmd.CommandText = "[dbo].[spSelectWaterUsesByRightID]";
var param = cmd.CreateParameter();
param.Direction = ParameterDirection.Input;
param.DbType = DbType.Int32;
param.ParameterName = "#RightID";
param.Value = this.RightID;
cmd.Parameters.Add(param);
EE.Database.Connection.Open();
var reader = cmd.ExecuteReader();
List<WaterUses> ListOfWaterUses = (((System.Data.Entity.Infrastructure.IObjectContextAdapter)EE)
.ObjectContext
.Translate<WaterUses>(reader, "WaterUses",System.Data.Objects.MergeOption.AppendOnly)).ToList();
When I get to the ExecuteReader line I get an error message that the stored procedure requires Parameter #RightID but that's what I'm passing. I checked the parameter count right before it executes and it's at 1.
You have to add
cmd.CommandType = CommandType.StoredProcedure;
somewhere before cmd.ExecuteReader().

ASP.net MVC wkhtmltopdf system process font issue

I'm using the wkhtmltopdf application to convert my ASP.net MVC 2 rendered HTML into a PDF and display the PDF instead of the standard view for better print ability. Everything works great minus one thing. When I run wkhtmltopdf as a process in my MVC application on our webserver it does not display the installed barcode font in the PDF.
Here is the code for the process.
public void HtmlToPdf(string url, string appPath)
{
string message = null;
// to build command argument
StringBuilder argument = new StringBuilder();
// input html file
string switches = "";
switches += "--print-media-type ";
switches += "--margin-top 10mm --margin-bottom 10mm --margin-right 10mm --margin-left 10mm ";
switches += "--page-size Letter ";
switches += "--load-error-handling ignore ";
switches += "--username admin ";
switches += "--password pass ";
argument.Append(switches + " " + url + " " + "C:\\PDF\\temp.pdf");
// to call the exe to convert
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.FileName = "C:\\wkhtmltopdf\\wkhtmltopdf.exe";
p.StartInfo.WorkingDirectory = "C:\\wkhtmltopdf";
p.StartInfo.Arguments = argument.ToString();
p.Start();
p.WaitForExit();
message = p.StandardError.ReadToEnd();
if (string.IsNullOrEmpty(message))
{
message = p.StandardOutput.ReadToEnd();
}
else
{
System.Diagnostics.Debug.WriteLine(message);
}
}
Not really sure why it wont show the barcode because it shows in the when you render the html but not in when the wkhtmltopddf converts it to pdf. It also works correctly if you run wkhtmltopdf out side of my MVC application.
-Thanks for any help
Have you tried it in a while with an updated version of wkhtmltopdf?
Which version was this a problem with? I recently tried to generate using a random font I downloaded and it worked fine.
If you generate the PDF on a server the server needs the font too, I assume you know that but someone else reading might not realize it :)
Could I get the font in question to test on my system?
Was the conversion done in what environment? (Most likely not Linux due to asp.net, but asking just in case)