Exemple #1
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(openFileDialog.InitialDirectory))
            {
                openFileDialog.InitialDirectory = Common.FolderIRCommands;
            }

            if (openFileDialog.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            using (FileStream file = File.OpenRead(openFileDialog.FileName))
            {
                if (file.Length == 0)
                {
                    MessageBox.Show(this, "The selected file is empty", "Empty file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                byte[] fileData = new byte[file.Length];
                file.Read(fileData, 0, (int)file.Length);

                IrCode newCode = IrCode.FromByteArray(fileData);
                if (newCode == null)
                {
                    MessageBox.Show(this, "Not a valid IR code file", "Bad file", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                _code = newCode;
            }

            _fileName = openFileDialog.FileName;

            RefreshForm();
        }
Exemple #2
0
        private void ReceivedMessage(IrssMessage received)
        {
            IrssLog.Debug("Received Message \"{0}\"", received.Type);

            try
            {
                switch (received.Type)
                {
                case MessageType.RegisterClient:
                    if ((received.Flags & MessageFlags.Success) == MessageFlags.Success)
                    {
                        _irServerInfo = IRServerInfo.FromBytes(received.GetDataAsBytes());
                        _registered   = true;

                        string message = "Connected";
                        IrssLog.Info(message);
                        Invoke(new UpdateWindowDel(UpdateWindow), new string[] { message });
                    }
                    else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure)
                    {
                        _registered = false;

                        string message = "Failed to connect";
                        IrssLog.Warn(message);
                        Invoke(new UpdateWindowDel(UpdateWindow), new string[] { message });
                    }
                    return;

                case MessageType.BlastIR:
                    if ((received.Flags & MessageFlags.Success) == MessageFlags.Success)
                    {
                        string message = "Blast successful";
                        IrssLog.Info(message);
                        Invoke(new UpdateWindowDel(UpdateWindow), new string[] { message });
                    }
                    else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure)
                    {
                        string message = "Failed to blast IR command";
                        IrssLog.Error(message);
                        Invoke(new UpdateWindowDel(UpdateWindow), new string[] { message });
                    }
                    break;

                case MessageType.LearnIR:
                    if ((received.Flags & MessageFlags.Success) == MessageFlags.Success)
                    {
                        byte[] dataBytes = received.GetDataAsBytes();

                        _code = IrCode.FromByteArray(dataBytes);

                        _fileName = null;

                        string message = "Learned IR Successfully";
                        IrssLog.Info(message);
                        Invoke(new UpdateWindowDel(UpdateWindow), new string[] { message });

                        RefreshForm();
                    }
                    else if ((received.Flags & MessageFlags.Failure) == MessageFlags.Failure)
                    {
                        string message = "Failed to learn IR command";

                        IrssLog.Warn(message);
                        Invoke(new UpdateWindowDel(UpdateWindow), new string[] { message });
                    }
                    else if ((received.Flags & MessageFlags.Timeout) == MessageFlags.Timeout)
                    {
                        string message = "Learn IR command timed-out";

                        IrssLog.Warn(message);
                        Invoke(new UpdateWindowDel(UpdateWindow), new string[] { message });
                    }
                    break;

                case MessageType.ServerShutdown:
                    _registered = false;
                    Invoke(new UpdateWindowDel(UpdateWindow), new string[] { "Server shut down" });
                    return;

                case MessageType.Error:
                    IrssLog.Error("Error from server: " + received.GetDataAsString());
                    return;
                }
            }
            catch (Exception ex)
            {
                IrssLog.Error(ex);
                MessageBox.Show(this, ex.Message, "IR File Tool Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }