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 CPOL
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 NUnit.Framework;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Criterion;
using NHibernate.Tool.hbm2ddl;

using InfoCenter.Agent.Helpers;
using InfoCenter.Persistence.Core;
using InfoCenter.Persistence.Entities;
using InfoCenter.Persistence;

namespace InfoCenter.Logic.Tests
{
    [TestFixture]
    public class Test_PacketParser
    {
        private ISessionFactory _sessionFactory;
        protected ISessionFactory SessionFactory 
		{ 
			get
			{
				return _sessionFactory;
			} 
			private set
			{
				_sessionFactory = value;
			}
		}
		
        IRepository<Computer> computers;
        IRepository<Process> processes;
		
        [TestFixtureSetUp]
        public void InitNHibernate()
        {
			//create new schema
            SessionFactory = Initializer.GetSessionFactory(false);
            computers = new Repository<Computer>(SessionFactory);
            processes = new Repository<Process>(SessionFactory);			
        }

        [Test]
        public void CanCompressAndDecompress()
        {
            string text = "This is a sample for my application";
            string compressed = Archiver.Compress(text);

            Assert.IsNotNullOrEmpty(compressed, "Compressed text is null or empty");
            Assert.AreNotEqual(text, compressed, "Compress method doesn't work");

            string decompressed = Archiver.Decompress(compressed);

            Assert.AreEqual(text, decompressed, "Decompressed text is invalid");

        }

        /// <summary>
        /// return fake compressed info
        /// </summary>
        /// <returns></returns>
        private string GetInfo()
        {
            string data = "<?xml version=\"1.0\" encoding=\"utf-8\"?><Computer xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Name>ILYA</Name><Ip>192.168.220.1</Ip><UserName>aidan</UserName><OsVersion>Microsoft Windows NT 5.1.2600 Service Pack 2</OsVersion></Computer>";
            return Archiver.Compress(data);
        }

        private string GetProcesses()
        {
            string data = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ArrayOfProcess xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Process><Pid>1164</Pid><Name>svchost</Name></Process><Process><Pid>568</Pid><Name>sqlbrowser</Name></Process><Process><Pid>4172</Pid><Name>Lingvo</Name></Process><Process><Pid>924</Pid><Name>services</Name></Process><Process><Pid>1536</Pid><Name>msdtc</Name></Process><Process><Pid>2516</Pid><Name>alg</Name></Process><Process><Pid>5076</Pid><Name>aspnet_wp</Name></Process><Process><Pid>936</Pid><Name>lsass</Name></Process><Process><Pid>2904</Pid><Name>vmware-authd</Name></Process><Process><Pid>736</Pid><Name>spoolsv</Name></Process><Process><Pid>3292</Pid><Name>mqtgsvc</Name></Process><Process><Pid>3092</Pid><Name>dllhost</Name></Process><Process><Pid>2500</Pid><Name>vmnat</Name></Process><Process><Pid>1120</Pid><Name>svchost</Name></Process><Process><Pid>2300</Pid><Name>VbaControlAgent</Name></Process><Process><Pid>1708</Pid><Name>mDNSResponder</Name></Process><Process><Pid>2884</Pid><Name>mqsvc</Name></Process><Process><Pid>3176</Pid><Name>vmnetdhcp</Name></Process><Process><Pid>500</Pid><Name>svchost</Name></Process><Process><Pid>1304</Pid><Name>Tutor</Name></Process><Process><Pid>3860</Pid><Name>Maxthon</Name></Process><Process><Pid>4056</Pid><Name>explorer</Name></Process><Process><Pid>2672</Pid><Name>RTHDCPL</Name></Process><Process><Pid>5836</Pid><Name>devenv</Name></Process><Process><Pid>4688</Pid><Name>mmc</Name></Process><Process><Pid>3456</Pid><Name>wmiprvse</Name></Process><Process><Pid>1288</Pid><Name>sqlwriter</Name></Process><Process><Pid>1680</Pid><Name>SynSched</Name></Process><Process><Pid>4240</Pid><Name>ConsoleApplication12.vshost</Name></Process><Process><Pid>2072</Pid><Name>Vba32NS</Name></Process><Process><Pid>3252</Pid><Name>searchprotocolhost</Name></Process><Process><Pid>2196</Pid><Name>Vba32PMS</Name></Process><Process><Pid>3644</Pid><Name>SynGUI</Name></Process><Process><Pid>3720</Pid><Name>ctfmon</Name></Process><Process><Pid>3440</Pid><Name>qttask</Name></Process><Process><Pid>6008</Pid><Name>Ssms</Name></Process><Process><Pid>876</Pid><Name>winlogon</Name></Process><Process><Pid>2648</Pid><Name>rundll32</Name></Process><Process><Pid>3040</Pid><Name>GrooveMonitor</Name></Process><Process><Pid>5600</Pid><Name>Skype</Name></Process><Process><Pid>3628</Pid><Name>nunit</Name></Process><Process><Pid>2248</Pid><Name>Vba32SS</Name></Process><Process><Pid>668</Pid><Name>devenv</Name></Process><Process><Pid>836</Pid><Name>MsDtsSrvr</Name></Process><Process><Pid>4212</Pid><Name>cmd</Name></Process><Process><Pid>1256</Pid><Name>nvsvc32</Name></Process><Process><Pid>2932</Pid><Name>WPFFontCache_v0400</Name></Process><Process><Pid>1972</Pid><Name>Winamp</Name></Process><Process><Pid>852</Pid><Name>csrss</Name></Process><Process><Pid>5060</Pid><Name>ConsoleApplication12</Name></Process><Process><Pid>4832</Pid><Name>searchfilterhost</Name></Process><Process><Pid>608</Pid><Name>sqlservr</Name></Process><Process><Pid>452</Pid><Name>jqs</Name></Process><Process><Pid>1436</Pid><Name>ServiceQtn</Name></Process><Process><Pid>3992</Pid><Name>VbaUpdateService</Name></Process><Process><Pid>1232</Pid><Name>msmdsrv</Name></Process><Process><Pid>640</Pid><Name>skypePM</Name></Process><Process><Pid>1624</Pid><Name>RedGate.Profiler.IISService</Name></Process><Process><Pid>2016</Pid><Name>svchost</Name></Process><Process><Pid>3672</Pid><Name>VSTraceLog</Name></Process><Process><Pid>1812</Pid><Name>svchost</Name></Process><Process><Pid>3584</Pid><Name>wmiapsrv</Name></Process><Process><Pid>3780</Pid><Name>sqlmangr</Name></Process><Process><Pid>2596</Pid><Name>iexplore</Name></Process><Process><Pid>792</Pid><Name>smss</Name></Process><Process><Pid>1464</Pid><Name>ReportingServicesService</Name></Process><Process><Pid>1800</Pid><Name>inetinfo</Name></Process><Process><Pid>3964</Pid><Name>miranda32</Name></Process><Process><Pid>5736</Pid><Name>firefox</Name></Process><Process><Pid>1596</Pid><Name>RedGate.Profiler.IISProfileHost</Name></Process><Process><Pid>1396</Pid><Name>jusched</Name></Process><Process><Pid>2380</Pid><Name>Vba32CCService</Name></Process><Process><Pid>3952</Pid><Name>TOTALCMD</Name></Process><Process><Pid>2572</Pid><Name>searchindexer</Name></Process><Process><Pid>3828</Pid><Name>WindowsSearch</Name></Process><Process><Pid>4</Pid><Name>System</Name></Process><Process><Pid>2760</Pid><Name>LvAgent</Name></Process><Process><Pid>0</Pid><Name>Idle</Name></Process></ArrayOfProcess>";

            return Archiver.Compress(data);
        }

