private void Save()
        {
            if (!App.IsSilentMode)
            {
                BinaryFormatter formatter = new BinaryFormatter();

                SerializeChannels(lbSelectedChannels.DataContext as ObservableCollection<Channel>);

                var restoreFile = FILE_WINDOWS_STATE + "rest";

                if (File.Exists(FILE_WINDOWS_STATE))
                {
                    File.Copy(FILE_WINDOWS_STATE, restoreFile, true);
                }

                FileStream writer = null;
                try
                {
                    writer = File.Create(FILE_WINDOWS_STATE);

                    WindowsState ws = new WindowsState()
                    {
                        WindowHeight = wMain.ActualHeight,
                        WindowWidth = wMain.ActualWidth
                    };

                    formatter.Serialize(writer, ws);
                }
                catch (Exception e)
                {
                    File.AppendAllText("log.txt", e.ToString());
                    if (File.Exists(restoreFile))
                    {
                        File.Copy(restoreFile, FILE_WINDOWS_STATE, true);
                    }
                }
                finally
                {
                    if (writer != null)
                    {
                        writer.Close();
                        writer.Dispose();
                    }
                }
            }

            var targetFile = ConfigurationManager.AppSettings["TargetDir"] + "\\" +
                             ConfigurationManager.AppSettings["FileName"];

            if (bool.Parse(ConfigurationManager.AppSettings["IsNetPalyer"]))
            {
                ConvertToXML(Config.SourceFile, targetFile);
            }
            else
            {
                Convert(Config.SourceFile, targetFile);
            }

            if (!string.IsNullOrEmpty(Config.FTPServer))
            {
                var request = (FtpWebRequest)WebRequest.Create(Config.FTPServer + "//" + ConfigurationManager.AppSettings["FileName"]);
                request.Method = WebRequestMethods.Ftp.UploadFile;

                var sourceStream = new StreamReader(targetFile);

                byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
                sourceStream.Close();
                request.ContentLength = fileContents.Length;

                Stream requestStream = request.GetRequestStream();
                requestStream.Write(fileContents, 0, fileContents.Length);
                requestStream.Close();

                var response = (FtpWebResponse)request.GetResponse();
                response.Close();
            }
        }
        private WindowsState ReadState()
        {
            var formatter = new BinaryFormatter();
            FileStream fs = null;
            var state = new WindowsState();
            try
            {
                fs = File.Open(FILE_WINDOWS_STATE, FileMode.Open);
                state = (WindowsState)formatter.Deserialize(fs);
            }
            catch
            {
            }
            finally
            {
                if (fs != null)
                    fs.Close();
            }

            return state;
        }