コード例 #1
0
        public void NTPDateTime_AreEqual()
        {
            DateTime data = DateTime.Now;
            DateTime result = NTPDateTime.FromWindowsServers();

            data = new DateTime(data.Year, data.Month, data.Day, data.Hour, data.Minute, 0);
            result = new DateTime(result.Year, result.Month, result.Day, result.Hour, result.Minute, 0);

            var newLine = Environment.NewLine;

            var message = string.Format(
                    newLine +
                    newLine + "-----------------------------------" +
                    newLine + "| Expected for [" + data.ToString() + "] --> [True]" +
                    newLine + "|" +
                    newLine + "| - " + data.Year +
                    newLine + "| - " + data.Month +
                    newLine + "| - " + data.Day +
                    newLine + "| - " + data.Hour +
                    newLine + "| - " + data.Minute +
                    newLine + "|" +
                    newLine + "| Obtained for [" + data.ToString() + "] --> [False]" +
                    newLine + "| - " + result.Year +
                    newLine + "| - " + result.Month +
                    newLine + "| - " + result.Day +
                    newLine + "| - " + result.Hour +
                    newLine + "| - " + result.Minute +
                    newLine + "-----------------------------------"
                );

            Assert.AreEqual(data, result, message);
        }
コード例 #2
0
        public void NTPDateTime_ThrowException()
        {
            try
            {
                var result = NTPDateTime.FromServerURL(string.Empty);
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(true);
                return;
            }
            catch (Exception)
            {
                Assert.IsTrue(true);
                return;
            }

            Assert.Fail();
        }
