Fixing ClickOnce installer missing DLL.
2 // Copyright (C) 2014-2015 Stéphane Lenclud.
4 // This file is part of SharpDisplayManager.
6 // SharpDisplayManager is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // SharpDisplayManager is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with SharpDisplayManager. If not, see <http://www.gnu.org/licenses/>.
21 using System.Collections.Generic;
24 using System.Threading.Tasks;
25 using System.Windows.Forms;
27 using System.ServiceModel;
28 using System.ServiceModel.Channels;
31 namespace SharpDisplayClient
34 /// Client side Sharp Display callback implementation.
36 [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
37 public class Callback : ICallback, IDisposable
39 private MainForm MainForm { get; set; }
41 public Callback(MainForm aMainForm)
47 /// Not used I believe.
49 public void OnConnected()
51 //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
52 //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId);
54 MessageBox.Show("OnConnected()", "Client");
58 public void OnCloseOrder()
60 //Debug.Assert(Thread.CurrentThread.IsThreadPoolThread);
61 //Trace.WriteLine("Callback thread = " + Thread.CurrentThread.ManagedThreadId);
63 //MessageBox.Show("OnServerClosing()", "Client");
64 MainForm.CloseConnectionThreadSafe();
65 MainForm.CloseThreadSafe();
77 /// Client side implementation of our Sharp Display Service.
79 [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
80 public class Client : DuplexClientBase<IService>
82 public string SessionId { get { return InnerChannel.SessionId; } }
84 public Client(ICallback aCallback)
85 : base(new InstanceContext(aCallback), new NetTcpBinding(SecurityMode.None, true), new EndpointAddress("net.tcp://localhost:8001/DisplayService"))
88 public void SetName(string aClientName)
90 Channel.SetName(aClientName);
93 public void SetLayout(TableLayout aLayout)
95 Channel.SetLayout(aLayout);
98 public void SetField(DataField aField)
100 Channel.SetField(aField);
103 public void SetFields(System.Collections.Generic.IList<DataField> aFields)
105 Channel.SetFields(aFields);
108 public int ClientCount()
110 return Channel.ClientCount();
113 public bool IsReady()
115 return State == CommunicationState.Opened || State == CommunicationState.Created;
121 /// Handle connection with our Sharp Display Server.
122 /// If the connection is faulted it will attempt to restart it.
124 public class DisplayClient
126 private Client iClient;
127 private Callback iCallback;
128 private bool resetingConnection = false;
130 private MainForm MainForm { get; set; }
131 public string SessionId { get { return iClient.SessionId; } }
132 public string Name { get; private set; }
133 private TableLayout Layout { get; set; }
134 private System.Collections.Generic.IList<DataField> Fields { get; set; }
137 public DisplayClient(MainForm aMainForm)
139 MainForm = aMainForm;
141 Fields = new DataField[]{};
145 /// Initialize our server connection.
149 iCallback = new Callback(MainForm);
150 iClient = new Client(iCallback);
154 /// Terminate our server connection.
165 /// Tells whether a server connection is available.
167 /// <returns>True if a server connection is available. False otherwise.</returns>
168 public bool IsReady()
170 return (iClient != null && iCallback != null && iClient.IsReady());
174 /// Check if our server connection is available and attempt reset it if it isn't.
175 /// This is notably dealing with timed out connections.
177 public void CheckConnection()
179 if (!IsReady() && !resetingConnection)
184 //Avoid stack overflow in case of persisting failure
185 resetingConnection = true;
189 //On reconnect there is a bunch of properties we need to reset
192 iClient.SetName(Name);
196 iClient.SetFields(Fields);
200 //Make sure our this state does not get out of sync
201 resetingConnection = true;
207 /// Set our client's name.
208 /// Client's name is typically user friendly.
209 /// It does not have to be unique.
211 /// <param name="aClientName">Our client name.</param>
212 public void SetName(string aClientName)
216 iClient.SetName(aClientName);
220 /// Set your client fields' layout.
222 /// <param name="aLayout">The layout to apply for this client.</param>
223 public void SetLayout(TableLayout aLayout)
227 iClient.SetLayout(aLayout);
231 /// Set the specified field.
233 /// <param name="aField"></param>
234 /// <returns>True if the specified field was set client side. False means you need to redefine all your fields using CreateFields.</returns>
235 public bool SetField(DataField aField)
238 bool fieldFound = false;
239 foreach (DataField field in Fields)
241 if (field.Index == aField.Index)
243 //Update our field then
253 //Field not found, make sure to use CreateFields first after setting your layout.
258 iClient.SetField(aField);
263 /// Use this function when updating existing fields.
265 /// <param name="aFields"></param>
266 public bool SetFields(System.Collections.Generic.IList<DataField> aFields)
268 int fieldFoundCount = 0;
269 foreach (DataField fieldUpdate in aFields)
272 foreach (DataField existingField in Fields)
274 if (existingField.Index == fieldUpdate.Index)
276 //Update our field then
277 Fields[i] = fieldUpdate;
279 //Move on to the next field
287 if (fieldFoundCount!=aFields.Count)
289 //Field not found, make sure to use CreateFields first after setting your layout.
294 iClient.SetFields(aFields);
299 /// Use this function when creating your fields.
300 /// This must be done at least once after setting your layout.
302 /// <param name="aFields"></param>
303 public void CreateFields(System.Collections.Generic.IList<DataField> aFields)
307 iClient.SetFields(aFields);
311 /// Provide the number of clients currently connected to our server.
313 /// <returns>Number of clients currently connected to our server.</returns>
314 public int ClientCount()
317 return iClient.ClientCount();