/// <summary>
        /// Returns an OSAEObject with the specified name
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static OSAEObject GetObjectByName(string name)
        {
            MySqlCommand command = new MySqlCommand();
            DataSet      dataset = new DataSet();

            try
            {
                command.CommandText = "SELECT object_name, object_description, object_type, address, container_name, enabled, state_name, base_type, coalesce(time_in_state, 0) as time_in_state FROM osae_v_object WHERE object_name=@Name";
                command.Parameters.AddWithValue("@Name", name);
                dataset = OSAESql.RunQuery(command);

                if (dataset.Tables[0].Rows.Count > 0)
                {
                    OSAEObject obj = new OSAEObject(dataset.Tables[0].Rows[0]["object_name"].ToString(), dataset.Tables[0].Rows[0]["object_description"].ToString(), dataset.Tables[0].Rows[0]["object_type"].ToString(), dataset.Tables[0].Rows[0]["address"].ToString(), dataset.Tables[0].Rows[0]["container_name"].ToString(), int.Parse(dataset.Tables[0].Rows[0]["enabled"].ToString()));
                    obj.State.Value       = dataset.Tables[0].Rows[0]["state_name"].ToString();
                    obj.State.TimeInState = Convert.ToInt64(dataset.Tables[0].Rows[0]["time_in_state"]);
                    obj.BaseType          = dataset.Tables[0].Rows[0]["base_type"].ToString();

                    obj.Properties = OSAEObjectPropertyManager.GetObjectProperties(obj.Name);

                    obj.Methods = GetObjectMethods(obj.Name);

                    return(obj);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Logging.GetLogger().AddToLog("API - GetObjectByName (" + name + ")error: " + ex.Message, true);
                return(null);
            }
        }
 private void btnUpdate_Click(object sender, RoutedEventArgs e)
 {
     if (ValidateForm("Update"))
     {
         sWorkingName = cntrlName.Text;
         OSAE.OSAEObject obj = OSAEObjectManager.GetObjectByName(sOriginalName);
         //We call an object update here in case the Name was changed, then perform the updates against the New name
         OSAEObjectManager.ObjectUpdate(sOriginalName, sWorkingName, obj.Alias, obj.Description, obj.Type, obj.Address, obj.Container, obj.MinTrustLevel, obj.Enabled);
         string sName = cntrlName.Text;
         OSAEObjectManager.ObjectUpdate(sOriginalName, sName, "", sName, osaeControlType + " " + _pluginName, "", currentScreen, 30, true);
         OSAEObjectPropertyManager.ObjectPropertySet(sName, "Control Type", osaeControlType + " " + _pluginName, currentUser);
         OSAEObjectPropertyManager.ObjectPropertySet(sName, "Object Name", objectsComboBox.Text, currentUser);
         OSAEObjectPropertyManager.ObjectPropertySet(sName, "X", cntrlX.Text, currentUser);
         OSAEObjectPropertyManager.ObjectPropertySet(sName, "Y", cntrlY.Text, currentUser);
         OSAEObjectPropertyManager.ObjectPropertySet(sName, "ZOrder", cntrlZOrder.Text, currentUser);
         if (hasParams == true)
         {
             foreach (objParams op in oParams)
             {
                 OSAEObjectPropertyManager.ObjectPropertySet(sName, op.Name, op.Value, currentUser);
             }
         }
         OSAEScreenControlManager.ScreenObjectUpdate(currentScreen, objectsComboBox.Text, sName);
         NotifyParentFinished();
     }
     // else
     // {
     // Do not save until feilds are correct
     //  }
 }
 // Code to Initialize your custom User Control
 public CustomUserControl(OSAEObject sObj, string ControlName)
 {
     InitializeComponent();
     _controlname = ControlName;
     screenObject = sObj;
     _mjpeg = new MjpegDecoder();
     _mjpeg.FrameReady += mjpeg_FrameReady;
     _mjpeg.Error += _mjpeg_Error;
     var imgsWidth = OSAEObjectPropertyManager.GetObjectPropertyValue(sObj.Property("Object Name").Value, "Width").Value;
     var imgsHeight = OSAEObjectPropertyManager.GetObjectPropertyValue(sObj.Property("Object Name").Value, "Height").Value;
     streamURI = OSAEObjectPropertyManager.GetObjectPropertyValue(sObj.Property("Object Name").Value, "Stream Address").Value;
     if (imgsWidth != "") { imgWidth = Convert.ToDouble(imgsWidth); }
     if (imgsHeight != "") { imgHeight = Convert.ToDouble(imgsHeight); }
     this.Width = imgWidth;
     this.Height = imgHeight;
     image.Width = imgWidth;
     image.Height = imgHeight;
     if (streamURI == null)
     {
         this.Log.Error("Stream Path Not Found: " + streamURI);
         message.Content = "Can Not Open: " + streamURI;
     }
     else
     {
         streamURI = renameingSys(streamURI);
         this.Log.Info("Streaming: " + streamURI);
         _mjpeg.ParseStream(new Uri(streamURI));
     }
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        ObjectName = screenObject.Property("Object Name").Value;
        hdnObjName.Value = ObjectName;
        CurState = OSAEObjectStateManager.GetObjectStateValue(ObjectName).Value;
        cObj = OSAEObjectManager.GetObjectByName(ObjectName);
        hdnCurState.Value = CurState;
        LastStateChange = OSAEObjectStateManager.GetObjectStateValue(ObjectName).LastStateChange;

        foreach (OSAEObjectProperty p in screenObject.Properties)
        {
            if (p.Value.ToLower() == CurState.ToLower()) StateMatch = p.Name.Substring(0, p.Name.LastIndexOf(' '));
        }

        try { LightLevel = Convert.ToUInt16(OSAEObjectPropertyManager.GetObjectPropertyValue(ObjectName, "Light Level").Value); }
        catch { LightLevel = 100.00; }

        string imgName = screenObject.Property(StateMatch + " Image").Value;
        OSAEImage img = imgMgr.GetImage(imgName);

        if (img != null)
        {
            bool x = File.Exists(OSAE.Common.ApiPath + "/Plugins/Web Server/wwwroot/Images/" + img.Name + ".gif");
            if (x == false) imgStateImage.ImageUrl = "~/ImageHandler.ashx?id=" + img.ID;
            else imgStateImage.ImageUrl = "~/Images/" + imgName + ".gif";
            imgStateImage.Attributes.Add("Style", "position:absolute;top:" + (Int32.Parse(screenObject.Property(StateMatch + " Y").Value) + 50).ToString() + "px;left:" + (Int32.Parse(screenObject.Property(StateMatch + " X").Value) + 10).ToString() + "px;z-index:" + (Int32.Parse(screenObject.Property("ZOrder").Value) + 10).ToString() + ";opacity:" + LightLevel / 100.00 + ";");
            imgStateImage.Attributes.Add("Alt", "~/Images/" + imgName + ".gif");
            imgStateImage.ToolTip = ObjectName + "\n" + CurState + " since: " + LastStateChange;

            //REPLACE THIS with code block in screens to use state match and not on/off!
            if (CurState == "ON") imgStateImage.Attributes.Add("onclick", "runMethod('" + ObjectName + "','OFF','','', " + cObj.MinTrustLevel + ");");
            else imgStateImage.Attributes.Add("onclick", "runMethod('" + ObjectName + "','ON','','', " + cObj.MinTrustLevel + ");");
        }
    }
Exemplo n.º 5
0
        public static void CreateComputerObject(string sourceName)
        {
            Logging.GetLogger().AddToLog("Creating Computer object", true);
            string computerIp = Common.GetComputerIP();

            if (OSAEObjectManager.GetObjectByName(Common.ComputerName) == null)
            {
                OSAEObject obj = OSAEObjectManager.GetObjectByAddress(computerIp);
                if (obj == null)
                {
                    OSAEObjectManager.ObjectAdd(Common.ComputerName, Common.ComputerName, Common.ComputerName, "COMPUTER", computerIp, string.Empty, true);
                    OSAEObjectPropertyManager.ObjectPropertySet(Common.ComputerName, "Host Name", Common.ComputerName, sourceName);
                }
                else if (obj.Type == "COMPUTER")
                {
                    OSAEObjectManager.ObjectUpdate(obj.Name, Common.ComputerName, obj.Alias, obj.Description, "COMPUTER", computerIp, obj.Container, obj.Enabled);
                    OSAEObjectPropertyManager.ObjectPropertySet(Common.ComputerName, "Host Name", Common.ComputerName, sourceName);
                }
                else
                {
                    OSAEObjectManager.ObjectAdd(Common.ComputerName + "." + computerIp, Common.ComputerName, Common.ComputerName, "COMPUTER", computerIp, string.Empty, true);
                    OSAEObjectPropertyManager.ObjectPropertySet(Common.ComputerName + "." + computerIp, "Host Name", Common.ComputerName, sourceName);
                }
            }
            else
            {
                OSAEObject obj = OSAEObjectManager.GetObjectByName(Common.ComputerName);
                OSAEObjectManager.ObjectUpdate(obj.Name, obj.Name, obj.Alias, obj.Description, "COMPUTER", computerIp, obj.Container, obj.Enabled);
                OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, "Host Name", Common.ComputerName, sourceName);
            }
        }
        /// <summary>
        /// Returns an OSAEObject with the specified name
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static OSAEObject GetObjectByName(string name)
        {
            MySqlCommand command = new MySqlCommand();
            DataSet dataset = new DataSet();

            try
            {
                command.CommandText = "SELECT object_name, object_description, object_type, address, container_name, enabled, state_name, base_type, coalesce(time_in_state, 0) as time_in_state FROM osae_v_object WHERE object_name=@Name";
                command.Parameters.AddWithValue("@Name", name);
                dataset = OSAESql.RunQuery(command);

                if (dataset.Tables[0].Rows.Count > 0)
                {
                    OSAEObject obj = new OSAEObject(dataset.Tables[0].Rows[0]["object_name"].ToString(), dataset.Tables[0].Rows[0]["object_description"].ToString(), dataset.Tables[0].Rows[0]["object_type"].ToString(), dataset.Tables[0].Rows[0]["address"].ToString(), dataset.Tables[0].Rows[0]["container_name"].ToString(), int.Parse(dataset.Tables[0].Rows[0]["enabled"].ToString()));
                    obj.State.Value = dataset.Tables[0].Rows[0]["state_name"].ToString();
                    obj.State.TimeInState = Convert.ToInt64(dataset.Tables[0].Rows[0]["time_in_state"]);
                    obj.BaseType = dataset.Tables[0].Rows[0]["base_type"].ToString();

                    obj.Properties = OSAEObjectPropertyManager.GetObjectProperties(obj.Name);

                    obj.Methods = GetObjectMethods(obj.Name);

                    return obj;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                Logging.GetLogger().AddToLog("API - GetObjectByName (" + name + ")error: " + ex.Message, true);
                return null;
            }
        }
Exemplo n.º 7
0
        // Authorize
        /// <summary>
        /// Decrypts an OSAE Security encrypted Authentication string, and compares trust level with the object being accessed.
        /// Used to verify User Trust in GET request
        /// </summary>
        /// <param name="authkey">An OSAE Security encrypted String</param>
        /// <param name="objName">The name of the OSAE Object being accessed</param>
        /// <returns>True or False, depending on criteria matches.</returns>
        public static Boolean Authorize(string authkey, string objName)
        {
            OSAEObject OSAEobj = OSAEObjectManager.GetObjectByName(objName);

            Log.Debug("OSAE Security is Decoding an AuthKey");
            Boolean auth             = false;
            int     uTrustLevel      = 0;
            string  decryptedAuthKey = DecryptString(authkey);

            string[] user = decryptedAuthKey.Split(':');
            try
            {
                OSAEObject ouser = OSAE.OSAEObjectManager.GetObjectByName(user[0]);
                Log.Debug("Found User: "******"Password").Value)
                {
                    DateTime authDate = new DateTime();
                    try
                    {
                        authDate = Convert.ToDateTime(user[1].Substring(0, 4) + "-" + user[1].Substring(4, 2) + "-" + user[1].Substring(6, 2) + " " + user[1].Substring(8, 2) + ":" + user[1].Substring(10, 2) + ":" + user[1].Substring(12, 2));
                    }
                    catch
                    {
                        Log.Debug("Could not resolve TimeStamp: FAILED");
                        return(auth);
                    }
                    Log.Debug("Auth Date and Time: " + authDate.ToString());
                    //DateTime nowAuth = DateTime.Now;
                    DateTime sDate = DateTime.Now.AddSeconds(timeSplit - (timeSplit * 2));
                    DateTime eDate = DateTime.Now.AddSeconds(timeSplit);
                    if (authDate > sDate && authDate < eDate)
                    {
                        uTrustLevel = Convert.ToInt32(OSAEObjectPropertyManager.GetObjectPropertyValue(ouser.Name, "Trust Level").Value);
                        if (uTrustLevel > OSAEobj.MinTrustLevel)
                        {
                            Log.Debug("Authintication: PASSED");
                            auth = true;
                        }
                        else
                        {
                            Log.Debug("Trust Level too low. Access denied!");
                        }
                    }
                    else
                    {
                        Log.Debug("Authintication: FAILED");
                    }
                }
                else
                {
                    Log.Debug("Authintication: FAILED");
                }
            }
            catch
            {
                Log.Debug("Authintication: FAILED");
            }
            return(auth);
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Load_App_Name();

            OSAE.OSAEObject tempAlias = OSAE.OSAEObjectManager.GetObjectByName(gSystemName);
            if (tempAlias.Alias.Length > 0)
            {
                gSystemName = tempAlias.Alias;
            }

            try
            {
                oRecognizer.SpeechRecognized  += new EventHandler <SpeechRecognizedEventArgs>(oRecognizer_SpeechRecognized);
                oRecognizer.AudioStateChanged += new EventHandler <AudioStateChangedEventArgs>(oRecognizer_StateChanged);
            }
            catch (Exception ex)
            {
                AddToLog("Unable to configure oRecognizer");
                AddToLog("Error: " + ex.Message);
            }

            Load_Settings();
            Common.CheckComputerObject(gAppName);
            oRecognizer = OSAEGrammar.Load_User_Grammar(oRecognizer);
            try
            {
                gSpeechPlugin = OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Can Hear this Plugin").Value.ToString();
                if (gSpeechPlugin == "")
                {
                    gSpeechPlugin = "Speech";
                    OSAEObjectPropertyManager.ObjectPropertySet(gAppName, "Can Hear this Plugin", "Speech", "VR Client");
                }
                AddToLog("--  I will ignore speech from: " + gSpeechPlugin);

                oRecognizer = OSAEGrammar.Load_Direct_Grammar(oRecognizer);
                oRecognizer = OSAEGrammar.Load_Voice_Grammars(oRecognizer);
                SaveGrammars();

                AddToLog("Finished Loading...");
                AddToLog("_______________________________________________");
                AddToLog("Who are you?");

                Thread t1 = new Thread(delegate()
                {
                    oRecognizer.SetInputToDefaultAudioDevice();
                    oRecognizer.RecognizeAsync(RecognizeMode.Multiple);
                    while (!gAppClosing)
                    {
                        Thread.Sleep(333);
                    }
                });
                t1.Start();
            }
            catch (Exception ex)
            {
                AddToLog("Unable to set Default Audio Device.  Check Sound Card.");
                AddToLog("Error: " + ex.Message);
            }
        }
        private void updateObjectCoordsStateImg(OSAE.OSAEObject obj, string state, string X, string Y)
        {
            OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, state + " X", X, "GUI");
            OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, state + " Y", Y, "GUI");

            obj.Property(state + " X").Value = X;
            obj.Property(state + " Y").Value = Y;
        }
        // Code to Initialize your custom User Control
        public CustomUserControl(OSAEObject sObj, string ControlName)
        {
            InitializeComponent();
            _controlname = ControlName;
            screenObject = sObj;

            //var imgsWidth = OSAEObjectPropertyManager.GetObjectPropertyValue(sObj.Property("Object Name").Value, "Width").Value;
            //var imgsHeight = OSAEObjectPropertyManager.GetObjectPropertyValue(sObj.Property("Object Name").Value, "Height").Value;
        }
 public CustomUserControl(OSAEObject sObj, string ControlName)
 {
     InitializeComponent();
     _controlname = ControlName;
     screenObject = sObj;
     System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
     dispatcherTimer.Tick += new EventHandler(timMain_Tick);
     dispatcherTimer.Interval = new TimeSpan(0, 30, 0);
     dispatcherTimer.Start();
     Load_All_Weather();
 }