コード例 #3
0
ファイル: mainClass.cs プロジェクト: LucianoFM/udyat
        public mainClass()
        {
            // Cria o objeto de legendas
            ScreenCapturing.LegendData = new DataImage();

            // Indica se o arquivo INI existe
            bool iniExists = File.Exists(Config.ConfigFullFileName);

            // Parâmetros de linha de comando que não necessitam de parâmetros do arquivo de configuração .ini
            string[] args = Environment.GetCommandLineArgs();
            if (args.Length > 1)
            {
                command = args[1].ToUpper();

                if (args.Length > 2)
                {
                    subCommand1         = command = args[2].ToUpper();
                    showConsoleMessages = subCommand1 == CMD_INSTAL_NOCONSOLE;
                }

                if ((command == CMD_INSTAL) && (!iniExists))
                {
                    Util.ShowConsoleMessage("Arquivo de configuração não encontrado", showConsoleMessages);
                    Environment.Exit(0);
                }
                else if (command == CMD_QUIT)
                {
                    // Finaliza o processo que estiver em execução
                    EndRunningProcess();
                    Environment.Exit(0);
                }
            }

            // Carrega as configurações do sistema
            sysConfig = new Config();
            try
            {
                if (!sysConfig.LoadConfig())
                {
                    Util.ShowConsoleMessage("Arquivo de configuração não encontrado", showConsoleMessages);
                    Environment.Exit(0);
                }
            } catch (Exception ex)
            {
                if (command == CMD_INSTAL)
                {
                    Util.ShowConsoleMessage("Erro ao ler o .ini: " + ex.Message, showConsoleMessages);
                }
                Environment.Exit(0);
            }


            // Arquivo de log
            Log.logFullFileName = sysConfig.TargetPath + string.Format("{0:yyyyMMdd}", DateTime.Now) + "_" + Log.LOG_FILE;


            // Testa a conexão com a internet
            // Se não tem conexão com a internet: então fecha o sistema.
            if (!HasConection())
            {
                Environment.Exit(0);
            }

            // Iniciliza o relógio do sistema buscando a data e hora brasileira
            internalClock = NTPDateTime.GetNetworkTime(sysConfig.Data.Proxy);
            ClockTimer    = new Timer(new TimerCallback(ClockTimerTick), null, 0, sysConfig.Data.ClockLoop);

            // Adiciona log informando que está em modo de teste
            Log.AddStartLog(sysConfig.Data.TestMode, sysConfig.TempPath, sysConfig.TargetPath);

            // Inicia a Thread de comunicação P2P com o Servidor
            try
            {
                StartServerConnection();
            }
            catch (Exception ex)
            {
                Log.AddLog("P2P", "Erro: " + ex.Message);
            }


            // Mode teste (gera somente 10 imagens)
            // sysConfig.Data.TestMode = true;



            // Parâmetros de linha de comando que necessitam de parâmetros
            if (args.Length > 1)
            {
                if (command == CMD_CHKIMAGE) // Verificação de Imagem
                {
                    // Verifica se uma imagem foi gerada pelo Udyat
                    ImageIsUdyat(args);
                    Environment.Exit(0);
                }
                else if (command == CMD_INSTAL) // Instalação do sistema
                {
                    // Tenta ativar a licença
                    License actLicense = new License(sysConfig.Data);
                    try
                    {
                        if (!actLicense.ActivateLicense())
                        {
                            if (actLicense.ExceptionMessage.Length > 0)
                            {
                                Log.AddLog("License", "Erro: " + actLicense.ExceptionMessage);
                                Util.ShowConsoleMessage(actLicense.ExceptionMessage, showConsoleMessages);
                            }
                            else
                            {
                                Log.AddLog("License", "Erro: essa licença não autorizada");
                                Util.ShowConsoleMessage("Essa não é uma licença válida.", showConsoleMessages);
                            }
                            Environment.Exit(0);
                        }
                        // Adiciona os parâmetros do arquivo .ini no registro do windows
                        sysConfig.SaveIniInWinRegister();
                    }
                    catch (Exception ex)
                    {
                        Log.AddLog("License", "Erro de validação da licença: " + ex.Message);
                        Util.ShowConsoleMessage("Erro ao tentar validar a licença: " + ex.Message, showConsoleMessages);
                        Environment.Exit(0);
                    }
                }
                else if (command == CMD_UNINSTAL) // Desinstalação do sistema
                {
                    // Encerra o processamento do sistema que estiver sendo executado (se houver algum)
                    EndRunningProcess(false);
                    // Elimina os registros de configuração do sistema
                    sysConfig.RemoveIniFromRegister();
                    // Finaliza
                    Environment.Exit(0);
                }
            }

            // Finaliza a aplicação se ela já estiver sendo executada
            if (System.Diagnostics.Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1)
            {
                Log.AddLog("Processo", "Tentativa de execução com processo rodando");
                Environment.Exit(0);
            }

            // Verifica LICENÇA do sistema quando não for a instalação
            if (command != CMD_INSTAL)
            {
                if (!License.IsLicenseOk(sysConfig.Data))
                {
                    Environment.Exit(0);
                }
            }

            // MAC Address da máquina
            MACAddress = Util.GetMacAddres();

            // Dados do build
            AssemblyName versionIndo = typeof(mainClass).Assembly.GetName();

            // Configurações de legenda
            ScreenCapturing.Version                   = versionIndo.Name + " " + versionIndo.Version.ToString();
            ScreenCapturing.BitmapLogo                = Udyat.Properties.Resources.logo;
            ScreenCapturing.LegendFont                = new Font("Tahoma", 15);
            ScreenCapturing.LegendDateFont            = new Font("Tahoma", 30);
            ScreenCapturing.LegendColor               = Color.Gray;
            ScreenCapturing.FooterBackgroundColor     = Color.Black;
            ScreenCapturing.LegendData.IP             = Util.GetLocalIpAddress();
            ScreenCapturing.LegendData.IsTrialVersion = sysConfig.Data.IsTrialLicense;

            // Se existir arquivos de imanges no temp (que ainda não foram enviados), então envia para o destino
            MoveExistingFiles();

            // Inicia o timer
            if (sysConfig.Data.TestMode)
            {
                // Mode teste
                callbackTemp = new TimerCallback(ModeTestSaveTempVideoTick);
                Timer1       = new Timer(callbackTemp, null, 0, sysConfig.Data.IntervalToPrint);
            }
            else
            {
                // Mode produção
                callbackTemp = new TimerCallback(SaveTempVideoTick);
                Timer1       = new Timer(callbackTemp, null, 0, sysConfig.Data.IntervalToPrint);
            }
        }