/// <summary>
 /// The initialize.
 /// </summary>
 /// <param name="_networkSession">
 /// The _network session.
 /// </param>
 internal void Initialize(NikseWebServiceSession _networkSession)
 {
     this.textBoxSessionKey.Text = _networkSession.SessionId;
     this.textBoxUserName.Text = _networkSession.CurrentUser.UserName;
     this.textBoxWebServiceUrl.Text = _networkSession.WebServiceUrl;
     this.textBoxLog.Text = _networkSession.GetLog();
 }
        /// <summary>
        /// The initialize.
        /// </summary>
        /// <param name="networkSession">
        /// The network session.
        /// </param>
        internal void Initialize(NikseWebServiceSession networkSession)
        {
            this._networkSession = networkSession;

            this.textBoxSessionKey.Text = Configuration.Settings.NetworkSettings.SessionKey;
            if (this.textBoxSessionKey.Text.Trim().Length < 2)
            {
                this.textBoxSessionKey.Text = Guid.NewGuid().ToString().Replace("-", string.Empty);
            }

            this.comboBoxWebServiceUrl.Text = Configuration.Settings.NetworkSettings.WebServiceUrl;
            this.textBoxUserName.Text = Configuration.Settings.NetworkSettings.UserName;
            if (this.textBoxUserName.Text.Trim().Length < 2)
            {
                this.textBoxUserName.Text = Dns.GetHostName();
            }
        }
Esempio n. 3
0
        internal void Initialize(NikseWebServiceSession networkSession)
        {
            _networkSession = networkSession;
            Text = Configuration.Settings.Language.NetworkChat.Title + " - " + _networkSession.CurrentUser.UserName;

            listViewUsers.Items.Clear();
            foreach (var user in _networkSession.Users)
            {
                AddUser(user);
            }

            listViewChat.Items.Clear();
            foreach (var message in _networkSession.ChatLog)
            {
                AddChatMessage(message.User, message.Message);
                listViewChat.EnsureVisible(listViewChat.Items.Count - 1);
            }
        }
Esempio n. 4
0
        internal void Initialize(Nikse.SubtitleEdit.Logic.Networking.NikseWebServiceSession networkSession)
        {
            _networkSession = networkSession;
            Text            = Configuration.Settings.Language.NetworkChat.Title + " - " + _networkSession.CurrentUser.UserName;

            listViewUsers.Items.Clear();
            foreach (var user in _networkSession.Users)
            {
                AddUser(user);
            }

            listViewChat.Items.Clear();
            foreach (var message in _networkSession.ChatLog)
            {
                AddChatMessage(message.User, message.Message);
                listViewChat.EnsureVisible(listViewChat.Items.Count - 1);
            }
        }
Esempio n. 5
0
        private void LeaveSessionToolStripMenuItemClick(object sender, EventArgs e)
        {
            if (_networkSession != null)
            {
                _networkSession.TimerStop();
                _networkSession.Leave();
            }
            if (_networkChat != null && !_networkChat.IsDisposed)
            {
                _networkChat.Close();
                _networkChat = null;
            }
            _networkSession = null;
            EnableDisableControlsNotWorkingInNetworkMode(true);
            toolStripStatusNetworking.Visible = false;
            SubtitleListview1.HideExtraColumn();
            _networkChat = null;

            var format = GetCurrentSubtitleFormat();
            if (format.HasStyleSupport && _networkSession == null)
            {
                if (format.GetType() == typeof(Sami) || format.GetType() == typeof(SamiModern))
                    SubtitleListview1.ShowExtraColumn(_languageGeneral.Class);
                else
                    SubtitleListview1.ShowExtraColumn(_languageGeneral.Style);
                SubtitleListview1.DisplayExtraFromExtra = true;
            }
        }
