Coder Social home page Coder Social logo

Add dynamic property in send about dlid.mihome HOT 4 CLOSED

dlid avatar dlid commented on August 23, 2024
Add dynamic property in send

from dlid.mihome.

Comments (4)

thejoe8495 avatar thejoe8495 commented on August 23, 2024 1

Hi i try it but i became a error:
System.ArgumentException: "Could not determine JSON object type for type <>f__AnonymousType1`3[System.Int32,System.String,System.String]."
image

But for the readme i can create the object with:

            dynamic jsonObject = new JObject();
            jsonObject.method = "dnld_install_sound";
            jsonObject.@params = new JObject();
            [email protected] = 1;
            [email protected] = ws.baseurl + localfile.Replace("\\", "/");
            [email protected] = CalculateMD5(localfile);

Thank you i use this lines.

from dlid.mihome.

dlid avatar dlid commented on August 23, 2024

Hi!

The Send-method that accept the method name is meant for the average command - I believe most of them will take an array of parameters so that's why I created this overload to easily invoke most commands.

But is a version of Send - Send(object data) - that will allow you to send any data, but then you must also specify the method name in your object.

dynamic jsonObject = new JObject();
jsonObject.method = "dnld_install_sound";
jsonObject.@params = new {
 sid = 1,
 url = (ws.baseurl + localfile.Replace("\\", "/")),
 md5 = CalculateMD5(localfile)
};

var device = new MiDevice(**IP**, **TOKEN**);
device.Send(jsonObject);

I hope that will make it possible for you to create your install_sound request properly.

Regards
David

from dlid.mihome.

dlid avatar dlid commented on August 23, 2024

Ah ok, I never tried it out with the JObject so I take it it's an issue with how that one is serializing anonymous objects .

I usually just use anonymous objects so I would choose to do it like this:

using(var device = new MiDevice("**IP**", "**TOKEN**")) {
 device.Send(new {
  method = "dnld_install_sound",
  @params = new {
   sid = 1,
   url = (ws.baseurl + localfile.Replace("\\", "/")),
   md5 = CalculateMD5(localfile)
   }
 });
}

Glad it worked out though!

from dlid.mihome.

thejoe8495 avatar thejoe8495 commented on August 23, 2024

Ok yes this work too. But i love the dynamics a little more, when i want i can extend the dynamic at a later point ;)

            var test = new {
                method = "dnld_install_sound",
                @params = new {
                    sid = 1,
                    url = (ws.baseurl + localfile.Replace("\\", "/")),
                    md5 = CalculateMD5(localfile)
                }
            };

from dlid.mihome.

Related Issues (5)

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.