Changeset 4

User picture

Author: cmeschini

(2009/12/17 21:25) About 2 years ago

Abandonada la DI por innecesaria. Ahora se puede cambiar dinamicamente el provider.

Affected files

Added src/FmwkPoiesis.ObjectSearch.Test/CastleNHAppInitializer.cs

Show contents

Updated src/FmwkPoiesis.ObjectSearch.Test/FmwkPoiesis.ObjectSearch.Test.csproj Download diff

34
31
    <WarningLevel>4</WarningLevel>
31
    <WarningLevel>4</WarningLevel>
32
  </PropertyGroup>
32
  </PropertyGroup>
33
  <ItemGroup>
33
  <ItemGroup>
34
    <Reference Include="Castle.Core, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
35
      <SpecificVersion>False</SpecificVersion>
36
      <HintPath>..\..\lib\Castle\Castle.Core.dll</HintPath>
37
    </Reference>
38
    <Reference Include="Castle.DynamicProxy2, Version=2.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
39
      <SpecificVersion>False</SpecificVersion>
40
      <HintPath>..\..\lib\Castle\Castle.DynamicProxy2.dll</HintPath>
41
    </Reference>
42
    <Reference Include="Castle.MicroKernel, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
43
      <SpecificVersion>False</SpecificVersion>
44
      <HintPath>..\..\lib\Castle\Castle.MicroKernel.dll</HintPath>
45
    </Reference>
46
    <Reference Include="Castle.Windsor, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
47
      <SpecificVersion>False</SpecificVersion>
48
      <HintPath>..\..\lib\Castle\Castle.Windsor.dll</HintPath>
49
    </Reference>
50
    <Reference Include="CommonServiceLocator.WindsorAdapter, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
51
      <SpecificVersion>False</SpecificVersion>
52
      <HintPath>..\..\lib\CommonServiceLocator.WindsorAdapter.dll</HintPath>
53
    </Reference>
54
    <Reference Include="Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35,
processorArchitecture=MSIL">
55
      <SpecificVersion>False</SpecificVersion>
56
      <HintPath>..\..\lib\Microsoft.Practices.ServiceLocation.dll</HintPath>
57
    </Reference>
34
    <Reference Include="nunit.core, Version=2.5.2.9222, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
58
    <Reference Include="nunit.core, Version=2.5.2.9222, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
35
      <SpecificVersion>False</SpecificVersion>
59
      <SpecificVersion>False</SpecificVersion>
36
      <HintPath>..\..\tools\NUnit\nunit.core.dll</HintPath>
60
      <HintPath>..\..\tools\NUnit\nunit.core.dll</HintPath>
...
...
53
    <Reference Include="System.Xml" />
77
    <Reference Include="System.Xml" />
54
  </ItemGroup>
78
  </ItemGroup>
55
  <ItemGroup>
79
  <ItemGroup>
80
    <Compile Include="CastleNHAppInitializer.cs" />
56
    <Compile Include="GeneralTest.cs" />
81
    <Compile Include="GeneralTest.cs" />
82
    <Compile Include="IAppInitializer.cs" />
57
    <Compile Include="Model\Persona.cs" />
83
    <Compile Include="Model\Persona.cs" />
58
    <Compile Include="SearchPersona.cs" />
84
    <Compile Include="SearchPersona.cs" />
59
    <Compile Include="Properties\AssemblyInfo.cs" />
85
    <Compile Include="Properties\AssemblyInfo.cs" />
60
  </ItemGroup>
86
  </ItemGroup>
61
  <ItemGroup>
87
  <ItemGroup>
88
    <ProjectReference Include="..\FmwkPoiesis.ObjectSearchProvider.Hql\FmwkPoiesis.ObjectSearchProvider.Hql.csproj">
89
      <Project>{8D83E74C-4D68-46EE-8480-DC332518AC03}</Project>
90
      <Name>FmwkPoiesis.ObjectSearchProvider.Hql</Name>
91
    </ProjectReference>
92
    <ProjectReference Include="..\FmwkPoiesis.ObjectSearchProvider.Linq\FmwkPoiesis.ObjectSearchProvider.Linq.csproj">
93
      <Project>{BA53F5A9-B32D-4BF5-89E7-7094CB9ED247}</Project>
94
      <Name>FmwkPoiesis.ObjectSearchProvider.Linq</Name>
95
    </ProjectReference>
62
    <ProjectReference Include="..\FmwkPoiesis.ObjectSearch\FmwkPoiesis.ObjectSearch.csproj">
96
    <ProjectReference Include="..\FmwkPoiesis.ObjectSearch\FmwkPoiesis.ObjectSearch.csproj">
63
      <Project>{8BBCB623-8D5C-4EA7-9678-A79D011F4990}</Project>
97
      <Project>{8BBCB623-8D5C-4EA7-9678-A79D011F4990}</Project>