Exemplo n.º 12
0
 public override void ProcessCommand(OSAEMethod method)
 {
     this.Log.Info("RECEIVED: " + method.ObjectName + " - " + method.MethodName);
     sMethod = method.MethodName;
     camName = method.ObjectName;
     camobj = OSAEObjectManager.GetObjectByName(camName);
     if (sMethod == "SNAPSHOT")
     {
         string i = DateTime.Now.ToLongTimeString();
         string j = DateTime.Now.ToShortDateString();
         i = i.Replace(":", "_");
         j = j.Replace("/", "_");
         i = j + "_" + i;
         i = i.Replace(" ", "");
         try
         {
             string camSnapShot = camobj.Property("camSnapShot").Value;
             string camSloc = camobj.Property("Save Location").Value;
             camSloc = camSloc + @"\";
             string filename = camSloc + camName + "_" + i + ".jpg";
             var URI = new Uri(renameingSys(camSnapShot, "",""));
             WebClient wc = new WebClient();
             wc.Headers["Content-Type"] = "application/x-www-form-urlencoded";
             wc.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCallback2);
             wc.DownloadFile(URI, filename);  
             this.Log.Info(filename + " was created");
         }
         catch (Exception ex)
         {
             this.Log.Error("An error occurred durning the snapshot!!!: " + ex.Message);
         }
     }
     else
     {
         try
         {
             WebClient wc = new WebClient();
             sProperty = camobj.Property(sMethod).Value.ToString();
             wc.Headers["Content-Type"] = "application/x-www-form-urlencoded";
             wc.UploadStringCompleted += new UploadStringCompletedEventHandler(UploadStringCallback2);
             sProperty = renameingSys(sProperty, method.Parameter1, method.Parameter2);
             wc.UploadStringAsync(new Uri(sProperty), "POST", "");
             this.Log.Info("SENT TO: " + method.ObjectName + ": " + sProperty);
         }
         catch (Exception ex)
         {
             this.Log.Error("An error occurred!!!: " + ex.Message);
         }
     }
     this.Log.Info("===================================================");
 }
        // Code to Initialize your custom User Control
        public CustomUserControl(OSAEObject sObj, string ControlName)
        {
            InitializeComponent();
            _controlname = ControlName;
            screenObject = sObj;
            objName = sObj.Property("Object Name").Value;
            CurState = OSAEObjectStateManager.GetObjectStateValue(objName).Value;
            LastStateChange = OSAEObjectStateManager.GetObjectStateValue(objName).LastStateChange;

            // Retreive any other information needed from the database here....

            // Execute the refreshControl function. See below!
            refreshControl();
        }
Exemplo n.º 14
0
        /// <summary>
        /// Decrypts an OSAE Security encrypted Authentication string.
        /// Used to verify User to use in POST request.
        /// </summary>
        /// <param name="authkey">An OSAE Security encrypted String</param>
        /// <returns>Returns the Username, if criteria matches</returns>
        public static string DecryptUser(string authkey)
        {
            Log.Info("OSAE Security is Decoding an AuthKey");
            string uName            = null;
            string decryptedAuthKey = DecryptString(authkey);

            string[] user = decryptedAuthKey.Split(':');
            try
            {
                OSAEObject ouser = OSAE.OSAEObjectManager.GetObjectByName(user[0]);
                Log.Debug("Found User: "******"Password").Value)
                {
                    DateTime authDate = new DateTime();
                    try
                    {
                        authDate = Convert.ToDateTime(user[1].Substring(0, 4) + "-" + user[1].Substring(4, 2) + "-" + user[1].Substring(6, 2) + " " + user[1].Substring(8, 2) + ":" + user[1].Substring(10, 2) + ":" + user[1].Substring(12, 2));
                    }
                    catch
                    {
                        Log.Debug("Could not resolve TimeStamp: FAILED");
                        return(uName);
                    }
                    Log.Debug("Auth Date and Time: " + authDate.ToString());
                    //DateTime nowAuth = DateTime.Now;
                    DateTime sDate = DateTime.Now.AddSeconds(timeSplit - (timeSplit * 2));
                    DateTime eDate = DateTime.Now.AddSeconds(timeSplit);
                    if (authDate > sDate && authDate < eDate)
                    {
                        Log.Debug("Authintication: PASSED");
                        uName = ouser.Name;
                    }
                    else
                    {
                        Log.Debug("Authintication: FAILED");
                    }
                }
                else
                {
                    Log.Debug("Authintication: FAILED");
                }
            }
            catch
            {
                Log.Debug("Invalid Authintication key: FAILED");
            }
            return(uName);
        }
        public static OSAEAdmin GetAdminSettings()
        {
            OSAEAdmin  adSets  = new OSAEAdmin();
            OSAEObject oObject = OSAEObjectManager.GetObjectByName("WEB SERVER");

            adSets.ScreenTrust              = Convert.ToInt32(oObject.Property("Screen Trust").Value);
            adSets.defaultScreen            = Convert.ToString(oObject.Property("Screen Trust").Value);
            adSets.ObjectsTrust             = Convert.ToInt32(oObject.Property("Objects Trust").Value);
            adSets.ObjectsAddTrust          = Convert.ToInt32(oObject.Property("Objects Add Trust").Value);
            adSets.ObjectsUpdateTrust       = Convert.ToInt32(oObject.Property("Objects Update Trust").Value);
            adSets.ObjectsDeleteTrust       = Convert.ToInt32(oObject.Property("Objects Delete Trust").Value);
            adSets.AnalyticsTrust           = Convert.ToInt32(oObject.Property("Analytics Trust").Value);
            adSets.LogsTrust                = Convert.ToInt32(oObject.Property("Logs Trust").Value);
            adSets.LogsClearTrust           = Convert.ToInt32(oObject.Property("Logs Clear Trust").Value);
            adSets.EventLogTrust            = Convert.ToInt32(oObject.Property("Event Log Trust").Value);
            adSets.MethodLogTrust           = Convert.ToInt32(oObject.Property("Method Log Trust").Value);
            adSets.ServerLogTrust           = Convert.ToInt32(oObject.Property("Server Log Trust").Value);
            adSets.DebugLogTrust            = Convert.ToInt32(oObject.Property("Debug Log Trust").Value);
            adSets.ValuesTrust              = Convert.ToInt32(oObject.Property("Values Trust").Value);
            adSets.ManagementTrust          = Convert.ToInt32(oObject.Property("Management Trust").Value);
            adSets.ObjectTypeTrust          = Convert.ToInt32(oObject.Property("ObjectType Trust").Value);
            adSets.ObjectTypeAddTrust       = Convert.ToInt32(oObject.Property("ObjectType Add Trust").Value);
            adSets.ObjectTypeUpdateTrust    = Convert.ToInt32(oObject.Property("ObjectType Update Trust").Value);
            adSets.ObjectTypeDeleteTrust    = Convert.ToInt32(oObject.Property("ObjectType Delete Trust").Value);
            adSets.ScriptTrust              = Convert.ToInt32(oObject.Property("Script Trust").Value);
            adSets.ScriptAddTrust           = Convert.ToInt32(oObject.Property("Script Add Trust").Value);
            adSets.ScriptUpdateTrust        = Convert.ToInt32(oObject.Property("Script Update Trust").Value);
            adSets.ScriptDeleteTrust        = Convert.ToInt32(oObject.Property("Script Delete Trust").Value);
            adSets.ScriptObjectAddTrust     = Convert.ToInt32(oObject.Property("Script Object Add Trust").Value);
            adSets.ScriptObjectTypeAddTrust = Convert.ToInt32(oObject.Property("Script ObjectType Add Trust").Value);
            adSets.PatternTrust             = Convert.ToInt32(oObject.Property("Pattern Trust").Value);
            adSets.PatternAddTrust          = Convert.ToInt32(oObject.Property("Pattern Add Trust").Value);
            adSets.PatternUpdateTrust       = Convert.ToInt32(oObject.Property("Pattern Update Trust").Value);
            adSets.PatternDeleteTrust       = Convert.ToInt32(oObject.Property("Pattern Delete Trust").Value);
            adSets.ReaderTrust              = Convert.ToInt32(oObject.Property("Reader Trust").Value);
            adSets.ReaderAddTrust           = Convert.ToInt32(oObject.Property("Reader Add Trust").Value);
            adSets.ReaderUpdateTrust        = Convert.ToInt32(oObject.Property("Reader Update Trust").Value);
            adSets.ReaderDeleteTrust        = Convert.ToInt32(oObject.Property("Reader Delete Trust").Value);
            adSets.ScheduleTrust            = Convert.ToInt32(oObject.Property("Schedule Trust").Value);
            adSets.ScheduleAddTrust         = Convert.ToInt32(oObject.Property("Schedule Add Trust").Value);
            adSets.ScheduleUpdateTrust      = Convert.ToInt32(oObject.Property("Schedule Update Trust").Value);
            adSets.ScheduleDeleteTrust      = Convert.ToInt32(oObject.Property("Schedule Delete Trust").Value);
            adSets.ImagesTrust              = Convert.ToInt32(oObject.Property("Images Trust").Value);
            adSets.ImagesAddTrust           = Convert.ToInt32(oObject.Property("Images Add Trust").Value);
            adSets.ImagesDeleteTrust        = Convert.ToInt32(oObject.Property("Images Delete Trust").Value);
            adSets.ConfigTrust              = Convert.ToInt32(oObject.Property("Config Trust").Value);
            return(adSets);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Returns a Dataset of all objects in a specified container
        /// </summary>
        /// <param name="ContainerName"></param>
        /// <returns></returns>
        public static OSAEObjectCollection GetObjectsByContainer(string ContainerName)
        {
            MySqlCommand         command = new MySqlCommand();
            DataSet              dataset = new DataSet();
            OSAEObject           obj     = new OSAEObject();
            OSAEObjectCollection objects = new OSAEObjectCollection();

            try
            {
                if (ContainerName == string.Empty)
                {
                    command.CommandText = "SELECT object_name, object_alias, object_description, object_type, address, container_name, enabled, state_name, base_type, coalesce(time_in_state, 0) as time_in_state, last_updated FROM osae_v_object WHERE container_name is null ORDER BY object_name ASC";
                }
                else
                {
                    command.CommandText = "SELECT object_name, object_alias, object_description, object_type, address, container_name, enabled, state_name, base_type, coalesce(time_in_state, 0) as time_in_state, last_updated FROM osae_v_object WHERE container_name=@ContainerName AND enabled = 1 ORDER BY object_name ASC";
                    command.Parameters.AddWithValue("@ContainerName", ContainerName);
                }

                dataset = OSAESql.RunQuery(command);
                if (dataset.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in dataset.Tables[0].Rows)
                    {
                        obj                   = new OSAEObject(dr["object_name"].ToString(), dr["object_alias"].ToString(), dr["object_description"].ToString(), dr["object_type"].ToString(), dr["address"].ToString(), dr["container_name"].ToString(), int.Parse(dr["enabled"].ToString()));
                        obj.State.Value       = dr["state_name"].ToString();
                        obj.State.TimeInState = Convert.ToInt64(dr["time_in_state"]);
                        obj.BaseType          = dr["base_type"].ToString();
                        obj.LastUpd           = dr["last_updated"].ToString();
                        obj.Properties        = OSAEObjectPropertyManager.GetObjectProperties(obj.Name);
                        obj.Methods           = GetObjectMethods(obj.Name);
                        objects.Add(obj);
                    }

                    return(objects);
                }

                return(objects);
            }
            catch (Exception ex)
            {
                Logging.GetLogger().AddToLog("API - GetObjectsByContainer error: " + ex.Message, true);
                return(objects);
            }
        }
