5
// Martin Baulig <martin.baulig@xamarin.com>
7
// Copyright (c) 2012 Xamarin Inc. (http://www.xamarin.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
using System.Collections.Generic;
29
using MonoDevelop.WebReferences.WCF;
30
using System.ServiceModel.Description;
33
namespace MonoDevelop.WebReferences.Dialogs
35
[System.ComponentModel.ToolboxItem(true)]
36
public partial class WCFConfigWidget : Gtk.Bin
38
public WCFConfigWidget (ClientOptions options)
40
this.Options = options;
43
listTypes = new List<Type> (DefaultListTypes);
44
PopulateBox (listCollection, "List", listTypes);
46
dictTypes = new List<Type> (DefaultDictionaryTypes);
47
PopulateBox (dictionaryCollection, "Dictionary", dictTypes);
50
public ClientOptions Options {
54
static readonly Type[] DefaultListTypes = {
56
typeof (System.Collections.Generic.LinkedList<>),
57
typeof (System.Collections.Generic.List<>),
58
typeof (System.Collections.ObjectModel.Collection<>),
59
typeof (System.Collections.ObjectModel.ObservableCollection<>),
60
typeof (System.ComponentModel.BindingList<>)
63
static readonly Type[] DefaultDictionaryTypes = {
64
typeof (System.Collections.Generic.Dictionary<,>),
65
typeof (System.Collections.Generic.SortedList<,>),
66
typeof (System.Collections.Generic.SortedDictionary<,>)
69
public bool Modified {
77
static bool? runtimeSupport;
79
internal static bool IsSupported ()
81
if (runtimeSupport != null)
82
return runtimeSupport.Value;
85
// Test runtime support.
86
var ms = new MetadataSet ();
87
var importer = new WsdlImporter (ms);
88
importer.State.GetType ();
89
runtimeSupport = true;
92
runtimeSupport = false;
97
internal static bool IsSupported (WebReferenceItem item)
101
return item.MapFile.FilePath.Extension == ".svcmap";
104
internal static Type GetType (string name)
106
var type = typeof (char).Assembly.GetType (name);
109
type = typeof (System.Collections.Generic.LinkedList<>).Assembly.GetType (name);
115
internal static string GetTypeName (Type type)
117
var name = type.FullName;
118
var pos = name.IndexOf ("`");
121
return name.Substring (0, pos);
124
void PopulateBox (ComboBox box, string category, List<Type> types)
126
var mapping = Options.CollectionMappings.FirstOrDefault (m => m.Category == category);
130
current = GetType (mapping.TypeName);
134
if (!types.Contains (current))
137
foreach (var type in types)
138
box.AppendText (GetTypeName (type));
140
box.Active = types.IndexOf (current);
143
void UpdateBox (ComboBox box, string category, List<Type> types)
145
var mapping = Options.CollectionMappings.FirstOrDefault (m => m.Category == category);
146
if (mapping == null) {
147
mapping = new CollectionMapping { Category = category };
148
Options.CollectionMappings.Add (mapping);
152
var current = types [box.Active];
153
if (mapping.TypeName != current.FullName) {
154
mapping.TypeName = current.FullName;
159
internal void Update ()
161
UpdateBox (listCollection, "List", listTypes);
162
UpdateBox (dictionaryCollection, "Dictionary", dictTypes);