I'm currently working on a scenario where I am developing an activity for UiPath. The class library is a project setting where I am creating this activity. Specifically, for this activity, I am using Winforms, and the class library (activity) will launch and pass a DataTable to the WinForms project. My question is: How can I establish communication between two different projects, each having its own DLL file?
One potential solution I considered is to include both projects in the same solution. However, the activity is implemented as a class library (.NET Framework), and the WinForms project is separate. How can I reference System.Activities
and System.ComponentModel
in the class file that I am manually creating in the WinForms project?
Class library (Activity):
using System;
using System.Activities;
using System.ComponentModel;
using System.Data;
namespace Datatable_Visualizer_Activity
{
public class DatatableVisualizer : CodeActivity
{
[DisplayName("Datatable")]
public InArgument<DataTable> Datatable { get; set; }
protected override void Execute(CodeActivityContext context)
{
DataTable dt = Datatable.Get(context);
}
}
}
Winforms:
using MaterialSkin;
using MaterialSkin.Controls;
using System.Data;
using System.Drawing.Drawing2D;
using System.Reflection;
using System.Windows.Forms;
namespace Data_Table_Visualizer___Editor
{
public partial class MainForm : Form
{
public MainForm()
{
this.DoubleBuffered = true;
InitializeComponent();
dataGridView.Visible = false;
ShowLoading(true); // Show the circular progress bar
InitializeDataGridViewAsync();
}
private void ShowLoading(bool show)
{
// Show or hide the circular progress bar based on the 'show' parameter
progressBar.Visible = show;
}
private async void InitializeDataGridViewAsync()
{
// Use the DataTable from the event
private DataTable dataTable = ;//Datatable which i wanted to get from activity;
await Task.Run(() =>
{
// Simulate a delay for loading data (replace this with your actual data loading logic)
System.Threading.Thread.Sleep(3000);
// Invoke on UI thread to update UI controls
Invoke(new Action(() =>
{
// Bind the DataTable to the DataGridView
dataGridView.DataSource = dataTable;
dataGridView.DoubleBuffered(true);
// Auto resize columns
dataGridView.AutoResizeColumns();
// Set labels based on the initial state
label_TotalNoColumns.Text = "Total No Of Columns = " + dataTable.Columns.Count.ToString();
label_TotalNoRows.Text = "Total No Of Rows = " + dataTable.Rows.Count.ToString();
ShowLoading(false); // Hide the circular progress bar
dataGridView.Visible = true; // Show the DataGridView
}));
});
}
/* private void CreateDataTable()
{
int totalRows = 10000; //Billion No Rows Count 1000000000
int totalColumns = 100; // Ten Lakhs no rows count 1000000
int batchSize = 10000;
// Create columns
for (int i = 1; i <= totalColumns; i++)
{
dataTable.Columns.Add($"Column{i}", typeof(int));
}
// Batch processing with parallelization
Parallel.For(0, (totalRows - 1) / batchSize + 1, batch =>
{
DataTable tempTable = new DataTable("MyDataTable");
// Add columns to tempTable
foreach (DataColumn column in dataTable.Columns)
{
tempTable.Columns.Add(column.ColumnName, column.DataType);
}
for (int row = 1; row <= batchSize && (batch * batchSize) + row <= totalRows; row++)
{
DataRow dataRow = tempTable.NewRow();
// Assign sample values to each column
for (int col = 0; col < totalColumns; col++)
{
dataRow[col] = (batch * batchSize) + row;
}
tempTable.Rows.Add(dataRow);
}
lock (dataTable)
{
dataTable.Merge(tempTable);
}
});
}*/
private void dataGridView_ColumnAdded(object sender, DataGridViewColumnEventArgs e)
{
e.Column.FillWeight = 10; // <<this line will help you
}
}
public static class ExtensionMethods
{
public static void DoubleBuffered(this DataGridView dgv, bool setting)
{
Type dgvType = dgv.GetType();
PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
pi.SetValue(dgv, setting, null);
}
}
}
And in the end both the dll file will be added into a nuget pakage for use in uipath