public WebBoolResult IsMediaPortalRunning() { return(new WebBoolResult(Mediaportal.IsMediaPortalRunning())); }
public WebAccessRequestResponse CreateAccessRequest(string clientName) { // generate the request string ip = WCFUtil.GetClientIPAddress(); string token = RandomGenerator.GetRandomString(40); WebAccessRequestResponse request = new WebAccessRequestResponse() { ClientName = clientName, IsAllowed = false, UserHasResponded = false, Token = token }; if (!Configuration.Services.AccessRequestEnabled) { Log.Info("User access request from {0} (claims to be client {1}) denied because user access requests are disabled on this system (check configuration)", ip, clientName); request.UserHasResponded = true; request.Token = null; return(request); } requests[token] = request; Log.Info("Received access request from {0} (claims to be client {1}), gave it token {2}", ip, clientName, token); CancellationTokenSource cancelToken = new CancellationTokenSource(); cancelTokens[token] = cancelToken; // ask the user askUserTasks[token] = Task.Factory.StartNew(delegate() { String result = null; if (Mediaportal.IsMediaPortalRunning() && WifiRemote.IsInstalled) { Log.Debug("Requesting user response through WifiRemote"); result = RequestAccessThroughWifiRemote(clientName, ip, cancelToken); } else { Log.Debug("Requesting user response through USS"); result = RequestAccessThroughPrivateUSS(token, clientName, ip, cancelToken); } Log.Debug("Finish asking user about access request with token {0}: {1}", token, result); // make sure that the request is still active (not cancelled) if (requests.ContainsKey(token)) { lock (requests[token]) { // set the necessary flags var matchingUsers = Configuration.Authentication.Users.Where(x => x.Username == result); requests[token].ErrorDuringProcessing = result == ERROR || !matchingUsers.Any(); requests[token].IsAllowed = !requests[token].ErrorDuringProcessing && result != null; requests[token].UserHasResponded = true; if (matchingUsers.Any()) { Log.Info("Sending account {0} in response to access request {1}", matchingUsers.First().Username, token); requests[token].Username = matchingUsers.First().Username; requests[token].Password = matchingUsers.First().GetPassword(); } else if (result == ERROR) { Log.Error("Failure during access request for token {0}", token); } else if (result != null) { Log.Warn("Didn't find a user named '{0}' - something strange is going on!", result); } } } return(true); }, cancelToken.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default); // return the token to the client return(request); }