예제 #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            WindowLog.Init(this);
            WindowLog.Debug("Main::Load", "Loading settings from INI file");

            Program.CreateIniFile();

            Program.cacheDataDisplayMode = Program.ini.Read("Display", "CacheDataDisplayMode");

            if (Database.Database.Init() == false)
            {
                WindowLog.Error("Main::Load", "Cannot connect to database");
                Application.Exit();
            }

            WindowLog.Debug("Main::Load", "Loading cache names for common cache");

            // Load the cache list for common caches
            cacheNames = CacheDB.GetCommonCacheNames();

            foreach (string name in cacheNames)
            {
                WindowLog.Debug("Main::Load", "Adding cache " + name + " to cache list");
                listBox1.Items.Add(name);
            }

            WindowLog.Debug("Main::Load", "Application started");
        }
        public List <Duplicate> Execute()
        {
            ProcessUpdate?.Invoke($"Updating Cache ({Configuration.CacheFileName})");

            using (var cacheDB = new CacheDB(Configuration.CacheFileName))
            {
                var methodExtractor = new MethodExtractor();
                var finder          = new DuplicateFinder(Configuration);

                var files = Directory.EnumerateFiles(Configuration.SourceDirectory, "*.prg", SearchOption.AllDirectories).ToList();
                ProcessUpdate?.Invoke($"Found {files.Count} source files");

                var index = 1;
                foreach (var fileName in files)
                {
                    var sourceCodeFile = new SourceCodeFile(fileName);

                    ProcessUpdate?.Invoke($"[{index++} of {files.Count}] {sourceCodeFile.RelativeFileName(Configuration.SourceDirectory)}");

                    try
                    {
                        if (!cacheDB.TryGetValue(sourceCodeFile, out var codeInfo))
                        {
                            codeInfo = methodExtractor.Execute(sourceCodeFile);
                            cacheDB.Add(codeInfo);
                        }
                        finder.AddSourceCodeFile(sourceCodeFile, codeInfo);
                    }
                    catch
                    {
                        ProcessUpdate?.Invoke("File could not be parsed and will be skipped");
                    }
                }

                ProcessUpdate?.Invoke("Identifying duplicates");
                var result = finder.Execute();
                ProcessUpdate?.Invoke($"{(result.Count > 0 ? result.Count.ToString() : "No")} duplicates found");

                return(result);
            }
        }
예제 #3
0
        public void NotFoundInsertFound()
        {
            var dbName = GetTempDBName();

            using (var cache = new CacheDB(dbName))
            {
                var sourceCodeFile = new SourceCodeFile("XXX", "test");

                cache.TryGetValue(sourceCodeFile, out var codeInfo).Should().Be(false);

                var newCodeInfo = BuildDummyCodeInfo(sourceCodeFile);

                cache.Add(newCodeInfo);

                cache.TryGetValue(sourceCodeFile, out codeInfo).Should().Be(true);

                codeInfo.Should().BeEquivalentTo(newCodeInfo);
            }

            File.Delete(dbName);
        }
예제 #4
0
        public SchumixBase()
        {
            try
            {
                ExitStatus = false;

                if (ServerConfig.Enabled)
                {
                    var listener = new ClientSocket(ServerConfig.Host, ServerConfig.Port, ServerConfig.Password);
                    Log.Debug("SchumixServer", sLConsole.GetString("Initiating connection."));
                    listener.Socket();

                    while (ThreadStop)
                    {
                        Thread.Sleep(100);
                    }
                }

                if (ListenerConfig.Enabled)
                {
                    Log.Debug("SchumixBot", sLConsole.GetString("SchumixListener starting..."));
                    var sListener = new SchumixListener(ListenerConfig.Port);
                    new Thread(() => sListener.Listen()).Start();
                }

                if (sPlatform.IsLinux)
                {
                    ServicePointManager.ServerCertificateValidationCallback += (s, ce, ca, p) => true;
                }

                WebRequest.DefaultWebProxy = null;

                Log.Debug("SchumixBase", sLConsole.GetString("Timer is starting..."));
                sTimer = new Timer();
                sTimer.Start();

                Log.Debug("SchumixBase", sLConsole.GetString("MySql is starting..."));
                DManager = new DatabaseManager();

                Log.Debug("SchumixBase", sLConsole.GetString("CacheDB is starting..."));
                sCacheDB = new CacheDB();
                sCacheDB.Load();

                Log.Notice("SchumixBase", sLConsole.GetString("Successfully connected to the database."));
                sLManager.Locale = LocalizationConfig.Locale;

                SqlInfoReConfig();

                Log.Debug("SchumixBase", sLConsole.GetString("CleanManager is starting..."));
                sCleanManager = new CleanManager();
                sCleanManager.Initialize();

                if (AddonsConfig.Enabled)
                {
                    Log.Debug("SchumixBase", sLConsole.GetString("AddonManager is loading..."));
                    sAddonManager.Initialize();
                    sAddonManager.LoadPluginsFromDirectory(AddonsConfig.Directory);
                }
            }
            catch (Exception e)
            {
                Log.Error("SchumixBase", sLConsole.GetString("Failure details: {0}"), e.Message);
            }
        }