Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

The platform-independent code with Mono: Client-server application sample

, 24 Mar 2010
This article shows how we can develop the platform-independent software with Mono usage
InfoCenter.zip
InfoCenter
ConfigSamples
InfoCenter.Agent
Agent.pidb
Agent.userprefs
bin
Debug
Agent.exe
Agent.exe.mdb
Agent.pdb
Entities
Helpers
ObjectSerializer.cs~
obj
x86
Debug
TempPE
Service
InfoCenterService.wsdl
InfoCenter.Logic
Agent
Entities
Helpers
bin
Debug
Antlr3.Runtime.dll
Iesi.Collections.dll
InfoCenter.Logic.dll
InfoCenter.Logic.dll.mdb
InfoCenter.Logic.pdb
InfoCenter.Persistence.dll
InfoCenter.Persistence.dll.mdb
InfoCenter.Persistence.pdb
log4net.dll
Release
InfoCenter.Logic.pidb
obj
Debug
InfoCenter.Logic.dll
InfoCenter.Logic.pdb
ResolveAssemblyReference.cache
TempPE
Properties
InfoCenter.Logic.Tests
bin
Debug
Antlr3.Runtime.dll
Castle.Core.dll
Castle.DynamicProxy2.dll
Iesi.Collections.dll
InfoCenter.Logic.dll
InfoCenter.Logic.dll.mdb
InfoCenter.Logic.pdb
InfoCenter.Logic.Tests.dll
InfoCenter.Logic.Tests.dll.mdb
InfoCenter.Logic.Tests.pdb
InfoCenter.Persistence.dll
InfoCenter.Persistence.dll.mdb
InfoCenter.Persistence.pdb
log4net.dll
MySql.Data.dll
NHibernate.ByteCode.Castle.dll
nunit.framework.dll
Release
InfoCenter.Logic.Tests.pidb
obj
Debug
InfoCenter.Logic.Tests.dll
InfoCenter.Logic.Tests.pdb
ResolveAssemblyReference.cache
TempPE
Properties
test-results
InfoCenter.Logic.Tests.csproj.test-cache
InfoCenter.Persistence
bin
Debug
Antlr3.Runtime.dll
Iesi.Collections.dll
InfoCenter.Persistence.dll
InfoCenter.Persistence.dll.mdb
InfoCenter.Persistence.pdb
log4net.dll
Release
Core
Entities
InfoCenter.Persistence.pidb
Mapping
obj
Debug
InfoCenter.Persistence.dll
InfoCenter.Persistence.pdb
ResolveAssemblyReference.cache
TempPE
Properties
InfoCenter.Persistence.Test
bin
Debug
Antlr3.Runtime.dll
Castle.Core.dll
Castle.DynamicProxy2.dll
Iesi.Collections.dll
InfoCenter.Persistence.dll
InfoCenter.Persistence.dll.mdb
InfoCenter.Persistence.pdb
InfoCenter.Persistence.Tests.dll
InfoCenter.Persistence.Tests.dll.mdb
InfoCenter.Persistence.Tests.pdb
log4net.dll
MySql.Data.dll
NHibernate.ByteCode.Castle.dll
NHibernate.dll
nunit.framework.dll
Release
InfoCenter.Persistence.Tests.pidb
obj
Debug
InfoCenter.Persistence.Test.dll
InfoCenter.Persistence.Test.pdb
InfoCenter.Persistence.Tests.dll
InfoCenter.Persistence.Tests.pdb
ResolveAssemblyReference.cache
TempPE
Properties
test-results
InfoCenter.Persistence.Tests.csproj.test-cache
InfoCenter.userprefs
InfoCenter.WebConsole
bin
Antlr3.Runtime.dll
Castle.Core.dll
Castle.DynamicProxy2.dll
Iesi.Collections.dll
InfoCenter.Logic.dll
InfoCenter.Logic.dll.mdb
InfoCenter.Logic.pdb
InfoCenter.Persistence.dll
InfoCenter.Persistence.dll.mdb
InfoCenter.Persistence.pdb
InfoCenter.WebConsole.dll
InfoCenter.WebConsole.dll.mdb
InfoCenter.WebConsole.pdb
log4net.dll
MySql.Data.dll
NHibernate.ByteCode.Castle.dll
Global.asax
InfoCenter.WebConsole.pidb
InfoCenter.WebConsole.userprefs
SharedLibs
Antlr3.Runtime.dll
Castle.Core.dll
Castle.DynamicProxy2.dll
Iesi.Collections.dll
log4net.dll
MySql.Data.dll
NHibernate.ByteCode.Castle.dll
NHibernate.dll
nunit.framework.dll
test-results
using System;
using System.Collections.Generic;
using System.Text;

