コード例 #1
0
        private void DecodeFileOnSeparateThread(PFFileEncoder encoder, string encryptedInputFile, string tempFileName, StatusTimer st)
        {
            TimeSpan      ts    = new TimeSpan(0, 0, _statusReportIntervalSeconds);
            PFThread      t     = new PFThread(new ParameterizedThreadStart(DecodeFileFromBase64), "DecodeFileFromBase64");
            List <object> parms = new List <object>();

            parms.Add(encoder);
            parms.Add(encryptedInputFile);
            parms.Add(tempFileName);
            parms.Add(st);
            t.ThreadDescription       = "Decode File from Base64 Text.";
            t.ShowElapsedMilliseconds = false;
            t.StartTime = DateTime.Now;
            st.ShowElapsedTimeMilliseconds = false;
            st.NumSecondsInterval          = _statusReportIntervalSeconds;
            if (st.StatusTimerIsRunning == false)
            {
                st.Start();
            }
            t.Start(parms);
            while (t.ThreadObject.Join(ts) == false)
            {
                if (st.StatusReportDue())
                {
                    FileInfo fi = new FileInfo(tempFileName);
                    currentStatusReport("DecodeEncryptionFromBase64", "InProgress", fi.Length, (int)st.GetElapsedTime().TotalSeconds, st.GetFormattedElapsedTime());
                    fi = null;
                }
            }
            t.FinishTime = DateTime.Now;
        }
コード例 #2
0
        private void HandleStatusTimerTick(object sender, EventArgs e)
        {
            StatusTimer.Stop();
            var status = VideoDedupDlg.WcfProxy.GetVideoComparisonStatus(
                ComparisonToken.Value,
                ImageComparisonIndex);

            UpdateVideoComparisonResult(status.VideoCompareResult);
            UpdateImageComparisonResult(status);

            if (!status.ImageComparisons.Any())
            {
                StatusTimer.Start();
                return;
            }

            ImageComparisonIndex = status.ImageComparisons
                                   .Max(kvp => kvp.Item1);
            ImageComparisonIndex += 1;
            var maxImages = (int)NumMaxImageComparison.Value;

            if (ImageComparisonIndex >= maxImages)
            {
                VideoDedupDlg.WcfProxy.CancelCustomVideoComparison(
                    ComparisonToken.Value);
                return;
            }

            StatusTimer.Start();
        }
コード例 #3
0
        private void AlarmsActivate_Click(object sender, EventArgs e)
        {
            AlarmsLoad.Enabled = false;
            Active             = !Active;
            if (Active)
            {
                BattlelistTimer          = new Timer(AlarmTimeIntervals);
                BattlelistTimer.Execute += BattlelistTimer_Execute;
                StatusTimer.Interval     = StatusTimeInterval;
                StatusTimer.Enabled      = true;
                StatusTimer.Start();
                AlarmsActivate.Text = "Deactivate";
                BattlelistTimer.Start();
            }
            else
            {
                StatusTimer.Stop();
                StatusTimer.Enabled = false;
                AlarmsActivate.Text = "Activate";
                BattlelistTimer.Stop();
            }

            statusText         = "";
            RunStatus          = false;
            Tabs.Enabled       = !Active;
            AlarmsLoad.Enabled = !Active;
        }
