Example #1
0
        public static string FindDevice(string message)
        {
            Propities     propities = new Propities();
            ServerMessage m         = ServerMessageConvert(message);

            return(propities.GetTypeOfDevice(m.deviceid));
        }
Example #2
0
        public static List <object> ChangeParam(string message, string deviceType)
        {
            Propities     propities = new Propities();
            ServerMessage m         = ServerMessageConvert(message);

            switch (deviceType)
            {
            case "tv.json":
                List <TVDevicePropities> tVDevicePropities = propities.GetTVDevicePropities();
                TVDevicePropities        currentTv         = tVDevicePropities.Find(tVDevicePropities => tVDevicePropities.deviceId == m.deviceid);



                if (currentTv != null)
                {
                    currentTv.ParamChange(m.param, m.val);
                }
                else
                {
                    Console.WriteLine(DateTime.Now.ToShortTimeString() + " (WARNING): Device not found in tv.json-----------------------");
                }


                List <object> listTv = new List <object>();
                foreach (TVDevicePropities cur in tVDevicePropities)
                {
                    listTv.Add((object)cur);
                }
                return(listTv);

            case "projector.json":
                List <ProjectorDevicePropities> projectorDevicePropities = propities.GetProjectorDevicePropities();
                ProjectorDevicePropities        currentProj = projectorDevicePropities.Find(projectorDevicePropities => projectorDevicePropities.deviceId == m.deviceid);
                //for projector here

                if (currentProj != null)
                {
                    currentProj.ParamChange(m.param, m.val);
                }
                else
                {
                    Console.WriteLine(DateTime.Now.ToShortTimeString() + " (WARNING): Device not found in projector.json");
                }

                List <object> listProj = new List <object>();
                foreach (ProjectorDevicePropities cur in projectorDevicePropities)
                {
                    listProj.Add((object)cur);
                }
                return(listProj);

            default:
                Console.WriteLine(DateTime.Now.ToShortTimeString() + " (WARNING): Device with recived token not found in devices");
                return(null);
            }
        }
        private static void Controller_On_Exception(object sender, EventArgs e)
        {
            Propities propities = new Propities();

            reconect            = true;
            controller.reconect = true;

            ControllerCommands.StopLisen(controller);

            Thread.Sleep((propities.GetControllerPropities().reconectTimeOut / 2) * 1000);
            Main();
        }
Example #4
0
        public static void TokenAuth(ControllerConnection controllerConnection, bool reconect)
        {
            if (reconect)
            {
                Propities propities = new Propities();
                Thread.Sleep((propities.GetControllerPropities().reconectTimeOut / 2) * 1000);
            }

            Console.WriteLine(DateTime.Now.ToShortTimeString() + " (INFO): SENDING TOKEN");
            Propities           controller          = new Propities();
            ControllerPropities controllerPropities = controller.GetControllerPropities();

            controllerConnection.Send(controllerPropities.token);
        }
Example #5
0
        public static string ChangeParamSending(string message, string deviceType)
        {
            string        json;
            Propities     propities         = new Propities();
            ServerMessage m                 = ServerMessageConvert(deviceType);
            string        currentDeviceType = FindDevice(deviceType);

            //change param analog here
            switch (currentDeviceType)
            {
            case "tv.json":
                List <TVDevicePropities> tVDevicePropities = propities.GetTVDevicePropities();
                TVDevicePropities        curentTv          = tVDevicePropities.Find(tVDevicePropities => tVDevicePropities.deviceId == m.deviceid);

                if (curentTv != null)
                {
                    curentTv.ParamChange(m.param, m.val);
                }
                else
                {
                    Console.WriteLine(DateTime.Now.ToShortTimeString() + " (WARNING): Device not found in tv.json");
                }

                return(propities.DeviceToServerMessage(curentTv, currentDeviceType));

            case "projector.json":

                List <ProjectorDevicePropities> projectorDevicePropities = propities.GetProjectorDevicePropities();
                ProjectorDevicePropities        currentProj = projectorDevicePropities.Find(projectorDevicePropities => projectorDevicePropities.deviceId == m.deviceid);

                if (currentProj != null)
                {
                    currentProj.ParamChange(m.param, m.val);
                }
                else
                {
                    Console.WriteLine(DateTime.Now.ToShortTimeString() + " (WARNING): Device not found in projector.json");
                }

                return(propities.DeviceToServerMessage(currentProj, currentDeviceType));

            default:
                return(null);
            }
        }
