Exemplo n.º 1
0
        private void LoadOnvifCameras()
        {
            string cameraIdsConcatString = GetValue(OnvifCameraIds, string.Empty);
            var    cameraIds             = cameraIdsConcatString.Split(idsSeparator);

            foreach (var cameraId in cameraIds)
            {
                if (string.IsNullOrWhiteSpace(cameraId))
                {
                    continue;
                }

                try
                {
                    onvifCameras.Add(cameraId, new OnvifCameraSetting(cameraId,
                                                                      GetValue(nameof(OnvifCameraSetting.Name), string.Empty, cameraId),
                                                                      GetValue(nameof(OnvifCameraSetting.CameraHost), string.Empty, cameraId),
                                                                      GetValue(nameof(OnvifCameraSetting.Login), string.Empty, cameraId),
                                                                      HS.DecryptString(GetValue(nameof(OnvifCameraSetting.Password), string.Empty, cameraId), nameof(HikCameraSetting.Password)),
                                                                      GetTimeSpanValue(nameof(OnvifCameraSetting.AlarmCancelInterval), TimeSpan.Zero, cameraId),
                                                                      GetValue(nameof(OnvifCameraSetting.SnapshotDownloadDirectory), string.Empty, cameraId)));
                }
                catch (Exception ex)
                {
                    Trace.TraceError(Invariant($"Failed to read config for {cameraId} with {ExceptionHelper.GetFullMessage(ex)}"));
                }
            }
        }
Exemplo n.º 2
0
        private void LoadHikvisionIsapiCameras()
        {
            string cameraIdsConcatString = GetValue(HikvisionIsapiCameraIds, string.Empty);
            var    cameraIds             = cameraIdsConcatString.Split(idsSeparator);

            var periodicFetchedProperties = hikvisionIsapiCameraProperties.ToImmutableDictionary();

            foreach (var cameraId in cameraIds)
            {
                if (string.IsNullOrWhiteSpace(cameraId))
                {
                    continue;
                }

                try
                {
                    hikvisionIsapiCameras.Add(cameraId, new HikCameraSetting(cameraId,
                                                                             GetValue(nameof(HikCameraSetting.Name), string.Empty, cameraId),
                                                                             GetValue(nameof(HikCameraSetting.CameraHost), string.Empty, cameraId),
                                                                             GetValue(nameof(HikCameraSetting.Login), string.Empty, cameraId),
                                                                             HS.DecryptString(GetValue(nameof(HikCameraSetting.Password), string.Empty, cameraId), nameof(HikCameraSetting.Password)),
                                                                             GetTimeSpanValue(nameof(HikCameraSetting.AlarmCancelInterval), TimeSpan.Zero, cameraId),
                                                                             periodicFetchedProperties,
                                                                             GetTimeSpanValue(nameof(HikCameraSetting.CameraPropertiesRefreshInterval), TimeSpan.Zero, cameraId),
                                                                             GetValue(nameof(HikCameraSetting.SnapshotDownloadDirectory), string.Empty, cameraId),
                                                                             GetValue(nameof(HikCameraSetting.VideoDownloadDirectory), string.Empty, cameraId)));
                }
                catch (Exception ex)
                {
                    Trace.TraceError(Invariant($"Failed to read config for {cameraId} with {ExceptionHelper.GetFullMessage(ex)}"));
                }
            }
        }
