How do I add an array of names in a single event? - azure-application-insights

In my application I can add more than one person at a time. I want to log multiple names in a single event.
I have a bunch of data is "Persons". Persons contains Name
In my application I can add more than one person at a time. I want to log multiple names in an event
What is the best way to log the data in AI?
The only way I can think of this, but its not the ideal way
foreach (Persons person in persons) {
if (person.IsNew)
{
personName += Person.Name + ",";
}
metricRecorder.AddProperty("personNameAdded", personName);
}
The above is not ideal way as when the data gets into AI, it would require regex to separate the name or even get the count of the names etc...
I can't find anything in the documents, how would I approach this?

You can add each name as a property of EventTelemetry.
A sample code like below, you can modify your code as per the sample:
TelemetryClient client = new TelemetryClient { InstrumentationKey = "xxxxxxxxxxxx" };
EventTelemetry eventTelemetry = new EventTelemetry();
eventTelemetry.Name = "event_1";
List<string> names = new List<string>();
names.Add("ivan");
names.Add("jack");
names.Add("nancy");
names.Add("tina");
names.Add("sarah");
int i = 0;
foreach (string n in names)
{
eventTelemetry.Properties.Add("name_"+i, n);
i++;
}
client.TrackEvent(eventTelemetry);
Then in the logs of application insights:

Related

How to retrieve a property of collection as a collection of string using Java Stream api

I have a list of class Category which contains many attributes like code, name, description, supercategory, productlist, etc. Now I want to iterate over it and retrieve each category's code and store add it in list of string. This is how I am doing it with old school way. I want to know if this can be done in better, cleaner and efficient way with Java 8 Streams.
List<Category> categories = categoryService.getCategoriesForProductCode(productCode);
List<String> categoryCodes = new ArrayList<>();
if(CollectionUtils.isNotEmpty(categories)){
for(Category cat : categories){
categoryCodes.add(cat.getCode);
}
}
You can do like this
categoryCodes = categories.stream()
.map(category->catgory.getCode()) // .map(Category::getCode)
.collect(Collectors.toList());

WCF Transaction with multiple inserts

When creating a user, entries are required in multiple tables. I am trying to create a transaction that creates a new entry into one table and then pass the new entityid into the parent table and so on. The error I am getting is
The transaction manager has disabled its support for remote/network
transactions. (Exception from HRESULT: 0x8004D024)
I believe this is caused by creating multiple connections within a single TransactionScope, but I am unsure on what the best/most efficient way of doing this is.
[OperationBehavior(TransactionScopeRequired = true)]
public int CreateUser(CreateUserData createData)
{
// Create a new family group and get the ID
var familyGroupId = createData.FamilyGroupId ?? CreateFamilyGroup();
// Create the APUser and get the Id
var apUserId = CreateAPUser(createData.UserId, familyGroupId);
// Create the institution user and get the Id
var institutionUserId = CreateInsUser(apUserId, createData.AlternateId, createData.InstitutionId);
// Create the investigator group user and return the Id
return AddUserToGroup(createData.InvestigatorGroupId, institutionUserId);
}
This is an example of one of the function calls, all the other ones follow the same format
public int CreateFamilyGroup(string familyGroupName)
{
var familyRepo = _FamilyRepo ?? new FamilyGroupRepository();
var familyGroup = new FamilyGroup() {CreationDate = DateTime.Now};
return familyRepo.AddFamilyGroup(familyGroup);
}
And the repository call for this is as follows
public int AddFamilyGroup(FamilyGroup familyGroup)
{
using (var context = new GameDbContext())
{
var newGroup = context.FamilyGroups.Add(familyGroup);
context.SaveChanges();
return newGroup.FamilyGroupId;
}
}
I believe this is caused by creating multiple connections within a single TransactionScope
Yes, that is the problem. It does not really matter how you avoid that as long you avoid it. A common thing to do is to have one connection and one EF context per WCF request. You need to find a way to pass that EF context along.
The method AddFamilyGroup illustrates a common anti-pattern with EF: You are using EF as a CRUD facility. It's supposed to me more like a live object graph connected to the database. The entire WCF request should share the same EF context. If you move in that direction the problem goes away.

Add new tags on dcm4chee