Exemplo n.º 17
0
        // Creates a current Authentication Key for the current user and timestamp.
        /// <summary>
        /// Creates a current Authentication Key for the current user and timestamp.
        /// </summary>
        /// <param name="currentUser">The name of the user to use for Authentication.</param>
        /// <returns>Returns a 64bit Encrypted Authentication Key</returns>
        public static string generateCurrentAuthKey(string currentUser)
        {
            OSAEObject cUser     = OSAE.OSAEObjectManager.GetObjectByName(currentUser);
            string     uname     = cUser.Name;
            string     uPass     = OSAE.OSAEObjectPropertyManager.GetObjectPropertyValue(uname, "Password").Value;
            DateTime   authDate  = DateTime.Now;
            string     authMonth = authDate.Month.ToString();

            if (authMonth.Length < 2)
            {
                authMonth = "0" + authMonth;
            }
            string authYear = authDate.Year.ToString();
            string authDay  = authDate.Day.ToString();

            if (authDay.Length < 2)
            {
                authDay = "0" + authDay;
            }
            string authHour = authDate.Hour.ToString();

            if (authHour.Length < 2)
            {
                authHour = "0" + authHour;
            }
            string authMin = authDate.Minute.ToString();

            if (authMin.Length < 2)
            {
                authMin = "0" + authMin;
            }
            string authSec = authDate.Second.ToString();

            if (authSec.Length < 2)
            {
                authSec = "0" + authSec;
            }
            string timeStamp    = authYear + "" + authMonth + "" + authDay + "" + authHour + "" + authMin + "" + authSec;
            string userPassDate = EncryptString(uname + ":" + timeStamp + ":" + uPass);

            return(userPassDate);
        }
        public static OSAEObjectCollection GetObjectsByOwner(string ObjectOwner)
        {
            OSAEObjectCollection objects = new OSAEObjectCollection();

            try
            {
                using (MySqlCommand command = new MySqlCommand())
                {
                    DataSet    dataset = new DataSet();
                    OSAEObject obj     = new OSAEObject();

                    command.CommandText = "SELECT object_name, object_description, object_type, address, container_name, enabled, state_name, base_type, coalesce(time_in_state, 0) as time_in_state FROM osae_v_object WHERE owned_by=@ObjectOwner";
                    command.Parameters.AddWithValue("@ObjectOwner", ObjectOwner);
                    dataset = OSAESql.RunQuery(command);

                    if (dataset.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow dr in dataset.Tables[0].Rows)
                        {
                            obj                   = new OSAEObject(dr["object_name"].ToString(), dr["object_description"].ToString(), dr["object_type"].ToString(), dr["address"].ToString(), dr["container_name"].ToString(), int.Parse(dr["enabled"].ToString()));
                            obj.State.Value       = dr["state_name"].ToString();
                            obj.State.TimeInState = Convert.ToInt64(dr["time_in_state"]);
                            obj.BaseType          = dr["base_type"].ToString();

                            obj.Properties = OSAEObjectPropertyManager.GetObjectProperties(obj.Name);
                            obj.Methods    = GetObjectMethods(obj.Name);
                            objects.Add(obj);
                        }

                        return(objects);
                    }
                }

                return(objects);
            }
            catch (Exception ex)
            {
                Logging.GetLogger().AddToLog("API - GetObjectsByBaseType error: " + ex.Message, true);
                return(objects);
            }
        }
        /// <summary>
        /// Returns an OSAEObject with the specified property
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static OSAEObjectCollection GetObjectsByPropertyValue(string property, string value)
        {
            MySqlCommand         command = new MySqlCommand();
            DataSet              dataset = new DataSet();
            OSAEObject           obj     = new OSAEObject();
            OSAEObjectCollection objects = new OSAEObjectCollection();

            try
            {
                command.CommandText = "SELECT object_name, object_alias, object_description, object_type, address, container_name, min_trust_level, enabled, state_name, base_type, coalesce(time_in_state, 0) as time_in_state, last_updated FROM osae_v_object_property WHERE property_name=@Property AND UPPER(property_value) = UPPER(@Value)";
                command.Parameters.AddWithValue("@Property", property);
                command.Parameters.AddWithValue("@Value", value);
                dataset = OSAESql.RunQuery(command);

                if (dataset.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in dataset.Tables[0].Rows)
                    {
                        obj                   = new OSAEObject(dataset.Tables[0].Rows[0]["object_name"].ToString(), dataset.Tables[0].Rows[0]["object_alias"].ToString(), dataset.Tables[0].Rows[0]["object_description"].ToString(), dataset.Tables[0].Rows[0]["object_type"].ToString(), dataset.Tables[0].Rows[0]["address"].ToString(), dataset.Tables[0].Rows[0]["container_name"].ToString(), Convert.ToUInt16(dataset.Tables[0].Rows[0]["min_trust_level"].ToString()), (dataset.Tables[0].Rows[0]["enabled"].ToString() != "0"));
                        obj.State.Value       = dataset.Tables[0].Rows[0]["state_name"].ToString();
                        obj.State.TimeInState = Convert.ToInt64(dataset.Tables[0].Rows[0]["time_in_state"]);
                        obj.BaseType          = dataset.Tables[0].Rows[0]["base_type"].ToString();
                        obj.LastUpd           = dataset.Tables[0].Rows[0]["last_updated"].ToString();
                        obj.Properties        = OSAEObjectPropertyManager.GetObjectProperties(obj.Name);
                        obj.Methods           = GetObjectMethods(obj.Name);
                        objects.Add(obj);
                    }
                    return(objects);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Logging.GetLogger().AddToLog("API - GetObjectByPropertyValue (" + property + ") error: " + ex.Message, true);
                return(null);
            }
        }
        /// <summary>
        /// Returns an OSAEObject with the specified address
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        public static OSAEObject GetObjectByAddress(string address)
        {
            OSAEObject obj = null;

            try
            {
                using (MySqlCommand command = new MySqlCommand())
                {
                    DataSet dataset = new DataSet();

                    command.CommandText = "SELECT object_name, object_alias, object_description, object_type, address, container_name, min_trust_level, enabled, state_name, base_type, coalesce(time_in_state, 0) as time_in_state, last_updated FROM osae_v_object WHERE address=@Address";
                    command.Parameters.AddWithValue("@Address", address);
                    dataset = OSAESql.RunQuery(command);

                    if (dataset.Tables[0].Rows.Count > 0)
                    {
                        obj                   = new OSAEObject(dataset.Tables[0].Rows[0]["object_name"].ToString(), dataset.Tables[0].Rows[0]["object_alias"].ToString(), dataset.Tables[0].Rows[0]["object_description"].ToString(), dataset.Tables[0].Rows[0]["object_type"].ToString(), dataset.Tables[0].Rows[0]["address"].ToString(), dataset.Tables[0].Rows[0]["container_name"].ToString(), Convert.ToInt16(dataset.Tables[0].Rows[0]["min_trust_level"].ToString()), (dataset.Tables[0].Rows[0]["enabled"].ToString() != "0"));
                        obj.State.Value       = dataset.Tables[0].Rows[0]["state_name"].ToString();
                        obj.State.TimeInState = Convert.ToInt64(dataset.Tables[0].Rows[0]["time_in_state"]);
                        obj.BaseType          = dataset.Tables[0].Rows[0]["base_type"].ToString();
                        obj.LastUpd           = dataset.Tables[0].Rows[0]["last_updated"].ToString();

                        obj.Properties = OSAEObjectPropertyManager.GetObjectProperties(obj.Name);
                        obj.Methods    = GetObjectMethods(obj.Name);
                        return(obj);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.GetLogger().AddToLog("API - GetObjectByAddress (" + address + ")error: " + ex.Message, true);
                return(obj);
            }
        }
        /// <summary>
        /// Returns an OSAEObject with the specified address
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        public static OSAEObject GetObjectByAddress(string address)
        {
            OSAEObject obj = null;

            try
            {
                using (MySqlCommand command = new MySqlCommand())
                {
                    DataSet dataset = new DataSet();

                    command.CommandText = "SELECT object_name, object_alias, object_description, object_type, address, container_name, min_trust_level, enabled, state_name, base_type, coalesce(time_in_state, 0) as time_in_state, last_updated FROM osae_v_object WHERE address=@Address";
                    command.Parameters.AddWithValue("@Address", address);
                    dataset = OSAESql.RunQuery(command);

                    if (dataset.Tables[0].Rows.Count > 0)
                    {
                        obj = new OSAEObject(dataset.Tables[0].Rows[0]["object_name"].ToString(), dataset.Tables[0].Rows[0]["object_alias"].ToString(), dataset.Tables[0].Rows[0]["object_description"].ToString(), dataset.Tables[0].Rows[0]["object_type"].ToString(), dataset.Tables[0].Rows[0]["address"].ToString(), dataset.Tables[0].Rows[0]["container_name"].ToString(), Convert.ToInt16(dataset.Tables[0].Rows[0]["min_trust_level"].ToString()), (dataset.Tables[0].Rows[0]["enabled"].ToString() != "0"));
                        obj.State.Value = dataset.Tables[0].Rows[0]["state_name"].ToString();
                        obj.State.TimeInState = Convert.ToInt64(dataset.Tables[0].Rows[0]["time_in_state"]);
                        obj.BaseType = dataset.Tables[0].Rows[0]["base_type"].ToString();
                        obj.LastUpd = dataset.Tables[0].Rows[0]["last_updated"].ToString();

                        obj.Properties = OSAEObjectPropertyManager.GetObjectProperties(obj.Name);
                        obj.Methods = GetObjectMethods(obj.Name);
                        return obj;
                    }
                    else
                        return null;
                }
            }
            catch (Exception ex)
            {
                Logging.GetLogger().AddToLog("API - GetObjectByAddress (" + address + ")error: " + ex.Message, true);
                return obj;
            }
        }
Exemplo n.º 22
0
        public static void CheckComputerObject(string sourceName)
        {
            Logging.GetLogger().AddToLog("Checking for Computer object", true);
            string computerIp = Common.GetComputerIP();

            if (OSAEObjectManager.GetObjectByName(Common.ComputerName) == null)
            {
                OSAEObject obj = OSAEObjectManager.GetObjectByAddress(computerIp);
                if (obj == null)
                {
                    Logging.GetLogger().AddToLog("Computer Object not found, creating it...", true);
                    OSAEObjectManager.ObjectAdd(Common.ComputerName, "", Common.ComputerName, "COMPUTER", computerIp, "", 30, true);
                    OSAEObjectPropertyManager.ObjectPropertySet(Common.ComputerName, "Host Name", Common.ComputerName, sourceName);
                    Logging.GetLogger().AddToLog("Computer Object created called: " + Common.ComputerName, true);
                }
                else if (obj.Type == "COMPUTER")
                {
                    Logging.GetLogger().AddToLog("Computer Object found under a different name, updating it...", true);
                    OSAEObjectManager.ObjectUpdate(obj.Name, Common.ComputerName, obj.Alias, obj.Description, "COMPUTER", computerIp, obj.Container, obj.MinTrustLevel, obj.Enabled);
                    OSAEObjectPropertyManager.ObjectPropertySet(Common.ComputerName, "Host Name", Common.ComputerName, sourceName);
                }
                else
                {
                    Logging.GetLogger().AddToLog("Computer Object found under a different Name and Object Type, updating it...", true);
                    OSAEObjectManager.ObjectAdd(Common.ComputerName, "", Common.ComputerName, "COMPUTER", computerIp, string.Empty, obj.MinTrustLevel, true);
                    OSAEObjectPropertyManager.ObjectPropertySet(Common.ComputerName + "." + computerIp, "Host Name", Common.ComputerName, sourceName);
                }
            }
            else
            {
                Logging.GetLogger().AddToLog("Computer Object found, updating it...", true);
                OSAEObject obj = OSAEObjectManager.GetObjectByName(Common.ComputerName);
                OSAEObjectManager.ObjectUpdate(obj.Name, obj.Name, obj.Alias, obj.Description, "COMPUTER", computerIp, obj.Container, obj.MinTrustLevel, obj.Enabled);
                OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, "Host Name", Common.ComputerName, sourceName);
            }
        }
        private void Update_Objects()
        {
            while (!closing)
            {
                if (!loadingScreen)
                {
                    bool oldCtrl = false;
                    logging.AddToLog("Entering Update_Objects", false);
                    List <OSAE.OSAEScreenControl> controls = OSAEScreenControlManager.GetScreenControls(gCurrentScreen);

                    foreach (OSAE.OSAEScreenControl newCtrl in controls)
                    {
                        oldCtrl = false;

                        #region CONTROL STATE IMAGE
                        if (newCtrl.ControlType == "CONTROL STATE IMAGE")
                        {
                            foreach (StateImage sImage in stateImages)
                            {
                                if (newCtrl.ControlName == sImage.screenObject.Name)
                                {
                                    if (newCtrl.LastUpdated != sImage.LastUpdated)
                                    {
                                        logging.AddToLog("Updating:  " + newCtrl.ControlName, false);
                                        sImage.LastUpdated = newCtrl.LastUpdated;
                                        sImage.Update();

                                        this.Dispatcher.Invoke((Action)(() =>
                                        {
                                            Canvas.SetLeft(sImage, sImage.Location.X);
                                            Canvas.SetTop(sImage, sImage.Location.Y);
                                        }));
                                        logging.AddToLog("Complete:  " + newCtrl.ControlName, false);
                                    }
                                    oldCtrl = true;
                                }
                            }
                        }
                        #endregion

                        #region CONTROL PROPERTY LABEL
                        else if (newCtrl.ControlType == "CONTROL PROPERTY LABEL")
                        {
                            foreach (PropertyLabel pl in propLabels)
                            {
                                if (newCtrl.ControlName == pl.screenObject.Name)
                                {
                                    if (newCtrl.LastUpdated != pl.LastUpdated)
                                    {
                                        logging.AddToLog("Updating:  " + newCtrl.ControlName, false);
                                        pl.LastUpdated = newCtrl.LastUpdated;
                                        pl.Update();
                                        logging.AddToLog("Complete:  " + newCtrl.ControlName, false);
                                    }
                                    oldCtrl = true;
                                }
                            }
                        }
                        #endregion

                        #region CONTROL TIMER LABEL
                        else if (newCtrl.ControlType == "CONTROL TIMER LABEL")
                        {
                            foreach (OSAE.UI.Controls.TimerLabel tl in timerLabels)
                            {
                                if (newCtrl.ControlName == tl.screenObject.Name)
                                {
                                    if (newCtrl.LastUpdated != tl.LastUpdated)
                                    {
                                        logging.AddToLog("Updating:  " + newCtrl.ControlName, false);
                                        tl.LastUpdated = newCtrl.LastUpdated;
                                        tl.Update();
                                        logging.AddToLog("Complete:  " + newCtrl.ControlName, false);
                                    }
                                    oldCtrl = true;
                                }
                            }
                        }
                        #endregion

                        #region CONTROL STATIC LABEL
                        else if (newCtrl.ControlType == "CONTROL STATIC LABEL")
                        {
                            foreach (OSAE.UI.Controls.StaticLabel sl in staticLabels)
                            {
                                if (newCtrl.ControlName == sl.screenObject.Name)
                                {
                                    oldCtrl = true;
                                }
                            }
                        }
                        #endregion

                        #region CONTROL NAVIGATION IMAGE
                        else if (newCtrl.ControlType == "CONTROL NAVIGATION IMAGE")
                        {
                            foreach (OSAE.UI.Controls.NavigationImage nav in navImages)
                            {
                                if (newCtrl.ControlName == nav.screenObject.Name)
                                {
                                    oldCtrl = true;
                                }
                            }
                        }
                        #endregion

                        #region CONTROL NAVIGATION IMAGE
                        else if (newCtrl.ControlType == "CONTROL METHOD IMAGE")
                        {
                            foreach (OSAE.UI.Controls.MethodImage method in methodImages)
                            {
                                if (newCtrl.ControlName == method.screenObject.Name)
                                {
                                    oldCtrl = true;
                                }
                            }
                        }
                        #endregion

                        #region CONTROL CAMERA VIEWER
                        else if (newCtrl.ControlType == "CONTROL CAMERA VIEWER")
                        {
                            foreach (OSAE.UI.Controls.VideoStreamViewer vsv in cameraViewers)
                            {
                                if (newCtrl.ControlName == vsv.screenObject.Name)
                                {
                                    oldCtrl = true;
                                }
                            }
                        }
                        #endregion

                        #region CONTROL USAER CONTROL
                        else if (newCtrl.ControlType == "USER CONTROL")
                        {
                            foreach (dynamic obj in userControls)
                            {
                                if (newCtrl.ControlName == obj.screenObject.Name)
                                {
                                    oldCtrl = true;
                                }
                            }
                        }
                        #endregion

                        if (!oldCtrl)
                        {
                            OSAE.OSAEObject obj = OSAEObjectManager.GetObjectByName(newCtrl.ControlName);
                            logging.AddToLog("Load new control: " + newCtrl.ControlName, false);
                            LoadControl(obj);
                        }
                    }
                    logging.AddToLog("Leaving Update_Objects", false);
                }
                System.Threading.Thread.Sleep(1000);
            }
        }
 public void InitializeMainCtrl(OSAEObject obj, string appName, string cuser)
 {
     MainCtrl = new CustomUserControl(obj, myName, appName, cuser);
 }
        /// <summary>
        /// Returns an OSAEObject with the specified property
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static OSAEObjectCollection GetObjectsByPropertyValue(string property, string value)
        {
            MySqlCommand command = new MySqlCommand();
            DataSet dataset = new DataSet();
            OSAEObject obj = new OSAEObject();
            OSAEObjectCollection objects = new OSAEObjectCollection();

            try
            {
                command.CommandText = "SELECT object_name, object_alias, object_description, object_type, address, container_name, min_trust_level, enabled, state_name, base_type, coalesce(time_in_state, 0) as time_in_state, last_updated FROM osae_v_object_property WHERE property_name=@Property AND UPPER(property_value) = UPPER(@Value)";
                command.Parameters.AddWithValue("@Property", property);
                command.Parameters.AddWithValue("@Value", value);
                dataset = OSAESql.RunQuery(command);

                if (dataset.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in dataset.Tables[0].Rows)
                    {
                        obj = new OSAEObject(dataset.Tables[0].Rows[0]["object_name"].ToString(), dataset.Tables[0].Rows[0]["object_alias"].ToString(), dataset.Tables[0].Rows[0]["object_description"].ToString(), dataset.Tables[0].Rows[0]["object_type"].ToString(), dataset.Tables[0].Rows[0]["address"].ToString(), dataset.Tables[0].Rows[0]["container_name"].ToString(), Convert.ToUInt16(dataset.Tables[0].Rows[0]["min_trust_level"].ToString()), (dataset.Tables[0].Rows[0]["enabled"].ToString() != "0"));
                        obj.State.Value = dataset.Tables[0].Rows[0]["state_name"].ToString();
                        obj.State.TimeInState = Convert.ToInt64(dataset.Tables[0].Rows[0]["time_in_state"]);
                        obj.BaseType = dataset.Tables[0].Rows[0]["base_type"].ToString();
                        obj.LastUpd = dataset.Tables[0].Rows[0]["last_updated"].ToString();
                        obj.Properties = OSAEObjectPropertyManager.GetObjectProperties(obj.Name);
                        obj.Methods = GetObjectMethods(obj.Name);
                        objects.Add(obj);
                    }
                    return objects;
                }
                else
                    return null;
            }
            catch (Exception ex)
            {
                Logging.GetLogger().AddToLog("API - GetObjectByPropertyValue (" + property + ") error: " + ex.Message, true);
                return null;
            }
        }