        [Test]
        public void CanAddInfoFromAgent()
        {
			DetachedCriteria criteria = DetachedCriteria.For<Computer>()
                .Add(NHibernate.Criterion.Expression.Like("Name","ILYA"));
			/*Computer initComputer = computers.FindOne(criteria);
			if((initComputer !=null)&&(initComputer.Name == "ILYA"))
				throw new Exception("Comp exists in database!");*/
			
            //call expected method
            PacketParser pp = new PacketParser(computers, null);
            pp.AddInfo(GetInfo());


			Computer computer = computers.FindOne(criteria);
			//Computer computer = computers.FindOne(c => c.Name == "ILYA");

            Assert.IsNotNull(computer, "Can't get computer");

            Assert.AreEqual("ILYA", computer.Name, "Computer name is invalid");
            Assert.AreEqual("aidan", computer.UserName, "User name is invalid");
            Assert.AreEqual("Microsoft Windows NT 5.1.2600 Service Pack 2", computer.OsVersion, "OS name is invalid");
            Assert.AreEqual("192.168.220.1", computer.Ip, "IP is invalid");
        }

        [Test]
        public void CanAddProcessesFromAgent()
        {
            PacketParser pp = new PacketParser(computers, processes);
            pp.AddProcesses("ILYA",GetProcesses());

			DetachedCriteria criteria = DetachedCriteria.For<Process>().CreateAlias("Host","c")
                .Add(NHibernate.Criterion.Expression.Like("c.Name","ILYA"));
			
			//ICollection<Process> procs = processes.FindAll(criteria);
			
			IList<Process> procs = new List<Process>();
			foreach(Process item in processes.FindAll(criteria))
			{
				procs.Add(item);
			}
			
            //IList<Process> procs = processes.FindAll(p => p.Host.Name =="ILYA").ToList();


			
            Assert.IsNotNull(procs, "Can't get processes");
            Assert.AreNotEqual(0, procs.Count, "Count of processes is 0");

            Assert.AreEqual("ILYA", procs[0].Host.Name,"Invalid computer name");

            //IList<Process> emptyList = processes.FindAll(p => p.Host.Name != "ILYA").ToList();
            //Assert.AreEqual(0, emptyList.Count, "Invalid count");
        }
		
		[Test]
		public void DirtyCanAddInfoFromAgent()
		{
			this.CanAddInfoFromAgent();
		}
		
		[Test]
		public void DirtyCanAddProcessesFromAgent()
		{
			this.CanAddProcessesFromAgent();
		}

    }
}

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)

Share

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 | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 24 Mar 2010
Article Copyright 2010 by Ilya Builuk
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid