public void Start()
        {
            var device = RootDevice.GetInstance();

            device.Initialize();

            var i = 0;
        }
Пример #2
0
        static void Main(string[] args)
        {
            FixUpRegistry();

            while (true)
            {
                Console.Clear();
                Console.Out.WriteLine("--START--");
                PrintSensorsAndSubDevices(RootDevice.GetInstance(), "");
                Console.Out.WriteLine("-- END --");
                Thread.Sleep(1000);
            }
        }
Пример #3
0
        public MainPage()
        {
            InitializeComponent();

            logger   = new TextBoxLogger(svLog, TbLog);
            wiFiInfo = new WiFiInfo(logger);

            controlPoint = new ControlPoint(logger)
            {
                Target = "spatium"
            };
            controlPoint.DeviceDiscovered += DiscoveredCallback;
            controlPoint.DeviceGone       += GoneCallback;
            rootDevice = new RootDevice(logger)
            {
                Target = "spatium",
                Name   = "Spatium device",
                USN    = "123-321",
                Port   = 12345
            };
            eventTimer       = new EventTimer(logger);
            eventTimer.Tick += async(s, t) =>
            {
                logger.WriteLine(t.ToString());
                IsAvailable.Text = (await wiFiInfo.IsAvailable()).ToString();
                IsEnabled.Text   = (await wiFiInfo.IsEnabled()).ToString();
                IsConnected.Text = (await wiFiInfo.IsConnected()).ToString();
            };

            Loaded += async(s, e) =>
            {
                try
                {
                    HostName localIp = GetLocalIp();
                    LocalIp.Text = (localIp != null) ? localIp.CanonicalName : "Unknown";
                }
                catch (Exception ex)
                {
                    LocalIp.Text = "Error";
                    logger.WriteLine(ex.ToString());
                }

                IsAvailable.Text = (await wiFiInfo.IsAvailable()) ? "Available" : "Unavailable";
                IsEnabled.Text   = (await wiFiInfo.IsEnabled()) ? "Enabled" : "Disabled";
                IsConnected.Text = (await wiFiInfo.IsConnected()) ? "Connected" : "Disconnected";

                wiFiInfo.AvailabilityChanged  += (s2, a) => IsAvailable.Text = a.Available ? "Available" : "Unavailable";
                wiFiInfo.AdapterStatusChanged += (s2, a) => IsEnabled.Text = a.Enabled ? "Enabled" : "Disabled";
                wiFiInfo.ConnectionChanged    += (s2, a) => IsConnected.Text = a.Connected ? "Connected" : "Disconnected";
            };
        }
Пример #4
0
        static void Main(string[] args)
        {
            var root = new RootDevice();

            root.AddDevice(new LocalDevice());
            root.AddDevice(new HttpDevice());

            var archives = new ArchiveManager();

            archives.AddType(new ZipArchiveType());

#if true
            {
                var remoteFile = root.GetFile(@"https://www.sample-videos.com/zip/10mb.zip");

                var archive = archives.Open(remoteFile);

                foreach (var archiveFile in archive.Files)
                {
                    Console.WriteLine("File: {0}", archiveFile.Name);
                }

                var inputFile  = archive.GetFile("big_buck_bunny_240p_10mb.mp4");
                var outputFile = root.GetFile(@"W:\test.mp4");

                inputFile.CopyTo(outputFile);
            }
#endif

#if false
            {
                var inputFile  = root.GetFile(@"https://ci.appveyor.com/api/buildjobs/bcm5wji44wsg2eye/artifacts/Release-0.12.0.40.zip");
                var outputFile = root.GetFile(@"W:\test.zip");

                inputFile.CopyTo(outputFile);

                Console.WriteLine("Length: {0}", outputFile.Length);
            }
#endif
        }
Пример #5
0
        public override void Call()
        {
            IController controller = ControllerRegistry.Get(GetRequiredArgument <string>("Controller")).New();

            //Set thermistors
            if (controller is ITemperatureDependantController)
            {
                ((ITemperatureDependantController)controller).SetThermistor((IThermistor)RootDevice.FindDeviceByPath(GetRequiredArgument <string>("Thermistor")));
            }

            //Set fixed values
            if (controller is IFixedNumberController)
            {
                ((IFixedNumberController)controller).Value = GetRequiredArgument <double>("Value");
            }

            if (controller is IFixedColorController)
            {
                ((IFixedColorController)controller).Value = GetRequiredArgument <Color>("Value");
            }

            if (controller is IFixedColorCycleController)
            {
                ((IFixedColorCycleController)controller).Value = new List <Color>(GetRequiredArgument <IEnumerable <Color> >("Value")).ToArray();
            }

            //Set curves
            if (controller is ICurveColorController)
            {
                ((ICurveColorController)controller).Value = GetRequiredArgument <ControlCurve <double, Color> >("Value");
            }

            if (controller is ICurveNumberController)
            {
                ((ICurveNumberController)controller).Value = GetRequiredArgument <ControlCurve <double, double> >("Value");
            }

            ((IControllableSensor)Device).Controller = controller;
        }
