Comments for Chinh Do https://www.chinhdo.com/ Chinh's semi-random thoughts on software development, gadgets, and other things. Sat, 23 Nov 2024 12:32:35 +0000 hourly 1 https://wordpress.org/?v=6.8.1 Comment on Convert List<T>/IEnumerable to DataTable/DataView by DMITRIY SABITOV https://www.chinhdo.com/20090402/convert-list-to-datatable/comment-page-1/#comment-821237 Sat, 23 Nov 2024 12:32:35 +0000 https://www.chinhdo.com/20090402/convert-list-to-datatable/#comment-821237 Dear Chinh Do!

I suggest a slightly revised version of your code. As a result, you can get a datatable from an IEnumerable with values of value type and strings.

public static DataTable ToDataTable(IEnumerable input)
{
DataTable dt = new DataTable(typeof(T).Name);

PropertyInfo[] properties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);

if (typeof(T).IsValueType || typeof(T) == typeof(System.String))
{
Type t = GetCoreType(typeof(T));
dt.Columns.Add(typeof(T).Name+”C”, t);
}
else
{
foreach (PropertyInfo property in properties)
{
Type t = GetCoreType(property.PropertyType);
dt.Columns.Add(property.Name, t);
}
}

foreach (T item in input)
{
if (typeof(T).IsValueType || typeof(T) == typeof(System.String))
{
dt.Rows.Add(item);
}
else
{
object[] values = new object[properties.Length];
for (int i = 0; i < properties.Length; i++)
{
values[i] = properties[i].GetValue(item, null);
}
dt.Rows.Add(values);
}
}
return dt;
}
public static Type GetCoreType(Type t)
{
if (t != null && IsNullable(t))
{
if (!t.IsValueType) { return t; }
else { return Nullable.GetUnderlyingType(t); }
}
else { return t; }
}
public static bool IsNullable(Type t)
{
return !t.IsValueType || (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable));
}

]]>
Comment on Tee-Object and Invoke-Expression in PowerShell by software akuntansi https://www.chinhdo.com/20100105/powershell-invoke-expression-tee-object/comment-page-1/#comment-819923 Tue, 31 Oct 2023 09:40:54 +0000 https://www.chinhdo.com/20100105/powershell-invoke-expression-tee-object/#comment-819923 software akuntansi

Tee-Object and Invoke-Expression in PowerShell – Chinh Do

]]>
Comment on Tee-Object and Invoke-Expression in PowerShell by school ict suites https://www.chinhdo.com/20100105/powershell-invoke-expression-tee-object/comment-page-1/#comment-819857 Thu, 19 Oct 2023 07:51:03 +0000 https://www.chinhdo.com/20100105/powershell-invoke-expression-tee-object/#comment-819857 school ict suites

Tee-Object and Invoke-Expression in PowerShell – Chinh Do

]]>
Comment on Tee-Object and Invoke-Expression in PowerShell by shooting eye protection https://www.chinhdo.com/20100105/powershell-invoke-expression-tee-object/comment-page-1/#comment-819821 Fri, 13 Oct 2023 17:46:02 +0000 https://www.chinhdo.com/20100105/powershell-invoke-expression-tee-object/#comment-819821 shooting eye protection

Tee-Object and Invoke-Expression in PowerShell – Chinh Do

]]>
Comment on Monitor & Visualize Your SmartThings Smart Home with Splunk by Chinh Do https://www.chinhdo.com/20200330/monitor-visualize-your-smart-home-with-splunk/comment-page-1/#comment-817720 Sun, 12 Feb 2023 01:23:33 +0000 https://www.chinhdo.com/?p=701#comment-817720 In reply to Jay Theriot.

Hi Jay, Yeah I just saw that it stopped working around Jan 11 of this year. I haven’t looked into it but when I have some time I will take a look. Thanks

]]>
Comment on Monitor & Visualize Your SmartThings Smart Home with Splunk by Jay Theriot https://www.chinhdo.com/20200330/monitor-visualize-your-smart-home-with-splunk/comment-page-1/#comment-817237 Mon, 02 Jan 2023 22:56:14 +0000 https://www.chinhdo.com/?p=701#comment-817237 Chinh, with smartthings switching over recently to processing things locally on the hubs and moving more to matter centric automation, my live logging is no longer visible on hub. Splunk is no longer logging the data. Have you found a workaround for this?

]]>
Comment on Monitor & Visualize Your SmartThings Smart Home with Splunk by Chinh Do https://www.chinhdo.com/20200330/monitor-visualize-your-smart-home-with-splunk/comment-page-1/#comment-816103 Sat, 10 Sep 2022 23:06:42 +0000 https://www.chinhdo.com/?p=701#comment-816103 In reply to Raja.

Hi Raja, Glad to hear you got it working. Chinh

]]>
Comment on Monitor & Visualize Your SmartThings Smart Home with Splunk by Raja https://www.chinhdo.com/20200330/monitor-visualize-your-smart-home-with-splunk/comment-page-1/#comment-816084 Fri, 09 Sep 2022 03:38:30 +0000 https://www.chinhdo.com/?p=701#comment-816084 In reply to Raja.

I solved it. Hostname was not getting resolved for some reason, switched it to the IP address and it started working like a charm. Thanks

]]>
Comment on Monitor & Visualize Your SmartThings Smart Home with Splunk by Raja https://www.chinhdo.com/20200330/monitor-visualize-your-smart-home-with-splunk/comment-page-1/#comment-816082 Fri, 09 Sep 2022 03:22:13 +0000 https://www.chinhdo.com/?p=701#comment-816082 Hello Chinh,
Thank you for this tutorial. While I followed the steps and I am seeing the data flow thru SmartThings Live Logging, I am not seeing the data on the Splunk Enterprise side. I did test pushing data locally on the Splunk server using curl and that data is reflected in Splunk. What else could I be missing ?

]]>
Comment on Tee-Object and Invoke-Expression in PowerShell by Бэтмен комикстері https://www.chinhdo.com/20100105/powershell-invoke-expression-tee-object/comment-page-1/#comment-814404 Thu, 20 Jan 2022 05:35:11 +0000 https://www.chinhdo.com/20100105/powershell-invoke-expression-tee-object/#comment-814404 Бэтмен комикстері

Tee-Object and Invoke-Expression in PowerShell – Chinh Do

]]>