I'm working with dcm4chee now,and I have the demand to add some custom fields,for example patient's ID card number,mobile fhone number and address.
After googling some related information,I am still confused and don't know what to do.Has any one ever done this?
i've done it on some other cases. In my case i've to modify existing tag with new value. Here the code, hope it give you some pointer.
public static void changementTag(File file, int tagChooser, String aModify, VR vr, String newString )
{
try
{
DicomInputStream dis = new DicomInputStream(file);
DicomObject dio = dis.readDicomObject();
dis.close();
String fileName = file.getAbsolutePath() + ".ori";
File originFile = new File(fileName);
file.renameTo(originFile);
boolean change = false;
dio.putString(tagChooser, vr, newString);
change = true;
if(change)
{
FileOutputStream fos = new FileOutputStream( new File(file.getParent()+ "/" + file.getName()));
BufferedOutputStream bos = new BufferedOutputStream(fos);
DicomOutputStream dos = new DicomOutputStream(bos);
dos.writeDicomFile(dio);
dos.close();
originFile.delete();
}
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
As already pointed out by #jap1968, you can add
Other Patient IDs (0010,1000)
to include any additional patient ID numbers. This attribute is part of the Patient Identification Module, which attributes are generally expected in most DICOM objects.
From the Patient Demographic Module, which is normally an optional set of attributes, you can then for example reuse these attributes:
Patient’s Telephone Numbers (0010,2154)
Patient’s Address (0010,1040)
Depending on which DICOM toolkit you are using to process your DICOM objects, there will be different methods for attribute insertion. In dcm4che, you should be able to use one of the available DicomObject.put... methods to insert a new value in your DICOM object. Just remember that for correctness, you should update the SOP Instance UID (and potentially other UID:s) for the modified object.
Have a look at these Dicom fields:
Other Patient IDs (0010,1000)
Other Patient IDs Sequence (0010,1002)
Maybe you do not need to add custom fields (at least for the patient ID card), but just use some of the already existing ones.

How to find number of elements when adding and deleting elemnts dynamically using jQuery?

I'm working on a web application (with ASP.NET 2.0 (C#) and jQuery)
In my application we have an interface using which our employees are able to enter records of a comany. We provided the interface with basic fields, Company Name, Contact Person, phone, etc. Now as you know some companies have thier branches, some have few (1 to 10) and some have many (100-200) branches. We have also provided a dynamic interface using jQuery, which allows our employees to add branches depending on number of branches a particular company have.
For addition, we have used jQuery's append function as ..
$("#branches").append("branch html fields text liek a html input field with id 'Namebranch1' ");
Now, with adding we have also provided a button with evey branch field seprately for deleting that particular branch. For deleting I have used
$("#branch1").remove()
Let's say, I have added 5 branches, then before submitting, I feel that branch number 3 is not necessary to enter, So I have deleted that branch data.
So the process of adding and removing is as follows, we have added
1,2,3,4,5
Then, We deleted 3rd branch and now we have
1,2,4,5
Now as we have 4 elements, so whenever my user is adding or deleting a branch I am adding 1 and substracting 1 from a javascript variable respectively. And then entering that variable in a hidden field, so that when user submit data then I'll have the correct number of count that how any branches are added by the user and on the basis of this count, I know that how many times I have to run the loop to catch up all branches data seprately.
But the problem is when user submit the form then I am running a loop 4 times, what it means, I'll get data of 1,2 and 4 branches but as loop will stop when it completed 4 cycles then, data of 5th branch which is actully 4 will be missing. Because elements which will be posted when user will sibmit form are as (branchName5, branchTitle5 etc.)
I hope you guys understand what I need? Please tell me some logical solution of this problem.
Thanks
Get rid of the hidden counter variable, and just iterate through Request.Form.Keys looking for branch*. Then, you'll just process any form variables that start with branch.
class Branch { public string Name; public string Title; }
void OnLoad(EventArgs e) {
base.OnLoad(e);
var branches = new Dictionary<int, Branch>();
foreach (string key in Request.Form.Keys) {
if (!key.StartsWith("branch")) continue;
int id;
if (key.StartsWith("branchTitle")) {
id = int.Parse(key.Substring("branchTitle".Length));
branches.Ensure(i).Title = Request.Form[key];
} else if (key.StartsWith("branchName")) {
id = int.Parse(key.Substring("branchName".Length));
branches.Ensure(i).Name = Request.Form[key];
}
}
}
// Ensure extension method
T Ensure<K, T>(this Dictionary<K, T> d, K key) where T:new {
if (!d.ContainsKey(key)) {
d.Add(key, new T());
}
return d[key];
}
maybe this is a clue? in submit do ....
$('#branches').each( function (i) { this.id = 'branch' + i } );

Saving CheckBox control values

I am using asp.net and I am trying to save checkbox values into a database. Multiple checkboxes may be entered into the same field in the database. So for instance I have two checkboxes with names "Comma" and "Hyphen" and if the user checks both of these then the database will store the values ',','-'. How do you do this?
thanks
To save multiple values into the same column I'd recommend using a flag enumeration. Here is a code sample using checkboxes.
If you really have to store the values in a comma-delimited format, might try something like this:
List<string> values = new List<string>();
if (cbComma.Checked) {
values.Add("','");
}
...
string result = values.ToArray().Join(",");
I'd agree with David Thomas Garcia's recommendation if you can save the value to the database using the enumeration (as an int or whatever was appropriate for the amount of options you'll have).
If that's not an option though, and you are bound to storing them in the database as a string of characters I'd do something like the following:
private void LoadData()
{
string dbVal = DataAccess.GetDbVal(); //Get your value from the database.
chkComma.Checked = dbVal.Contains(",");
chkDash.Checked = dbVal.Contains("-");
}
private void SaveData()
{
string dbVal = "";
if(chkComma.Checked)
dbVal += ",";
if(chkDash.Checked)
dbVal += "-";
DataAccess.SaveDbVal(dbVal); //Send the value of dbVal to your data layer to be saved.
}
Note that this does not include any separation of the values to be saved in the value stored in the database, but if you needed that you could use a List and do what David Thomas Garcia mentioned with the .ToArray().Join(","); in the SaveData() and in the LoadData() just make dbVal a List and the syntax doesn't need change.

Resources