i'm making user inactivity logger internal application @ work, , i'm having trouble writing consumed messages mysql database, when try call method writes messages database, throws error: 'accesseye.logdata' 'type', not valid in given context
any , appreciated, it's windows forms project topshelf service being used rabbitmq consumer, forward messages database mentioned =]
using system; using system.collections.generic; using system.linq; using system.text; using system.diagnostics; using nlog; using iwshruntimelibrary; using topshelf; using system.data.odbc; using easynetq; using rabbitmq; using easynetq.topology; using system.threading.tasks; using system.windows.forms; using accesseye; using system.componentmodel; namespace logservice { public class windowsservicehost : servicecontrol, serviceshutdown { public static readonly logger logger = logmanager.getcurrentclasslogger(); public static void writelogdatatodb(logdata data) { using (var db = new logservice.useractivitydatacontext()) { dblogdata logdata = automapper.mapper.map<logdata, dblogdata>(data); int t = (int)data.eventtype; eventtype eventtype = db.eventtypes.firstordefault(r => r.id == t); if (eventtype == null) { eventtype = db.eventtypes.add(new eventtype { event = getenumdescriptionattributevalue(data.eventtype), id = (int)data.eventtype }); db.savechanges(); } logdata.eventtypeid = eventtype.id; db.logevents.add(logdata); db.savechanges(); } } public static string getenumdescriptionattributevalue(enum value) { var fieldinfo = value.gettype().getfield(value.tostring()); var attributes = (descriptionattribute[])fieldinfo.getcustomattributes(typeof(descriptionattribute), false); return attributes.length > 0 ? attributes[0].description : value.tostring(); } public bool start(hostcontrol hostcontrol) { program.bus = rabbithutch.createbus("host=as01.access.local;virtualhost=dev-reece;username=reece;password=reece").advanced; //var bus = rabbithutch.createbus("host=as01.access.local;virtualhost=dev-reece;username=reece;password=reece").advanced; var queue = queue.declare(true, false, true, null); var exchange = exchange.declarefanout("useractivityfanout", true, false, null); var exchangetopic = exchange.declaretopic("useractivity", true, false, null); queue.bindto(exchange, "#"); exchange.bindto(exchangetopic, "#"); program.bus.subscribe<accesseye.logdata>(queue, (msg, messagerecinfo) => task.factory.startnew(() => { writelogdatatodb(accesseye.logdata); //appform.writelogdatatodb(data); //console.writeline(msg.body.username + " -- " + msg.body.computername + " -- " + msg.body.eventtype + " -- " + msg.body.teamviewerid); })); return true; } public bool stop(hostcontrol hostcontrol) { logger.trace("stop"); program.bus.dispose(); return true; } public void shutdown(hostcontrol hostcontrol) { logger.trace("shutdown"); program.bus.dispose(); } } }
you passing type
parameter writelogdatatodb()
method, when expected instance of accesseye.logdata
.
i don't know initialize variable, "fix" (you initializing default instance suggested code) issue must change piece of code.
program.bus.subscribe<accesseye.logdata>(queue, (msg, messagerecinfo) => task.factory.startnew(() => { writelogdatatodb(new accesseye.logdata()); }));
note don't know constructors defined accesseye.logdata
type, know.
at other hand, suppose 1 of parameters lambda expression instance of required type.
what of suscribe()
method of type accesseye.logdata
?
edit:
as op says in comment, solution replace original code code snippet:
program.bus.subscribe<accesseye.logdata>(queue, (msg, messagerecinfo) => task.factory.startnew(() => { var data2 = logdatafactory.collectdata(); data2.eventtype = accesseye.userstateevents.logon; writelogdatatodb(data2); }));
Comments
Post a Comment