|
How to filter one interface with multiple method by diffrent class in C#. Please give answer with example.
|
|
|
|
|
Using IsAssignableFrom can help you figure out if the class uses that interface.
For e.g.
typeof(IMyInterface).IsAssignableFrom(typeof(MyClass));
|
|
|
|
|
Thank u sir, please explain in detail ,I am fresher so define it with C# example
|
|
|
|
|
You can also do this to determine if a class implements a specific interface:
if (myObject is IMyInterface)
{
}
else
{
}
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I know this is long, so please try not to TLDR me I have a reporting service that allows users to queue reports. All fine and dandy, they queue it, it goes into a database. I have a service that polls the DB queue and runs reports. I am stuck on the run part right now. The reports are Telerik reports, but it is not really relevant as it would be the same if they were crystal or anything else. I want to store the report type in the DB and pull it at run time. The report queue looks like this:
USE [litigatorPro]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ReportQueue](
[id] [int] IDENTITY(1,1) NOT NULL,
[reportId] [int] NOT NULL,
[userId] [int] NOT NULL,
[statusId] [int] NOT NULL,
[claimId] [int] NULL,
[propertyId] [int] NULL,
[startDate] [datetime] NULL,
[endDate] [datetime] NULL,
[datestamp] [datetime] NOT NULL,
CONSTRAINT [PK_ReportQueue] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
And the Report table:
USE [litigatorPro]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Report](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](100) NOT NULL,
[fileName] [nvarchar](100) NOT NULL,
[queryString] [nvarchar](2500) NOT NULL,
[scopeId] [int] NOT NULL,
[reportType] [nvarchar](50) NULL,
CONSTRAINT [PK_Report] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
Some of the fields are not use, but the important point is that the service checks the report queue table and gets the report type and parameters. I want to then process the report using something like this:
private bool RunReport<T>(int id) where T: Telerik.Reporting.Report
{
var targetReport = (T)Activator.CreateInstance(typeof(T), new object[] { id });
return false;
}
The issue, for now, is how to call the function with information from the DB. Here is what I am looking at with crossed eyes right now:
private int ProcessReport(ReportQueue item)
{
using (litigatorProEntities _db = new litigatorProEntities())
{
ReportPolling.Model.Report report = _db.Reports.Single(r => r.id == item.reportId);
Type type = Type.GetType(report.reportType);
if (RunReport<type>(report))
{
return 1;
}
return 2;
}
return 2;
}
I need to figure out how to supply the type based on a text field from the DB as seen in the line that says:
if (RunReport<type>(report))
After that I will figure out how to pass the arguments (userId, claimId, propertyId, etc...)
I am not great with some of the fundamental items like generics and boxing, so forgive me if the question is stupid.
Cheers, --EA
|
|
|
|
|
I've just started using Telerik reports and use the .trdx file, have not worked out how to pass in parameters but I'm certain it can be done then the viewer displays! Ahh the light goes on, you want it to process, I'll await further enlightenment (should have deleted this reply I suppose )
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
 I have used Telerik a bit so I am not super unfamiliar with it. So that I am not sitting on my hands all day I decided to just switch() the report name parameter until I can figure out the anonymous access piece.
