Exemplo n.º 1
0
        public void ValueChangedCallBack(OpcDaGroup group, OpcDaItemValue[] values)
        {
            JsonObject result = new JsonObject();

            result.Add("timestamp", DgiotHelper.Now());
            string groupKey = "";

            JsonObject  properties = new JsonObject();
            List <Item> collection = new List <Item>();

            values.ToList().ForEach(v =>
            {
                if (v.Item != null && v.Value != null)
                {
                    properties.Add(v.Item.ItemId, v.Value);
                    groupKey = v.Item.UserData as string;
                    OpcDa.setItems(groupKey, v.Item.ItemId, properties);
                }
            });
            int i = OpcDa.getItemsCount(groupKey);

            if (i <= 0)
            {
                properties = OpcDa.getItems(group, groupKey);
                string topic = "$dg/thing/" + productId + "/" + devAddr + "/properties/report";
                int    flag1 = OpcDa.GetGroupFlag(groupKey);
                if (flag1 > 0)
                {
                    properties.Add("dgiotcollectflag", 0);
                    LogHelper.Log(" topic: " + topic + " payload: " + properties);
                }
                else
                {
                    properties.Add("dgiotcollectflag", 1);
                }
                result.Add("properties", properties);
                MqttClientHelper.Publish(topic, Encoding.UTF8.GetBytes(properties.ToString()));
                // LogHelper.Log("properties: " + properties.ToString());
            }
        }
Exemplo n.º 2
0
        public static void Scan_mdb(Dictionary <string, object> json)
        {
            if (json.ContainsKey("dbq"))
            {
                try
                {
                    dbq = (string)json["dbq"];
                }
                catch (Exception ex)
                {
                    Console.WriteLine("{0}", ex.ToString());
                }
            }

            if (json.ContainsKey("security"))
            {
                try
                {
                    security = (string)json["security"];
                    security = security.ToUpper();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("{0}", ex.ToString());
                }
            }

            if (json.ContainsKey("uid"))
            {
                try
                {
                    uid = (string)json["uid"];
                }
                catch (Exception ex)
                {
                    Console.WriteLine("{0}", ex.ToString());
                }
            }

            if (json.ContainsKey("pwd"))
            {
                try
                {
                    pwd = (string)json["pwd"];
                }
                catch (Exception ex)
                {
                    Console.WriteLine("{0}", ex.ToString());
                }
            }

            if (security == "TRUE")
            {
                odbcconnectionString = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=" + dbq + "; Uid=" + uid + "; Pwd=" + pwd + ";";
            }
            else
            {
                odbcconnectionString = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=" + dbq;
            }

            Console.WriteLine(odbcconnectionString);

            using (var db = new OdbcConnection(odbcconnectionString))
            {
                db.Open();
                var schemaTable = db.GetSchema("Tables");
                var dataSet     = new DataSet();
                for (var i = 0; i < schemaTable.Rows.Count; i++)
                {
                    // only source tables
                    if (schemaTable.Rows[i]["TABLE_TYPE"].ToString() == "TABLE")
                    {
                        var tableName = schemaTable.Rows[i]["TABLE_NAME"].ToString();
                        var sql       = "SELECT TOP 1 * FROM [" + tableName + "]";

                        var dataTable = new DataTable(tableName);
                        using (var command = new OdbcCommand(sql, db))
                        {
                            using (var adapter = new OdbcDataAdapter(command))
                            {
                                adapter.Fill(dataTable);
                            }
                        }

                        // Console.WriteLine(tableName + "(" + dataTable.Rows.Count + " rows)");
                        dataSet.Tables.Add(dataTable);
                    }
                }

                dataSet.AcceptChanges();
                var jsonResults = DataSetToJson(dataSet);
                MqttClientHelper.Publish(scantopic, Encoding.UTF8.GetBytes(jsonResults.ToString()));
                LogHelper.Log(jsonResults);
            }
        }