Cliff Karlsson
Cliff Karlsson
CC#
Created by Cliff Karlsson on 2/21/2023 in #help
❔ How to access variable from AccessibilityObject ?
I am trying to make canges to an old Winforms or Window forms application and my main goal is to populate a dropdown-menu with some values.
internal class OrderdocumentValuePickerEditor : UITypeEditor
{

IWindowsFormsEditorService m_editorService;

public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}

public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
m_editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
Form f = Application.OpenForms["LabelmakerDesignForm"];

internal class OrderdocumentValuePickerEditor : UITypeEditor
{

IWindowsFormsEditorService m_editorService;

public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}

public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
m_editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
Form f = Application.OpenForms["LabelmakerDesignForm"];

The EditValue function is called when I click on the dropdown and I am trying to access a public variable called m_orderdoc. If I search for a value in the orderdoc in the "locals" part of Visual studio I see that the m_orderdoc is located in: provider.AccessibilityObject -> PropertyGridView -> TopLevelControl -> m_orderdoc But how can I access this value? I also tried using Application.OpenForms to get a form that contains the variable. But I can't access it from there either even tho I see that f contains m_orderdoc.
2 replies
CC#
Created by Cliff Karlsson on 11/23/2022 in #help
❔ Help with simple regex
How do I use regex replace to transform a string with four numbers to have dots between them? Like this: 1234 -> 1.2.3.4 3690 -> 3.6.9.0
37 replies
CC#
Created by Cliff Karlsson on 11/22/2022 in #help
❔ Creating a XML-document and adding subnodes
Can anyone show me how to use XmlDocument or XDocument to create a new Xml-document that has a "<root>" -node. Then in the loop writer.toString() is a new xmldocument in sting-format that I want to add to the root-node.
public static XmlDocument CreateOrderXML(string materialId)
{
Dictionary<string, object> dict = GetData(materialId).Result;

XmlDocument xmlDoc = new XmlDocument();
XDocument xdoc = XDocument.Parse(@"<Root/>");

foreach (var entry in dict)
{

using (var writer = new StringWriter())
{

new XmlSerializer(Type.GetType(entry.Key)).Serialize(writer, entry.Value);

//XmlDocumentFragment fragment = xmlDoc.CreateDocumentFragment();
//fragment.InnerXml = writer.ToString();

}

}

return xmlDoc;
}
public static XmlDocument CreateOrderXML(string materialId)
{
Dictionary<string, object> dict = GetData(materialId).Result;

XmlDocument xmlDoc = new XmlDocument();
XDocument xdoc = XDocument.Parse(@"<Root/>");

foreach (var entry in dict)
{

using (var writer = new StringWriter())
{

new XmlSerializer(Type.GetType(entry.Key)).Serialize(writer, entry.Value);

//XmlDocumentFragment fragment = xmlDoc.CreateDocumentFragment();
//fragment.InnerXml = writer.ToString();

}

}

return xmlDoc;
}
2 replies
CC#
Created by Cliff Karlsson on 11/17/2022 in #help
❔ Returning an async dictionary ?
I am calling this function from an api endpoint and want to return the results from the tasks. Right now I store all results in a dictionary but am returning a Task. Is there a better way to do this so that I just return the result as a plain dictionary instead of a Task ?
public class DataGatherer
{
static async Task<Dictionary<string, object>> GetData()
{
Dictionary<string, object> dict = new Dictionary<string, object>();

using HttpClient client = new();

try
{

var tasks = new Task[] {
Task.Run(async () => await ExternalTablesGatherer.ProcessRepositoriesAsync(client, "6382963", dict)),
Task.Run(async () => await QueueDataGatherer.GetDataAsync(client, "6010081", dict))
};

await Task.WhenAll(tasks);

return dict;

}
catch (Exception exception)
{
Console.WriteLine(exception);
return null;
}
}
}
public class DataGatherer
{
static async Task<Dictionary<string, object>> GetData()
{
Dictionary<string, object> dict = new Dictionary<string, object>();

using HttpClient client = new();

try
{

var tasks = new Task[] {
Task.Run(async () => await ExternalTablesGatherer.ProcessRepositoriesAsync(client, "6382963", dict)),
Task.Run(async () => await QueueDataGatherer.GetDataAsync(client, "6010081", dict))
};

await Task.WhenAll(tasks);

return dict;

}
catch (Exception exception)
{
Console.WriteLine(exception);
return null;
}
}
}
4 replies
CC#
Created by Cliff Karlsson on 10/21/2022 in #help
How do I get all DbSets from a Context ?
I have multiple DbSets where I query each set and parse the results like this:
var result1 = _context.EXT_PRAMET_INSERTS.Where(x => x.MaterialID == MaterialID).ToList();
var result2 = _context.EXT_DORMER.Where(x => x.MaterialID == MaterialID).ToList();
...
var result1 = _context.EXT_PRAMET_INSERTS.Where(x => x.MaterialID == MaterialID).ToList();
var result2 = _context.EXT_DORMER.Where(x => x.MaterialID == MaterialID).ToList();
...
How can I do the same using a loop where I iterate over each DbSet in the Context and use a query ?
2 replies