/// <summary> /// Terminates the session async. /// </summary> /// <param name="postLogoffAction">The act.</param> public static void TerminateSessionAsync(Action postLogoffAction = null) { Messenger.Default.Send(new NavigateMvvmMessage() { Header = WaitInfo.Header, ViewName = WaitView.ID, Parameter = WaitInfo }); Logger.Info("{0}, Reason: {1}", WaitInfo.Title, WaitInfo.Reason); FxLog <AuthenticationHost> .DebugFormat(WaitInfo.Title); _postLogoffAction = postLogoffAction; if (WulkaSession.Current != null) { AuthenticationPortal .Authentication .TerminateSessionAsync(TerminateSessionAsyncCompleted); } else { if (_postLogoffAction != null) { _postLogoffAction.Invoke(); } } }
// Statics methods goes here. #endregion #region Publics /// <summary> /// Resolves the DNS host name or IP address to an IPHostEntry instance. /// </summary> public void Resolve() { try { IPHostEntry ipHostInfo; if (String.IsNullOrEmpty(_host)) { // Get the Hostname given the IP Address. ipHostInfo = Dns.GetHostEntry(_ip); _host = ipHostInfo.HostName; } else { // Get the IP Address given the Hostname. ipHostInfo = Dns.GetHostEntry(_host); _ip = ipHostInfo.AddressList[0]; } _endpoint = new IPEndPoint(_ip, _port); } catch (Exception ex) { FxLog<AsyncTcpClient> .Error("Exception raised trying to resolve the DNS host name or IP address to an IPHostEntry instance.", ex); } }
/// <summary> /// Creates a Type instance from information contained in the appSettings of the configuration file. /// </summary> /// <param name="appSettingsKey">The key in the app settings where the Type information is stored.</param> /// <returns>Type.</returns> /// <exception cref="System.ApplicationException"></exception> public static Type CreateTypeFromConfiguration(string appSettingsKey) { string typeName; if (GetTypeInfo(appSettingsKey, out typeName)) { Type type; try { type = Type.GetType(typeName, throwOnError: true /* throw error if not found */); } catch (Exception ex) { string errorMessage = string.Format( "Failed to create Type object from information in configuration file (AppSettings key {0})" + ", typeName = {1}", appSettingsKey, typeName); throw new ApplicationException(errorMessage, ex); } FxLog <TypeFactory> .DebugFormat("Created Type object from information in configuration file (AppSettings key {0})" + ", typeName = {1}", appSettingsKey, typeName); return(type); } return(null); }
/// <summary> /// Sends a file to a queue of choise, the queue will be created if it does not yet exists. /// </summary> /// <param name="transaction">The transaction (string format)</param> /// <param name="queueName">The name of the queue</param> protected void SendToQueue(TransactionItem transaction, string queueName) { queueName = queueName.ToLower().Replace("service", ""); FxLog.Debug(GetType(), "Sending To Queue: {0}", queueName); // Create the transacted MSMQ queue if necessary. var queuePath = @".\private$\" + queueName; if (!MessageQueue.Exists(queuePath)) { FxLog.Debug(GetType(), "{0} does not yet exist", queuePath); var queue = MessageQueue.Create(queuePath, true); queue.Authenticate = false; queue.SetPermissions("EveryOne", MessageQueueAccessRights.FullControl); FxLog.Debug(GetType(), "{0} Created", queuePath); } // Create proxy for the MSMQ if necessary. if (!QueueProxyCollection.ContainsKey(queueName)) { var proxy = CreateProxyForQueue(queueName); QueueProxyCollection.Add(queueName, proxy); } //Get proxy to for MSMQ var msmqProxy = QueueProxyCollection[queueName]; msmqProxy.SendTransactionMessage(transaction); }
/// <summary> /// Tries the native authentication. /// </summary> private static void TryNativeAuthentication() { FxLog <AuthenticationHost> .InfoFormat("Trying Native Authentication"); Messenger.Default.Send(new NavigateMvvmMessage() { Header = LoginView.HEADER, ViewName = LoginView.ID }); }
/// <summary> /// Gets the cloud contract. /// </summary> /// <param name="contractId">The contract identifier.</param> /// <returns>CloudContract.</returns> public CloudContract GetCloudContract(string contractId) { FxLog <CloudContracts> .DebugFormat("Get Cloud Contract: {0}", contractId); var res = Provider <CloudContract> .GetById(contractId); FxLog <CloudContracts> .DebugFormat("\t{0} | {1}", res.Id, res.Binding); return(res); }
/// <summary> /// Gets the type information. /// </summary> /// <param name="appSettingsKey">The application settings key.</param> /// <param name="instanceTypeName">Name of the instance type.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> private static bool GetTypeInfo(string appSettingsKey, out string instanceTypeName) { instanceTypeName = ConfigurationManager.AppSettings[appSettingsKey]; if (string.IsNullOrEmpty(instanceTypeName)) { FxLog <TypeFactory> .DebugFormat( "No Type information found in configuration file for AppSettings key {0})", appSettingsKey); return(false); } return(true); }
/// <summary> /// Connect to the remote host.<br/> /// SendTimeout is set to 3000ms by default. /// </summary> /// <remarks> /// As the connection is made asynchronously a call to <see cref="Send"/> may failed if this call is /// made right after the Connect().<br /> /// </remarks> public void Connect() { try { Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); newsock.SendTimeout = 3000; newsock.BeginConnect(_endpoint, new AsyncCallback(EndConnect), newsock); } catch (Exception ex) { FxLog<AsyncTcpClient> .Error("Exception raised trying to connect to the remote host.", ex); } }
/// <summary> /// To the XML document. /// </summary> /// <param name="inputStream">The input stream.</param> /// <returns>XmlDocument.</returns> private static XmlDocument ToXmlDocument(Stream inputStream) { XmlDocument xmlDocument = new XmlDocument(); try { xmlDocument.Load(inputStream); } catch (Exception ex) { FxLog <XmlFormatter> .DebugFormat("Failed to load XmlDocument from input stream --> {0}", ex.Message); } return(xmlDocument); // Empty if error occurred }
/// <summary> /// Gets all endpoint addresses. /// </summary> /// <returns>DiscoItem[][].</returns> public DiscoItem[] GetAllEndpointAddresses() { try { return(Business.DiscoProvider .Discos .GetAllEndpointAddresses()); } catch (Exception exception) { FxLog <DiscoSentry> .DebugFormat("Error getting all endpoint addresses. Error: {0}", exception.Message); throw; } }
/// <summary> /// To the XML document. /// </summary> /// <param name="input">The input.</param> /// <returns>XmlDocument.</returns> private static XmlDocument ToXmlDocument(byte[] input) { MemoryStream memoryStream = new MemoryStream(input); XmlDocument xmlDocument = new XmlDocument(); try { xmlDocument.Load(memoryStream); } catch (Exception ex) { FxLog <XmlFormatter> .DebugFormat("Failed to load XmlDocument from byte array --> {0}", ex.GetCombinedMessages()); } return(xmlDocument); // Empty if error occurred }
/// <summary> /// Gets the endpoints. /// </summary> /// <param name="contractType">The scope.</param> /// <returns>SerializableEndpoint[][].</returns> public SerializableEndpoint[] GetEndpoints(string contractType) { try { return(DiscoProvider .Discos .GetEndpoints(contractType)); } catch (Exception exception) { FxLog <DiscoSentry> .DebugFormat("Error getting Endpoints from {0}. Error: {1}", contractType, exception.Message); throw; } }
//protected override void RegisterRequiredDomainObjects() //{ // _FxLog<DiscoSentry>.DebugFormat("Hello"); //} #region IDiscoService Members /// <summary> /// Gets all endpoints. /// </summary> /// <returns>SerializableEndpoint[][].</returns> public SerializableEndpoint[] GetAllEndpoints() { try { return(Business.DiscoProvider .Discos .GetAllEndpoints()); } catch (Exception exception) { FxLog <DiscoSentry> .LogException(exception); throw; } }
/// <summary> /// Requests from pool. /// </summary> /// <typeparam name="T"></typeparam> /// <returns>T.</returns> internal static T RequestFromPool <T>() where T : class { if (EnableConnectionPool) { IClientBase instance; if (Current._openProxiesByType.TryGetValue(typeof(T), out instance)) { FxLog <ProxyConnectionPool> .DebugFormat("Retrieving proxy {0} from ConnectionPool.", instance); return((T)instance); } } return(null); }
/// <summary> /// Saves the cloud contract. /// </summary> /// <param name="contract">The contract.</param> /// <returns>CloudContract.</returns> public CloudContract SaveCloudContract(CloudContract contract) { FxLog <CloudContracts> .DebugFormat("Registering service contract for [{0}]", contract.Id); try { contract = Provider <CloudContract> .Save(contract); } catch (Exception ex) { FxLog <CloudContracts> .LogException(ex); contract.AddError(ex.Message); } return(contract); }
/// <summary> /// Send data to the remote host (async method). /// </summary> /// <param name="data"></param> public void Send(byte[] data) { try { if (_client != null && _client.Connected) { _client.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(SendData), _client); } } catch (Exception ex) { if (Error != null) { Error(this, new AsyncTcpClientEventArgs(null, ex.GetBaseException())); } FxLog<AsyncTcpClient> .Error("Exception raised trying to send message to the remote host.", ex); } }
/// <summary> /// Handles the file in case of a zip File /// </summary> /// <param name="file">The File</param> /// <param name="fileName">Name of the zip file.</param> /// <returns>Returns true if the code should continue, false when the processing stops here</returns> protected virtual bool HandleZipFile(byte[] file, string fileName) { try { var stream = new MemoryStream(file); ZipHelper.Decompress(stream, fileName, TransactionConfigurationHelper.TemporaryPath); var files = Directory.GetFiles(TransactionConfigurationHelper.TemporaryPath); foreach (var tempFile in files) { File.Move(tempFile, Path.Combine(TransactionConfigurationHelper.InboxPath, new FileInfo(tempFile).Name)); } } catch (Exception ex) { FxLog.Debug(GetType(), ex.GetCombinedMessages()); throw; } return(false); }
/// <summary> /// Close the connection. /// </summary> public void Close() { try { if (_client != null && _client.Connected) { // Disconnected Event are raised only if a "real" disconnection occurred (not when Stop() is called). _stopping = true; _client.Shutdown(SocketShutdown.Both); _client.Disconnect(false); _client.Close(); _client = null; _stopping = false; } } catch (Exception ex) { FxLog<AsyncTcpClient> .Error("Exception raised trying to close the connection.", ex); } }
/// <summary> /// Saves the cloud contracts. /// </summary> /// <param name="contracts">The contracts.</param> /// <returns>CloudContract[][].</returns> public CloudContract[] SaveCloudContracts(CloudContract[] contracts) { var lst = new List <CloudContract>(); FxLog <CloudContracts> .DebugFormat("Registering Cloud Contracts:"); foreach (var cloudContract in contracts) { try { var res = SaveCloudContract(cloudContract); lst.Add(res); } catch (Exception ex) { FxLog <CloudContracts> .LogException(ex); cloudContract.AddError(ex.Message); lst.Add(cloudContract); } } return(lst.ToArray()); }
/// <summary> /// Starts the session. /// </summary> /// <param name="loginCompletedAction">The login completed action.</param> /// <param name="canceledAction"></param> /// <param name="loginCanceledAction">The login canceled action.</param> public static void StartSessionAsync(Action loginCompletedAction = null, Action loginCanceledAction = null) { _loginCompletedAction = loginCompletedAction; _loginCanceledAction = loginCanceledAction; if ((WulkaSession.Current != null) && (!WulkaSession.Current.IsDefaultSession)) { return; } FxLog <AuthenticationHost> .InfoFormat("****************************"); FxLog <AuthenticationHost> .InfoFormat("* Starting Session *"); FxLog <AuthenticationHost> .InfoFormat("****************************"); if (WulkaSession.Current != null) { FxLog <AuthenticationHost> .InfoFormat("Starting Session {0}", WulkaSession.Current.Id); } // By Default, we try to authenticate the user using Windows Authentication //TryWindowsAuthenticationAsync(); TryNativeAuthentication(); }
/// <summary> /// Internals the register. /// </summary> /// <param name="clientBase">The client base.</param> private void InternalRegister(IClientBase clientBase) { FxLog <ProxyConnectionPool> .DebugFormat("Registering client {0}", clientBase); _openProxies[clientBase] = clientBase; }