64
      <Name>FmwkPoiesis.ObjectSearch</Name>
98
      <Name>FmwkPoiesis.ObjectSearch</Name>

Updated src/FmwkPoiesis.ObjectSearch.Test/GeneralTest.cs Download diff

34
1
using System;
1
using System;
2
using System.Collections.Generic;
2
using FmwkPoiesis.ObjectSearchProvider.Hql;
3
using System.Linq;
3
using FmwkPoiesis.ObjectSearchProvider.Linq;
4
using System.Text;
4
using Microsoft.Practices.ServiceLocation;
5
6
using NUnit.Framework;
5
using NUnit.Framework;
7
6
8
using MDS.Simpatia.Model.ObjectSearch;
7
using MDS.Simpatia.Model.ObjectSearch;
8
using Poiesis.FrameWork.ObjectSearch;
9
using Ushuaia.WebUI;
9
10
10
namespace FmwkPoiesis.ObjectSearch.Test
11
namespace FmwkPoiesis.ObjectSearch.Test
11
{
12
{
...
...
14
	{
15
	{
15
		SearchPersona sp;
16
		SearchPersona sp;
16
17
18
		private static IAppInitializer initializer;
19
    
17
		[TestFixtureSetUp]
20
		[TestFixtureSetUp]
18
		public void Setup()
21
		public void Setup()
19
		{
22
		{
23
			//initializer = new CastleNHAppInitializer();
24
			//initializer.Startup();
25
26
			//Poiesis.FrameWork.ObjectSearch.ObjectSearch.DefaultProvider = ServiceLocator.Current.GetInstance<IObjectSearchProvider>();
27
28
			Poiesis.FrameWork.ObjectSearch.ObjectSearch.DefaultProvider = new LinqObjectSearchProvider();
29
20
			sp = new SearchPersona();
30
			sp = new SearchPersona();
21
			sp.Apellido.ValueToCompare = "Borges";
31
			sp.Apellido.ValueToCompare = "Borges";
22
			sp.Nombre.ValueToCompare = "Jorge Luis";
32
			sp.Nombre.ValueToCompare = "Jorge Luis";
...
...
27
		[Test]
37
		[Test]
28
		public void TestBuildCommand()
38
		public void TestBuildCommand()
29
		{
39
		{
30
			string outPut = sp.BuildCommandSearch();
40
			string outPut = "Generando para " + Poiesis.FrameWork.ObjectSearch.ObjectSearch.DefaultProvider.Name;
31
			Console.WriteLine(outPut);
41
			Console.WriteLine(outPut);
42
			outPut = sp.BuildCommandSearch();
43
			Console.WriteLine(outPut);
44
45
			var providerHql = new HqlObjectSearchProvider();
46
			string outPut2 = "Generando para " + providerHql.Name ;
47
			Console.WriteLine(outPut2);
48
			outPut2 = sp.BuildCommandSearch();
49
			Console.WriteLine(outPut2);
32
		}
50
		}
33
	}
51
	}
34
}
52
}

Added src/FmwkPoiesis.ObjectSearch.Test/IAppInitializer.cs

Show contents

Updated src/FmwkPoiesis.ObjectSearch/Equal.cs Download diff

34
2
using System.Collections.Generic;
2
using System.Collections.Generic;
3
using System.Linq;
3
using System.Linq;
4
using System.Text;
4
using System.Text;
5
using Microsoft.Practices.ServiceLocation;
5
//using Microsoft.Practices.ServiceLocation;
6
using CommonServiceLocator.WindsorAdapter;
6
//using CommonServiceLocator.WindsorAdapter;
7
7
8
namespace Poiesis.FrameWork.ObjectSearch
8
namespace Poiesis.FrameWork.ObjectSearch
9
{
9
{
...
...
22
		public T ValueToCompare { get; set; }
22
		public T ValueToCompare { get; set; }
23
		
23
		
24
		#region Miembros de IComparator
24
		#region Miembros de IComparator
25
		public string BuildCommandSearch(bool isLastElement)
25
		public string BuildCommandSearch(IObjectSearchProvider provider, bool isLastElement)
26
		{
26
		{
27
			return ObjectSearch.Provider.BuildCommandEqual<T>(this, isLastElement);
27
			return provider.BuildCommandEqual<T>(this, isLastElement);
28
		}
28
		}
29
		#endregion
29
		#endregion
30
	}
30
	}

Updated src/FmwkPoiesis.ObjectSearch/FmwkPoiesis.ObjectSearch.csproj Download diff

34
31
    <WarningLevel>4</WarningLevel>
31
    <WarningLevel>4</WarningLevel>
32
  </PropertyGroup>
32
  </PropertyGroup>
33
  <ItemGroup>
33
  <ItemGroup>
34
    <Reference Include="CommonServiceLocator.WindsorAdapter, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
35
      <SpecificVersion>False</SpecificVersion>
36
      <HintPath>..\..\lib\CommonServiceLocator.WindsorAdapter.dll</HintPath>
37
    </Reference>
38
    <Reference Include="Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
39
      <SpecificVersion>False</SpecificVersion>
40
      <HintPath>..\..\lib\Microsoft.Practices.ServiceLocation.dll</HintPath>
41
    </Reference>
42
    <Reference Include="System" />
34
    <Reference Include="System" />
43
    <Reference Include="System.Core">
35
    <Reference Include="System.Core">
44
      <RequiredTargetFramework>3.5</RequiredTargetFramework>
36
      <RequiredTargetFramework>3.5</RequiredTargetFramework>

Updated src/FmwkPoiesis.ObjectSearch/IComparator.cs Download diff

34
8
	public interface IComparator
8
	public interface IComparator
9
	{
9
	{
10
		string NameProperty { get; }
10
		string NameProperty { get; }
11
		string BuildCommandSearch(bool isLastElement);
11
		string BuildCommandSearch(IObjectSearchProvider provider, bool isLastElement);
12
		bool And { get; set; }
12
		bool And { get; set; }
13
	}
13
	}
14
14

Updated src/FmwkPoiesis.ObjectSearch/IObjectSearchProvider.cs Download diff

34
7
{
7
{
8
	public interface IObjectSearchProvider
8
	public interface IObjectSearchProvider
9
	{
9
	{
10
		string Name { get; }
10
		string BuildCommandEqual<T>(Equal<T> comparator, bool isLast) where T : IComparable;
11
		string BuildCommandEqual<T>(Equal<T> comparator, bool isLast) where T : IComparable;
12
		string BuildCommandRange<T>(Range<T> comparator, bool isLast) where T : IComparable;
13
		
11
	}
14
	}
12
}
15
}

Updated src/FmwkPoiesis.ObjectSearch/ObjectSearch.cs Download diff

34
3
using System.Linq;
3
using System.Linq;
4
using System.Text;
4
using System.Text;
5
using System.Reflection;
5
using System.Reflection;
6
using CommonServiceLocator.WindsorAdapter;
6
//using CommonServiceLocator.WindsorAdapter;
7
using Microsoft.Practices.ServiceLocation;
7
//using Microsoft.Practices.ServiceLocation;
8
8
9
9
10
namespace Poiesis.FrameWork.ObjectSearch
10
namespace Poiesis.FrameWork.ObjectSearch
...
...
15
15
16
	public class ObjectSearch : IObjectSearch  
16
	public class ObjectSearch : IObjectSearch  
17
	{
17
	{
18
		public static IObjectSearchProvider Provider = ServiceLocator.SetLocatorProvider(new WindsorServiceLocator());
18
		public static IObjectSearchProvider DefaultProvider { get; set;}
19
	}
19
	}
20
20
21
	abstract public class ObjectSearch<T> : ObjectSearch 
21
	abstract public class ObjectSearch<T> : ObjectSearch 
...
...
27
27
28
		public IObjectSearchProvider GetProvider()
28
		public IObjectSearchProvider GetProvider()
29
		{
29
		{
30
			return ObjectSearch.Provider;
30
			return ObjectSearch.DefaultProvider;
31
		}
31
		}
32
32
33
		private List<IComparator> FindComparators()
33
		private List<IComparator> FindComparators()
...
...
44
			return this.Comparators;
44
			return this.Comparators;
45
		}
45
		}
