Пример #1
0
        private static object UploadProcess(object userSpecific)
        {
            Notice("CloudLog UploadProcess Started");

            while (true)
            {
                CrestronEnvironment.AllowOtherAppsToRun();

                if (_linkDown && !_programEnding)
                {
                    Thread.Sleep(60000);
                }
                else if (!_linkDown)
                {
                    try
                    {
                        var entries = PendingLogs.Take(50);

                        try
                        {
#if DEBUG
                            //CrestronConsole.PrintLine("Updating autodiscovery query...");
#endif
                            var query = EthernetAutodiscovery.Query();

#if DEBUG
                            //CrestronConsole.PrintLine("Autodiscovery {0}", query);
#endif
                            if (query ==
                                EthernetAutodiscovery.eAutoDiscoveryErrors.AutoDiscoveryOperationSuccess)
                            {
                                var adresults = EthernetAutodiscovery.DiscoveredElementsList;
#if DEBUG
                                //CrestronConsole.PrintLine("Found {0} devivces:", adresults.Count);
#endif
                                foreach (var adresult in adresults)
                                {
                                    //CrestronConsole.PrintLine("{0}, {1}, {2}", adresult.IPAddress,
                                    //adresult.HostName, adresult.DeviceIdString);
                                }
                            }
#if DEBUG
                            //CrestronConsole.PrintLine("CloudLog uploading to cloud...");
#endif

                            var contents = Post("submit_logs", entries);
                            var data     = JObject.Parse(contents);
#if DEBUG
                            //CrestronConsole.PrintLine("CloudLog client response: {0}", data["status"].Value<string>());
#endif
                            var results = data["results"];
                            foreach (var id in results.Select(result => result["id"].Value <string>()))
                            {
                                InternalDictionary[id].CloudId = id;
                            }
                        }
                        catch (Exception e)
                        {
                            Error("Error with CloudLog upload process, {0}", e.Message);
                            if (_programEnding)
                            {
                                return(null);
                            }
                            CrestronConsole.PrintLine("CloudLog could not upload to cloud service. {0} items pending",
                                                      PendingLogs.Count);
                            Thread.Sleep(60000);
                        }
                    }
                    catch (Exception e)
                    {
                        ErrorLog.Error("Error in CloudLog.PostToCloudProcess, {1}", e.Message);
                    }
                }

                if (_programEnding)
                {
                    return(null);
                }

                if (PendingLogs.Count == 0)
                {
                    UploadEvent.Wait(60000);
                }
            }
        }
Пример #2
0
 public static AutoDiscoveryResults Query()
 {
     EthernetAutodiscovery.Query();
     return(new AutoDiscoveryResults(EthernetAutodiscovery.DiscoveredElementsList));
 }