1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System.Diagnostics;
|
---|
23 | using System.IO;
|
---|
24 | using System.ServiceModel;
|
---|
25 | using System.Text;
|
---|
26 | using HeuristicLab.Services.Hive.DataAccess;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Services.Hive {
|
---|
29 | public class HiveOperationContext : IExtension<OperationContext> {
|
---|
30 | public static HiveOperationContext Current {
|
---|
31 | get {
|
---|
32 | var context = OperationContext.Current.Extensions.Find<HiveOperationContext>();
|
---|
33 | if (context == null) {
|
---|
34 | context = new HiveOperationContext();
|
---|
35 | OperationContext.Current.Extensions.Add(context);
|
---|
36 | }
|
---|
37 | return context;
|
---|
38 | }
|
---|
39 | }
|
---|
40 |
|
---|
41 | public HiveDataContext DataContext { get; private set; }
|
---|
42 |
|
---|
43 | public void Attach(OperationContext owner) {
|
---|
44 | DataContext = HiveDao.CreateContext();
|
---|
45 | //DataContext.Log = new DebugWriter();
|
---|
46 | }
|
---|
47 |
|
---|
48 | public void Detach(OperationContext owner) {
|
---|
49 | // nothing
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | internal class DebugWriter : TextWriter {
|
---|
54 | public override Encoding Encoding {
|
---|
55 | get { return Encoding.UTF8; }
|
---|
56 | }
|
---|
57 |
|
---|
58 | public override void Write(char value) {
|
---|
59 | Debug.Write(value);
|
---|
60 | }
|
---|
61 |
|
---|
62 | public override void Write(string value) {
|
---|
63 | Debug.Write(value);
|
---|
64 | }
|
---|
65 |
|
---|
66 | public override void WriteLine(string value) {
|
---|
67 | Debug.WriteLine(value);
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|