46
46
47
48
		public string BuildCommandSearch()
47
		public string BuildCommandSearch()
49
		{
48
		{
49
			return BuildCommandSearch(ObjectSearch.DefaultProvider );
50
		}
51
52
		public string BuildCommandSearch(IObjectSearchProvider provider)
53
		{
50
			this.Comparators = FindComparators();
54
			this.Comparators = FindComparators();
51
			int count = this.Comparators.Count;
55
			int count = this.Comparators.Count;
52
56
...
...
55
				StringBuilder sb = new StringBuilder();
59
				StringBuilder sb = new StringBuilder();
56
				for (int i = 0; i < count; i++)
60
				for (int i = 0; i < count; i++)
57
				{
61
				{
58
					sb.Append(Comparators[i].BuildCommandSearch(i == (count - 1)));
62
					sb.Append(Comparators[i].BuildCommandSearch( provider, i == (count - 1)));
59
				}
63
				}
60
				return sb.ToString();
64
				return sb.ToString();
61
			}
65
			}

Updated src/FmwkPoiesis.ObjectSearch/Range.cs Download diff

34
21
		public T MaxValue { get; set; }
21
		public T MaxValue { get; set; }
22
22
23
		#region Miembros de IComparator
23
		#region Miembros de IComparator
24
		public string BuildCommandSearch(bool isLastElement)
24
		public string BuildCommandSearch(IObjectSearchProvider provider,   bool isLastElement)
25
		{
25
		{
26
			string command = String.Format("({0} >= {1} and {0} <= {2})",
26
			return provider.BuildCommandRange(this, isLastElement);
27
											this.NameProperty, this.MinValue.ToString(), this.MaxValue.ToString());
28
29
			if (isLastElement)
30
				return command;
31
32
			if (this.And)
33
				return command + " and ";
34
			else
35
				return command + " or ";
36
		}
27
		}
37
		#endregion
28
		#endregion
38
	}
29
	}

Updated src/FmwkPoiesis.ObjectSearchProvider.Hql/HqlObjectSearchProvider.cs Download diff

34
2
using System.Collections.Generic;
2
using System.Collections.Generic;
3
using System.Linq;
3
using System.Linq;
4
using System.Text;
4
using System.Text;
5
using Poiesis.FrameWork.ObjectSearch; 
5
using Poiesis.FrameWork.ObjectSearch;
6
6
7
namespace FmwkPoiesis.ObjectSearchProvider.Hql
7
namespace FmwkPoiesis.ObjectSearchProvider.Hql
8
{
8
{
9
	public class HqlObjectSearchProvider : IObjectSearchProvider 
9
	public class HqlObjectSearchProvider : IObjectSearchProvider
10
	{
10
	{
11
		public string BuildCommandEqual<T>(Equal<T> comparator,  bool isLast) where T : IComparable 
11
		public string Name
12
		{
12
		{
13
			string command = String.Format("({0} = {1})",	comparator.NameProperty, comparator.ValueToCompare.ToString());
13
			get { return "HQLProvider"; }
14
		}
14
15
16
		public string BuildCommandEqual<T>(Equal<T> comparator, bool isLast) where T : IComparable
17
		{
18
			string command = String.Format("({0} = {1})", comparator.NameProperty, comparator.ValueToCompare.ToString());
19
15
			if (isLast)
20
			if (isLast)
16
				return command;
21
				return command;
17
22
...
...
20
			else
25
			else
21
				return command + " or ";
26
				return command + " or ";
22
		}
27
		}
28
29
		public string BuildCommandRange<T>(Range<T> comparator, bool isLast) where T : IComparable
30
		{
31
			string command = String.Format("({0} >= {1} and {0} <= {2})", comparator.NameProperty, comparator.MinValue.ToString(),
comparator.MaxValue.ToString());
32
33
			if (isLast)
34
				return command;
35
36
			if (comparator.And)
37
				return command + " and ";
38
			else
39
				return command + " or ";
40
		}
41
42
23
	}
43
	}
24
}
44
}

Updated src/FmwkPoiesis.ObjectSearchProvider.Linq/LinqObjectSearchProvider.cs Download diff

34
2
using System.Collections.Generic;
2
using System.Collections.Generic;
3
using System.Linq;
3
using System.Linq;
4
using System.Text;
4
using System.Text;
5
using Poiesis.FrameWork.ObjectSearch; 
5
using Poiesis.FrameWork.ObjectSearch;
6
6
7
namespace FmwkPoiesis.ObjectSearchProvider.Linq
7
namespace FmwkPoiesis.ObjectSearchProvider.Linq
8
{
8
{
9
	public class LinqObjectSearchProvider : IObjectSearchProvider 
9
	public class LinqObjectSearchProvider : IObjectSearchProvider
10
	{
10
	{
11
		public string Name
12
		{
13
			get { return "LinqProvider"; }
14
		}
15
11
		public string BuildCommandEqual<T>(Equal<T> comparator, bool isLast) where T : IComparable
16
		public string BuildCommandEqual<T>(Equal<T> comparator, bool isLast) where T : IComparable
12
		{
17
		{
13
			string command = String.Format("({0} = {1})", comparator.NameProperty, comparator.ValueToCompare.ToString());
18
			string command = String.Format("|{0} = {1}|", comparator.NameProperty, comparator.ValueToCompare.ToString());
14
19
15
			if ( isLast)
20
			if (isLast)
16
				return command;
21
				return command;
17
22
18
			if (comparator.And)
23
			if (comparator.And)
...
...
20
			else
25
			else
21
				return command + " or ";
26
				return command + " or ";
22
		}
27
		}
28
29
		public string BuildCommandRange<T>(Range<T> comparator, bool isLast) where T : IComparable
30
		{
31
			string command = String.Format("|{0} >= {1} and {0} <= {2}|", comparator.NameProperty, comparator.MinValue.ToString(),
comparator.MaxValue.ToString() );
32
33
			if (isLast)
34
				return command;
35
36
			if (comparator.And)
37
				return command + " and ";
38
			else
39
				return command + " or ";
40
		}
41
23
	}
42
	}
24
}
43
}