When I try to read an X12 204 using EDI Fabric, I get "Invalid Node Name: ST", but the file is well formed. Any idea why? - edi

Here's an example 204 I have made. It validates with a couple different validation tools (EDI Notepad and Altova), but when I try to use EDI fabric to parse it, it gets the ISA and GS data just fine, but then errors out with "Invalid Node Name: ST".
I can't figure out why, any ideas?
ISA*ZZ* *ZZ* *ZZ*XXXX *ZZ*YYYY *170130*1025*U*00401*485789958*0*P*~
GS*SM*YYYY*XXXX*20170130*1027*485790079*X*004010
ST*204*485790093
B2**YYYY**123456789**CC
B2A*00
L11*123456789*CR
S5*1*LD
G62*64*20160131*1*1351
SE*7*485790093
GE*1*485790079
IEA*1*485789958
Here is the code:
internal static void Parse204(FileStream file,
List<MyCompany.TruckRouteInfo> result)
{
var reader = EdiFabric.Framework.Readers.X12Reader.Create(file);
file.Flush();
var qEdiItems = reader.ReadToEnd();
var ediItems = qEdiItems.ToList();
var m204 = ediItems.OfType<M_204>().ToList();
foreach (var item in m204)
{
MyCompany.TruckRouteInfo stop = new MyCompany.TruckRouteInfo ();
foreach (var l11 in item.S_L11)
{
if (l11.D_128_2 == EdiFabric.Rules.X12004010204.X12_ID_128.CR)
{
stop.Reference1 = l11.D_127_1;
}
}
result.Add(stop);
}
}

I've just literally copied your example and pasted it to a file which was processed fine. Works on my machine :)
My best guess would be to open the file and inspect the line terminators for any discrepancies, which might have been sorted when I copied it\pasted it.

Related

Random image from folder

How can I make possible that the app will load all of the images from the specific folder and then put in array and choose one image randomly? When chose one then pass to the fronted to show the image. How to do that too?
I am C# developer but not long time ago I found ElectronJS and this framework does everything easier so therefore I am moving to this framework.
I did in C# programming this way:
// basic settings.
var ext = new List<string> { ".jpg", ".gif", ".png" };
// we use same directory where program is.
string targetDirectory = Directory.GetCurrentDirectory() + "\\assets\\" + "images\\" + "animals\\";
// Here we create our list of files
// New list
// Use GetFiles to getfilenames
// Filter unwanted stuff away (like our program)
if (Directory.Exists(targetDirectory))
{
Files = new List<string>
(Directory.GetFiles(targetDirectory, "*.*", SearchOption.TopDirectoryOnly)
.Where(s => ext.Any(es => s.EndsWith(es))));
// Show first picture so we dont need wait 3 secs.
ChangePicture();
}
else
{
panel5.BackgroundImage = new Bitmap(Resources.doggy);
}
I don't know how to do in ElectronJS.
Thank you in advance the answers.
Alright. I found the solution.
However I don't understand the people who are giving negative reputation for the opened question. If they are giving negative reputation then they could explain why.
Well anyway, I did fix this issue with this way:
I created images.js file and added this:
var fs = require('fs');
function getRandImage() {
var files = fs.readdirSync('./assets/images/animals/')
/* now files is an Array of the name of the files in the folder and you can pick a random name inside of that array */
let chosenFile = files[Math.floor(Math.random() * files.length)]
console.log('../assets/images/animals/' + chosenFile);
return '../assets/images/animals/' + chosenFile;
}
module.exports = { getRandImage }
I used console to see if the value is correct, otherwise others can delete that part.
Sending the data to the renderer process:
const { getRandImage } = require('./images');
child.webContents.send('random-image', getRandImage());
I did put in the preload.js file the following (I used the starter pack electronjs github to start with something):
var { ipcRenderer } = require('electron');
ipcRenderer.on('random-image', function (event, store) {
document.getElementById("randompic").src = store;
console.log(store);
});
Same here, I did use console.log just for test the value is correct and I used to change the randompic ID related image src html to the randomly chosen image.
Hopefully I did helping those people who are newbie as me.

