static void Main(string[] args)
        {
            Console.WriteLine("Start the program");

            Console.WriteLine("Initialiaze CloudConnect Wrapper");
            MD.CloudConnect.CloudConnect cc = new MD.CloudConnect.CloudConnect("integration", Properties.Settings.Default.account, Properties.Settings.Default.token);

            List<AssetData> assets = cc.Asset.Get();

            foreach (AssetData asset in assets)
                Console.WriteLine("Imei : {0}", asset.Imei);

            if (assets.Count > 0)
            {
                List<TrackingData> tracks = cc.Track.Get("asset:" + assets[0].Imei, per_page: "100");

                foreach (TrackingData track in tracks)
                    Console.WriteLine("Long. : {0} Lat. : {1} Time. : {2}", track.Longitude, track.Latitude, track.Recorded_at);
            }

            List<FieldData> fields = cc.Field.Get();
            if (fields.Count > 0)
            {
                foreach (FieldData f in fields)
                    Console.WriteLine(f.Name);
            }

            List<MessageData> messages = cc.Message.Get();
            if (messages.Count > 0)
            {
                foreach (MessageData m in messages)
                    Console.WriteLine("Asset: {0}; msg : {1}", m.Asset, m.Payload);
            }

            if (assets.Count > 0)
            {
                if (cc.Message.PostMessage(assets[0].Imei, "com.mdi.services.adminProtocol"
                    , "{\"request\": \"getval\", \"data\":{ \"pwrManager\":{ \"ignitionManagement\" }}}") > 0)
                {
                    Console.WriteLine("Error happening with the POST message");
                }
            }

            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
        }
 public JsonResult CheckMessage(string asset, string environment, string account, string token, string message)
 {
     string res = "";
     if (Session["MsgDate"] != null)
     {
         MD.CloudConnect.CloudConnect cc = new MD.CloudConnect.CloudConnect(environment, account, token);
         DateTime date = (DateTime)Session["MsgDate"];
         List<MessageData> messages = cc.Message.Get("asset:" + asset);
         foreach (MessageData msg in messages)
         {
             if (msg.Channel == "com.mdi.applications.message" && msg.Asset == asset && msg.Sender == asset
                 && msg.Received_at.HasValue && msg.Received_at.Value.Ticks > date.Ticks)
             {
                 res = msg.Message;
                 if (msg.Received_at.HasValue)
                     Session["MsgDate"] = msg.Received_at.Value;
                 else
                     Session["MsgDate"] = DateTime.Now;
             }
         }
     }
     return Json(res, JsonRequestBehavior.AllowGet);
 }
        public JsonResult SendTasks(JsonTasksModel data)
        {
            string res = "OK";
            DeviceModel device = RepositoryFactory.Instance.DeviceDb.GetDevice(data.Asset);

            if (device != null)
            {
                if (!device.IdLastTask.HasValue)
                    device.IdLastTask = 0;
                device.IdLastTask++;
                data.ID = device.IdLastTask.Value;

                MD.CloudConnect.CloudConnect cc = new MD.CloudConnect.CloudConnect(data.Environment, data.Account, data.Token);

                if (cc.Message.PostMessage(data.Asset, "com.mdi.task_manager", data.getMessage()) > 0)
                {
                    res = "BAD";
                }

                RepositoryFactory.Instance.DeviceDb.Save(device);
            }
            else
                res = "Device does not exists";
            return Json(res);
        }
        public JsonResult SendMessage(string asset, string environment, string account, string token, string message)
        {
            string res = "OK";
            Session["MsgDate"] = null;

            MD.CloudConnect.CloudConnect cc = new MD.CloudConnect.CloudConnect(environment, account, token);

            if (cc.Message.PostMessage(asset, "com.mdi.applications.message", message) > 0)
            {
                res = "BAD";
            }

            List<MessageData> messages = cc.Message.Get("asset:" + asset);
            foreach (MessageData msg in messages)
            {
                if (msg.Channel == "com.mdi.applications.message" && msg.Asset == asset && msg.Sender != asset)
                {
                    Session["MsgDate"] = msg.Received_at;
                    break;
                }
            }

            return Json(res, JsonRequestBehavior.AllowGet);
        }