Search Results

Search found 3 results on 1 pages for 'sudaly'.

Page 1/1 | 1 

  • My First F# program

    - by sudaly
    Hi I just finish writing my first F# program. Functionality wise the code works the way I wanted, but not sure if the code is efficient. I would much appreciate if someone could review the code for me and point out the areas where the code can be improved. Thanks Sudaly open System open System.IO open System.IO.Pipes open System.Text open System.Collections.Generic open System.Runtime.Serialization [<DataContract>] type Quote = { [<field: DataMember(Name="securityIdentifier") >] RicCode:string [<field: DataMember(Name="madeOn") >] MadeOn:DateTime [<field: DataMember(Name="closePrice") >] Price:float } let m_cache = new Dictionary<string, Quote>() let ParseQuoteString (quoteString:string) = let data = Encoding.Unicode.GetBytes(quoteString) let stream = new MemoryStream() stream.Write(data, 0, data.Length); stream.Position <- 0L let ser = Json.DataContractJsonSerializer(typeof<Quote array>) let results:Quote array = ser.ReadObject(stream) :?> Quote array results let RefreshCache quoteList = m_cache.Clear() quoteList |> Array.iter(fun result->m_cache.Add(result.RicCode, result)) let EstablishConnection() = let pipeServer = new NamedPipeServerStream("testpipe", PipeDirection.InOut, 4) let mutable sr = null printfn "[F#] NamedPipeServerStream thread created, Wait for a client to connect" pipeServer.WaitForConnection() printfn "[F#] Client connected." try // Stream for the request. sr <- new StreamReader(pipeServer) with | _ as e -> printfn "[F#]ERROR: %s" e.Message sr while true do let sr = EstablishConnection() // Read request from the stream. printfn "[F#] Ready to Receive data" sr.ReadLine() |> ParseQuoteString |> RefreshCache printfn "[F#]Quot Size, %d" m_cache.Count let quot = m_cache.["MSFT.OQ"] printfn "[F#]RIC: %s" quot.RicCode printfn "[F#]MadeOn: %s" (String.Format("{0:T}",quot.MadeOn)) printfn "[F#]Price: %f" quot.Price

    Read the article

  • F# script to application

    - by sudaly
    I have written two small scripts, First one maintains a dictionary of current stock prices for a set of securities. I am using recursion to listen to a named pipe. Whenever there is something available on the name pipe, it updates the security price and goes right back and start listening to the pipe. The second one periodically reads the stock price of some security from the price cache of the first program and performs come calculation. But I have no idea how to make these two programs communicate. I somehow need to make my second programs start the first program and let it run in the background and get the price whenever it needs it. Can someone point me in the right direction? Thank you, -Niran

    Read the article

  • How to update a table in database using LINQ in F#?

    - by sudaly
    I have seen plenty of examples on how to query the database but nothing on how to update records. Below is the simple code that I wrote to retrieve a table, but can someone explain me how can I modify a field, say lastActiveDate, and update the table on the database Thank you, suday open System open Microsoft.FSharp.Linq let connString = "Server=localhost;Database=myDb;Trusted_Connection=True;" let db = new MyDb(connString) db.Log <- System.Console.Out let res = Query.query <@ seq { for users in db.userAccounts do yield users } @> |> List.ofSeq printfn "Totla users: %d" res.Length

    Read the article

1