Free cookie consent management tool by TermsFeed Policy Generator

source: branches/UserManagement/HeuristicLab.Services.Authentication.ServiceClients/ServiceClients/AuthenticationItem.cs @ 7567

Last change on this file since 7567 was 5257, checked in by mjesner, 14 years ago

#1196

File size: 4.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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
21using System;
22using System.Collections.Generic;
23using System.Linq;
24using System.Text;
25using System.ComponentModel;
26using HeuristicLab.Core;
27using System.Runtime.Serialization;
28using HeuristicLab.Common;
29using System.Drawing;
30
31namespace HeuristicLab.Services.Authentication {
32   [Item("AuthenticationItem", "Base class for all authentication items.")]
33  public partial class AuthenticationItem : IItem {
34
35    public virtual string ItemName {
36      get { return ItemAttribute.GetName(this.GetType()); }
37    }
38    public virtual string ItemDescription {
39      get { return ItemAttribute.GetDescription(this.GetType()); }
40    }
41    public Version ItemVersion {
42      get { return ItemAttribute.GetVersion(this.GetType()); }
43    }
44    public virtual Image ItemImage {
45      get {
46        if (Modified)
47          return HeuristicLab.Common.Resources.VS2008ImageLibrary.DatabaseModified;
48        else
49          return HeuristicLab.Common.Resources.VS2008ImageLibrary.Database;
50      }
51    }
52
53    protected AuthenticationItem(AuthenticationItem original, Cloner cloner) {
54      cloner.RegisterClonedObject(original, this);
55      modified = true;
56      Name = original.Name;
57      Id = original.Id;
58    }
59
60    protected AuthenticationItem() {
61      modified = true;
62    }
63
64
65    private bool modified;
66    public bool Modified {
67      get { return modified; }
68      private set {
69        if (value != modified) {
70          modified = value;
71          OnModifiedChanged();
72          RaisePropertyChanged("Modified");
73          OnItemImageChanged();
74          RaisePropertyChanged("ItemImage");
75        }
76      }
77    }
78
79    public void Store() {
80      if (AuthenticationClient.Instance.Store(this))
81        Modified = false;
82    }
83
84    protected void RaisePropertyChanged(string propertyName) {
85      OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
86      if ((propertyName != "Id") && (propertyName != "Modified")) {
87        Modified = true;
88      }
89    }
90 
91    protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) {
92      PropertyChangedEventHandler handler = PropertyChanged;
93      if (handler != null) handler(this, e);
94    }
95
96    public event EventHandler ModifiedChanged;
97    protected virtual void OnModifiedChanged() {
98      EventHandler handler = ModifiedChanged;
99      if (handler != null) handler(this, EventArgs.Empty);
100    }
101
102    [OnDeserialized]
103    private void OnDeserialized(StreamingContext context) {
104      modified = false;
105    }
106
107    public object Clone() {
108      return Clone(new Cloner());
109    }
110    public virtual IDeepCloneable Clone(Cloner cloner) {
111      return new AuthenticationItem(this, cloner);
112    }
113
114    public override string ToString() {
115      return Name;
116    }
117    public event EventHandler ItemImageChanged;
118    protected virtual void OnItemImageChanged() {
119      EventHandler handler = ItemImageChanged;
120      if (handler != null) handler(this, EventArgs.Empty);
121    }
122    public event EventHandler ToStringChanged;
123    protected virtual void OnToStringChanged() {
124      EventHandler handler = ToStringChanged;
125      if (handler != null) handler(this, EventArgs.Empty);
126    }
127  }
128}
129
Note: See TracBrowser for help on using the repository browser.