Example #6
0
        private TcpClient Connect()
        {
            try
            {
                Propities           propities           = new Propities();
                ConnectionPropities connectionPropities = propities.GetConnect();

                TcpClient tcpClient = new TcpClient();
                tcpClient.Connect(connectionPropities.ip, connectionPropities.port);

                return(tcpClient);
            }
            catch (Exception e)
            {
                //EventArgs eventArgs = new EventArgs();
                //On_Exception.Invoke(e, eventArgs);
                Console.WriteLine(DateTime.Now.ToShortTimeString() + " (CRITYCAL): " + e.Message);
                return(null);
            }
        }
Example #7
0
        public static void ProjectorLamp(ControllerConnection controllerConnection)
        {
            Propities controller = new Propities();
            List <ProjectorDevicePropities> projectorDevicePropities = controller.GetProjectorDevicePropities();



            foreach (ProjectorDevicePropities projectorDevice in projectorDevicePropities)
            {
                projectorDevice.lamphours += 1;
                controllerConnection.Send(controller.DeviceToServerMessage(projectorDevice, "projector.json"));
            }


            List <object> list = new List <ProjectorDevicePropities>().Cast <object>().ToList();

            list.InsertRange(0, projectorDevicePropities.Cast <object>().ToList());

            controller.SaveDevices(list);
        }
Example #8
0
        public static void RandomError(ControllerConnection controllerConnection, Random random)
        {
            int    type;
            string message = null;

            type = random.Next(2);

            Console.WriteLine(DateTime.Now.ToShortTimeString() + " (INFO): Randomize error for type number " + type + "");

            string    deviceType;
            Propities controller = new Propities();
            int       deviceIndex;

            switch (type)
            {
            case 0:
                List <TVDevicePropities> tVDevicePropities = controller.GetTVDevicePropities();
                deviceType = "tv.json";

                deviceIndex = random.Next(0, tVDevicePropities.Count - 1);
                TVDevicePropities.ErrorCode errorCodeT = (TVDevicePropities.ErrorCode)(random.Next(0, 5) * 100);

                tVDevicePropities[deviceIndex].errorCode = errorCodeT;
                message = controller.DeviceToServerMessage(tVDevicePropities[deviceIndex], deviceType);
                break;

            case 1:
                List <ProjectorDevicePropities> projectorDevicePropities = controller.GetProjectorDevicePropities();
                deviceType = "projector.json";

                deviceIndex = random.Next(0, projectorDevicePropities.Count - 1);
                ProjectorDevicePropities.ErrorCode errorCodeP = (ProjectorDevicePropities.ErrorCode)(random.Next(0, 5) * 100);

                projectorDevicePropities[deviceIndex].errorCode = errorCodeP;
                message = controller.DeviceToServerMessage(projectorDevicePropities[deviceIndex], deviceType);
                break;
            }
            controllerConnection.Send(message);

            Console.WriteLine(DateTime.Now.ToShortTimeString() + " (INFO): Error was sended");
        }
Example #9
0
        public static void Device(ControllerConnection controllerConnection, string message)
        {
            //on load try
            Propities device = new Propities();

            //change
            string        deviceType      = ServerMessage.FindDevice(message);
            List <object> devicePropities = ServerMessage.ChangeParam(message, deviceType);

            //send
            string m = ServerMessage.ChangeParamSending(device.DeviceToServerMessage(devicePropities, deviceType), message);

            Console.WriteLine(DateTime.Now.ToShortTimeString() + " (SENDING): " + m);
            controllerConnection.Send(m);

            //save
            if (devicePropities != null)
            {
                device.SaveDevices(devicePropities);
            }
        }
Example #10
0
        public static void FullSend(ControllerConnection controllerConnection)
        {
            Console.WriteLine(DateTime.Now.ToShortTimeString() + " (INFO): Sending list of all devices");

            string    deviceType;
            Propities controller = new Propities();

            List <TVDevicePropities> tVDevicePropities = controller.GetTVDevicePropities();

            deviceType = "tv.json";
            foreach (TVDevicePropities tVDevice in tVDevicePropities)
            {
                controllerConnection.Send(controller.DeviceToServerMessage(tVDevice, deviceType));
            }

            List <ProjectorDevicePropities> projectorDevicePropities = controller.GetProjectorDevicePropities();

            deviceType = "projector.json";
            foreach (ProjectorDevicePropities projectorDevice in projectorDevicePropities)
            {
                controllerConnection.Send(controller.DeviceToServerMessage(projectorDevice, deviceType));
            }
            Console.WriteLine(DateTime.Now.ToShortTimeString() + " (INFO): Done");
        }