Пример #6
0
 public CorsairRootDevice()
     : base(RootDevice.GetInstance())
 {
 }
Пример #7
0
        private void _Start()
        {
            string absoluteUri = request.Uri.AbsolutePath;

            while (absoluteUri.IndexOf("//") >= 0)
            {
                absoluteUri = absoluteUri.Replace("//", "/");
            }

            if (absoluteUri.StartsWith("/api"))
            {
                if (!request.Headers.Contains("Authorization"))
                {
                    RespondWithJSON("Please authenticate", false, 401, new Dictionary <string, string> {
                        { "WWW-Authenticate", "Basic realm=\"CorsairLinkPlusPlus API\"" }
                    });
                    return;
                }

                currentUser = GetCurrentUser(request.Headers["Authorization"]);
                if (currentUser == null)
                {
                    RespondWithJSON("Invalid login", false, 401, new Dictionary <string, string> {
                        { "WWW-Authenticate", "Basic realm=\"CorsairLinkPlusPlus API\"" }
                    });
                    return;
                }

                if (request.HttpMethod == "OPTIONS" || request.HttpMethod == "HEAD")
                {
                    RespondWithJSON("Yep yep, no need for these");
                    return;
                }

                try
                {
                    IDevice device = RootDevice.FindDeviceByPath(absoluteUri.Substring(4));

                    if (device == null)
                    {
                        RespondWithJSON("Device not found", false, 404);
                        return;
                    }

                    if (request.HttpMethod == "POST")
                    {
                        if (currentUser.Value.readOnly)
                        {
                            RespondWithJSON("Your user is read-only", false, 403);
                            return;
                        }

                        JSONMethodCall methodCall;
                        using (StreamReader bodyReader = new StreamReader(request.Body))
                        {
                            methodCall = JsonConvert.DeserializeObject <JSONMethodCall>(bodyReader.ReadToEnd());
                        }
                        BaseMethod.Execute(methodCall.Name, device, methodCall.Params);
                        RespondWithJSON("OK");
                        return;
                    }

                    RespondWithDevice(device);
                    return;
                }
                catch (Exception e)
                {
                    try
                    {
                        RespondWithJSON(e.Message, false, 500);

                        Console.Error.WriteLine("------------------");
                        Console.Error.WriteLine("Error in HTTP");
                        Console.Error.WriteLine(e);
                        Console.Error.WriteLine("------------------");
                    }
                    catch (Exception se)
                    {
                        Console.Error.WriteLine("------------------");
                        Console.Error.WriteLine("Error in HTTP error handler");
                        Console.Error.WriteLine(se);
                        Console.Error.WriteLine("Caused by");
                        Console.Error.WriteLine(e);
                        Console.Error.WriteLine("------------------");
                    }
                    return;
                }
            }
            else
            {
                if (absoluteUri == "/" || absoluteUri == "")
                {
                    absoluteUri = "index.html";
                }
                else
                {
                    absoluteUri = absoluteUri.Substring(1);
                }

                FileInfo fileInfo = new FileInfo(Program.WEB_ROOT_ABSOLUTE + '/' + absoluteUri);

                if (!fileInfo.Exists)
                {
                    RespondWithJSON("Static content not found", false, 404);
                    return;
                }

                if (fileInfo.Attributes.HasFlag(FileAttributes.Directory))
                {
                    RespondWithJSON("Static content is a directory", false, 403);
                    return;
                }

                DirectoryInfo directory = fileInfo.Directory;
                do
                {
                    if (Program.WEB_ROOT_ABSOLUTE.Equals(directory.FullName))
                    {
                        break;
                    }
                    directory = directory.Parent;
                } while (directory != null);

                if (directory == null)
                {
                    RespondWithJSON("Nope, sorry!", false, 403);
                    return;
                }

                string mineType = MIMEAssistant.GetMIMEType(fileInfo.Extension);

                RespondWithRaw(fileInfo.OpenRead(), 200, mineType);
            }
        }