Esempio n. 6
0
        private void NetworkGetSendUpdates(List<int> deleteIndices, int insertIndex, Paragraph insertParagraph)
        {
            _networkSession.TimerStop();

            bool doReFill = false;
            bool updateListViewStatus = false;
            SubtitleListview1.SelectedIndexChanged -= SubtitleListview1_SelectedIndexChanged;
            string message = string.Empty;

            int numberOfLines = 0;
            List<SeNetworkService.SeUpdate> updates = null;
            int numberOfRetries = 10;
            while (numberOfRetries > 0)
            {
                numberOfRetries--;
                try
                {
                    updates = _networkSession.GetUpdates(out message, out numberOfLines);
                    numberOfRetries = 0;
                }
                catch (Exception exception)
                {
                    if (numberOfRetries <= 0)
                    {
                        if (exception.InnerException != null)
                            MessageBox.Show(string.Format(_language.NetworkUnableToConnectToServer, exception.InnerException.Message + Environment.NewLine + exception.InnerException.StackTrace));
                        else
                            MessageBox.Show(string.Format(_language.NetworkUnableToConnectToServer, exception.Message + Environment.NewLine + exception.StackTrace));
                        _networkSession.TimerStop();
                        if (_networkChat != null && !_networkChat.IsDisposed)
                        {
                            _networkChat.Close();
                            _networkChat = null;
                        }
                        _networkSession = null;
                        EnableDisableControlsNotWorkingInNetworkMode(true);
                        toolStripStatusNetworking.Visible = false;
                        SubtitleListview1.HideExtraColumn();
                        _networkChat = null;
                        return;
                    }

                    Application.DoEvents();
                    System.Threading.Thread.Sleep(250);
                }
            }
            int currentSelectedIndex = -1;
            if (SubtitleListview1.SelectedItems.Count > 0)
                currentSelectedIndex = SubtitleListview1.SelectedItems[0].Index;
            int oldCurrentSelectedIndex = currentSelectedIndex;
            if (message == "OK")
            {
                foreach (var update in updates)
                {
                    if (!string.IsNullOrEmpty(update.Text))
                    {
                        if (!update.Text.Contains(Environment.NewLine))
                            update.Text = update.Text.Replace("\n", Environment.NewLine);
                        update.Text = WebUtility.HtmlDecode(update.Text).Replace("<br />", Environment.NewLine);
                    }
                    if (update.User.Ip != _networkSession.CurrentUser.Ip || update.User.UserName != _networkSession.CurrentUser.UserName)
                    {
                        if (update.Action == "USR")
                        {
                            _networkSession.Users.Add(update.User);
                            if (_networkChat != null && !_networkChat.IsDisposed)
                            {
                                _networkChat.AddUser(update.User);
                            }
                            _networkSession.AppendToLog(string.Format(_language.NetworkNewUser, update.User.UserName, update.User.Ip));
                        }
                        else if (update.Action == "MSG")
                        {
                            _networkSession.ChatLog.Add(new NikseWebServiceSession.ChatEntry { User = update.User, Message = update.Text });
                            if (_networkChat == null || _networkChat.IsDisposed)
                            {
                                _networkChat = new NetworkChat();
                                _networkChat.Initialize(_networkSession);
                                _networkChat.Show(this);
                            }
                            else
                            {
                                _networkChat.AddChatMessage(update.User, update.Text);
                            }
                            if (!string.IsNullOrEmpty(Configuration.Settings.NetworkSettings.NewMessageSound) && File.Exists(Configuration.Settings.NetworkSettings.NewMessageSound))
                            {
                                try
                                {
                                    using (var soundPlayer = new System.Media.SoundPlayer(Configuration.Settings.NetworkSettings.NewMessageSound))
                                    {
                                        soundPlayer.Play();
                                    }
                                }
                                catch
                                {
                                }
                            }
                            _networkSession.AppendToLog(string.Format(_language.NetworkMessage, update.User.UserName, update.User.Ip, update.Text));
                        }
                        else if (update.Action == "DEL")
                        {
                            doReFill = true;
                            _subtitle.Paragraphs.RemoveAt(update.Index);
                            if (_networkSession.LastSubtitle != null)
                                _networkSession.LastSubtitle.Paragraphs.RemoveAt(update.Index);
                            _networkSession.AppendToLog(string.Format(_language.NetworkDelete, update.User.UserName, update.User.Ip, update.Index));
                            _networkSession.AdjustUpdateLogToDelete(update.Index);

                            if (deleteIndices.Count > 0)
                            {
                                for (int i = deleteIndices.Count - 1; i >= 0; i--)
                                {
                                    int index = deleteIndices[i];
                                    if (index == update.Index)
                                        deleteIndices.RemoveAt(i);
                                    else if (index > update.Index)
                                        deleteIndices[i] = index - 1;
                                }
                            }

                            if (insertIndex > update.Index)
                                insertIndex--;
                            if (currentSelectedIndex >= 0 && currentSelectedIndex > update.Index)
                                currentSelectedIndex--;
                        }
                        else if (update.Action == "INS")
                        {
                            doReFill = true;
                            var p = new Paragraph(update.Text, update.StartMilliseconds, update.EndMilliseconds);
                            _subtitle.Paragraphs.Insert(update.Index, p);
                            if (_networkSession.LastSubtitle != null)
                                _networkSession.LastSubtitle.Paragraphs.Insert(update.Index, new Paragraph(p));
                            _networkSession.AppendToLog(string.Format(_language.NetworkInsert, update.User.UserName, update.User.Ip, update.Index, update.Text.Replace(Environment.NewLine, Configuration.Settings.General.ListViewLineSeparatorString)));
                            _networkSession.AddToWsUserLog(update.User, update.Index, update.Action, false);
                            updateListViewStatus = true;
                            _networkSession.AdjustUpdateLogToInsert(update.Index);

                            if (deleteIndices.Count > 0)
                            {
                                for (int i = deleteIndices.Count - 1; i >= 0; i--)
                                {
                                    int index = deleteIndices[i];
                                    if (index > update.Index)
                                        deleteIndices[i] = index + 1;
                                }
                            }
                            if (insertIndex > update.Index)
                                insertIndex++;
                            if (currentSelectedIndex >= 0 && currentSelectedIndex > update.Index)
                                currentSelectedIndex++;
                        }
                        else if (update.Action == "UPD")
                        {
                            updateListViewStatus = true;
                            var p = _subtitle.GetParagraphOrDefault(update.Index);
                            if (p != null)
                            {
                                p.StartTime.TotalMilliseconds = update.StartMilliseconds;
                                p.EndTime.TotalMilliseconds = update.EndMilliseconds;
                                p.Text = update.Text;
                                SubtitleListview1.SetTimeAndText(update.Index, p);
                                _networkSession.AppendToLog(string.Format(_language.NetworkUpdate, update.User.UserName, update.User.Ip, update.Index, update.Text.Replace(Environment.NewLine, Configuration.Settings.General.ListViewLineSeparatorString)));
                                _networkSession.AddToWsUserLog(update.User, update.Index, update.Action, true);
                                updateListViewStatus = true;
                            }
                            if (_networkSession.LastSubtitle != null)
                            {
                                p = _networkSession.LastSubtitle.GetParagraphOrDefault(update.Index);
                                if (p != null)
                                {
                                    p.StartTime.TotalMilliseconds = update.StartMilliseconds;
                                    p.EndTime.TotalMilliseconds = update.EndMilliseconds;
                                    p.Text = update.Text;
                                }
                            }
                        }
                        else if (update.Action == "BYE")
                        {
                            if (_networkChat != null && !_networkChat.IsDisposed)
                                _networkChat.RemoveUser(update.User);

                            SeNetworkService.SeUser removeUser = null;
                            foreach (var user in _networkSession.Users)
                            {
                                if (user.UserName == update.User.UserName)
                                {
                                    removeUser = user;
                                    break;
                                }
                            }
                            if (removeUser != null)
                                _networkSession.Users.Remove(removeUser);

                            _networkSession.AppendToLog(string.Format(_language.NetworkByeUser, update.User.UserName, update.User.Ip));
                        }
                        else
                        {
                            _networkSession.AppendToLog("UNKNOWN ACTION: " + update.Action + " by " + update.User.UserName + " (" + update.User.Ip + ")");
                        }
                    }
                }
                if (numberOfLines != _subtitle.Paragraphs.Count)
                {
                    _subtitle = _networkSession.ReloadSubtitle();
                    SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                    UpdateListviewWithUserLogEntries();
                    _networkSession.LastSubtitle = new Subtitle(_subtitle);
                    _oldSelectedParagraph = null;
                    SubtitleListview1.SelectedIndexChanged += SubtitleListview1_SelectedIndexChanged;
                    _networkSession.TimerStart();
                    RefreshSelectedParagraph();
                    return;
                }
                if (deleteIndices.Count > 0)
                {
                    deleteIndices.Sort();
                    deleteIndices.Reverse();
                    foreach (int i in deleteIndices)
                    {
                        _subtitle.Paragraphs.RemoveAt(i);
                        if (_networkSession.LastSubtitle != null && i < _networkSession.LastSubtitle.Paragraphs.Count)
                            _networkSession.LastSubtitle.Paragraphs.RemoveAt(i);
                    }

                    _networkSession.DeleteLines(deleteIndices);
                    doReFill = true;
                }
                if (insertIndex >= 0 && insertParagraph != null)
                {
                    _subtitle.Paragraphs.Insert(insertIndex, insertParagraph);
                    if (_networkSession.LastSubtitle != null && insertIndex < _networkSession.LastSubtitle.Paragraphs.Count)
                        _networkSession.LastSubtitle.Paragraphs.Insert(insertIndex, insertParagraph);
                    _networkSession.InsertLine(insertIndex, insertParagraph);
                    doReFill = true;
                }
                _networkSession.CheckForAndSubmitUpdates(); // updates only (no inserts/deletes)
            }
            else
            {
                if (message == "Session not found!")
                {
                    message = _networkSession.Restart();
                    if (message == "Reload")
                    {
                        _subtitle = _networkSession.ReloadSubtitle();
                        SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                        UpdateListviewWithUserLogEntries();
                        _networkSession.LastSubtitle = new Subtitle(_subtitle);
                        _oldSelectedParagraph = null;
                        SubtitleListview1.SelectedIndexChanged += SubtitleListview1_SelectedIndexChanged;
                        _networkSession.TimerStart();
                        RefreshSelectedParagraph();
                        return;
                    }
                    if (message == "OK")
                    {
                        _networkSession.TimerStart();
                        RefreshSelectedParagraph();
                        return;
                    }
                }
                else if (message == "User not found!")
                {
                    message = _networkSession.ReJoin();
                    if (message == "Reload")
                    {
                        _subtitle = _networkSession.ReloadSubtitle();
                        SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                        UpdateListviewWithUserLogEntries();
                        _networkSession.LastSubtitle = new Subtitle(_subtitle);
                        _oldSelectedParagraph = null;
                        SubtitleListview1.SelectedIndexChanged += SubtitleListview1_SelectedIndexChanged;
                        _networkSession.TimerStart();
                        RefreshSelectedParagraph();
                        return;
                    }
                }

                MessageBox.Show(message);
                LeaveSessionToolStripMenuItemClick(null, null);
                SubtitleListview1.SelectedIndexChanged += SubtitleListview1_SelectedIndexChanged;
                return;
            }
            if (doReFill)
            {
                _subtitle.Renumber();
                SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                UpdateListviewWithUserLogEntries();

                if (oldCurrentSelectedIndex != currentSelectedIndex)
                {
                    _oldSelectedParagraph = null;
                    _subtitleListViewIndex = currentSelectedIndex;
                    SubtitleListview1.SelectIndexAndEnsureVisible(_subtitleListViewIndex);
                }
                else if (_oldSelectedParagraph != null)
                {
                    var p = _subtitle.GetFirstAlike(_oldSelectedParagraph);
                    if (p == null)
                    {
                        var tmp = new Paragraph(_oldSelectedParagraph);
                        tmp.Text = textBoxListViewText.Text;
                        p = _subtitle.GetFirstAlike(tmp);
                    }

                    if (p == null)
                    {
                        int idx = oldCurrentSelectedIndex;
                        if (idx >= _subtitle.Paragraphs.Count)
                            idx = _subtitle.Paragraphs.Count - 1;

                        if (idx >= 0 && idx < _subtitle.Paragraphs.Count)
                        {
                            SubtitleListview1.SelectIndexAndEnsureVisible(idx);
                            _listViewTextUndoIndex = -1;
                            SubtitleListView1SelectedIndexChange();
                            textBoxListViewText.Text = _subtitle.Paragraphs[idx].Text;
                        }
                    }
                    else
                    {
                        _subtitleListViewIndex = _subtitle.GetIndex(p);
                        SubtitleListview1.SelectIndexAndEnsureVisible(_subtitleListViewIndex);
                        _listViewTextUndoIndex = -1;
                        SubtitleListView1SelectedIndexChange();
                    }
                }
            }
            else if (updateListViewStatus)
            {
                UpdateListviewWithUserLogEntries();
            }
            _networkSession.LastSubtitle = new Subtitle(_subtitle);
            SubtitleListview1.SelectedIndexChanged += SubtitleListview1_SelectedIndexChanged;
            _networkSession.TimerStart();
        }
