Giter Club home page Giter Club logo

novadaqassignment's Introduction

Project structure

The logic for Fibonacci and file IO is separated into a shared library targeting NetStandard 2.0 to maximize the potability. By doing this the Novadaq.Core could be reused by any other platform such as Xamarin, ASP.NET. However, to be able to use it portably on other platform, the FileIO need to be abstracted. This feature is out of scope for this assignment.

  • Novadaq.Core : Shared code library targeting NetStandard 2.0

    • This project depends on System.Reative. It will be restored automatically by Nuget Package Manager if the project is built by Visual Studio

    • This project contains:

      • FibonacciFinder: a static class provides a recursive method to find Fibonacci number. This method is not optimized in order to demonstrate how the threading management done in FileWatcher. Inded, the ammount of time it takes to calculate Fibonacci(50) is 8 minutes as in this picture

        Benchmark picture

      • FileWatcher: The file watcher represents a session with a given observed folder. Whenever a new folder is given, a new instance of FileWatcher should be created. This file watcher uses Task Parallel Libary (TPL) to schedule tasks that will be excuted by the default task scheduler (ThreadPool). The task will be interupted using CancellationTokenSource which is explained in Cancellation in Managed Threads. When the user asks to observe the folder by calling StartMonitoring() on an instance of FileWatcher, a new task will be spawn and run in the while loop to look for a file named input in the given folder. If the user decides to terminate the task by either calling StopMonitoring() or disposing the instance of FileWatcher, the cancellation token will be propagated correctly to cancel all outstanding tasks. By using TPL, the input observation runs on a seperate thread and doesn't block the main thread at all. Even when the Fibonacci is calculated, the current task will spawn the new task, schedule a callback by using await keyword and return the current thread to threadpool. The whole behavior could be observed using breakpoint at certain stages; when a breakpoint is hit, use Parallel Stacks and Tasks windows under Debug/Windows menu.

        Parallel Stacks

      The FileWatcher uses ReactiveX to provide a fluent IObservable to signal any event happens in the process. More on this will be explained in the Novadaq.UI.

  • Novadaq.Core.Test : xUnit test project for testing Novadaq.Core.

  • Novadaq.UI : UI application using WPF targeting .Net Framework 4.7.

    • The UI thread is not blocked by the FileWatcher and FibonacciFinder. Indeed, the UI thread is free to do any operation even cancelling the running task for file observation and Fibonacci finding. The UI thread subscribes to the IObservable declared in FileWatcher to listen to any events signaled by the watcher. This approach is similiar to the .NET event delegate. However, it is more preferable because removing event delegate requires manually removing the delegate. With IObservable, we only need to call Dispose on subscription object. Also, it will allow many more complex logic applied on the event stream such as filtering, throttling, delaying, etc. Finally, the state of Start/Stop is managed manually using the _isFileWatcherRunning. This could be improved by implementing proper lifecycle manager for the file watcher instance.

Requirement

Time reports

Task Time
Designing code 30 minutes
Implement code 1.5 hours
Debuging and test 1.5 hours
Documentation 1 hours

novadaqassignment's People

Contributors

lamlex avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.