public UserPendingAuthorization(IConnectKeys connectKeys) { LicenseKey = connectKeys.LicenseKey; CompanyKey = connectKeys.CompanyKey; MachineKey = connectKeys.MachineKey; DepotKey = connectKeys.DepotName; }
public ConnectUserNode(IConnectKeys connectKeys) { LicenseKey = connectKeys.LicenseKey; CompanyKey = connectKeys.CompanyKey; MachineKey = connectKeys.MachineKey; DepotName = connectKeys.DepotName; }
public ConnectTokenProvider(IConnectKeys connectKeys) { if (connectKeys == null) { throw new ArgumentNullException(nameof(connectKeys)); } _connectKeys = connectKeys; }
public ConnectClientCredentials(IConnectKeys connectKeys) { if (connectKeys == null) { throw new ArgumentNullException(nameof(connectKeys)); } _connectKeys = connectKeys; }
private static Exception IsAuthorized(IConnectKeys connectKeys) { Exception result = null; if (!LicenseManager.IsValid(connectKeys.LicenseKey.ToString())) { return(new FaultException("The license key is invalid or has expired.")); } try { using (var context = new ConnectContext()) { var company = context.Users.FirstOrDefault(c => c.CompanyKey == connectKeys.CompanyKey); if (company == null) { result = new FaultException("Your computer is not currently authorized to use Connect at this time."); } if (result == null) { var connectUserNode = context.UserNodes.FirstOrDefault(c => c.MachineKey == connectKeys.MachineKey && c.CompanyKey == connectKeys.CompanyKey); if (connectUserNode == null) { var connectUser = context.Users.FirstOrDefault(c => c.CompanyKey == connectKeys.CompanyKey); if (connectUser == null) { result = new FaultException("Your computer is not currently authorized to use Connect at this time."); return(result); } context.UserNodes.Add(new ConnectUserNode(connectKeys) { IsAuthorized = true, ConnectUser = connectUser }); context.SaveChanges(); return(null); } if (!connectUserNode.IsAuthorized) { result = new FaultException("Your computer is not currently authorized to use Connect at this time."); } } } } catch (Exception ex) { result = new FaultException("An unexcepted error occurred; " + ex.Message); } return(result); }
public ConnectToken(IConnectKeys connectKeys, string id) { if (connectKeys == null) { throw new ArgumentNullException("connectKeys"); } if (id == null) { throw new ArgumentNullException("id"); } _connectKeys = connectKeys; _id = id; _securityKeys = new ReadOnlyCollection <SecurityKey>(new List <SecurityKey>()); }
public void Open(IConnectKeys connectKeys) { if (_channelFactory != null) { if (_channelFactory.State == CommunicationState.Opened || _channelFactory.State == CommunicationState.Opening) { return; } } var serviceAddress = new EndpointAddress(connectKeys.Url); _channelFactory = new ChannelFactory <IConnectService>(GetBinding(), serviceAddress); var credentials = new ConnectClientCredentials(connectKeys); credentials.ServiceCertificate.DefaultCertificate = GetCertificate(); _channelFactory.Endpoint.Behaviors.Remove(typeof(ClientCredentials)); _channelFactory.Endpoint.Behaviors.Add(credentials); Service = _channelFactory.CreateChannel(); }
public static void CallAsync <TResult>(this IConnectClient client, IConnectKeys connectKeys, Func <IConnectClient, TResult> beginCall, Action <ConnectOperationResult> endCall = null, Action <Exception> exceptionHandler = null, Action alwaysCall = null) { if (connectKeys == null) { if (alwaysCall != null) { alwaysCall(); } return; } try { var synchronizationContext = TaskScheduler.FromCurrentSynchronizationContext(); Task.Factory.StartNew(() => { client.Open(connectKeys); return(Try(() => { var result = default(TResult); Application.Current.Dispatcher.Invoke(() => { result = beginCall(client); }); return result; })); }) .ContinueWith(mainTask => { if (mainTask.IsFaulted) { BuildException(mainTask, exceptionHandler); } else { if (endCall != null) { endCall(mainTask.Result); } } }, synchronizationContext) .ContinueWith(exceptionTask => Application.Current.Dispatcher.Invoke(() => { BuildException((Task <ConnectOperationResult>)exceptionTask, exceptionHandler); }, DispatcherPriority.Normal), TaskContinuationOptions.OnlyOnFaulted) .ContinueWith(alwaysTask => { Application.Current.Dispatcher.Invoke(() => { if (alwaysCall != null) { alwaysCall(); } }, DispatcherPriority.Normal); client.Close(); }); } catch (Exception ex) { if (exceptionHandler != null) { exceptionHandler(ex); } } }
public ConnectToken(IConnectKeys connectKeys) : this(connectKeys, Guid.NewGuid().ToString()) { }