Esempio n. 7
0
        private void joinSessionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _networkSession = new NikseWebServiceSession(_subtitle, _subtitleAlternate, TimerWebServiceTick, OnUpdateUserLogEntries);
            using (var networkJoin = new NetworkJoin())
            {
                networkJoin.Initialize(_networkSession);

                if (networkJoin.ShowDialog(this) == DialogResult.OK)
                {
                    _subtitle = _networkSession.Subtitle;
                    _subtitleAlternate = _networkSession.OriginalSubtitle;
                    if (_subtitleAlternate != null && _subtitleAlternate.Paragraphs.Count > 0)
                        SubtitleListview1.ShowAlternateTextColumn(_languageGeneral.OriginalText);
                    _fileName = networkJoin.FileName;
                    SetTitle();
                    Text = Title;
                    toolStripStatusNetworking.Visible = true;
                    toolStripStatusNetworking.Text = _language.NetworkMode;
                    EnableDisableControlsNotWorkingInNetworkMode(false);
                    _networkSession.AppendToLog(string.Format(_language.XStartedSessionYAtZ, _networkSession.CurrentUser.UserName, _networkSession.SessionId, DateTime.Now.ToLongTimeString()));
                    SubtitleListview1.ShowExtraColumn(_language.UserAndAction);
                    SubtitleListview1.AutoSizeAllColumns(this);
                    _subtitleListViewIndex = -1;
                    _oldSelectedParagraph = null;

                    if (Configuration.Settings.General.AllowEditOfOriginalSubtitle && _subtitleAlternate != null && _subtitleAlternate.Paragraphs.Count > 0)
                    {
                        buttonUnBreak.Visible = false;
                        buttonAutoBreak.Visible = false;
                        buttonSplitLine.Visible = false;

                        textBoxListViewText.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom;
                        textBoxListViewText.Width = (groupBoxEdit.Width - (textBoxListViewText.Left + 10)) / 2;
                        textBoxListViewTextAlternate.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom;
                        textBoxListViewTextAlternate.Left = textBoxListViewText.Left + textBoxListViewText.Width + 3;
                        textBoxListViewTextAlternate.Width = textBoxListViewText.Width;
                        textBoxListViewTextAlternate.Visible = true;
                        labelAlternateText.Text = _languageGeneral.OriginalText;
                        labelAlternateText.Visible = true;
                        labelAlternateCharactersPerSecond.Visible = true;
                        labelTextAlternateLineLengths.Visible = true;
                        labelAlternateSingleLine.Visible = true;
                        labelTextAlternateLineTotal.Visible = true;

                        labelCharactersPerSecond.Left = textBoxListViewText.Left + (textBoxListViewText.Width - labelCharactersPerSecond.Width);
                        labelTextLineTotal.Left = textBoxListViewText.Left + (textBoxListViewText.Width - labelTextLineTotal.Width);
                        AddAlternate();
                        Main_Resize(null, null);
                        _changeAlternateSubtitleToString = _subtitleAlternate.ToText(new SubRip()).Trim();
                    }
                    else
                    {
                        RemoveAlternate(false);
                    }
                    SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                    SubtitleListview1.SelectIndexAndEnsureVisible(0);
                    TimerWebServiceTick(null, null);
                }
                else
                {
                    _networkSession = null;
                }
            }
        }
Esempio n. 8
0
        private void startServerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var networkNew = new NetworkStart())
            {
                _networkSession = new NikseWebServiceSession(_subtitle, _subtitleAlternate, TimerWebServiceTick, OnUpdateUserLogEntries);
                networkNew.Initialize(_networkSession, _fileName);
                if (networkNew.ShowDialog(this) == DialogResult.OK)
                {
                    if (GetCurrentSubtitleFormat().HasStyleSupport)
                    {
                        SubtitleListview1.HideExtraColumn();
                    }

                    _networkSession.AppendToLog(string.Format(_language.XStartedSessionYAtZ, _networkSession.CurrentUser.UserName, _networkSession.SessionId, DateTime.Now.ToLongTimeString()));
                    toolStripStatusNetworking.Visible = true;
                    toolStripStatusNetworking.Text = _language.NetworkMode;
                    EnableDisableControlsNotWorkingInNetworkMode(false);
                    SubtitleListview1.ShowExtraColumn(_language.UserAndAction);
                    SubtitleListview1.AutoSizeAllColumns(this);
                    TimerWebServiceTick(null, null);
                }
                else
                {
                    _networkSession = null;
                }
            }
        }