Exemplo n.º 26
0
        public List<OSAEObject> GetObjectsByOwner(string ObjectOwner)
        {
            MySqlCommand command = new MySqlCommand();
            DataSet dataset = new DataSet();
            OSAEObject obj = new OSAEObject();
            List<OSAEObject> objects = new List<OSAEObject>();
            try
            {
                command.CommandText = "SELECT object_name, object_description, object_type, address, container_name, enabled, state_name, base_type, coalesce(time_in_state, 0) as time_in_state FROM osae_v_object WHERE owned_by=@ObjectOwner";
                command.Parameters.AddWithValue("@ObjectOwner", ObjectOwner);
                dataset = RunQuery(command);

                if (dataset.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in dataset.Tables[0].Rows)
                    {
                        obj = new OSAEObject(dr["object_name"].ToString(), dr["object_description"].ToString(), dr["object_type"].ToString(), dr["address"].ToString(), dr["container_name"].ToString(), Int32.Parse(dr["enabled"].ToString()));
                        obj.State.Value = dr["state_name"].ToString();
                        obj.State.TimeInState = Convert.ToInt64(dr["time_in_state"]);
                        obj.BaseType = dr["base_type"].ToString();

                        obj.Properties = GetObjectProperties(obj.Name);
                        obj.Methods = GetObjectMethods(obj.Name);
                        objects.Add(obj);
                    }
                    return objects;
                }
                return objects;
            }
            catch (Exception ex)
            {
                logging.AddToLog("API - GetObjectsByBaseType error: " + ex.Message, true);
                return objects;
            }
        }
 public void InitializeMainCtrl(OSAEObject obj)
 {
     MainCtrl = new CustomUserControl(obj, myName);
 }
    private void LoadControl(OSAEObject obj)
    {
        #region State Image
        if (obj.Type == "CONTROL STATE IMAGE")
        {
            // Create instance of the UserControl SimpleControl
            ASP.ctrlStateImage ctrl = (ASP.ctrlStateImage)LoadControl("~/controls/ctrlStateImage.ascx");
            // Set the Public Properties
            ctrl.screenObject = OSAEObjectManager.GetObjectByName(obj.Name);
            UpdatePlaceholder.Controls.Add(ctrl);
            //stateImages.Add(ctrl);
        }
        #endregion

        #region Click Image
        else if (obj.Type == "CONTROL CLICK IMAGE")
        {
            // Create instance of the UserControl SimpleControl
            ASP.ctrlClickImage ctrl = (ASP.ctrlClickImage)LoadControl("~/controls/ctrlClickImage.ascx");
            // Set the Public Properties
            ctrl.screenObject = OSAEObjectManager.GetObjectByName(obj.Name);
            StaticPlaceholder.Controls.Add(ctrl);
        }
        #endregion

        #region Navigation Image
        else if (obj.Type == "CONTROL NAVIGATION IMAGE")
        {
            // Create instance of the UserControl SimpleControl
            ASP.ctrlNavigationImage ctrl = (ASP.ctrlNavigationImage)LoadControl("~/controls/ctrlNavigationImage.ascx");
            // Set the Public Properties
            ctrl.screenObject = OSAEObjectManager.GetObjectByName(obj.Name);
            StaticPlaceholder.Controls.Add(ctrl);
        }
        #endregion

        #region Property Label
        else if (obj.Type == "CONTROL PROPERTY LABEL")
        {
            // Create instance of the UserControl SimpleControl
            ASP.ctrlPropertyLabel ctrl = (ASP.ctrlPropertyLabel)LoadControl("~/controls/ctrlPropertyLabel.ascx");
            // Set the Public Properties
            ctrl.screenObject = OSAEObjectManager.GetObjectByName(obj.Name);
            UpdatePlaceholder.Controls.Add(ctrl);
        }
        #endregion

        #region Timer Label
        else if (obj.Type == "CONTROL TIMER LABEL")
        {
            // Create instance of the UserControl SimpleControl
            ASP.ctrlTimerLabel ctrl = (ASP.ctrlTimerLabel)LoadControl("~/controls/ctrlTimerLabel.ascx");
            // Set the Public Properties
            ctrl.screenObject = OSAEObjectManager.GetObjectByName(obj.Name);
            UpdatePlaceholder.Controls.Add(ctrl);
        }
        #endregion

        #region Camera Viewer
        else if (obj.Type == "CONTROL CAMERA VIEWER")
        {
            // Create instance of the UserControl SimpleControl
            ASP.ctrlEmbedded ctrl = (ASP.ctrlEmbedded)LoadControl("~/controls/ctrlEmbedded.ascx");
            // Set the Public Properties
            ctrl.screenObject = OSAEObjectManager.GetObjectByName(obj.Name);
            //ctrl.initialize();
            ctrl.Source = OSAEObjectManager.GetObjectByName(ctrl.screenObject.Property("Object Name").Value).Property("Stream Address").Value;
            ctrl.width = "400";
            ctrl.height = "300";
            StaticPlaceholder.Controls.Add(ctrl);
        }
        #endregion

        #region User Control
        else if (obj.BaseType == "USER CONTROL")
        {
            string sUCType = obj.Property("Control Type").Value;
            string ucName = sUCType.Replace("USER CONTROL ", "");
            // Create instance of the UserControl SimpleControl
            dynamic ctrl = LoadControl("~/controls/usercontrols/" + ucName + "/ctrlUserControl.ascx") as System.Web.UI.UserControl;
            // Set the Public Properties
            ctrl.screenObject = obj;
            ctrl.initialize();
            UpdatePlaceholder.Controls.Add(ctrl);
        }
        #endregion

        #region Browser Control
        else if (obj.Type == "CONTROL BROWSER")
        {
            // Create instance of the UserControl SimpleControl
            ASP.ctrlBrowser ctrl = (ASP.ctrlBrowser)LoadControl("~/controls/ctrlBrowser.ascx");
            // Set the Public Properties
            ctrl.screenObject = OSAEObjectManager.GetObjectByName(obj.Name);
            StaticPlaceholder.Controls.Add(ctrl);
        }
        #endregion
    }
        private void Load_All_Weather()
        {
            weatherObj = OSAEObjectManager.GetObjectByName("Weather");
            lblCurTemp.Content = weatherObj.Property("Temp").Value + "°";
            lblConditions.Content = weatherObj.Property("Today Forecast").Value;
            lblLastUpd.Content = weatherObj.Property("Last Updated").Value;

            LoadLows();
            LoadHighs();
            LoadDayLabels();
            LoadDaySummaryLabels();
            LoadNightSummaryLabels();
            LoadDates();
            LoadImageControls();

            lblForcast.Text = "";
        }
        public CustomUserControl(OSAEObject sObj, string ControlName, string appName, string user)
        {
            InitializeComponent();
            sizes[0] = 90;
            sizes[1] = 157;
            sizes[2] = 220;
            sizes[3] = 295;
            sizes[4] = 365;
            sizes[5] = 435;
            sizes[6] = 504;
            sizes[7] = 574;

            gAppName = appName;
            currentUser = user;
            _controlname = ControlName;
            screenObject = sObj;
            objName = sObj.Property("Object Name").Value;

            try
            {
                //ControlWidth = Convert.ToInt32(OSAEObjectPropertyManager.GetObjectPropertyValue(screenObject.Name, "Width").Value);
                ControlHeight = Convert.ToInt32(OSAEObjectPropertyManager.GetObjectPropertyValue(screenObject.Name, "Height").Value);
                maxDays = Convert.ToInt32(OSAEObjectPropertyManager.GetObjectPropertyValue(screenObject.Name, "Max Days").Value);
            }
            catch (Exception ex)
            { }

            string sBackColor = screenObject.Property("Back Color").Value;
            string sForeColor = screenObject.Property("Fore Color").Value;
            string iFontSize = screenObject.Property("Font Size").Value;
            string sFontName = screenObject.Property("Font Name").Value;
            bool minimized = Convert.ToBoolean( screenObject.Property("Minimized").Value);

            if (minimized)
            {
                sMode = "Min";
                this.Width = sizes[0];
                ControlWidth = sizes[0];
                OSAEObjectPropertyManager.ObjectPropertySet(screenObject.Name, "Width", sizes[0].ToString(), gAppName);
            }
            else
            {
                sMode = "Max";
                this.Width = sizes[maxDays];
                ControlWidth = sizes[maxDays];
                OSAEObjectPropertyManager.ObjectPropertySet(screenObject.Name, "Width", sizes[maxDays].ToString(), gAppName);
            }

            if (sBackColor != "")
            {
                try
                {
                    BrushConverter conv = new BrushConverter();
                    SolidColorBrush brush = conv.ConvertFromString(sBackColor) as SolidColorBrush;
                    this.Background = brush;
                }
                catch (Exception)
                { }
            }
            if (sForeColor != "")
            {
                try
                {
                    BrushConverter conv = new BrushConverter();
                    SolidColorBrush brush = conv.ConvertFromString(sForeColor) as SolidColorBrush;
                    lblCurTemp.Foreground = brush;
                    lblConditions.Foreground = brush;
                    lblDay1.Foreground = brush;
                    lblDay2.Foreground = brush;
                    lblDay3.Foreground = brush;
                    lblDay4.Foreground = brush;
                    lblDay5.Foreground = brush;
                    lblForcast.Foreground = brush;
                }
                catch (Exception)
                { }
            }
            if (iFontSize != "")
            {
                try
                {
                    lblConditions.FontSize = Convert.ToDouble(iFontSize);
                    lblDay1.FontSize = Convert.ToDouble(iFontSize) - 1;
                    lblDay2.FontSize = Convert.ToDouble(iFontSize) - 1;
                    lblDay3.FontSize = Convert.ToDouble(iFontSize) - 1;
                    lblDay4.FontSize = Convert.ToDouble(iFontSize) - 1;
                    lblDay5.FontSize = Convert.ToDouble(iFontSize) - 1;
                    lblDay6.FontSize = Convert.ToDouble(iFontSize) - 1;
                    lblDay7.FontSize = Convert.ToDouble(iFontSize) - 1;
                    lblForcast.FontSize = Convert.ToDouble(iFontSize);
                }
                catch (Exception)
                { }
            }
            if (sFontName != "")
            {
                try
                {
                    lblConditions.FontFamily = new FontFamily(sFontName);
                    lblDay1.FontFamily = new FontFamily(sFontName);
                    lblDay2.FontFamily = new FontFamily(sFontName);
                    lblDay3.FontFamily = new FontFamily(sFontName);
                    lblDay4.FontFamily = new FontFamily(sFontName);
                    lblDay5.FontFamily = new FontFamily(sFontName);
                    lblDay6.FontFamily = new FontFamily(sFontName);
                    lblDay7.FontFamily = new FontFamily(sFontName);
                    lblForcast.FontFamily = new FontFamily(sFontName);
                }
                catch (Exception)
                { }
            }

            System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
            dispatcherTimer.Tick += new EventHandler(timMain_Tick);
            dispatcherTimer.Interval = new TimeSpan(0, 30, 0);
            dispatcherTimer.Start();
            Load_All_Weather();
        }
        /// <summary>
        /// Returns a Dataset of all objects of specified type
        /// </summary>
        /// <param name="ObjectType"></param>
        /// <returns></returns>
        public static OSAEObjectCollection GetObjectsByType(string ObjectType)
        {
            DataSet dataset = new DataSet();
            OSAEObject obj = new OSAEObject();
            OSAEObjectCollection objects = new OSAEObjectCollection();

            using (MySqlCommand command = new MySqlCommand())
            {
                try
                {
                    command.CommandText = "SELECT object_name, object_description, object_type, address, container_name, enabled, state_name, base_type, coalesce(time_in_state, 0) as time_in_state FROM osae_v_object WHERE object_type=@ObjectType";
                    command.Parameters.AddWithValue("@ObjectType", ObjectType);
                    dataset = OSAESql.RunQuery(command);

                    if (dataset.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow dr in dataset.Tables[0].Rows)
                        {
                            obj = new OSAEObject(dr["object_name"].ToString(), dr["object_description"].ToString(), dataset.Tables[0].Rows[0]["object_type"].ToString(), dr["address"].ToString(), dr["container_name"].ToString(), int.Parse(dr["enabled"].ToString()));
                            obj.State.Value = dr["state_name"].ToString();
                            obj.State.TimeInState = Convert.ToInt64(dr["time_in_state"]);
                            obj.BaseType = dr["base_type"].ToString();
                            obj.Properties = OSAEObjectPropertyManager.GetObjectProperties(obj.Name);
                            obj.Methods = OSAEObjectManager.GetObjectMethods(obj.Name);
                            objects.Add(obj);
                        }
                        return objects;
                    }
                    return objects;
                }
                catch (Exception ex)
                {
                    Logging.GetLogger().AddToLog("API - GetObjectsByType error: " + ex.Message, true);
                    return objects;
                }
            }
        }
        private void LoadControl(OSAE.OSAEObject obj)
        {
            this.Dispatcher.Invoke((Action)(() =>
            {
                String sStateMatch = "";

                #region CONTROL STATE IMAGE
                if (obj.Type == "CONTROL STATE IMAGE")
                {
                    StateImage stateImageControl = new StateImage(obj);

                    foreach (OSAE.OSAEObjectProperty p in obj.Properties)
                    {
                        if (p.Value.ToLower() == stateImageControl.CurState.ToLower())
                        {
                            sStateMatch = p.Name.Substring(0, p.Name.LastIndexOf(' '));
                        }
                    }
                    int dZ = Int32.Parse(obj.Property("ZOrder").Value);
                    stateImageControl.Location.X = Double.Parse(obj.Property(sStateMatch + " X").Value);
                    stateImageControl.Location.Y = Double.Parse(obj.Property(sStateMatch + " Y").Value);
                    canGUI.Children.Add(stateImageControl);
                    Canvas.SetLeft(stateImageControl, stateImageControl.Location.X);
                    Canvas.SetTop(stateImageControl, stateImageControl.Location.Y);
                    Canvas.SetZIndex(stateImageControl, dZ);
                    stateImages.Add(stateImageControl);
                    controlTypes.Add(typeof(StateImage));
                    stateImageControl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                }
                #endregion

                #region CONTROL PROPERTY LABEL
                else if (obj.Type == "CONTROL PROPERTY LABEL")
                {
                    logging.AddToLog("Loading PropertyLabelControl: " + obj.Name, false);
                    PropertyLabel pl = new PropertyLabel(obj);
                    canGUI.Children.Add(pl);
                    int dZ = Int32.Parse(obj.Property("ZOrder").Value);
                    pl.Location.X = Double.Parse(obj.Property("X").Value);
                    pl.Location.Y = Double.Parse(obj.Property("Y").Value);
                    Canvas.SetLeft(pl, pl.Location.X);
                    Canvas.SetTop(pl, pl.Location.Y);
                    Canvas.SetZIndex(pl, dZ);
                    propLabels.Add(pl);
                    controlTypes.Add(typeof(PropertyLabel));
                    pl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                }
                #endregion

                #region CONTROL STATIC LABEL
                else if (obj.Type == "CONTROL STATIC LABEL")
                {
                    logging.AddToLog("Loading PropertyLabelControl: " + obj.Name, false);
                    OSAE.UI.Controls.StaticLabel sl = new OSAE.UI.Controls.StaticLabel(obj);
                    canGUI.Children.Add(sl);
                    int dZ = Int32.Parse(obj.Property("ZOrder").Value);
                    sl.Location.X = Double.Parse(obj.Property("X").Value);
                    sl.Location.Y = Double.Parse(obj.Property("Y").Value);
                    Canvas.SetLeft(sl, sl.Location.X);
                    Canvas.SetTop(sl, sl.Location.Y);
                    Canvas.SetZIndex(sl, dZ);
                    staticLabels.Add(sl);
                    controlTypes.Add(typeof(OSAE.UI.Controls.StaticLabel));
                    sl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                }
                #endregion

                #region CONTROL TIMER LABEL
                else if (obj.Type == "CONTROL TIMER LABEL")
                {
                    logging.AddToLog("Loading PropertyLabelControl: " + obj.Name, false);
                    OSAE.UI.Controls.TimerLabel tl = new OSAE.UI.Controls.TimerLabel(obj);
                    canGUI.Children.Add(tl);
                    int dZ = Int32.Parse(obj.Property("ZOrder").Value);
                    tl.Location.X = Double.Parse(obj.Property("X").Value);
                    tl.Location.Y = Double.Parse(obj.Property("Y").Value);
                    Canvas.SetLeft(tl, tl.Location.X);
                    Canvas.SetTop(tl, tl.Location.Y);
                    Canvas.SetZIndex(tl, dZ);
                    timerLabels.Add(tl);
                    controlTypes.Add(typeof(OSAE.UI.Controls.TimerLabel));
                    tl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                }
                #endregion

                #region CONTROL METHOD IMAGE
                else if (obj.Type == "CONTROL METHOD IMAGE")
                {
                    try
                    {
                        MethodImage methodImageControl = new MethodImage(obj);
                        canGUI.Children.Add(methodImageControl);

                        OSAE.OSAEObjectProperty pZOrder = obj.Property("ZOrder");
                        OSAE.OSAEObjectProperty pX = obj.Property("X");
                        OSAE.OSAEObjectProperty pY = obj.Property("Y");
                        Double dX = Convert.ToDouble(pX.Value);
                        Canvas.SetLeft(methodImageControl, dX);
                        Double dY = Convert.ToDouble(pY.Value);
                        Canvas.SetTop(methodImageControl, dY);
                        int dZ = Convert.ToInt32(pZOrder.Value);
                        Canvas.SetZIndex(methodImageControl, dZ);
                        methodImageControl.Location.X = dX;
                        methodImageControl.Location.Y = dY;
                        methodImages.Add(methodImageControl);
                        controlTypes.Add(typeof(MethodImage));
                        methodImageControl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (MySqlException myerror)
                    {
                        MessageBox.Show("GUI Error Load Navigation Image: " + myerror.Message);
                    }
                }
                #endregion

                #region CONTROL NAVIGATION IMAGE
                else if (obj.Type == "CONTROL NAVIGATION IMAGE")
                {
                    try
                    {
                        NavigationImage navImageControl = new NavigationImage(obj.Property("Screen").Value, obj);
                        navImageControl.MouseLeftButtonUp += new MouseButtonEventHandler(Navigaton_Image_MouseLeftButtonUp);
                        canGUI.Children.Add(navImageControl);

                        OSAE.OSAEObjectProperty pZOrder = obj.Property("ZOrder");
                        OSAE.OSAEObjectProperty pX = obj.Property("X");
                        OSAE.OSAEObjectProperty pY = obj.Property("Y");
                        Double dX = Convert.ToDouble(pX.Value);
                        Canvas.SetLeft(navImageControl, dX);
                        Double dY = Convert.ToDouble(pY.Value);
                        Canvas.SetTop(navImageControl, dY);
                        int dZ = Convert.ToInt32(pZOrder.Value);
                        Canvas.SetZIndex(navImageControl, dZ);
                        navImageControl.Location.X = dX;
                        navImageControl.Location.Y = dY;
                        navImages.Add(navImageControl);
                        controlTypes.Add(typeof(NavigationImage));
                        navImageControl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (MySqlException myerror)
                    {
                        MessageBox.Show("GUI Error Load Navigation Image: " + myerror.Message);
                    }
                }
                #endregion

                #region CONTROL CAMERA VIEWER
                else if (obj.Type == "CONTROL CAMERA VIEWER")
                {
                    try
                    {
                        string stream = OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Property("Object Name").Value, "Stream Address").Value;
                        VideoStreamViewer vsv = new VideoStreamViewer(stream, obj);
                        canGUI.Children.Add(vsv);
                        OSAE.OSAEObjectProperty pZOrder = obj.Property("ZOrder");
                        OSAE.OSAEObjectProperty pX = obj.Property("X");
                        OSAE.OSAEObjectProperty pY = obj.Property("Y");
                        Double dX = Convert.ToDouble(pX.Value);
                        Canvas.SetLeft(vsv, dX);
                        Double dY = Convert.ToDouble(pY.Value);
                        Canvas.SetTop(vsv, dY);
                        int dZ = Convert.ToInt32(pZOrder.Value);
                        Canvas.SetZIndex(vsv, dZ);
                        vsv.Location.X = dX;
                        vsv.Location.Y = dY;
                        cameraViewers.Add(vsv);
                        controlTypes.Add(typeof(VideoStreamViewer));
                        vsv.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (MySqlException myerror)
                    {
                        MessageBox.Show("GUI Error Load Camera Viewer: " + myerror.Message);
                    }
                }
                #endregion

                #region USER CONTROL
                else if (obj.Type == "USER CONTROL")
                {
                    string sUCType = obj.Property("Control Type").Value;
                    if (sUCType == "USER CONTROL WEATHER")
                    {
                        Weather wc = new Weather(obj);
                        canGUI.Children.Add(wc);
                        OSAE.OSAEObjectProperty pZOrder = obj.Property("ZOrder");
                        OSAE.OSAEObjectProperty pX = obj.Property("X");
                        OSAE.OSAEObjectProperty pY = obj.Property("Y");
                        Double dX = Convert.ToDouble(pX.Value);
                        Canvas.SetLeft(wc, dX);
                        Double dY = Convert.ToDouble(pY.Value);
                        Canvas.SetTop(wc, dY);
                        int dZ = Convert.ToInt32(pZOrder.Value);
                        Canvas.SetZIndex(wc, dZ);

                        wc.Location.X = dX;
                        wc.Location.Y = dY;
                        userControls.Add(wc);
                        controlTypes.Add(typeof(Weather));
                        wc.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                }
                #endregion
            }));
        }
Exemplo n.º 33
0
        public OSAEObjectCollection GetAllObjects()
        {
            MySqlCommand command = new MySqlCommand("SELECT object_name, object_description, object_type_description, container_name, state_label, last_updated, address, enabled, time_in_state, base_type FROM osae_v_object");
            DataSet ds = OSAESql.RunQuery(command);

            OSAEObjectCollection objs = new OSAEObjectCollection();
            OSAEObject obj;

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                obj = new OSAEObject(dr["object_name"].ToString(), dr["object_description"].ToString(), dr["object_type_description"].ToString(), dr["address"].ToString(), dr["container_name"].ToString(), Int32.Parse(dr["enabled"].ToString()));
                obj.LastUpd = dr["last_updated"].ToString();
                obj.State.Value = dr["state_label"].ToString();
                obj.State.TimeInState = long.Parse(dr["time_in_state"].ToString());
                obj.BaseType = dr["base_type"].ToString();
                objs.Add(obj);
            }
            return objs;
        }
        public void LoadPlugins()
        {
            osae.AddToLog("Entered LoadPlugins", true);
            string path = osae.APIpath;

            AddInStore.Update(path);

            Collection <AddInToken> tokens = null;

            tokens = AddInStore.FindAddIns(typeof(IOpenSourceAutomationAddInv2), path);
            foreach (AddInToken token in tokens)
            {
                plugins.Add(new Plugin(token));
            }

            foreach (Plugin plugin in plugins)
            {
                try
                {
                    osae.AddToLog("---------------------------------------", true);
                    osae.AddToLog("plugin name: " + plugin.PluginName, true);
                    osae.AddToLog("plugin type: " + plugin.PluginType, true);

                    if (plugin.PluginName != "")
                    {
                        OSAE.OSAEObject obj = osae.GetObjectByName(plugin.PluginName);
                        osae.AddToLog("setting found: " + obj.Name + " - " + obj.Enabled.ToString(), true);
                        bool isSystemPlugin = false;
                        foreach (ObjectProperty p in obj.Properties)
                        {
                            if (p.Name == "System Plugin")
                            {
                                if (p.Value == "TRUE")
                                {
                                    isSystemPlugin = true;
                                }
                                break;
                            }
                        }
                        osae.AddToLog("isSystemPlugin?: " + isSystemPlugin.ToString(), true);
                        if (!isSystemPlugin)
                        {
                            if (obj.Enabled.ToString() == "1")
                            {
                                try
                                {
                                    if (plugin.ActivatePlugin())
                                    {
                                        plugin.addin.RunInterface(plugin.PluginName);
                                    }
                                    osae.ObjectStateSet(plugin.PluginName, "ON");
                                }
                                catch (Exception ex)
                                {
                                    osae.AddToLog("Error activating plugin (" + plugin.PluginName + "): " + ex.Message + " - " + ex.InnerException, true);
                                }
                                catch
                                {
                                    osae.AddToLog("Error activating plugin", true);
                                }
                            }
                            else
                            {
                                plugin.Enabled = false;
                            }

                            osae.AddToLog("status: " + plugin.Enabled.ToString(), true);
                            osae.AddToLog("PluginName: " + plugin.PluginName, true);
                            osae.AddToLog("PluginVersion: " + plugin.PluginVersion, true);
                            Thread thread = new Thread(() => messageHost("plugin", "plugin|" + plugin.PluginName + "|" + plugin.Status
                                                                         + "|" + plugin.PluginVersion + "|" + plugin.Enabled));
                            thread.Start();
                        }
                        //else
                        //    plugins.Remove(plugin);
                    }
                    else
                    {
                        //add code to create the object.  We need the plugin to specify the type though
                        osae.AddToLog("Plugin object doesn't exist", true);
                        DataSet dataset = wcfObj.ExecuteSQL("SELECT * FROM osae_object_type_property p inner join osae_object_type t on p.object_type_id = t.object_type_id WHERE object_type='" + plugin.PluginType + "' AND property_name='Computer Name'");
                        osae.AddToLog("dataset count: " + dataset.Tables[0].Rows.Count.ToString(), true);

                        // if object type has a property called 'Computer Name' we know it is not a System Plugin
                        if (dataset.Tables[0].Rows.Count > 0)
                        {
                            plugin.PluginName = plugin.PluginType + "-" + osae.ComputerName;

                            osae.AddToLog("Plugin object does not exist in DB: " + plugin.PluginName, true);
                            osae.ObjectAdd(plugin.PluginName, plugin.PluginName, plugin.PluginType, "", "System", false);
                            osae.ObjectPropertySet(plugin.PluginName, "Computer Name", osae.ComputerName);

                            osae.AddToLog("Plugin added to DB: " + plugin.PluginName, true);
                            Thread thread = new Thread(() => messageHost("plugin", "plugin|" + plugin.PluginName + "|" + plugin.Status
                                                                         + "|" + plugin.PluginVersion + "|" + plugin.Enabled));
                            thread.Start();
                        }
                    }
                }
                catch (Exception ex)
                {
                    osae.AddToLog("Error loading plugin: " + ex.Message, true);
                }
                catch
                {
                    osae.AddToLog("Error loading plugin", true);
                }
            }
            osae.AddToLog("Done loading plugins", true);
        }
Exemplo n.º 35
0
        /// <summary>
        /// Returns a Dataset of all objects of specified type
        /// </summary>
        /// <param name="ObjectType"></param>
        /// <returns></returns>
        public List<OSAEObject> GetObjectsByType(string ObjectType)
        {
            DataSet dataset = new DataSet();
            OSAEObject obj = new OSAEObject();
            List<OSAEObject> objects = new List<OSAEObject>();

            using (MySqlCommand command = new MySqlCommand())
            {
                try
                {
                    command.CommandText = "SELECT object_name, object_description, object_type, address, container_name, enabled, state_label, base_type, coalesce(time_in_state, 0) as time_in_state FROM osae_v_object WHERE object_type=@ObjectType";
                    command.Parameters.AddWithValue("@ObjectType", ObjectType);
                    dataset = RunQuery(command);

                    if (dataset.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow dr in dataset.Tables[0].Rows)
                        {
                            obj = new OSAEObject(dr["object_name"].ToString(), dr["object_description"].ToString(), dataset.Tables[0].Rows[0]["object_type"].ToString(), dr["address"].ToString(), dr["container_name"].ToString(), Int32.Parse(dr["enabled"].ToString()));
                            obj.State.Value = dr["state_label"].ToString();
                            obj.State.TimeInState = Convert.ToInt64(dr["time_in_state"]);
                            obj.BaseType = dr["base_type"].ToString();
                            DataSet ds = GetObjectProperties(obj.Name);
                            List<ObjectProperty> props = new List<ObjectProperty>();
                            foreach (DataRow drp in ds.Tables[0].Rows)
                            {
                                ObjectProperty p = new ObjectProperty();
                                p.Name = drp["property_name"].ToString();
                                p.Value = drp["property_value"].ToString();
                                p.DataType = drp["property_datatype"].ToString();
                                p.LastUpdated = drp["last_updated"].ToString();
                                p.Id = drp["object_property_id"].ToString();
                                props.Add(p);
                            }
                            obj.Properties = props;
                            obj.Methods = GetObjectMethods(obj.Name);
                            objects.Add(obj);
                        }
                        return objects;
                    }
                    return objects;
                }
                catch (Exception ex)
                {
                    AddToLog("API - GetObjectsByType error: " + ex.Message, true);
                    return objects;
                }
            }
        }
        public PropertyLabel(OSAEObject sObj)
        {
            InitializeComponent();
            screenObject = sObj;
            ObjectName = screenObject.Property("Object Name").Value;
            PropertyName = screenObject.Property("Property Name").Value;

            string sPropertyValue;
            if (string.Equals(PropertyName, "STATE", StringComparison.CurrentCultureIgnoreCase))
            {
                sPropertyValue = OSAEObjectStateManager.GetObjectStateValue(ObjectName).StateLabel;
                LastState = sPropertyValue;
                LastStateChange = OSAEObjectStateManager.GetObjectStateValue(ObjectName).LastStateChange;
                TimeSpan newSpan = (DateTime.Now - LastStateChange);
                sPropertyValue += " (" + newSpan.ToString(@"dd\ hh\:mm\:ss") + ")";
            }
            else
            {
                sPropertyValue = OSAEObjectPropertyManager.GetObjectPropertyValue(ObjectName, PropertyName).Value;
            }
            string sBackColor = screenObject.Property("Back Color").Value;
            string sForeColor = screenObject.Property("Fore Color").Value;
            string sPrefix = screenObject.Property("Prefix").Value;
            string sSuffix = screenObject.Property("Suffix").Value;
            string iFontSize = screenObject.Property("Font Size").Value;
            string sFontName = screenObject.Property("Font Name").Value;

            if (sPropertyValue != "")
            {
                if (sBackColor != "")
                {
                    try
                    {
                        BrushConverter conv = new BrushConverter();
                        SolidColorBrush brush = conv.ConvertFromString(sBackColor) as SolidColorBrush;
                        propLabel.Background = brush;
                    }
                    catch (Exception)
                    {}
                }
                if (sForeColor != "")
                {
                    try
                    {
                        BrushConverter conv = new BrushConverter();
                        SolidColorBrush brush = conv.ConvertFromString(sForeColor) as SolidColorBrush;
                        propLabel.Foreground = brush;
                    }
                    catch (Exception)
                    {}
                }
                if (iFontSize != "")
                {
                    try
                    {
                        propLabel.FontSize = Convert.ToDouble(iFontSize);
                    }
                    catch (Exception)
                    {}
                }
                if (sFontName != "")
                {
                    try
                    {
                        propLabel.FontFamily = new FontFamily(sFontName);
                    }
                    catch (Exception)
                    {}
                }
                propLabel.Content = sPrefix + sPropertyValue + sSuffix;
            }
            else
                propLabel.Content = "";
        }
        /// <summary>
        /// Returns a Dataset of all objects in a specified container
        /// </summary>
        /// <param name="ContainerName"></param>
        /// <returns></returns>
        public static OSAEObjectCollection GetObjectsByContainer(string ContainerName)
        {
            MySqlCommand command = new MySqlCommand();
            DataSet dataset = new DataSet();
            OSAEObject obj = new OSAEObject();
            OSAEObjectCollection objects = new OSAEObjectCollection();
            try
            {
                if (ContainerName == string.Empty)
                {
                    command.CommandText = "SELECT object_name, object_description, object_type, address, container_name, enabled, state_name, base_type, coalesce(time_in_state, 0) as time_in_state, last_updated FROM osae_v_object WHERE container_name is null ORDER BY object_name ASC";
                }
                else
                {
                    command.CommandText = "SELECT object_name, object_description, object_type, address, container_name, enabled, state_name, base_type, coalesce(time_in_state, 0) as time_in_state, last_updated FROM osae_v_object WHERE container_name=@ContainerName ORDER BY object_name ASC";
                    command.Parameters.AddWithValue("@ContainerName", ContainerName);
                }

                dataset = OSAESql.RunQuery(command);
                if (dataset.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in dataset.Tables[0].Rows)
                    {
                        obj = new OSAEObject(dr["object_name"].ToString(), dr["object_description"].ToString(), dr["object_type"].ToString(), dr["address"].ToString(), dr["container_name"].ToString(), int.Parse(dr["enabled"].ToString()));
                        obj.State.Value = dr["state_name"].ToString();
                        obj.State.TimeInState = Convert.ToInt64(dr["time_in_state"]);
                        obj.BaseType = dr["base_type"].ToString();
                        obj.LastUpd = dr["last_updated"].ToString();
                        obj.Properties = OSAEObjectPropertyManager.GetObjectProperties(obj.Name);
                        obj.Methods = GetObjectMethods(obj.Name);
                        objects.Add(obj);
                    }

                    return objects;
                }

                return objects;
            }
            catch (Exception ex)
            {
                Logging.GetLogger().AddToLog("API - GetObjectsByContainer error: " + ex.Message, true);
                return objects;
            }
        }