private bool RunReport(string reportName, int? claimId, int? propertyId, int? ecrId)
{
switch (reportName)
{
case "COR - Cost Summary By Address":
Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
CostSummaryByAddress myReport = new CostSummaryByAddress(ecrId, claimId);
instanceReportSource.ReportDocument = myReport;
Telerik.Reporting.Processing.RenderingResult result =
reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);
string fileName = result.DocumentName + "." + result.Extension;
string path = System.IO.Path.GetTempPath();
string filePath = System.IO.Path.Combine(path, fileName);
using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
{
fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
}
break;
}
return true;
}
And the report class:
public partial class CostSummaryByAddress : Telerik.Reporting.Report
{
public CostSummaryByAddress(int? ecrId, int? claimId)
{
if (ecrId == null)
{
ecrId = 1;
}
InitializeComponent();
using (litigatorProEntities _db = new litigatorProEntities())
{
var model = from d in _db.ECRDatas.Where(e => e.ecrId == ecrId)
select new CostSummaryViewModel
{
claimName = d.ECR.Claim.description,
property = d.property,
totalCost = d.totalCost
};
this.DataSource = model.ToList();
}
}
Frankly, I have built all of these reports in Crystal so I am not sure I am going to stick with Telerik for reporting as all of the reporting is done on an application server with a note being emailed to the user. Since none of it is being displayed in a viewer I am thinking it is more work than it is worth. We will see, though.
Cheers, --EA
|
|
|
|
|
We use SSRS for our server based reporting, Telerik will only be used for reports embedded into the application, there is no integrated viewer for any other reporting system in SilverLight.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm looking for direction on how to do this. I've looked at RegistryMonitor, but I'm having a hard time following how the code works.
I was expecting it to be like a normal event where I could use e.cancel and stop it if needed, but it appears that .net doesn't have that for the registry.
This code example monitors changes on "SYSTEM\CurrentControlSet\Control\Test" in HKLM, but how can I catch it and stop the change from completing?
<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
public class RegistryTester
{
const int INFINITE = -1;
const int WAIT_OBJECT_0 = 0;
const long HKEY_LOCAL_MACHINE = 0x80000002L;
const long REG_NOTIFY_CHANGE_LAST_SET = 0x00000004L;
[DllImport("advapi32.dll", EntryPoint = "RegNotifyChangeKeyValue")]
static extern long RegNotifyChangeKeyValue(IntPtr key,
bool watchSubTree, int notifyFilter, IntPtr regEvent, bool
async);
[DllImport("advapi32.dll", EntryPoint = "RegOpenKey")]
static extern IntPtr RegOpenKey(IntPtr key, String subKey,
out IntPtr resultSubKey);
[DllImport("kernel32.dll", EntryPoint = "CreateEvent")]
static extern IntPtr CreateEvent(IntPtr eventAttributes,
bool manualReset, bool initialState, String name);
[DllImport("kernel32.dll", EntryPoint = "WaitForMultipleObjects")]
static extern unsafe int WaitForMultipleObjects(int numHandles,
IntPtr* handleArrays, bool waitAll, int timeOut);
[DllImport("kernel32.dll", EntryPoint = "CloseHandle")]
static extern IntPtr CloseHandle(IntPtr handle);
public unsafe static void Main(String[] args)
{
args = new string[] { "1", @"SYSTEM\CurrentControlSet\Control\Test" };
int ret = 0;
if (args.Length < 2)
{
Console.WriteLine("Usage: RegistryTester NUMKEYS KEY1 KEY2...");
return;
}
int numKeys = 0;
try
{
numKeys = int.Parse(args[0]);
}
catch (Exception)
{
Console.WriteLine("Invalid argument for NUMKEYS");
return;
}
if (numKeys != args.Length - 1)
{
Console.WriteLine("Did not provide correct number of key arguments.");
return;
}
String[] keys = new String[numKeys];
for (int i = 0; i < numKeys; i++)
{
keys[i] = args[i + 1];
}
IntPtr[] eventHandles = new IntPtr[numKeys];
for (int i = 0; i < numKeys; i++)
{
eventHandles[i] = CreateEvent((IntPtr)null, false, false,
null);
IntPtr myKey;
unchecked
{
RegOpenKey(new IntPtr((int)HKEY_LOCAL_MACHINE),
keys[i], out myKey);
}
RegNotifyChangeKeyValue(myKey, true,
(int)REG_NOTIFY_CHANGE_LAST_SET, eventHandles[i],
true);
}
Console.WriteLine("Waiting on " + numKeys + " keys.");
fixed (IntPtr* handlePtr = eventHandles)
{
ret = WaitForMultipleObjects(numKeys, handlePtr, false,
INFINITE);
}
Console.WriteLine(keys[ret - WAIT_OBJECT_0] + " was changed.");
Console.ReadLine();
}
}
}
|
|
|
|
|
The short answer is you can't stop it from happening. If the user has the permissions to make the change, then the change will be made.
Having said that, the long answer is it's possible, depending on your requirements.
You could just change the permissions on the key for user in question. But, since it looks like you're trying to block something under KEY_LOCAL_MACHINE, the user will already have admin permissions and can just remove your permissions block and grant him/herself permissions to it again.
The other method is to intercept the API calls for registry access. You would need a library, called Detours, to do this. This library is not cheap if you want 64-bit support! This method is also NOT TRIVIAL! It's extremely complicated to do.
You would have to examine the caller to see what code is making the call to change the registry. You can't just stop all registry access because you'd be stopping the system from modifying critical values in the registry. You have to example not only where the call is being made from but who is running the code making the call! After all, what good is blocking the change from your app code if the user can just open RegEdit and make the change manually?!
|
|
|
|
|
Hi Dave, thanks for the reply.
I read an overview on Detours and an open source counterpart, Easy Hook. Do you have any experience with either? From your phraseology, this may be above my programming experience, but I like a challenge so I would like to give one a try.
|
|
|
|
|
Haven't used either. I've never had a reason to.
|
|
|
|
|
Hooking API's is not something trivial, and it is not meant as a generic extension point for plugin writers;
turbosupramk3 wrote: but I like a challenge so I would like to give one a try. It's something that probably requires multiple tries. Be sure to work from a VM, you don't want to kill your boot-environment.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
What about the approach to monitor the key and coerce your value if it gets changed by immediately resetting it?
modified 3-Aug-13 15:51pm.
|
|
|
|
|
Thanks for the reply, this is a good idea.
Although this would be easier in the short term, I would also like to do this with folder access and file access in the long term and a liaison application would be much better.
|
|
|
|
|
I have a table named login
I am binded login table with rdlc report in a table whose showing username and password from login table into report
but now m wanna tht in my rdlc report table show initially 10 rows thn as data comes from login table it just inerted automatically
but as the number of rows are more thn 10 thn the other rows will be displayed on the next page in the same manner.
can anyone help me with it???
|
|
|
|
|
Set the page height to only display 10 records.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
ka ka ka ka ka
Yes.......
|
|
|
|
|
The System.Timers.Timer is too slow in my application. Can you guys please give me a hint?
I wrote this short Code to test the timer.
At first I create a timer:
private void button2_Click(object sender, EventArgs e)
{
System.Timers.Timer Timer;
Timer = new System.Timers.Timer();
Timer.Interval = 20;
Timer.Enabled = true;
Timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
}
Afterwards I simple dispolay the elapsed time in a label, so that I can compare theese result with a stop watch:
private void OnTimedEvent(object source, ElapsedEventArgs e)
{
Invoke(new MethodInvoker(delegate
{
label1.Text = (Convert.ToInt32(label3.Text) + 20).ToString();
}));
}
|
|
|
|
|
Why not just use the Stopwatch class instead? As you currently have this implementation, you aren't actually displaying the elapsed time - you're just displaying an arbitrary value (oh, and if you use Debug.WriteLine in the OnTimedEvent, you can track the elapsed in the output window without having to marshall across to the UI thread.
|
|
|
|
|
Thanks for the tipp. I have a continuos signal and need to take measurements every 20ms. Can you give me a codeexample, how to use stopwatch in this case? Actually I think I need a thread that constantly tests if my stopwatch elapsed time is divisible by 20ms?
|
|
|
|
|
Hi,
Measure it manually and checking everytime for elapsed time never good option. timer is for that purpose. you are calling method every 20ms it means your code is executed 50 times per second. Please elaborate your actual problem. Why you need to execute function after 20ms ?
Thanks
-Amit Gajjar
|
|
|
|
|
Quote: Why you need to execute function after 20ms ?
As i said, I have contious time signal (by Leap Motion) and I want to sample it with 50 Hz, or at least 40 Hz.
|
|
|
|
|
|
Windows is not a real-time OS. 20 ms means that the event will be triggered "somewhere" after 20 ms passed, not "exactly" after 20 ms.
Don't, unless you're sure.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|