These are chat archives for CoraleStudios/Colore

17th
Nov 2016
Jeremy
@JeremyBYU
Nov 17 2016 03:31
Hi, I was interested in using your library with nodejs using "edgejs". Its an interop for communicaiton between javascript v8 (nodejs) and c#. I have used this before by writing code in c# and then loading it in nodejs file. I was even able to load external dll' this way as well. However I am a little confused as to how to do this Colore. Can I compile Colore as a dll (that relies upon another dll! (razer sdk)) so that the only c# code necessary is just calling your api?
Jeremy
@JeremyBYU
Nov 17 2016 04:44
Got it to work
// Javascript File
const edge = require('edge');

const changeColor = edge.func({
    source: 'colore.cs',
    references: [ 'Corale.Colore.dll' ]
});


let color = 1;

setInterval(() => {
    if (color > 2)
        color = 1

    args = { color }
    console.log(args)
    changeColor(args, (err, result) => {
        console.log(result)
    })
    color += 1;
}, 1000);
// CSHARP FILE
using System.Threading.Tasks;
using Corale.Colore.Core;
using ColoreColor = Corale.Colore.Core.Color;

public class Startup
{
    public async Task<object> Invoke(dynamic input)
    {
        int color = (int)input.color;
        ColoreColor col = Helper.GetColor(color);

        Chroma.Instance.SetAll(col);
        return 1;
    }
}

static class Helper
{
    public static ColoreColor GetColor(int colorCode)
    {
        switch (colorCode)
        {
            case 1:
                return ColoreColor.Red;
            case 2:
                return ColoreColor.White;
            default:
                return ColoreColor.Red;
        }
    }
}