Exemplo n.º 38
0
        private void Update_Objects()
        {
            //   try
            //   {

            while (!closing)
            {
                while (loadingScreen)
                {
                    System.Threading.Thread.Sleep(100);
                }
                ;

                bool oldCtrl = false;
                this.Log.Debug("Entering Update_Objects");
                List <OSAE.OSAEScreenControl> controls = OSAEScreenControlManager.GetScreenControls(gCurrentScreen);

                foreach (OSAE.OSAEScreenControl newCtrl in controls)
                {
                    while (loadingScreen)
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                    ;
                    oldCtrl = false;

                    #region CONTROL STATE IMAGE
                    if (newCtrl.ControlType == "CONTROL STATE IMAGE")
                    {
                        foreach (StateImage sImage in stateImages)
                        {
                            while (loadingScreen)
                            {
                                System.Threading.Thread.Sleep(100);
                            }
                            ;
                            if (newCtrl.ControlName == sImage.screenObject.Name)
                            {
                                if (newCtrl.LastUpdated != sImage.LastUpdated)
                                {
                                    this.Log.Debug("Updating:  " + newCtrl.ControlName);
                                    sImage.LastUpdated = newCtrl.LastUpdated;
                                    try
                                    {
                                        sImage.Update();
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                    this.Dispatcher.Invoke((Action)(() =>
                                    {
                                        Canvas.SetLeft(sImage, sImage.Location.X);
                                        Canvas.SetTop(sImage, sImage.Location.Y);
                                    }));
                                    this.Log.Debug("Complete:  " + newCtrl.ControlName);
                                }
                                oldCtrl = true;
                            }
                        }
                    }
                    #endregion

                    #region CONTROL PROPERTY LABEL
                    else if (newCtrl.ControlType == "CONTROL PROPERTY LABEL")
                    {
                        while (loadingScreen)
                        {
                            System.Threading.Thread.Sleep(100);
                        }
                        ;
                        foreach (PropertyLabel pl in propLabels)
                        {
                            while (loadingScreen)
                            {
                                System.Threading.Thread.Sleep(100);
                            }
                            ;
                            if (newCtrl.ControlName == pl.screenObject.Name)
                            {
                                if (newCtrl.LastUpdated != pl.LastUpdated)
                                {
                                    this.Log.Debug("Updating:  " + newCtrl.ControlName);
                                    pl.LastUpdated = newCtrl.LastUpdated;
                                    pl.Update();
                                    this.Log.Debug("Complete:  " + newCtrl.ControlName);
                                    while (loadingScreen)
                                    {
                                        System.Threading.Thread.Sleep(100);
                                    }
                                    ;
                                }
                                oldCtrl = true;
                            }
                        }
                    }
                    #endregion

                    #region CONTROL TIMER LABEL
                    else if (newCtrl.ControlType == "CONTROL TIMER LABEL")
                    {
                        foreach (OSAE.UI.Controls.TimerLabel tl in timerLabels)
                        {
                            while (loadingScreen)
                            {
                                System.Threading.Thread.Sleep(100);
                            }
                            ;
                            if (newCtrl.ControlName == tl.screenObject.Name)
                            {
                                if (newCtrl.LastUpdated != tl.LastUpdated)
                                {
                                    this.Log.Debug("Updating:  " + newCtrl.ControlName);
                                    tl.LastUpdated = newCtrl.LastUpdated;
                                    tl.Update();
                                    this.Log.Debug("Complete:  " + newCtrl.ControlName);
                                }
                                oldCtrl = true;
                            }
                        }
                    }
                    #endregion

                    #region CONTROL STATIC LABEL
                    else if (newCtrl.ControlType == "CONTROL STATIC LABEL")
                    {
                        foreach (OSAE.UI.Controls.StaticLabel sl in staticLabels)
                        {
                            if (newCtrl.ControlName == sl.screenObject.Name)
                            {
                                oldCtrl = true;
                            }
                        }
                    }
                    #endregion

                    #region CONTROL NAVIGATION IMAGE
                    else if (newCtrl.ControlType == "CONTROL NAVIGATION IMAGE")
                    {
                        foreach (OSAE.UI.Controls.NavigationImage nav in navImages)
                        {
                            if (newCtrl.ControlName == nav.screenObject.Name)
                            {
                                oldCtrl = true;
                            }
                        }
                    }
                    #endregion

                    #region CONTROL CLICK IMAGE
                    else if (newCtrl.ControlType == "CONTROL METHOD IMAGE")
                    {
                        foreach (OSAE.UI.Controls.ClickImage method in clickImages)
                        {
                            if (newCtrl.ControlName == method.screenObject.Name)
                            {
                                oldCtrl = true;
                            }
                        }
                    }
                    #endregion

                    #region CONTROL CAMERA VIEWER
                    else if (newCtrl.ControlType == "CONTROL CAMERA VIEWER")
                    {
                        foreach (OSAE.UI.Controls.VideoStreamViewer vsv in cameraViewers)
                        {
                            if (newCtrl.ControlName == vsv.screenObject.Name)
                            {
                                oldCtrl = true;
                            }
                        }
                    }
                    #endregion

                    #region CONTROL USAER CONTROL
                    else if (newCtrl.ControlType == "USER CONTROL")
                    {
                        foreach (dynamic obj in userControls)
                        {
                            if (newCtrl.ControlName == obj.screenObject.Name)
                            {
                                oldCtrl = true;
                            }
                        }
                    }
                    #endregion

                    #region CONTROL BROWSER
                    if (newCtrl.ControlType == "CONTROL BROWSER")
                    {
                        //    foreach (BrowserFrame oBrowser in browserFrames)
                        //     {
                        //      if (newCtrl.ControlName == oBrowser.screenObject.Name)
                        //      {
                        //  if (newCtrl.LastUpdated != sImage.LastUpdated)
                        //  {
                        //        this.Log.Debug("Updating:  " + newCtrl.ControlName);
                        //  sImage.LastUpdated = newCtrl.LastUpdated;
                        //   try
                        //   {
                        //      sImage.Update();
                        //  }
                        //   catch (Exception ex)
                        //   {

                        //    }
                        //        this.Dispatcher.Invoke((Action)(() =>
                        //        {
                        //           Canvas.SetLeft(oBrowser, oBrowser.Location.X);
                        //           Canvas.SetTop(oBrowser, oBrowser.Location.Y);
                        //           }));
                        //          this.Log.Debug("Complete:  " + newCtrl.ControlName);
                        //      }
                        //       oldCtrl = true;
                        //   }
                        //   }
                    }
                    #endregion

                    if (!oldCtrl)
                    {
                        OSAE.OSAEObject obj = OSAEObjectManager.GetObjectByName(newCtrl.ControlName);
                        this.Log.Debug("Load new control: " + newCtrl.ControlName);
                        LoadControl(obj);
                    }
                    this.Log.Debug("Leaving Update_Objects");
                }
                System.Threading.Thread.Sleep(1000);
            }

            //    }
            //      catch (Exception ex)
            //     {
            //         System.Threading.Thread.Sleep(100);
            //     }
        }
Exemplo n.º 39
0
        private void LoadControl(OSAE.OSAEObject obj)
        {
            this.Dispatcher.Invoke((Action)(() =>
            {
                String sStateMatch = "";

                #region CONTROL STATE IMAGE
                if (obj.Type == "CONTROL STATE IMAGE")
                {
                    StateImage stateImageControl = new StateImage(obj);

                    foreach (OSAE.OSAEObjectProperty p in obj.Properties)
                    {
                        try
                        {
                            if (p.Value.ToLower() == stateImageControl.CurState.ToLower())
                            {
                                sStateMatch = p.Name.Substring(0, p.Name.LastIndexOf(' '));
                            }
                        }
                        catch (Exception ex)
                        {
                            this.Log.Error("Error finding object ", ex);
                            return;
                        }
                    }
                    try
                    {
                        int dZ = Int32.Parse(obj.Property("ZOrder").Value);
                        stateImageControl.MouseRightButtonDown += new MouseButtonEventHandler(State_Image_MouseRightButtonDown);
                        stateImageControl.Location.X = Double.Parse(obj.Property(sStateMatch + " X").Value);
                        stateImageControl.Location.Y = Double.Parse(obj.Property(sStateMatch + " Y").Value);
                        canGUI.Children.Add(stateImageControl);
                        Canvas.SetLeft(stateImageControl, stateImageControl.Location.X);
                        Canvas.SetTop(stateImageControl, stateImageControl.Location.Y);
                        Canvas.SetZIndex(stateImageControl, dZ);
                        stateImages.Add(stateImageControl);
                        controlTypes.Add(typeof(StateImage));
                        stateImageControl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (Exception ex)
                    {
                        this.Log.Error("Error updating screenObject", ex);
                        return;
                    }
                }
                #endregion

                #region CONTROL PROPERTY LABEL
                else if (obj.Type == "CONTROL PROPERTY LABEL")
                {
                    this.Log.Debug("Loading PropertyLabelControl: " + obj.Name);
                    try
                    {
                        PropertyLabel pl = new PropertyLabel(obj);
                        pl.MouseRightButtonDown += new MouseButtonEventHandler(Property_Label_MouseRightButtonDown);
                        canGUI.Children.Add(pl);
                        int dZ = Int32.Parse(obj.Property("ZOrder").Value);
                        pl.Location.X = Double.Parse(obj.Property("X").Value);
                        pl.Location.Y = Double.Parse(obj.Property("Y").Value);
                        Canvas.SetLeft(pl, pl.Location.X);
                        Canvas.SetTop(pl, pl.Location.Y);
                        Canvas.SetZIndex(pl, dZ);
                        propLabels.Add(pl);
                        controlTypes.Add(typeof(PropertyLabel));
                        pl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (Exception ex)
                    {
                        this.Log.Error("Error updating PropertyLabelControl", ex);
                        return;
                    }
                }
                #endregion

                #region CONTROL STATIC LABEL
                else if (obj.Type == "CONTROL STATIC LABEL")
                {
                    this.Log.Debug("Loading PropertyLabelControl: " + obj.Name);
                    try
                    {
                        OSAE.UI.Controls.StaticLabel sl = new OSAE.UI.Controls.StaticLabel(obj);
                        canGUI.Children.Add(sl);
                        int dZ = Int32.Parse(obj.Property("ZOrder").Value);
                        sl.Location.X = Double.Parse(obj.Property("X").Value);
                        sl.Location.Y = Double.Parse(obj.Property("Y").Value);
                        Canvas.SetLeft(sl, sl.Location.X);
                        Canvas.SetTop(sl, sl.Location.Y);
                        Canvas.SetZIndex(sl, dZ);
                        staticLabels.Add(sl);
                        controlTypes.Add(typeof(OSAE.UI.Controls.StaticLabel));
                        sl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (Exception ex)
                    {
                        this.Log.Error("Error updating PropertyLabelControl", ex);
                        return;
                    }
                }
                #endregion

                #region CONTROL TIMER LABEL
                else if (obj.Type == "CONTROL TIMER LABEL")
                {
                    this.Log.Debug("Loading PropertyTimerControl: " + obj.Name);
                    try
                    {
                        OSAE.UI.Controls.TimerLabel tl = new OSAE.UI.Controls.TimerLabel(obj);
                        canGUI.Children.Add(tl);
                        int dZ = Int32.Parse(obj.Property("ZOrder").Value);
                        tl.Location.X = Double.Parse(obj.Property("X").Value);
                        tl.Location.Y = Double.Parse(obj.Property("Y").Value);
                        Canvas.SetLeft(tl, tl.Location.X);
                        Canvas.SetTop(tl, tl.Location.Y);
                        Canvas.SetZIndex(tl, dZ);
                        timerLabels.Add(tl);
                        controlTypes.Add(typeof(OSAE.UI.Controls.TimerLabel));
                        tl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (Exception ex)
                    {
                        this.Log.Error("Error updating PropertyTimerControl", ex);
                        return;
                    }
                }
                #endregion

                #region CONTROL CLICK IMAGE
                else if (obj.Type == "CONTROL CLICK IMAGE")
                {
                    try
                    {
                        ClickImage ClickImageControl = new ClickImage(obj);
                        ClickImageControl.MouseRightButtonDown += new MouseButtonEventHandler(Click_Image_MouseRightButtonDown);
                        canGUI.Children.Add(ClickImageControl);

                        OSAE.OSAEObjectProperty pZOrder = obj.Property("ZOrder");
                        OSAE.OSAEObjectProperty pX = obj.Property("X");
                        OSAE.OSAEObjectProperty pY = obj.Property("Y");
                        Double dX = Convert.ToDouble(pX.Value);
                        Canvas.SetLeft(ClickImageControl, dX);
                        Double dY = Convert.ToDouble(pY.Value);
                        Canvas.SetTop(ClickImageControl, dY);
                        int dZ = Convert.ToInt32(pZOrder.Value);
                        Canvas.SetZIndex(ClickImageControl, dZ);
                        ClickImageControl.Location.X = dX;
                        ClickImageControl.Location.Y = dY;
                        clickImages.Add(ClickImageControl);
                        controlTypes.Add(typeof(ClickImage));
                        ClickImageControl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (MySqlException myerror)
                    {
                        MessageBox.Show("GUI Error Load Click Image: " + myerror.Message);
                    }
                }
                #endregion

                #region CONTROL NAVIGATION IMAGE
                else if (obj.Type == "CONTROL NAVIGATION IMAGE")
                {
                    try
                    {
                        NavigationImage navImageControl = new NavigationImage(obj.Property("Screen").Value, obj);
                        navImageControl.MouseLeftButtonUp += new MouseButtonEventHandler(Navigaton_Image_MouseLeftButtonUp);
                        navImageControl.MouseRightButtonDown += new MouseButtonEventHandler(Navigaton_Image_MouseRightButtonDown);

                        canGUI.Children.Add(navImageControl);

                        OSAE.OSAEObjectProperty pZOrder = obj.Property("ZOrder");
                        OSAE.OSAEObjectProperty pX = obj.Property("X");
                        OSAE.OSAEObjectProperty pY = obj.Property("Y");
                        Double dX = Convert.ToDouble(pX.Value);
                        Canvas.SetLeft(navImageControl, dX);
                        Double dY = Convert.ToDouble(pY.Value);
                        Canvas.SetTop(navImageControl, dY);
                        int dZ = Convert.ToInt32(pZOrder.Value);
                        Canvas.SetZIndex(navImageControl, dZ);
                        navImageControl.Location.X = dX;
                        navImageControl.Location.Y = dY;
                        navImages.Add(navImageControl);
                        controlTypes.Add(typeof(NavigationImage));
                        navImageControl.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (MySqlException myerror)
                    {
                        MessageBox.Show("GUI Error Load Navigation Image: " + myerror.Message);
                    }
                }
                #endregion

                #region CONTROL CAMERA VIEWER
                else if (obj.Type == "CONTROL CAMERA VIEWER")
                {
                    try
                    {
                        string stream = OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Property("Object Name").Value, "Stream Address").Value;
                        VideoStreamViewer vsv = new VideoStreamViewer(stream, obj);
                        canGUI.Children.Add(vsv);
                        OSAE.OSAEObjectProperty pZOrder = obj.Property("ZOrder");
                        OSAE.OSAEObjectProperty pX = obj.Property("X");
                        OSAE.OSAEObjectProperty pY = obj.Property("Y");
                        Double dX = Convert.ToDouble(pX.Value);
                        Canvas.SetLeft(vsv, dX);
                        Double dY = Convert.ToDouble(pY.Value);
                        Canvas.SetTop(vsv, dY);
                        int dZ = Convert.ToInt32(pZOrder.Value);
                        Canvas.SetZIndex(vsv, dZ);
                        vsv.Location.X = dX;
                        vsv.Location.Y = dY;
                        cameraViewers.Add(vsv);
                        controlTypes.Add(typeof(VideoStreamViewer));
                        vsv.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (MySqlException myerror)
                    {
                        MessageBox.Show("GUI Error Load Camera Viewer: " + myerror.Message);
                    }
                }
                #endregion

                #region USER CONTROL
                else if (obj.Type == "USER CONTROL")
                {
                    string sUCType = obj.Property("Control Type").Value;
                    if (sUCType == "USER CONTROL WEATHER")
                    {
                        Weather wc = new Weather(obj);
                        canGUI.Children.Add(wc);
                        OSAE.OSAEObjectProperty pZOrder = obj.Property("ZOrder");
                        OSAE.OSAEObjectProperty pX = obj.Property("X");
                        OSAE.OSAEObjectProperty pY = obj.Property("Y");
                        Double dX = Convert.ToDouble(pX.Value);
                        Canvas.SetLeft(wc, dX);
                        Double dY = Convert.ToDouble(pY.Value);
                        Canvas.SetTop(wc, dY);
                        int dZ = Convert.ToInt32(pZOrder.Value);
                        Canvas.SetZIndex(wc, dZ);

                        wc.Location.X = dX;
                        wc.Location.Y = dY;
                        userControls.Add(wc);
                        controlTypes.Add(typeof(Weather));
                        wc.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                }
                #endregion

                #region CONTROL BROWSER
                else if (obj.Type == "CONTROL BROWSER")
                {
                    this.Log.Debug("Loading BrowserControl: " + obj.Name);
                    try
                    {
                        OSAE.UI.Controls.BrowserFrame bf = new OSAE.UI.Controls.BrowserFrame(obj);
                        bf.MouseRightButtonDown += new MouseButtonEventHandler(Broswer_Control_MouseRightButtonDown);
                        //OSAE.UI.Controls.StaticLabel sl = new OSAE.UI.Controls.StaticLabel(obj);
                        canGUI.Children.Add(bf);
                        int dZ = Int32.Parse(obj.Property("ZOrder").Value);
                        bf.Location.X = Double.Parse(obj.Property("X").Value);
                        bf.Location.Y = Double.Parse(obj.Property("Y").Value);
                        bf.Width = Double.Parse(obj.Property("Width").Value);
                        bf.Height = Double.Parse(obj.Property("Height").Value);
                        Canvas.SetLeft(bf, bf.Location.X);
                        Canvas.SetTop(bf, bf.Location.Y);
                        Canvas.SetZIndex(bf, dZ);
                        browserFrames.Add(bf);
                        controlTypes.Add(typeof(OSAE.UI.Controls.BrowserFrame));
                        //
                        bf.PreviewMouseMove += new MouseEventHandler(DragSource_PreviewMouseMove);
                    }
                    catch (Exception ex)
                    {
                        this.Log.Error("Error updating BrowserControl", ex);
                        return;
                    }
                }
                #endregion
            }));
        }
        // Code to Initialize your custom User Control
        public CustomUserControl(OSAEObject sObj, string ControlName, string appName, string user)
        {
            InitializeComponent();
            gAppName = appName;
            currentUser = user;
            _controlname = ControlName;
            screenObject = sObj;
            objName = sObj.Property("Object Name").Value;
            DataSet ds = OSAEObjectStateManager.ObjectStateListGet(objName);
            if (ds.Tables[0].Rows.Count > 0)
            {
                State1Name = ds.Tables[0].Rows[0]["state_name"].ToString();
                State1Label = ds.Tables[0].Rows[0]["state_label"].ToString();
            }
            if (ds.Tables[0].Rows.Count > 1)
            {
                State2Name = ds.Tables[0].Rows[1]["state_name"].ToString();
                State2Label = ds.Tables[0].Rows[1]["state_label"].ToString();
            }
            CurState = OSAEObjectStateManager.GetObjectStateValue(objName).Value;
            LastStateChange = OSAEObjectStateManager.GetObjectStateValue(objName).LastStateChange;
            try
            {
                ControlWidth = Convert.ToInt32(OSAEObjectPropertyManager.GetObjectPropertyValue(screenObject.Name, "Width").Value);
                ControlHeight = Convert.ToInt32(OSAEObjectPropertyManager.GetObjectPropertyValue(screenObject.Name, "Height").Value);
            }
            catch (Exception ex)
            { }

            string sBackColor = screenObject.Property("Back Color").Value;
            string sForeColor = screenObject.Property("Fore Color").Value;
            string iFontSize = screenObject.Property("Font Size").Value;
            string sFontName = screenObject.Property("Font Name").Value;
            if (sBackColor != "")
            {
                try
                {
                    BrushConverter conv = new BrushConverter();
                    SolidColorBrush brush = conv.ConvertFromString(sBackColor) as SolidColorBrush;
                    btnState.Background = brush;
                }
                catch (Exception)
                { }
            }
            if (sForeColor != "")
            {
                try
                {
                    BrushConverter conv = new BrushConverter();
                    SolidColorBrush brush = conv.ConvertFromString(sForeColor) as SolidColorBrush;
                    btnState.Foreground = brush;
                }
                catch (Exception)
                { }
            }
            if (iFontSize != "")
            {
                try
                { btnState.FontSize = Convert.ToDouble(iFontSize); }
                catch (Exception)
                { }
            }
            if (sFontName != "")
            {
                try
                { btnState.FontFamily = new FontFamily(sFontName); }
                catch (Exception)
                { }
            }
            //propLabel.Content = sPrefix + sPropertyValue + sSuffix;

            Update_Button();
        }