How to read json file from ESP8266's SPIFFS with ArduinoJSON 6?

I am currently working on a project with ESP8266 (ESP-12E) and I need to store information in a json file (more convenient to access via the web interface and easier to manage than EEPROM for me).
My problem is the following: I'm using the latest version of ArduinoJSON (6), but I haven't seen many examples except on their site, and this code doesn't work for me :
void DeleteCycle(size_t idtodelete) {
File schedules = SPIFFS.open("/schedules.json", "r");
if(schedules && schedules.size()) {
DynamicJsonDocument schedulesjson(1300);
DeserializationError err = deserializeJson(schedulesjson, schedules);
Serial.println(err.c_str());
if (err) {
Serial.print(F("deserializeJson() failed with code "));
Serial.println(err.c_str());
}
else {
JsonArray array = schedulesjson.to<JsonArray>();
// array.remove(0);
serializeJson(array, Serial);
}
schedules.close();
}
else {
Serial.println("Failed to read file.");
}
}
I guess the problem is the JsonArray, it's empty !
But my JsonDocument is not, because if I do
JsonObject obj = schedulesjson[0];
String test = obj["name"];
Serial.println("Test : " + test);
I get the first key value (name) of my array at index 0
This is my first post on StackOverflow, I hope I did it right, thanks in advance for your help!
I answer myself because I found the solution to my problem: writing
schedulesjson.to<JsonArray>();
empties the json document, so you have to put it before
DeserializationError err = deserializeJson(schedulesjson, schedules);

Azure DevOps Server 2019 Programmatially copy test case error Exception: 'TF237124: Work Item is not ready to save'."

