Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dbId"></param>
        /// <returns> window main module id matched with wnd id in client mimic screen</returns>
        public int LaunchVisionWindow(int dbId)
        {
            // get the info from db
            var result = ServerDbHelper.GetInstance().GetAllVisionInputs().First(t => t.id == dbId);

            if (result == null)
            {
                Trace.WriteLine("unable to launch vision window with db id: " + dbId);
                return(-1);
            }

            // create the lauching parameters
            System.Xml.Serialization.XmlSerializer wndSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Window));
            TextReader wndReader = new StringReader(result.windowStr);
            Window     window    = (Window)wndSerializer.Deserialize(wndReader);

            System.Xml.Serialization.XmlSerializer inputSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Input));
            TextReader inputReader = new StringReader(result.inputStr);
            Input      input       = (Input)inputSerializer.Deserialize(inputReader);

            System.Xml.Serialization.XmlSerializer osdSerializer = new System.Xml.Serialization.XmlSerializer(typeof(OnScreenDisplay));
            TextReader      osdReader = new StringReader(result.osdStr);
            OnScreenDisplay osd       = (OnScreenDisplay)osdSerializer.Deserialize(osdReader);

            return(launchVisionWindow(window, input, osd));
        }
Example #2
0
        public List <Tuple <int, Window, Input, OnScreenDisplay> > GetAllVisionInputs()
        {
            List <Tuple <int, Window, Input, OnScreenDisplay> > result = new List <Tuple <int, Window, Input, OnScreenDisplay> >();

            // get data from database
            List <VisionData> visionList = new List <VisionData>(ServerDbHelper.GetInstance().GetAllVisionInputs());

            foreach (VisionData data in visionList)
            {
                System.Xml.Serialization.XmlSerializer wndSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Window));
                TextReader wndReader = new StringReader(data.windowStr);

                System.Xml.Serialization.XmlSerializer inputSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Input));
                TextReader inputReader = new StringReader(data.inputStr);

                System.Xml.Serialization.XmlSerializer osdSerializer = new System.Xml.Serialization.XmlSerializer(typeof(OnScreenDisplay));
                TextReader osdReader = new StringReader(data.osdStr);

                Tuple <int, Window, Input, OnScreenDisplay> resultData = new Tuple <int, Window, Input, OnScreenDisplay>
                                                                         (
                    data.id,
                    (Window)wndSerializer.Deserialize(wndReader),
                    (Input)inputSerializer.Deserialize(inputReader),
                    (OnScreenDisplay)osdSerializer.Deserialize(osdReader)
                                                                         );

                result.Add(resultData);
            }

            return(result);
        }
Example #3
0
        public static ServerDbHelper GetInstance()
        {
            if (sInstance == null)
            {
                sInstance = new ServerDbHelper();
            }

            return(sInstance);
        }
Example #4
0
        public bool EditVisionInput(uint id, Window window, Input input, OnScreenDisplay osd)
        {
            System.Xml.Serialization.XmlSerializer wndSerializer = new System.Xml.Serialization.XmlSerializer(window.GetType());
            StringWriter wndTextWriter = new StringWriter();

            wndSerializer.Serialize(wndTextWriter, window);

            System.Xml.Serialization.XmlSerializer inputSerializer = new System.Xml.Serialization.XmlSerializer(input.GetType());
            StringWriter inputTextWriter = new StringWriter();

            inputSerializer.Serialize(inputTextWriter, input);

            System.Xml.Serialization.XmlSerializer osdSerializer = new System.Xml.Serialization.XmlSerializer(osd.GetType());
            StringWriter osdTextWriter = new StringWriter();

            osdSerializer.Serialize(osdTextWriter, osd);

            return(ServerDbHelper.GetInstance().EditVisionInput((int)id, wndTextWriter.ToString(), inputTextWriter.ToString(), osdTextWriter.ToString()));
        }
Example #5
0
        public int LaunchVisionWindow(int dbId, int left, int top, int width, int height)
        {
            if (left == 0 &&
                top == 0 &&
                width == 0 &&
                height == 0)
            {
                // no window stored
                return(LaunchVisionWindow(dbId));
            }

            // get the info from db
            var result = ServerDbHelper.GetInstance().GetAllVisionInputs().First(t => t.id == dbId);

            if (result == null)
            {
                Trace.WriteLine("unable to launch vision window with db id and rect: " + dbId);
                return(0);
            }

            // create the lauching parameters
            System.Xml.Serialization.XmlSerializer wndSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Window));
            TextReader wndReader = new StringReader(result.windowStr);
            Window     window    = (Window)wndSerializer.Deserialize(wndReader);

            // modify to match latest position
            window.WndPostLeft  = left;
            window.WndPosTop    = top;
            window.WndPostWidth = width;
            window.WndPosHeight = height;

            System.Xml.Serialization.XmlSerializer inputSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Input));
            TextReader inputReader = new StringReader(result.inputStr);
            Input      input       = (Input)inputSerializer.Deserialize(inputReader);

            System.Xml.Serialization.XmlSerializer osdSerializer = new System.Xml.Serialization.XmlSerializer(typeof(OnScreenDisplay));
            TextReader      osdReader = new StringReader(result.osdStr);
            OnScreenDisplay osd       = (OnScreenDisplay)osdSerializer.Deserialize(osdReader);

            return(launchVisionWindow(window, input, osd));
        }
