Announcement

Collapse
No announcement yet.

Scripting with C#

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Scripting with C#

    I see that the help file mentions we need to put \\css_reference MySql.Data.dll; in the script if we want to reference the dll. But where does it look for the dll? In the scripts folder?

    This is what I am trying to do as a precursor to making a db call to MySQL:

    Script:
    Code:
    public Object Main(Object[] parm) {
    
    //css_reference MySql.Data.dll;
    //css_reference System.dll;
    //css_reference System.Data.dll;
    
            string connStr = "Server=192.168.5.5;user=User;database=homeseerdb;
    port=3306;password=Password";
    
            MySqlConnection conn = new MySqlConnection(connStr);
            try
            {
                //Console.WriteLine("Connecting to MySQL...");
                conn.Open();
    
                string sql = "INSERT into thermostat (HomeStatus) VALUES (@HomeStatusValue)";
                using (MySqlCommand myCmd = new MySqlCommand(sql, conn))
                        {
                            myCmd.CommandType = CommandType.Text;
                            myCmd.Parameters.AddWithValue("@HomeStatusValue", "Script Testing");                        
                            myCmd.ExecuteNonQuery();
                        }            
    
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.ToString());
            }
    
            conn.Close();
    
    
    return null;
    }
    Here is the log entry:

    Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\mysql_datalogger.cs: {interactive}(4,6): error CS1525: Unexpected symbol `System', expecting `(' {interactive}(5,6): error CS1525: Unexpected symbol `System', expecting `(' {interactive}(6,6): error CS1525: Unexpected symbol `Scheduler', expecting `(' {interactive}(7,6): error CS1525: Unexpected symbol `HomeSeerAPI', expecting `(' {interactive}(8,0): error CS1525: Unexpected symbol `public', expecting `(' {interactive}(10,2): error CS1525: Unexpected symbol `public', expecting `(' {interactive}(12,1): error CS1525: Unexpected symbol `}', expecting `(' {interactive}(21,1): error CS1056: Unexpected character `​' {interactive}(21,2): error CS1056: Unexpected character `​' {interactive}(21,3): error CS1056: Unexpected character `​' {interactive}(21,4): error CS1056: Unexpected character `​' {interactive}(21,5): error CS1056: Unexpected character `​' {interactive}(21,6): error CS1056: Unexpected character `​' {interactive}(21,7): error CS1056: Unexpected character `​' {interactive}(26,0): error CS1010: Newline in constant {interactive}(27,0): error CS1010: Newline in constant {interactive}(80,0): error CS1525: Unexpected symbol `}' {interactive}(83,37): error CS8025: Parsing error

    Any ideas? Thanks!
    A computer's attention span is as long
    as it's powercord.
Working...
X