Exemplo n.º 3
0
        public override void AddOrUpdateHSDeviceProperties()
        {
            Console.WriteLine("FIXME: Adding HS Device control status");
//            hsDevice.MISC_Set(HS, Enums.dvMISC.NO_LOG);
            hsDevice.MISC_Set(HS, Enums.dvMISC.SHOW_VALUES);

            hsDevice.set_Relationship(HS, Enums.eRelationship.Standalone);

            // Clear existing VSP
            HS.DeviceVSP_ClearAll(hsDevice.get_Ref(null), true);

            VSVGPairs.VSPair v = new VSVGPairs.VSPair(ePairStatusControl.Status);
            v.PairType               = VSVGPairs.VSVGPairType.SingleValue;
            v.Value                  = 0;
            v.Status                 = "Closed";
            v.Render                 = Enums.CAPIControlType.Button;
            v.Render_Location.Row    = 1;
            v.Render_Location.Column = 1;
            v.ControlUse             = ePairControlUse._Off;
            HS.DeviceVSP_AddPair(hsDevice.get_Ref(null), v);

            VSVGPairs.VSPair v2 = new VSVGPairs.VSPair(ePairStatusControl.Status);
            v2.PairType               = VSVGPairs.VSVGPairType.SingleValue;
            v2.Value                  = 1;
            v2.Status                 = "Open";
            v2.Render                 = Enums.CAPIControlType.Button;
            v2.Render_Location.Row    = 1;
            v2.Render_Location.Column = 2;
            v2.ControlUse             = ePairControlUse._On;
            HS.DeviceVSP_AddPair(hsDevice.get_Ref(null), v2);

            SaveConfiguration();
        }
        private NameValueCollection GetCurrentDeviceImportDevices()
        {
            HSHelper hsHelper         = new HSHelper(HS);
            var      deviceEnumerator = HS.GetDeviceEnumerator() as clsDeviceEnumeration;

            var currentDevices    = new NameValueCollection();
            var importDevicesData = pluginConfig.ImportDevicesData;

            do
            {
                DeviceClass device = deviceEnumerator.GetNext();
                if ((device != null) &&
                    (device.get_Interface(HS) != null) &&
                    (device.get_Interface(HS).Trim() == PlugInData.PlugInName))
                {
                    string address = device.get_Address(HS);

                    var childDeviceData = DeviceIdentifier.Identify(device);
                    if (childDeviceData != null)
                    {
                        if (pluginConfig.ImportDevicesData.TryGetValue(childDeviceData.DeviceId, out var importDeviceData))
                        {
                            currentDevices.Add(device.get_Ref(HS).ToString(CultureInfo.CurrentCulture), hsHelper.GetName(device));
                        }
                    }
                }
            } while (!deviceEnumerator.Finished);

            return(currentDevices);
        }