Example #6
0
        private void onMonitorEdited(int monitorId)
        {
            MonitorData monitorData = ServerDbHelper.GetInstance().GetMonitorsList().First(data => data.MonitorId == monitorId);

            List <string>           usersList      = getUsersSocketIdFromMonitorId(monitorId);
            ServerViewingAreaStatus viewingAreaCmd = new ServerViewingAreaStatus()
            {
                ViewingArea = new Session.Data.SubData.MonitorInfo()
                {
                    LeftPos   = monitorData.Left,
                    TopPos    = monitorData.Top,
                    RightPos  = monitorData.Right,
                    BottomPos = monitorData.Bottom
                },
            };

            connectionManager.SendData((int)CommandConst.MainCommandServer.UserPriviledge,
                                       (int)CommandConst.SubCommandServer.ViewingArea,
                                       viewingAreaCmd,
                                       usersList);
        }
Example #7
0
        public void InitializeVisionDB()
        {
            // get the installed rgb executable path
            //if (Properties.Settings.Default.VisionPath == string.Empty)
            //{
            // auto search the rgb exe
            foreach (String matchPath in Utils.Files.DirSearch(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "rgbxcmd.com"))
            {
                rgbExecutablePath = matchPath;
                break;
            }

            if (rgbExecutablePath == String.Empty)
            {
                foreach (String matchPath in Utils.Files.DirSearch(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "rgbxcmd.com"))
                {
                    rgbExecutablePath = matchPath;
                    break;
                }
            }

            //Properties.Settings.Default.VisionPath = rgbExecutablePath;
            //Properties.Settings.Default.Save();
            //}

            // check if the db has data
            // if have return and do nothing, else proceed initialization
            if (GetAllVisionInputs().Count() > 0)
            {
                Trace.WriteLine("Already initialize");
                return;
            }

            // get number of input from API
            uint numberInputs = GetNumberOfInputs();

            if (numberInputs == 0)
            {
                Trace.WriteLine("Failed to get input count: initialize");
                return;
            }

            // contruct default input entry in DB
            RGBERROR error = RGBERROR.NO_ERROR;

            for (uint i = 1; i <= numberInputs; i++)
            {
                // get the input type
                SIGNALTYPE signalType;
                uint       captureWidth;
                uint       captureHeight;
                uint       refreshRate;
                if ((error = RGB.GetInputSignalType(i, out signalType, out captureWidth, out captureHeight, out refreshRate)) != RGBERROR.NO_ERROR)
                {
                    Trace.WriteLine("failed to get signal of input: " + i);
                }

                IntPtr hRgb;
                uint   croppingMode = 0;
                int    top          = 0;
                int    left         = 0;
                uint   width        = 0;
                uint   height       = 0;
                if ((error = RGB.OpenInput(i, out hRgb)) != RGBERROR.NO_ERROR)
                {
                    if ((error = RGB.IsCroppingEnabled(hRgb, out croppingMode)) != RGBERROR.NO_ERROR)
                    {
                        RGB.GetCropping(hRgb, out top, out left, out width, out height);
                    }

                    // clean up
                    RGB.CloseInput(hRgb);
                }

                Input visionInput = new Input()
                {
                    InputNumber        = i,
                    LabelName          = String.Format("{0}:{1}", System.Enum.GetName(typeof(Input.EInputType), signalType), i),
                    InputCaptureWidth  = captureWidth,
                    InputCaptureHeight = captureHeight,
                    InputCropping      = croppingMode > 0 ? true:false,
                    InputCropLeft      = left,
                    InputCropTop       = top,
                    InputCropWidth     = width,
                    InputCropHeight    = height
                };

                // get windows and OSD details
                Window          visionWnd = new Window();
                OnScreenDisplay visionOSD = new OnScreenDisplay();

                AddVisionInput(visionWnd, visionInput, visionOSD);
            }

            ServerDbHelper.GetInstance().AddSystemInputCount((int)numberInputs);
        }
Example #8
0
 public bool RemoveVisionInput(uint id)
 {
     return(ServerDbHelper.GetInstance().RemoveVisionInput((int)id));
 }