Skip to content

Commit

Permalink
Expose Server via an interface and remove dead code
Browse files Browse the repository at this point in the history
The server needs to be exposed as an interface, because F# Interactive on Mono
doesn't seem to like DLL files referencing EXE files (so the client cannot
reference the server directly).

This also removes the (never used) option for local execution, because this would
need testing (if we need it, it can be easily recovered) & one not used function.
Added documentation as a bonus :-).
  • Loading branch information
tpetricek committed Jan 13, 2015
1 parent 83cdeee commit 1c663b6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 27 deletions.
19 changes: 6 additions & 13 deletions src/RProvider.DesignTime/RInteropClient.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ open System.Diagnostics
open System.Threading
open Microsoft.Win32
open System.IO
open RProviderServer
open RProvider.Internal
open System.Security.AccessControl
open System.Security.Principal
Expand All @@ -19,9 +18,6 @@ let server = "RProvider.Server.exe"
/// Thrown when we want to show the specified string as a friendly error message to the user
exception RInitializationError of string

/// true to load the server in-process, false load the server out-of-process
let localServer = false

/// Asynchronously waits until the specifid file is deleted using FileSystemWatcher
let waitUntilDeleted file = async {
use watcher =
Expand Down Expand Up @@ -109,7 +105,7 @@ let startNewServer() =
p.Exited.Add(fun _ -> lastServer <- None)

Logging.logf "Attempting to connect via IPC"
Activator.GetObject(typeof<RInteropServer>, "ipc://" + channelName + "/RInteropServer") :?> RInteropServer
Activator.GetObject(typeof<IRInteropServer>, "ipc://" + channelName + "/RInteropServer") :?> IRInteropServer


/// Returns an instance of `RInteropServer` started via IPC
Expand All @@ -120,19 +116,16 @@ let getServer() =
match lastServer with
| Some s -> s
| None ->
match localServer with
| true -> new RInteropServer()
| false ->
let server = startNewServer()
lastServer <- Some server
Logging.logf "Got some server"
server )
let server = startNewServer()
lastServer <- Some server
Logging.logf "Got some server"
server )

/// Returns Some("...") when there is an 'expected' kind of error that we want
/// to show in the IntelliSense in a pleasant way (R is not installed, registry
/// key is missing or .rprovider.conf is missing)
let tryGetInitializationError () =
try getServer().RInitValue
try getServer().InitializationErrorMessage
with RInitializationError err -> err

let withServer f =
Expand Down
5 changes: 0 additions & 5 deletions src/RProvider.DesignTime/RProvider.DesignTime.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@
<Project>{80fd4284-c7bd-4170-8cc3-41e8548402e4}</Project>
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="../RProvider/RProvider.Server.fsproj">
<Name>RProvider.Server</Name>
<Project>{7ff9cfa3-2516-4970-9dd8-54c7d4ca24aa}</Project>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
2 changes: 1 addition & 1 deletion src/RProvider/Program.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module RProviderServer.Main
module RProvider.Server.Main

open System
open System.Diagnostics
Expand Down
12 changes: 4 additions & 8 deletions src/RProvider/RInteropServer.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace RProviderServer
namespace RProvider.Server

open Microsoft.FSharp.Core.CompilerServices
open Microsoft.Win32
Expand Down Expand Up @@ -69,9 +69,9 @@ module internal EventLoop =
/// Server object that is exposed via remoting and is called by the editor
/// to get information about R (packages, functions, RData files etc.)
type RInteropServer() =
inherit MarshalByRefObject()
member x.RInitValue =
inherit MarshalByRefObject()
interface IRInteropServer with
member x.InitializationErrorMessage =
// No need for event loop here, because this is initialized
// when the event loop starts (so initResult has value now)
match RInit.initResult.Value with
Expand All @@ -97,10 +97,6 @@ type RInteropServer() =
EventLoop.runServerCommandSafe <| fun () ->
getPackageDescription package

member x.MakeSafeName(name) =
EventLoop.runServerCommandSafe <| fun () ->
makeSafeName name

member x.GetRDataSymbols(file) =
EventLoop.runServerCommandSafe <| fun () ->
let env = REnv(file)
Expand Down
1 change: 1 addition & 0 deletions src/RProvider/RProvider.Runtime.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<Compile Include="..\Common\AssemblyInfo.fs">
<Link>AssemblyInfo.fs</Link>
</Compile>
<Compile Include="RInteropInterface.fs" />
<Compile Include="CharacterDeviceInterceptor.fs" />
<Compile Include="Configuration.fs" />
<Compile Include="Logging.fs" />
Expand Down

0 comments on commit 1c663b6

Please sign in to comment.