I'm able to copy most test cases with this code (trying to copy shared steps to be part of the test case itself) but this one will not copy but I can not see any error message as to why - could anyone suggest anything else to try. See output from Immediate windows. Thanks John.
?targetTestCase.Error
null
?targetTestCase.InvalidProperties
Count = 0
?targetTestCase.IsDirty
true
?targetTestCase.State
"Ready"
?targetTestCase.Reason
"New"
foreach (ITestAction step in testSteps)
{
if (step is ITestStep)
{
ITestStep sourceStep = (ITestStep)step;
ITestStep targetStep = targetTestCase.CreateTestStep();
targetStep.Title = sourceStep.Title;
targetStep.Description = sourceStep.Description;
targetStep.ExpectedResult = sourceStep.ExpectedResult;
//Copy Attachments
if (sourceStep.Attachments.Count > 0)
{
string attachmentRootFolder = _tfsServiceUtilities.GetAttachmentsFolderPath();
string testCaseFolder = _tfsServiceUtilities.CreateDirectory(attachmentRootFolder, "TestCase_" + targetTestCase.Id);
//Unique folder path for test step
string TestStepAttachementFolder = _tfsServiceUtilities.CreateDirectory(testCaseFolder, "TestStep_" + sourceStep.Id);
using (var client = new WebClient())
{
client.UseDefaultCredentials = true;
foreach (ITestAttachment attachment in sourceStep.Attachments)
{
string attachmentPath = TestStepAttachementFolder + "\\" + attachment.Name;
client.DownloadFile(attachment.Uri, attachmentPath);
ITestAttachment newAttachment = targetTestCase.CreateAttachment(attachmentPath);
newAttachment.Comment = attachment.Comment;
targetStep.Attachments.Add(newAttachment);
}
}
}
targetTestCase.Actions.Add(targetStep);
targetTestCase.Save();
}
Since this code works for most test cases, this issue may come from the particular test case. In order to narrow down the issue, please try the following items:
Run the code on another client machine to see whether it works.
Try to modify this particular test case using the account API uses, to see whether it can be saved successfully.
Try validate the WorkItem prior to save. The validate() method will return an arraylist of invalid fields.

How can I get the last commit for a folder using LibGit2Sharp?

I've got a large number of projects all in a single repository. I want to determine the volatility of all of these projects, i.e., when there was last a commit that affected each project. I've got a list of all of the project paths, and I'm trying to find the last commit for each one. My code looks like this:
public CommitInfo GetLastCommit(string path)
{
// resolve any \..\ and pathing weirdness
path = Path.GetDirectoryName(Path.GetFullPath(path));
var relativePath = path.Substring(BaseRepoPath.Length + 1).Replace("\\", "/");
if (!CommitCache.TryGetValue(relativePath, out CommitInfo result))
{
var options = new RepositoryOptions()
{
WorkingDirectoryPath = BaseRepoPath
};
using (var repo = new Repository(BaseRepoPath, options))
{
var filter = new CommitFilter()
{
IncludeReachableFrom = BranchName
};
var commit = repo.Commits.QueryBy(relativePath, filter).First().Commit;
result = new CommitInfo
{
When = commit.Author.When.DateTime,
Who = commit.Author.Name,
Message = commit.Message,
Files = commit.Tree.Select(x => x.Name).ToList()
};
repo.Dispose();
}
CommitCache.Add(relativePath, result);
}
return result;
}
This works, but the line where the commit is actually retrieved:
var commit = repo.Commits.QueryBy(relativePath, filter).First().Commit;
Can take up to eight minutes to complete. As far as I can tell, there's nothing especially complex about those folders...a sample of them reveals maybe twenty commits. I suspect I'm doing something wrong like loading the entire repo graph when I need something more specific, but I haven't been able to figure out a better way.
Thoughts?
Your requirement is producing following git command through lib2gitsharp package.
$ git log -1 -C "relativePath"
You can limit the size of commits with the help of Take(numberOfCommits) extension in lib2gitsharp. Please have a try with putting Take(1) before your First() like following;
var commit = repo.Commits.QueryBy(relativePath, filter).Take(1).First().Commit;
Hope this helps.

Messages not rendered when a pst is created from email messages located in another machine on a same network

I am creating a pst from message files which are located in another machine on a same network. But when I loaded the pst, messages are not rendered. I have added a screenshot. And code is below:
Issue do not occur when message files are imported from my local machine.
private static void GeneratePST(string [] messageFiles, string outputPstPath)
{
RDOSession pstSession = null;
RDOPstStore store = null;
RDOFolder folder = null;
RDOMail rdo_Mail = null;
RDOItems items = null;
try
{
pstSession = new RDOSession();
store = pstSession.LogonPstStore(outputPstPath, 1, Path.GetFileNameWithoutExtension(outputPstPath));
folder = store.IPMRootFolder;
folder = folder.Folders.Add("Loose Messages");
foreach (string messages in messageFiles)
{
items = folder.Items;
rdo_Mail = items.Add("IPM.NOTE");
rdo_Mail.Import(messages, rdoSaveAsType.olMSG);
rdo_Mail.Save();
}
}
catch (Exception ex)
{
//log exception
}
finally
{
Marshal.ReleaseComObject(rdo_Mail);
Marshal.ReleaseComObject(folder);
Marshal.ReleaseComObject(store);
Marshal.ReleaseComObject(items);
pstSession.Logoff();
Marshal.ReleaseComObject(pstSession);
GC.Collect();
}
}
I have also impersonated the network machine before importing message file. But still the issue persist.
The problem only exists for files in another machine. Messages are rendered for msg file located in my machine. Also, I noticed issue is only with message files. Eml file are rendered. So, it might not be the issue of impersonation.
Any help please.
Microsoft does not support accessing PST files on network drives. They must be on a local machine.
Also, there is no reason to continuously retrieve the RDOItems object - you never release on the old value, so those objects stay alive until your app exits. Ditto for the rdo_Mail object:
folder = folder.Folders.Add("Loose Messages");
items = folder.Items;
foreach (string messages in messageFiles)
{
if (rdo_Mail != null) Marshal.ReleaseComObject(rdo_Mail);
rdo_Mail = items.Add("IPM.NOTE");
rdo_Mail.Import(messages, rdoSaveAsType.olMSG);
rdo_Mail.Save();
}

Resources