コード例 #4
0
        private void stTimer()
        {
            Random rand = new Random();

            fortimerinterval1    = rand.Next(300, 500);
            StatusTimer.Interval = fortimerinterval1;
            StatusTimer.Enabled  = true;
            StatusTimer.Start();
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: coderli7/WinForm
 public Form1()
 {
     InitializeComponent();
     //启动timer,默认5分钟
     StatusTimer.Interval = 60000;
     StatusTimer.Elapsed += StatusTimer_Elapsed;
     StatusTimer.Start();
     //打开后自动连接
     //ConnectSocketServer();
     ConnectSocketServerNew();
     //结束已打开进程
     closeOpenedProcess();
 }
コード例 #6
0
        private void tsb_SaveToClipboard_Click(object sender, EventArgs e)
        {
            string strMsg;
            bool   blRes;

            fnc_ClearStatus();
            blRes = fnc_SaveIamgeToClip();
            if (blRes == true)
            {
                strMsg = "Save image to clipboard finshed.";
            }
            else
            {
                strMsg = "Save image to clipboard failed.";
            }

            tsl_msg.Text = strMsg;
            StatusTimer.Start();
        }
コード例 #7
0
        private void tsb_SaveImageToFile_Click(object sender, EventArgs e)
        {
            string strMsg;
            string strImageFile;

            fnc_ClearStatus();
            strImageFile = fnc_SaveImageToFile();
            if (strImageFile != "")
            {
                strMsg = "Save image file [ " + strImageFile + " ] finshed.";
            }
            else
            {
                strMsg = "Save image file [ " + strImageFile + " ] failed.";
            }

            tsl_msg.Text = strMsg;
            StatusTimer.Start();
        }
コード例 #8
0
        private void BtnStartComparison_Click(object sender, EventArgs e)
        {
            if (ComparisonToken.HasValue)
            {
                StatusTimer.Stop();
                VideoDedupDlg.WcfProxy.CancelCustomVideoComparison(
                    ComparisonToken.Value);
            }

            CleanUpResult();

            if ((int)NumMaxImageComparison.Value <= 0)
            {
                return;
            }

            var startData = VideoDedupDlg.WcfProxy.StartCustomVideoComparison(
                new CustomVideoComparisonData
            {
                AlwaysLoadAllImages       = true,
                LeftFilePath              = TxtLeftFilePath.Text,
                RightFilePath             = TxtRightFilePath.Text,
                MaxImageCompares          = (int)NumMaxImageComparison.Value,
                MaxImageDifferencePercent =
                    (int)NumMaxDifferentPercentage.Value,
                MaxDifferentImages = (int)NumMaxDifferentImages.Value,
            });

            if (startData.ComparisonToken == null)
            {
                _ = MessageBox.Show(
                    "Couldn't start comparison." + Environment.NewLine
                    + startData.ErrorMessage,
                    "Erro starting comparison",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return;
            }
            ComparisonToken = startData.ComparisonToken;

            StatusTimer.Start();
        }
コード例 #9
0
        private void SetStatus(string Text, Color Color, bool Temp = true)
        {
            if (StatusTimer != null && StatusTimer.IsEnabled)
            {
                StatusTimer.Stop();

                StatusText.Text      = Text;
                StatusBar.Background = new SolidColorBrush(Color);

                if (Temp)
                {
                    StatusTimer = new DispatcherTimer()
                    {
                        Interval = TimeSpan.FromSeconds(5)
                    };
                    StatusTimer.Tick += delegate
                    {
                        StatusBar.BeginAnimation(MarginProperty, new ThicknessAnimation()
                        {
                            From           = StatusBar.Margin,
                            To             = new Thickness(0, 0, 0, -30),
                            Duration       = TimeSpan.FromSeconds(0.5),
                            EasingFunction = new ExponentialEase()
                            {
                                EasingMode = EasingMode.EaseIn
                            }
                        });
                        StatusTimer.Stop();
                    };
                    StatusTimer.Start();
                }
            }
            else
            {
                StatusText.Text      = Text;
                StatusBar.Background = new SolidColorBrush(Color);

                if (Temp)
                {
                    StatusTimer = new DispatcherTimer()
                    {
                        Interval = TimeSpan.FromSeconds(5)
                    };
                    StatusTimer.Tick += delegate
                    {
                        StatusBar.BeginAnimation(MarginProperty, new ThicknessAnimation()
                        {
                            From           = StatusBar.Margin,
                            To             = new Thickness(0, 0, 0, -30),
                            Duration       = TimeSpan.FromSeconds(0.5),
                            EasingFunction = new ExponentialEase()
                            {
                                EasingMode = EasingMode.EaseIn
                            }
                        });
                        StatusTimer.Stop();
                    };
                }

                if (StatusBar.Margin.Bottom > -30)
                {
                    return;
                }
                var Animation = new ThicknessAnimation()
                {
                    From           = StatusBar.Margin,
                    To             = new Thickness(0, 0, 0, 0),
                    Duration       = TimeSpan.FromSeconds(0.5),
                    EasingFunction = new ExponentialEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                };
                if (Temp)
                {
                    Animation.Completed += delegate { StatusTimer.Start(); }
                }
                ;
                StatusBar.BeginAnimation(MarginProperty, Animation);
            }
        }
コード例 #10
0
        //WARNING: Status timer can slow down processing significantly if processing is in a tight loop.
        public void StatusTimerTest(MainForm frm)
        {
            StatusTimer timer          = new StatusTimer();
            long        loopMax        = 100000000;
            int         statusInterval = 5;

            try
            {
                _msg.Length = 0;
                _msg.Append("StatusTimerTest started ...\r\n");
                WriteMessageToLog(_msg.ToString());

                timer.NumSecondsInterval = statusInterval;
                timer.Start();  //report status every two seconds

                _msg.Length = 0;
                _msg.Append("\r\nLooping ");
                _msg.Append(loopMax.ToString("#,##0"));
                _msg.Append(" times... \r\n");
                WriteMessageToLog(_msg.ToString());

                for (long num = 1; num <= loopMax; num++)
                {
                    if (timer.StatusReportDue())
                    {
                        _msg.Length = 0;
                        _msg.Append("Loop count = ");
                        _msg.Append(num.ToString("#,##0"));
                        _msg.Append(" Elapsed time to this point: ");
                        _msg.Append(timer.GetFormattedElapsedTime());
                        WriteMessageToLog(_msg.ToString());
                    }
                }
                _msg.Length = 0;
                _msg.Append("Loop count = ");
                _msg.Append(loopMax.ToString("#,##0"));
                _msg.Append(" Elapsed time to this point: ");
                _msg.Append(timer.GetFormattedElapsedTime());
                WriteMessageToLog(_msg.ToString());


                _msg.Length = 0;
                _msg.Append(Environment.NewLine);
                _msg.Append(Environment.NewLine);
                _msg.Append("Total Elapsed Time:   ");
                _msg.Append(timer.GetFormattedElapsedTime());
                _msg.Append(Environment.NewLine);
                _msg.Append("Elapsed milliseconds: ");
                _msg.Append(timer.GetElapsedTime().TotalMilliseconds.ToString("#,##0"));
                _msg.Append(Environment.NewLine);
                WriteMessageToLog(_msg.ToString());

                timer.Stop();
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                WriteMessageToLog(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("\r\n... StatusTimerTest finished.");
                WriteMessageToLog(_msg.ToString());
            }
        }
コード例 #11
0
        public string DecryptFile(pfEncryptorRequest decryptorRequest, ref bool decryptionSuccessful)
        {
            PFFileEncryptor decryptor       = null;
            string          decryptedResult = string.Empty;
            StatusTimer     st = new StatusTimer();

            try
            {
                if (String.IsNullOrEmpty(decryptorRequest.SourceObject))
                {
                    _msg.Length = 0;
                    _msg.Append("You must specify path to a file to decrypt.");
                    throw new System.Exception(_msg.ToString());
                }

                if (String.IsNullOrEmpty(decryptorRequest.DestinationObject))
                {
                    decryptorRequest.DestinationObject = decryptorRequest.SourceObject + ".decrypted";
                }

                if (string.IsNullOrEmpty(decryptorRequest.EncryptionKey) ||
                    string.IsNullOrEmpty(decryptorRequest.EncryptionIV))
                {
                    _msg.Length = 0;
                    _msg.Append("You must specify both Key and IV values.");
                    throw new System.Exception(_msg.ToString());
                }

                if (decryptorRequest.SourceObject == decryptorRequest.DestinationObject)
                {
                    _msg.Length = 0;
                    _msg.Append("Source and destination file paths are the same. They must be different for decryption routine to work.");
                    throw new System.Exception(_msg.ToString());
                }


                decryptor = new PFFileEncryptor(decryptorRequest.EncryptionAlgorithm);
                decryptor.currentStatusReport        += UpdateStatus;
                decryptor.StatusReportIntervalSeconds = _statusReportIntervalSeconds;

                decryptor.Key = decryptorRequest.EncryptionKey;
                decryptor.IV  = decryptorRequest.EncryptionIV;

                st.ShowElapsedTimeMilliseconds = false;
                st.Start();

                if (decryptorRequest.UseBinaryEncryption == false)
                {
                    if (decryptorRequest.DestinationObjectType == pfEncryptorObjectType.File)
                    {
                        decryptedResult = decryptor.Decrypt(decryptorRequest.SourceObject, decryptorRequest.DestinationObject, st);
                    }
                    else
                    {
                        decryptedResult = decryptor.Decrypt(decryptorRequest.SourceObject);
                    }
                }
                else
                {
                    decryptedResult = decryptor.DecryptBinary(decryptorRequest.SourceObject, decryptorRequest.DestinationObject, st);
                }

                decryptorRequest.DestinationObject = decryptedResult;

                decryptionSuccessful = true;
            }
            catch (System.Exception ex)
            {
                decryptionSuccessful = false;
                _msg.Length          = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                if (decryptor != null)
                {
                    decryptor.currentStatusReport -= UpdateStatus;
                    decryptor = null;
                }
                if (st != null)
                {
                    if (st.StatusTimerIsRunning)
                    {
                        st.Stop();
                    }
                    st = null;
                }
            }


            return(decryptedResult);
        }
コード例 #12
0
        private bool fnc_DeleteListItem(int int_sel_idx)
        {
            bool blRes;
            int  intCnt;

            string[] strTempList;
            string   strSelText;
            string   strMsg;

            try
            {
                strTempList = new string[CON_COB_URL_CNT];

                intCnt = 0;
                // コンボアイテム取得
                for (intCnt = 0; intCnt < CON_COB_URL_CNT; intCnt++)
                {
                    if (intCnt < cob_url.Items.Count)
                    {
                        strTempList[intCnt] = cob_url.Items[intCnt].ToString().Trim();
                    }
                    else
                    {
                        strTempList[intCnt] = "";
                    }
                }

                // 指定されたアイテムをコンボリストから削除
                strSelText = "";
                cob_url.Items.Clear();
                for (intCnt = 0; intCnt < CON_COB_URL_CNT; intCnt++)
                {
                    if (strTempList[intCnt] != "")
                    {
                        if (intCnt != int_sel_idx)
                        {
                             cob_url.Items.Add(strTempList[intCnt]);
                        }
                        else
                        {
                            strSelText = strTempList[intCnt];
                        }
                    }
                }

                // URL再設定
                if (int_sel_idx == 0)
                {
                    cob_url.Text = cob_url.Items[0].ToString();
                }
                else
                {
                    cob_url.Text = cob_url.Items[int_sel_idx - 1].ToString();
                }

                // 削除されたURLをステータスバーに表示
                strMsg       = "Delete Url [" + strSelText + "] From List ComboBox.";
                tsl_msg.Text = strMsg;
                StatusTimer.Start();

                //// 設定されたURLに遷移
                //if (cob_url.Text.Trim() != "")
                //{
                //    TargetWebBrowser.Navigate(cob_url.Text);
                //}

                blRes = true;
            }
            catch (Exception ex)
            {
                blRes = false;
                CommonLogger.WriteLine(ex.Message);
            }
            return(blRes);
        }