Exemplo n.º 5
0
        private Dictionary <int, TasmotaDevice> GetCurrentDevices()
        {
            var refIds = HS.GetRefsByInterface(PlugInData.PlugInId);

            var devices = new Dictionary <int, TasmotaDevice>();

            foreach (var refId in refIds)
            {
                combinedToken.Token.ThrowIfCancellationRequested();
                try
                {
                    var relationship = (ERelationship)HS.GetPropertyByRef(refId, EProperty.Relationship);

                    //data is stored in feature(child)
                    if (relationship == ERelationship.Device)
                    {
                        var deviceType = HSDeviceHelper.GetDeviceTypeFromPlugInData(HS, refId);

                        if (deviceType == TasmotaDevice.RootDeviceType)
                        {
                            TasmotaDevice importDevice = new TasmotaDevice(HS, refId, hostedMQTTServerDetails, combinedToken.Token);
                            devices.Add(refId, importDevice);
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Warn(Invariant($"{HSDeviceHelper.GetName(HS, refId)} has invalid plugin data load failed with {ex.GetFullMessage()}. Please recreate it."));
                }
            }

            return(devices);
        }
Exemplo n.º 6
0
        public MyPipeline(HSBuffer <byte> inBuf)
        {
            Input = inBuf;
            // For this lesson, we'll use a two-stage pipeline that sharpens
            // and then applies a look-up-table (LUT).

            // First we'll define the LUT. It will be a gamma curve.

            Lut[I] = HS.Cast <byte>(HS.Clamp(HSMath.Pow(I / 255.0f, 1.2f) * 255.0f, 0, 255));

            // Augment the input with a boundary condition.
            Padded[X, Y, C] = Input[HS.Clamp(X, 0, Input.Width - 1),
                                    HS.Clamp(Y, 0, Input.Height - 1), C];

            // Cast it to 16-bit to do the math.
            Padded16[X, Y, C] = HS.Cast <ushort>(Padded[X, Y, C]);

            // Next we sharpen it with a five-tap filter.
            Sharpen[X, Y, C] = (Padded16[X, Y, C] * 2 -
                                (Padded16[X - 1, Y, C] +
                                 Padded16[X, Y - 1, C] +
                                 Padded16[X + 1, Y, C] +
                                 Padded16[X, Y + 1, C]) / 4);

            // Then apply the LUT.
            Curved[X, Y, C] = Lut[Sharpen[X, Y, C]];
        }
Exemplo n.º 7
0
        public Mixolydian(string keyNote)
        {
            string note1, note2, note3, note4, note5, note6, note7, note8;

            WS ws = new WS();
            HS hs = new HS();

            //System.out.println("W W H W W H W");
            note1         = keyNote;
            this.dominant = note1;
            //intervalli1 = "W";
            note2 = ws.getScales(note1);

            //intervalli2 = "W";
            note3 = ws.getScales(note2);

            //intervalli3 = "H";
            note4      = hs.getScales(note3);
            this.tonic = note4;

            //intervalli4 = "W";
            note5 = ws.getScales(note4);

            //intervalli5 = "W";
            note6 = ws.getScales(note5);

            //intervalli6 = "H";
            note7       = hs.getScales(note6);
            this.subDom = note7;

            //intervalli7 = "W";
            note8 = ws.getScales(note7);

            this.mixolydianScale = note1 + "   " + note2 + "   " + note3 + "   " + note4 + "   " + note5 + "   " + note6 + "   " + note7 + "   " + note8;
        }
Exemplo n.º 8
0
 public void LogDebug(string message)
 {
     if (this.EnableDebug)
     {
         HS.WriteLog(this.Name, String.Format(CultureInfo.InvariantCulture, "Debug:{0}", message));
     }
 }
        private void KeepAliveSink(LifeTimeMonitor sender, object obj)
        {
            if (IdleTimeout == false)
            {
                return;
            }
            ArrayList RemoveList = new ArrayList();

            lock (SessionTable)
            {
                IDictionaryEnumerator en = SessionTable.GetEnumerator();
                while (en.MoveNext())
                {
                    if (((HTTPSession)en.Value).Monitor.IsTimeout())
                    {
                        RemoveList.Add(en.Value);
                    }
                }
            }
            foreach (HTTPSession HS in RemoveList)
            {
                HS.Close();
            }
            KeepAliveTimer.Add(false, 7);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Creates the HS device.
        /// </summary>
        /// <param name="parent">The data for parent of device.</param>
        /// <param name="rootDeviceData">The root device data.</param>
        /// <param name="deviceData">The device data.</param>
        /// <returns>New Device</returns>
        private DeviceClass CreateDevice([AllowNull] DeviceClass parent, [AllowNull] RootDeviceData rootDeviceData, DeviceDataBase deviceData)
        {
            if (rootDeviceData != null)
            {
                LogDebug(Invariant($"Creating {deviceData.Name} under {rootDeviceData.Name}"));
            }
            else
            {
                LogDebug(Invariant($"Creating Root {deviceData.Name}"));
            }

            DeviceClass device = null;
            int         refId  = HS.NewDeviceRef(rootDeviceData != null ? Invariant($"{rootDeviceData.Name} {deviceData.Name}") : deviceData.Name);

            if (refId > 0)
            {
                device = (DeviceClass)HS.GetDeviceByRef(refId);
                string address = rootDeviceData != null?CreateChildAddress(rootDeviceData.Name, deviceData.Name) : deviceData.Name;

                device.set_Address(HS, address);
                device.set_Device_Type_String(HS, deviceData.HSDeviceTypeString);
                var deviceType = new DeviceTypeInfo_m.DeviceTypeInfo();
                deviceType.Device_API  = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In;
                deviceType.Device_Type = deviceData.HSDeviceType;

                device.set_DeviceType_Set(HS, deviceType);
                device.set_Interface(HS, Name);
                device.set_InterfaceInstance(HS, string.Empty);
                device.set_Last_Change(HS, DateTime.Now);
                device.set_Location(HS, Name);
                var pairs = deviceData.StatusPairs;
                foreach (var pair in pairs)
                {
                    HS.DeviceVSP_AddPair(refId, pair);
                }

                var gPairs = deviceData.GraphicsPairs;
                foreach (var gpair in gPairs)
                {
                    HS.DeviceVGP_AddPair(refId, gpair);
                }

                device.MISC_Set(HS, Enums.dvMISC.STATUS_ONLY);
                device.MISC_Set(HS, Enums.dvMISC.SHOW_VALUES);
                device.MISC_Clear(HS, Enums.dvMISC.AUTO_VOICE_COMMAND);
                device.MISC_Clear(HS, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE);
                device.set_Status_Support(HS, false);

                if (parent != null)
                {
                    parent.set_Relationship(HS, Enums.eRelationship.Parent_Root);
                    device.set_Relationship(HS, Enums.eRelationship.Child);
                    device.AssociatedDevice_Add(HS, parent.get_Ref(HS));
                    parent.AssociatedDevice_Add(HS, device.get_Ref(HS));
                }
                deviceData.SetInitialData(HS, device);
            }

            return(device);
        }
Exemplo n.º 11
0
        public ChurchModes(string keyNote)
        {
            string note1, note2, note3, note4, note5, note6, note7;
            WS     ws = new WS();
            HS     hs = new HS();;

            // Find the new roots for the Curch Modes from the Major scale  W W H W W W H

            note1       = keyNote;
            this.ionian = keyNote;
            //intervalli1 = "W";
            note2       = ws.getScales(note1);
            this.dorian = note2;
            //intervalli1 = "W";
            note3         = ws.getScales(note2);
            this.phrygian = note3;
            //intervalli1 = "H";
            note4       = hs.getScales(note3);
            this.lydian = note4;
            //intervalli1 = "W";
            note5           = ws.getScales(note4);
            this.mixolydian = note5;
            //intervalli1 = "W";
            note6        = ws.getScales(note5);
            this.aeolian = note6;
            //intervalli1 = "W";
            note7        = ws.getScales(note6);
            this.locrian = note7;
        }
Exemplo n.º 12
0
    void calculateHighScore()
    {
        int score = sword.getScore();

        print("score set");
        for (int i = 0; i < 10; i++)
        {
            print("current lap " + i);
            print(HS.GetValue(i));

            if (score > ((HighScoreStruct)HS.GetValue(i)).getScore()) //check if current score is higher than the old score
            {
                scoreChanged      = true;
                activateTextField = true;
                //while (!submittedText) { }
                HighScoreStruct temp = new HighScoreStruct(stringToEdit, score);
                print("created new highscorestruct");
                HighScoreStruct temp2 = (HighScoreStruct)HS.GetValue(i);
                HS.SetValue(temp, i);

                for (int y = i + 1; y < 10; y++)
                {
                    temp = (HighScoreStruct)HS.GetValue(y);
                    HS.SetValue(temp2, y);
                    temp2 = temp;
                }
                i = 10;
            }
        }
    }
Exemplo n.º 13
0
        public override bool ActionConfigured(IPlugInAPI.strTrigActInfo actionInfo)
        {
            try
            {
                switch (actionInfo.TANumber)
                {
                case ActionRefreshTANumber:
                    if (actionInfo.DataIn != null)
                    {
                        RefreshDeviceAction refreshDeviceAction = ObjectSerialize.DeSerializeFromBytes(actionInfo.DataIn) as RefreshDeviceAction;
                        if ((refreshDeviceAction != null) && (refreshDeviceAction.DeviceRefId != 0))
                        {
                            return(HS.GetDeviceByRef(refreshDeviceAction.DeviceRefId) != null);
                        }
                    }

                    return(false);

                default:
                    return(base.ActionConfigured(actionInfo));
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(Invariant($"Failed to ActionConfigured with {ex.GetFullMessage()}"));
                return(false);
            }
        }
Exemplo n.º 14
0
        private HashSet <string> GetFIRSTForBranch(List <SubRulePart> branch)
        {
            HashSet <string> res = new HashSet <string>();

            if (branch.Count == 0)
            {
                res.Add(StringConstants.EmptyProduction);
            }
            foreach (SubRulePart srp in branch)
            {
                if (srp is SubRuleAction)
                {
                    continue;
                }
                HashSet <string> HS;
                if (srp is SubRuleComplexPart)
                {
                    HS = GetFIRSTforComplexSubRulePart(srp as SubRuleComplexPart);
                }
                else
                {
                    HS = GetFIRST(srp.Name);
                }
                res.UnionWith(HS);
                if (!HS.Contains(StringConstants.EmptyProduction))
                {
                    break;
                }
            }
            return(res);
        }
Exemplo n.º 15
0
        public override string ConfigDevice(int deviceId, [AllowNull] string user, int userRights, bool newDevice)
        {
            if (newDevice)
            {
                return(string.Empty);
            }

            try
            {
                var deviceClass = (DeviceClass)HS.GetDeviceByRef(deviceId);

                if (deviceClass.get_Interface(HS) == PlugInData.PlugInName)
                {
                    var deviceIdentifier = DeviceIdentifier.Identify(deviceClass);
                    if (deviceIdentifier != null)
                    {
                        return(configPage.GetDeviceImportTab(deviceIdentifier));
                    }
                }
                else
                {
                    return(configPage.GetDeviceHistoryTab(deviceId));
                }
                return(string.Empty);
            }
            catch (Exception ex)
            {
                LogError(Invariant($"ConfigDevice for {deviceId} With {ex.Message}"));
                return(string.Empty);
            }
        }
Exemplo n.º 16
0
        public IPAddress CalculateServerIPAddress()
        {
            // if there is override address, use it
            var overrideIPAddress = WebServerIPAddress;

            if ((overrideIPAddress != null) && (!overrideIPAddress.Equals(IPAddress.Any)))
            {
                return(overrideIPAddress);
            }

            var ipAddresses = GetIPv4Addresses(NetworkInterfaceType.Unknown, true, false);

            var hsAddress = IPAddress.Parse(HS.GetIPAddress());

            // if nothing is specified and hs address is in local addresses, us it
            if (ipAddresses.Contains(hsAddress))
            {
                return(hsAddress);
            }

            if (ipAddresses.Length == 0)
            {
                throw new IOException("No Local IP4 Address Found");
            }
            return(ipAddresses.First());
        }
Exemplo n.º 17
0
 public static void GenerateAll()
 {
     lock (_locker)
         try
         {
             HS.GetOrCreateSericeStatus(nameof(SmsGenerator));
             using (var unitOfWork = new UnitOfWork(XpoDefault.DataLayer))
             {
                 var allSchedule = unitOfWork.Query <DoSoSmsSchedule>().Where(x => x.IsActive && x.NextExecutionDate < DateTime.Now && x.ExpiredOn == null);
                 foreach (var item in allSchedule)
                 {
                     if (!HS.EnableSmsGenerator)
                     {
                         return;
                     }
                     item.GenerateMessages(unitOfWork);
                     item.GetNextExecutionDate();
                     unitOfWork.CommitChanges();
                 }
             }
         }
         catch (Exception ex)
         {
             HS.GetOrCreateSericeStatus(nameof(SmsGenerator), true);
             HS.CreateExceptionLog(ex.Message, ex.ToString(), 6);
         }
 }
        /// <summary>
        /// Gets the highscores, and resets them when erroneous or missing.
        /// </summary>
        /// <param name="difficulty">Easy, Medium, or Hard. (string)</param>
        /// <param name="difficultyHighScore">outputs High Score variable (string)</param>
        /// <param name="lblHighScoreDifficulty">Name of the label to set (Control)</param>
        public void GetHighScores(string difficulty, out string difficultyHighScore, Control lblHighScoreDifficulty)
        {
            double score;
            string scoreStr;

            // If no save file exists, create a new one with score = -1
            if (!File.Exists(difficulty + "HighScore.txt"))
            {
                StreamWriter HS;
                HS = File.CreateText(difficulty + "HighScore.txt");
                HS.WriteLine(-1);
                Thread.Sleep(50);
                HS.Close();
            }

            // else if file is empty, add new score = -2
            else if (new FileInfo(difficulty + "HighScore.txt").Length == 0)
            {
                StreamWriter HS;
                HS = File.AppendText(difficulty + "HighScore.txt");
                HS.WriteLine(-1);
                Thread.Sleep(50);
                HS.Close();
            }

            // if file contains non-numeric data, create new file with score = -3
            StreamReader HSR;

            HSR      = File.OpenText(difficulty + "HighScore.txt");
            scoreStr = HSR.ReadLine();
            Thread.Sleep(50);
            HSR.Close();
            try
            {
                score = double.Parse(scoreStr);
            }
            catch
            {
                StreamWriter HS;
                HS = File.CreateText(difficulty + "HighScore.txt");
                HS.WriteLine(-1);
                Thread.Sleep(50);
                HS.Close();
                score = -3;
            }

            // if score <= 0, display "N/A" as the high score.
            if (score <= 0)
            {
                difficultyHighScore         = "-1";
                lblHighScoreDifficulty.Text = "N/A";
            }

            // if score > 0, save as difficultyHighScore.
            else
            {
                difficultyHighScore         = score.ToString();
                lblHighScoreDifficulty.Text = score.ToString();
            }
        }
Exemplo n.º 19
0
        private void GetCurrentDevices()
        {
            var deviceEnumerator = HS.GetDeviceEnumerator() as clsDeviceEnumeration;

            if (deviceEnumerator == null)
            {
                throw new HspiException(Invariant($"{PluginData.PlugInName} failed to get a device enumerator from HomeSeer."));
            }

            string parentAddress = DeviceIdentifier.CreateRootAddress(rootDeviceId);

            do
            {
                DeviceClass device = deviceEnumerator.GetNext();
                if ((device != null) &&
                    (device.get_Interface(HS) != null) &&
                    (device.get_Interface(HS).Trim() == PluginData.PlugInName))
                {
                    string address = device.get_Address(HS);
                    if (address == parentAddress)
                    {
                        parentRefId = device.get_Ref(HS);
                    }
                    else if (address.StartsWith(parentAddress, StringComparison.Ordinal))
                    {
                        DeviceData childDeviceData = GetDeviceData(device);
                        if (childDeviceData != null)
                        {
                            currentChildDevices.Add(address, childDeviceData);
                        }
                    }
                }
            } while (!deviceEnumerator.Finished);
        }
        /// <summary>
        /// Resets the highscore save files, variables, and labels.
        /// </summary>
        private void ResetHighScores()
        {
            StreamWriter HS;

            HS = File.CreateText("EasyHighScore.txt");
            HS.WriteLine(0);
            Thread.Sleep(50);
            HS.Close();

            StreamWriter HS2;

            HS2 = File.CreateText("MediumHighScore.txt");
            HS2.WriteLine(0);
            Thread.Sleep(50);
            HS2.Close();

            StreamWriter HS3;

            HS3 = File.CreateText("HardHighScore.txt");
            HS3.WriteLine(0);
            Thread.Sleep(50);
            HS3.Close();

            StreamWriter HS4;

            HS4 = File.CreateText("CustomHighScore.txt");
            HS4.WriteLine(0);
            Thread.Sleep(50);
            HS4.Close();

            LoadHighScores();
        }
Exemplo n.º 21
0
        public override string InitIO(string port)
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
            Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-US");

            Config = new PluginConfig(HS);

            LogInfo("Initializing Elasticsearch plugin...");

            esManager = new ElasticsearchManager(HS, this);
            esManager.Initialize();
            Callback.RegisterEventCB(Enums.HSEvent.CONFIG_CHANGE, Name, "");
            Callback.RegisterEventCB(Enums.HSEvent.LOG, Name, "");
            Callback.RegisterEventCB(Enums.HSEvent.SETUP_CHANGE, Name, "");
            Callback.RegisterEventCB(Enums.HSEvent.STRING_CHANGE, Name, "");
            Callback.RegisterEventCB(Enums.HSEvent.GENERIC, Name, "");

            string link = ConfigPage.Name;

            HS.RegisterPage(link, Name, string.Empty);

            HomeSeerAPI.WebPageDesc wpd = new HomeSeerAPI.WebPageDesc
            {
                plugInName = Name,
                link       = link,
                linktext   = "Configuration",
                page_title = $"{Name} Configuration"
            };
            Callback.RegisterConfigLink(wpd);
            Callback.RegisterLink(wpd);

            LogInfo("Initialization Complete!");
            return("");
        }
Exemplo n.º 22
0
        public static void SendAll()
        {
            lock (_locker)
                try
                {
                    HS.GetOrCreateSericeStatus(nameof(MailSender));
                    using (var unitOfWork = new UnitOfWork(XpoDefault.DataLayer))
                    {
                        var allMessage2Send = unitOfWork.Query <DoSoEmail>().Where(x => x.Status == BusinessObjects.Base.DoSoMessageBase.MessageStatusEnum.Active && x.ExpiredOn == null && x.SendingDate < DateTime.Now && (x.DoSoReportSchedule == null || x.DoSoReportSchedule.IsActive));

                        foreach (var message2Send in allMessage2Send)
                        {
                            if (!HS.EnableMailSender)
                            {
                                return;
                            }
                            Send(message2Send, unitOfWork);
                            unitOfWork.CommitChanges();
                        }
                    }
                }
                catch (Exception ex)
                {
                    HS.GetOrCreateSericeStatus(nameof(MailSender), true);
                    HS.CreateExceptionLog(ex.Message, ex.ToString(), 6);
                }
        }
Exemplo n.º 23
0
        public override string PostBackProc(string page, string data, string user, int userRights)
        {
            HS.WriteLog("Debug", "PostBackProc page name " + page + " by user " + user + " with rights " + userRights);
            if (page != "WebSocketNotificationConfig")
            {
                return("Unknown page " + page);
            }

            if ((userRights & 2) != 2)
            {
                // User is not an admin
                return("Access denied: you are not an administrative user.");
            }

            try
            {
                NameValueCollection postData = HttpUtility.ParseQueryString(data);

                string port = postData.Get("WebSocketPort");

                HS.SaveINISetting("Config", "Port", port, IniFilename);
            }
            catch (Exception ex)
            {
                HS.WriteLog("Warn", ex.ToString());
            }

            return("");
        }
Exemplo n.º 24
0
        /// <summary>
        /// Gets the current devices for plugin from Homeseer
        /// </summary>
        /// <returns>Current devices for plugin</returns>
        /// <exception cref="HspiException"></exception>
        private IDictionary <string, DeviceClass> GetCurrentDevices()
        {
            var deviceEnumerator = HS.GetDeviceEnumerator() as clsDeviceEnumeration;

            if (deviceEnumerator == null)
            {
                throw new HspiException(Invariant($"{Name} failed to get a device enumerator from HomeSeer."));
            }

            var currentDevices = new Dictionary <string, DeviceClass>();

            do
            {
                CancellationToken.ThrowIfCancellationRequested();
                DeviceClass device = deviceEnumerator.GetNext();
                if ((device != null) &&
                    (device.get_Interface(HS) != null) &&
                    (device.get_Interface(HS).Trim() == Name))
                {
                    string address = device.get_Address(HS);
                    currentDevices.Add(address, device);
                }
            } while (!deviceEnumerator.Finished);
            return(currentDevices);
        }
Exemplo n.º 25
0
        private void GetCurrentDevices()
        {
            if (!(HS.GetDeviceEnumerator() is clsDeviceEnumeration deviceEnumerator))
            {
                throw new HspiException(Invariant($"{PluginData.PlugInName} failed to get a device enumerator from HomeSeer."));
            }

            string baseAddress = DeviceIdentifier.CreateDeviceIdSpecficAddress(CameraSettings.Id);

            do
            {
                DeviceClass device = deviceEnumerator.GetNext();
                if ((device != null) &&
                    (device.get_Interface(HS) != null) &&
                    string.Equals(device.get_Interface(HS).Trim(), PluginData.PlugInName, StringComparison.Ordinal))
                {
                    string address = device.get_Address(HS);
                    if (address.StartsWith(baseAddress, StringComparison.Ordinal))
                    {
                        var deviceData = GetDeviceData(device);
                        if (deviceData != null)
                        {
                            devices.Add(address, deviceData);
                            deviceData.OnPlugInLoad(HS, CameraSettings);

                            if (deviceData.IsRootDevice)
                            {
                                parentRefId = device.get_Ref(HS);
                            }
                        }
                    }
                }
            } while (!deviceEnumerator.Finished);
        }
Exemplo n.º 26
0
        public override void SetIOMulti(List <CAPI.CAPIControl> colSend)
        {
            foreach (var control in colSend)
            {
                try
                {
                    int         refId       = control.Ref;
                    DeviceClass deviceClass = (DeviceClass)HS.GetDeviceByRef(refId);

                    var deviceIdentifier = DeviceIdentifier.Identify(deviceClass);

                    lock (connectorManagerLock)
                    {
                        if (connectorManager.TryGetValue(deviceIdentifier.DeviceId, out var connector))
                        {
                            connector.HandleCommand(deviceIdentifier, control.ControlValue, control.ControlUse).Wait();
                        }
                        else
                        {
                            throw new HspiException(Invariant($"{refId} Device Not Found for processing."));
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogError(Invariant($"Failed With {ExceptionHelper.GetFullMessage(ex)}"));
                }
            }
        }
Exemplo n.º 27
0
 private void Main_FormClosed(object sender, FormClosedEventArgs e)
 {
     HSession[] HSs = Program.Connections.Keys.ToArray();
     foreach (HSession HS in HSs)
     {
         HS.Disconnect();
     }
 }
Exemplo n.º 28
0
        public override void AddOrUpdateHSDeviceProperties()
        {
            Console.WriteLine("FIXME: Adding HS Device control status");
//            hsDevice.MISC_Set(HS, Enums.dvMISC.NO_LOG);
            hsDevice.MISC_Set(HS, Enums.dvMISC.SHOW_VALUES);

            hsDevice.set_Relationship(HS, Enums.eRelationship.Standalone);

            // Clear existing VSP
            HS.DeviceVSP_ClearAll(hsDevice.get_Ref(null), true);

            VSVGPairs.VSPair v = new VSVGPairs.VSPair(ePairStatusControl.Status);
            v.PairType = VSVGPairs.VSVGPairType.Range;
            var vg = new HomeSeerAPI.VSVGPairs.VGPair();

            vg.PairType = VSVGPairs.VSVGPairType.Range;
            //v.ControlStatus = ePairStatusControl.Status;
            //v.ControlUse = ePairControlUse.
            v.RangeStatusSuffix = " C";


            v.RangeStart          = -50;
            v.RangeEnd            = 100;
            v.RangeStatusDecimals = 2;

            vg.RangeStart = -50;
            vg.RangeEnd   = 100;
            vg.Graphic    = "/images/HomeSeer/status/Thermometer-50.png";

            v.Render = Enums.CAPIControlType.ValuesRange;

            hsDevice.MISC_Clear(HS, Enums.dvMISC.SHOW_VALUES); // Should be set or not ?
            HS.DeviceVSP_AddPair(hsDevice.get_Ref(null), v);
            HS.DeviceVGP_AddPair(hsDevice.get_Ref(null), vg);

/*
 *          VSVGPairs.VSPair v = new VSVGPairs.VSPair(ePairStatusControl.Status);
 *          v.PairType = VSVGPairs.VSVGPairType.SingleValue;
 *          v.Value = 0;
 *          v.Status = "Closed";
 *          v.Render = Enums.CAPIControlType.Button;
 *          v.Render_Location.Row = 1;
 *          v.Render_Location.Column = 1;
 *          v.ControlUse = ePairControlUse._Off;
 *          HS.DeviceVSP_AddPair(hsDevice.get_Ref(null), v);
 *
 *          VSVGPairs.VSPair v2 = new VSVGPairs.VSPair(ePairStatusControl.Status);
 *          v2.PairType = VSVGPairs.VSVGPairType.SingleValue;
 *          v2.Value = 1;
 *          v2.Status = "Open";
 *          v2.Render = Enums.CAPIControlType.Button;
 *          v2.Render_Location.Row = 1;
 *          v2.Render_Location.Column = 2;
 *          v2.ControlUse = ePairControlUse._On;
 *          HS.DeviceVSP_AddPair(hsDevice.get_Ref(null), v2);
 */
            SaveConfiguration();
        }
Exemplo n.º 29
0
 protected void SetValue <T>(string key, T value, ref T oldValue, string section)
 {
     if (!object.Equals(value, oldValue))
     {
         string stringValue = System.Convert.ToString(value, CultureInfo.InvariantCulture);
         HS.SaveINISetting(section, key, stringValue, fileName: PlugInData.SettingFileName);
         oldValue = value;
     }
 }
Exemplo n.º 30
0
        public override void SpeakIn(int deviceId, string text, bool wait, [AllowNull] string host)
        {
            try
            {
                host = (host != null) ? host.Trim() : string.Empty;
                var hostsList = host.Split(',');

                IDictionary <string, ChromecastDevice> selectedDevices = new Dictionary <string, ChromecastDevice>();

                var chromecastDevices = pluginConfig.Devices;
                foreach (var individualHost in hostsList)
                {
                    var individualHostReal = individualHost.Trim();

                    if (string.IsNullOrWhiteSpace(host) || individualHostReal == "*" || individualHostReal == "*:*")
                    {
                        foreach (var chromecastDevice in chromecastDevices)
                        {
                            selectedDevices.Add(chromecastDevice);
                        }
                        break;
                    }
                    else
                    {
                        string name = individualHost.Split(':').FirstOrDefault();

                        foreach (var chromecastDevice in chromecastDevices)
                        {
                            string deviceName = chromecastDevice.Value.Name;
                            if (string.Compare(name, deviceName, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                selectedDevices.Add(deviceName, chromecastDevice.Value);
                            }
                        }
                    }
                }

                if (selectedDevices.Count > 0)
                {
                    Task speakTask = Speak(text, selectedDevices.Values);

                    if (wait)
                    {
                        speakTask.Wait(ShutdownCancellationToken);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.TraceWarning(Invariant($"Failed to Speak [{text}] With: {ex.GetFullMessage()}"));
            }

            if (pluginConfig.ForwardSpeach)
            {
                HS.SpeakProxy(deviceId, text, wait, host);
            }
        }
Exemplo n.º 31
0
 public LOGBRUSH(BS style)
 {
     this.lbStyle = style;
     this.lbColor = 0;
     this.lbHatch = HS.HS_HORIZONTAL;
 }
Exemplo n.º 32
0
 public LOGBRUSH(System.Drawing.Color color)
 {
     this.lbStyle = BS.BS_SOLID;
     this.lbColor = WindowsWrapper.ColorToCOLORREF(color);
     this.lbHatch = HS.HS_HORIZONTAL;
 }