using InfoCenter.Agent.Helpers;

//When LinqToHibernate is implemented 
//we can remove this line and use System.Linq capabilities
using NHibernate.Criterion;
using InfoCenter.Persistence.Core;
using InfoCenter.Persistence.Entities;

namespace InfoCenter.Logic
{
    public class PacketParser
    {
        private IRepository<Computer> computers;
        private IRepository<Process> processes;

        public PacketParser(IRepository<Computer> computersRepository, IRepository<Process> processesRepository)
        {
            computers = computersRepository;
            processes = processesRepository;
        }

        /// <summary>
        /// Add infromation about computer in database
        /// </summary>
        /// <param name="compressedInfo"></param>
        public void AddInfo(string compressedInfo)
        {
            string decompressed = Archiver.Decompress(compressedInfo);
            Agent.Entities.Computer info = (Agent.Entities.Computer) ObjectSerializer.XmlStrToObj<Agent.Entities.Computer>(decompressed);
			
			DetachedCriteria criteria = DetachedCriteria.For<Computer>()
                .Add(NHibernate.Criterion.Expression.Like("Name",info.Name));
			
			Computer oldEntry = computers.FindOne(criteria);
						
			
			
			if(oldEntry != null)
			{
				oldEntry.Name = info.Name;
		        oldEntry.Ip = info.Ip;
		        oldEntry.UserName = info.UserName;
		        oldEntry.OsVersion = info.OsVersion;
		        oldEntry.RecentActivity = DateTime.Now;
				
				computers.Update(oldEntry);
			}
			else
			{
				Computer computer =  new Computer();
				
				computer.Name = info.Name;
		        computer.Ip = info.Ip;
		        computer.UserName = info.UserName;
		        computer.OsVersion = info.OsVersion;
		        computer.RecentActivity = DateTime.Now;
				
            	computers.Add(computer);
			}
        }
		
		
        /// <summary>
        /// Insert process
        /// </summary>
        /// <param name="compName"></param>
        /// <param name="compressedProcesses"></param>
        public void AddProcesses(string compName, string compressedProcesses)
        {
            //decompress input data
            string decompressed = Archiver.Decompress(compressedProcesses);

            //get computer with name 'compName'
            //var computer = computers.FindOne(c => c.Name == compName);
			
			DetachedCriteria criteria = DetachedCriteria.For<Computer>()
                .Add(NHibernate.Criterion.Expression.Like("Name",compName));
			Computer computer = computers.FindOne(criteria);
				
            //TODO Need to log this situation
            if (computer == null)
                return;

            //remove old processes
            //processes.Remove(p => p.Name == compName);
			DetachedCriteria procCriteria = DetachedCriteria.For<Process>().CreateAlias("Host","c")
                .Add(NHibernate.Criterion.Expression.Like("c.Name","ILYA"));
			
			processes.Remove(procCriteria);

            //convert from xml to agent.process collection
			
			
			IList<Agent.Entities.Process> procInfo = new List<Agent.Entities.Process>();
			foreach(Agent.Entities.Process proc in 
			        ObjectSerializer.XmlStrToObj<Agent.Entities.Process[]>(decompressed))
			{
				procInfo.Add(proc);
			}
            //IList<Agent.Entities.Process> procInfo = 
            //   ObjectSerializer.XmlStrToObj<Agent.Entities.Process[]>(decompressed). ToList();

            //convert and add to database
            foreach (Agent.Entities.Process p in procInfo)
			{
				Process process = new Process();
				process.Name = p.Name;
				process.Pid = p.Pid;
				process.Host = computer;
                processes.Add(process);
			}
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ilya Builuk
Software Developer (Senior) Nokia
Germany Germany
Interested in design/development of framework functionality using the best patterns and practices.

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 24 Mar 2010
Article Copyright 2010 by Ilya Builuk
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid