1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace PetStore
.Service
22 /// A clever recommendation service should use some
23 /// branch of AI to suggest meaningfull products
24 /// (think adaptive resonance theory / http://jroller.com/page/hammett?entry=finally_something_interesting_on_my)
25 /// based on the history of the customer (if available).
26 /// But we just pick up some random products
28 public class DefaultRecommendationService
: IRecommendationService
30 private readonly Random random
;
31 private readonly IProductDataAccess productDataAccess
;
33 public DefaultRecommendationService(IProductDataAccess productDataAccess
)
35 this.productDataAccess
= productDataAccess
;
36 this.random
= new Random((int) DateTime
.Now
.Ticks
);
39 public Product
[] GetProducts(Customer customer
)
41 int[] ids
= productDataAccess
.GetProductIds();
43 if (ids
.Length
== 0) return new Product
[0];
47 int firstIndex
= random
.Next(0, ids
.Length
- 1);
48 int secondIndex
= random
.Next(0, ids
.Length
- 1);
50 if (firstIndex
!= secondIndex
)
52 return new Product
[] {
53 Product
.Find(ids
[firstIndex
]),
54 Product
.Find(ids
[secondIndex
]) };
58 return new Product
[] { Product.Find(ids[firstIndex]) }
;