コード例 #1
0
 public async Task Setup()
 {
     using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Loxone.Client.Tests.LoxAPP3.json"))
     {
         _structureFile = await StructureFile.LoadAsync(stream, CancellationToken.None);
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: hpposch/Loxone.NET
        static async Task MainAsync(string[] args)
        {
            List <string> searchAdresses = await LoxoneMiniserverFinder.SearchForDevices();

            if (searchAdresses != null && searchAdresses.Count > 0)
            {
                _miniserverAddress = searchAdresses[0];
                Console.WriteLine("Discovered Miniserver at: " + _miniserverAddress);
            }

            var connection = new MiniserverConnection(new Uri(_miniserverAddress));

            // Specify Miniserver username and password.
            connection.Credentials = new NetworkCredential("admin", "admin");

            Console.WriteLine($"Opening connection to miniserver at {connection.Address}...");
            await connection.OpenAsync(CancellationToken.None).ConfigureAwait(false);

            // Load cached structure file or download a fresh one if the local file does not exist or is outdated.
            StructureFile structureFile = null;

            structureFile = await StructureFile.LoadAsync("LoxAPP3.json", CancellationToken.None).ConfigureAwait(false);

            var lastModified = await connection.GetStructureFileLastModifiedDateAsync(CancellationToken.None).ConfigureAwait(false);

            if (lastModified > structureFile.LastModified)
            {
                // Structure file cached locally is outdated, throw it away.
                structureFile = null;
            }

            if (structureFile == null)
            {
                // The structure file either did not exist on disk or was outdated. Download a fresh copy from
                // miniserver right now.
                Console.WriteLine("Downloading structure file...");
                structureFile = await connection.DownloadStructureFileAsync(CancellationToken.None).ConfigureAwait(false);

                // Save it locally on disk.
                await structureFile.SaveAsync("LoxAPP3.json", CancellationToken.None).ConfigureAwait(false);
            }

            Console.WriteLine($"Structure file loaded, culture {structureFile.Localization.Culture}.");


            Console.WriteLine("Enabling status updates...");
            await connection.EnableStatusUpdatesAsync(CancellationToken.None).ConfigureAwait(false);

            Thread.Sleep(500);
            await connection.EnableStatusUpdatesAsync(CancellationToken.None).ConfigureAwait(false);

            Thread.Sleep(Timeout.Infinite);
        }
コード例 #3
0
        static async Task MainAsync(string[] args)
        {
            using (var connection = new MiniserverConnection(new Uri(_miniserverAddress)))
            {
                // Specify Miniserver username and password.
                connection.Credentials = new NetworkCredential("web", "web");

                Console.WriteLine($"Opening connection to miniserver at {connection.Address}...");
                await connection.OpenAsync(CancellationToken.None).ConfigureAwait(false);

                // Load cached structure file or download a fresh one if the local file does not exist or is outdated.
                StructureFile structureFile = null;
                if (File.Exists("LoxAPP3.json"))
                {
                    structureFile = await StructureFile.LoadAsync("LoxAPP3.json", CancellationToken.None).ConfigureAwait(false);

                    var lastModified = await connection.GetStructureFileLastModifiedDateAsync(CancellationToken.None).ConfigureAwait(false);

                    if (lastModified > structureFile.LastModified)
                    {
                        // Structure file cached locally is outdated, throw it away.
                        structureFile = null;
                    }
                }

                if (structureFile == null)
                {
                    // The structure file either did not exist on disk or was outdated. Download a fresh copy from
                    // miniserver right now.
                    Console.WriteLine("Downloading structure file...");
                    structureFile = await connection.DownloadStructureFileAsync(CancellationToken.None).ConfigureAwait(false);

                    // Save it locally on disk.
                    await structureFile.SaveAsync("LoxAPP3.json", CancellationToken.None).ConfigureAwait(false);
                }

                Console.WriteLine($"Structure file loaded, culture {structureFile.Localization.Culture}.");

                Console.WriteLine("Enabling status updates...");
                await connection.EnableStatusUpdatesAsync(CancellationToken.None).ConfigureAwait(false);
            }
        }
コード例 #4
0
        private static void StructureFileRoundTrip()
        {
            var structureFile = StructureFile.LoadAsync("LoxAPP3.json", CancellationToken.None).GetAwaiter().GetResult();

            structureFile.SaveAsync("LoxAPP3.roundtripped.json", CancellationToken.None).GetAwaiter().GetResult();
        }
コード例 #5
0
    public static void InitClasses()
    {
        if (ClassesLoaded)
        {
            return;
        }
        ClassesLoaded = true;
        Registry reg         = new Registry("graphics/structures/structures.reg");
        int      ObjectCount = reg.GetInt("Global", "Count", 0);

        for (int i = 0; i < ObjectCount; i++)
        {
            string         on  = string.Format("Structure{0}", i);
            StructureClass cls = new StructureClass();
            cls.DescText = reg.GetString(on, "DescText", "");
            cls.ID       = reg.GetInt(on, "ID", -1);
            string file = reg.GetString(on, "File", null);
            if (file != null)
            {
                StructureFile sfile = new StructureFile();
                sfile.FileName = "graphics/structures/" + file;
                cls.File       = sfile;
            }
            cls.TileWidth   = reg.GetInt(on, "TileWidth", 1);
            cls.TileHeight  = reg.GetInt(on, "TileHeight", 1);
            cls.FullHeight  = reg.GetInt(on, "FullHeight", cls.TileHeight);
            cls.SelectionX1 = reg.GetInt(on, "SelectionX1", 0);
            cls.SelectionY1 = reg.GetInt(on, "SelectionY1", 0);
            cls.SelectionX2 = reg.GetInt(on, "SelectionX2", cls.TileWidth * 32);
            cls.SelectionY2 = reg.GetInt(on, "SelectionY2", cls.FullHeight * 32);
            cls.ShadowY     = reg.GetInt(on, "ShadowY", 0);
            if (cls.ShadowY < 0) // this is very bad. this means that Nival artists were trying to make this structure Flat, but didn't know about the feature.
            {                    // as such, they were setting ShadowY -20000 and the shadow was still appearing sometimes despite LOOKING AS IF it was flat.
                cls.Flat    = true;
                cls.ShadowY = 0;
            }

            // also this fixes Bee houses
            if (cls.ShadowY > cls.FullHeight * 32)
            {
                cls.ShadowY = 0;
            }

            cls.AnimMask = reg.GetString(on, "AnimMask", null);
            int phases = reg.GetInt(on, "Phases", 1);
            if (phases == 1)
            {
                cls.Frames          = new StructureClass.AnimationFrame[1];
                cls.Frames[0].Frame = 0;
                cls.Frames[0].Time  = 0;
            }
            else
            {
                int[] animFrame = reg.GetArray(on, "AnimFrame", null);
                int[] animTime  = reg.GetArray(on, "AnimTime", null);
                if (animFrame == null || animTime == null ||
                    animFrame.Length != animTime.Length)
                {
                    // some structures already have invalid definitions.
                    cls.Frames          = new StructureClass.AnimationFrame[1];
                    cls.Frames[0].Frame = 0;
                    cls.Frames[0].Time  = 0;
                }
                else
                {
                    cls.Frames = new StructureClass.AnimationFrame[animFrame.Length];
                    for (int j = 0; j < animFrame.Length; j++)
                    {
                        cls.Frames[j].Frame = animFrame[j];
                        cls.Frames[j].Time  = animTime[j];
                    }
                }
            }
            cls.Picture        = "graphics/infowindow/" + reg.GetString(on, "Picture", "") + ".bmp";
            cls.IconID         = reg.GetInt(on, "IconID", StructureClass.MagicIntNull);
            cls.Indestructible = reg.GetInt(on, "Indestructible", 0) != 0;
            cls.Usable         = reg.GetInt(on, "Usable", 0) != 0;
            cls.Flat           = reg.GetInt(on, "Flat", 0) != 0;
            cls.VariableSize   = reg.GetInt(on, "VariableSize", 0) != 0;
            cls.LightRadius    = reg.GetInt(on, "LightRadius", 0);
            cls.LightPulse     = reg.GetInt(on, "LightPulse", 0);
            Classes.Add(cls);
        }
    }