public static async Task <Launch> SmartMergeLaunchesAsync(
            this ICakeContext context,
            Service service,
            FilterOption filter,
            CleanOptions cleanOptions,
            MergeOptions mergeOptions = null,
            bool debug = true)
        {
            var cleaner = new ForciblyTerminatingLaunchCleaner(
                new LaunchCleaner(service, cleanOptions),
                service);

            var decoratedMerger = new CleanableLaunchMerger(new LaunchMerger(service, mergeOptions), cleaner);
            var merger          = new ForciblyTerminatingLaunchMerger(decoratedMerger, service);

            var launch = await new SmartLaunchMerger(merger, service, debug)
                         .MergeAsync(filter)
                         .ConfigureAwait(false);

            var message = $"Smart merging launches successfully completed.";

            context.Log.Write(Verbosity.Diagnostic, LogLevel.Debug, message);

            return(launch);
        }
Exemple #2
0
        private static int RunCleanAndReturnExitCode(CleanOptions opts)
        {
            if (!File.Exists(opts.InputFilePath))
            {
                Console.Error.WriteLine($"File '{opts.InputFilePath}' not found.");
                return(1);
            }

            if (!Directory.Exists(opts.FolderPath))
            {
                Console.Error.WriteLine($"Directory '{opts.FolderPath}' not found.");
                return(1);
            }

            var indexedFilesHashes = GetFileHashesFromIndexFile(opts.InputFilePath);

            var files = GetFilePaths(opts.FolderPath, opts.Recursive);

            foreach (var file in files.Where(f => indexedFilesHashes.Contains(GetFileHash(f))))
            {
                if (opts.DryRun)
                {
                    Console.WriteLine(file);
                }
                else
                {
                    File.Delete(file);
                }
            }

            return(0);
        }
Exemple #3
0
        private static int RunClean(CleanOptions options)
        {
            var solution = LoadSolution(options);

            var console = new ProgramConsole();

            IProject project = null;

            if (options.Project != null)
            {
                project = FindProject(solution, options.Project);
            }
            else
            {
                project = solution.StartupProject;
            }

            if (project != null)
            {
                project.ToolChain.Clean(console, project).Wait();
            }
            else
            {
                console.WriteLine("Nothing to clean.");
            }

            return(1);
        }
 protected override void ExecuteCommand(MantisDatabase db, DbCommand cmd, CleanOptions options, TaskDataStore store)
 {
     db.DeleteAll("api tokens", MantisTable.api_token);
     db.DeleteAll("tokens", MantisTable.tokens);
     db.DeleteAll("emails", MantisTable.email);
     db.DeleteAll("filters", MantisTable.filters);
     db.DeleteAll("news", MantisTable.news);
     db.DeleteAll("sponsorship entries", MantisTable.sponsorship);
 }
Exemple #5
0
        private static int Process(CleanOptions options)
        {
            var temporalDirectories = Directory.GetDirectories(AppDomain.CurrentDomain.BaseDirectory, "_temp_*");

            foreach (var temporalDirectory in temporalDirectories)
            {
                Directory.Delete(temporalDirectory, true);
            }
            return(0);
        }
Exemple #6
0
        protected override void ExecuteCommand(MantisDatabase db, DbCommand cmd, CleanOptions options, TaskDataStore store)
        {
            List <int> projectids = store.Get <List <int> >(DataKey.KeepProjectIDs);

            db.DeleteMatching("projects", $"DELETE FROM {db.Table(MantisTable.project)} WHERE id NOT IN @@ids", projectids);

            db.DeleteMatching("project files", $"DELETE FROM {db.Table(MantisTable.project_file)} WHERE project_id NOT IN @@ids", projectids);
            db.DeleteMatching("project hierarchy entries", $"DELETE FROM {db.Table(MantisTable.project_hierarchy)} WHERE parent_id NOT IN @@ids OR child_id NOT IN @@ids", projectids);
            db.DeleteMatching("project user assignments", $"DELETE FROM {db.Table(MantisTable.project_user_list)} WHERE project_id NOT IN @@ids", projectids);
            db.DeleteMatching("project versions", $"DELETE FROM {db.Table(MantisTable.project_version)} WHERE project_id NOT IN @@ids", projectids);
        }
Exemple #7
0
        protected override void ExecuteCommand(MantisDatabase db, DbCommand cmd, CleanOptions options, TaskDataStore store)
        {
            List <int> projectids = db.ReadList <int>($"SELECT id FROM {db.Table(MantisTable.project)}");

            // delete assignbment snon-existent projects
            db.DeleteMatching("custom field project assignments", $"DELETE FROM {db.Table(MantisTable.custom_field_project)} WHERE project_id NOT IN @@ids", projectids);

            // now delete all custom fields which do not have any assignments anymore
            List <int> customfieldids = db.ReadList <int>($"SELECT DISTINCT field_id FROM {db.Table(MantisTable.custom_field_project)}");

            db.DeleteMatching("custom fields", $"DELETE FROM {db.Table(MantisTable.custom_field)} WHERE id NOT IN @@ids", customfieldids);
            db.DeleteMatching("custom field strings", $"DELETE FROM {db.Table(MantisTable.custom_field_string)} WHERE field_id NOT IN @@ids", customfieldids);
        }
        protected override void ExecuteCommand(MantisDatabase db, DbCommand cmd, CleanOptions options, TaskDataStore store)
        {
            // delete bugs which belong to non-existent projects
            List <int> projectids = store.Get <List <int> >(DataKey.KeepProjectIDs);

            db.DeleteMatching("bugs", $"DELETE FROM {db.Table(MantisTable.bug)} WHERE project_id NOT IN @@ids", projectids);

            // we cannot use DELETE FROM WHERE [id] IN (SELECT **), see https://dba.stackexchange.com/questions/84805/delete-seems-to-hang
            // or multiple-table DELETES because they always time out
            // get the list of bug_ids beforehand and list them separately
            // todo: if tehre are too many ids (command gets too long), we might need to delete in batches

            // delete all bug_texts which are not used anymore
            List <int> bugtextids = db.ReadList <int>($"SELECT bug_text_id FROM {db.Table(MantisTable.bug)}");

            db.DeleteMatching("bug text entries", $"DELETE FROM {db.Table(MantisTable.bug_text)} WHERE id NOT IN @@ids", bugtextids);

            // delete all bug_notes which reference non-existent bugs
            List <int> bugids = db.ReadList <int>($"SELECT id FROM {db.Table(MantisTable.bug)}");

            db.DeleteMatching("bug notes", $"DELETE FROM {db.Table(MantisTable.bugnote)} WHERE bug_id NOT IN @@ids", bugids);

            // delete all bug_note_texts which reference non-existent bug notes
            List <int> notetextids = db.ReadList <int>($"SELECT bugnote_text_id FROM {db.Table(MantisTable.bugnote)}");

            db.DeleteMatching("bug note text entries", $"DELETE FROM {db.Table(MantisTable.bugnote_text)} WHERE id NOT IN @@ids", notetextids);

            // delete all bug files which reference non-existent bugs (takes some time)
#if RELEASE
            int oldTimeout = cmd.CommandTimeout;
            cmd.CommandTimeout = (int)TimeSpan.FromSeconds(30).TotalMilliseconds;
            db.DeleteMatching("bug attached files", $"DELETE FROM {db.Table(MantisTable.bug_file)} WHERE bug_id NOT IN @@ids", bugids);
            cmd.CommandTimeout = oldTimeout;
#endif

            // delete all bug history entries which reference non-existent bugs
            db.DeleteMatching("bug history entries", $"DELETE FROM {db.Table(MantisTable.bug_history)} WHERE bug_id NOT IN @@ids", bugids);

            // delete all bug monitor entries which reference non-existent bugs
            db.DeleteMatching("bug monitor entries", $"DELETE FROM {db.Table(MantisTable.bug_monitor)} WHERE bug_id NOT IN @@ids", bugids);

            // delete all bug relationships which reference non-existent bugs
            db.DeleteMatching("bug relationships", $"DELETE FROM {db.Table(MantisTable.bug_relationship)} WHERE source_bug_id NOT IN @@ids OR destination_bug_id NOT IN @@ids", bugids);

            // delete all bug revision entries which reference non-existent bugs
            db.DeleteMatching("bug revision entries", $"DELETE FROM {db.Table(MantisTable.bug_revision)} WHERE bug_id NOT IN @@ids", bugids);

            // delete all bug tags which reference non-existent bugs
            db.DeleteMatching("bug tags", $"DELETE FROM {db.Table(MantisTable.bug_tag)} WHERE bug_id NOT IN @@ids", bugids);
        }
        private static void CleanOutputDirectory(CleanOptions options, ConfigModel config)
        {
            Logger.Log(LogCategory.Info, "Cleaning output folder " + config.Build.OutputDirectory);

            DirectoryInfo di = new DirectoryInfo(config.Build.OutputDirectory);

            foreach (FileInfo file in di.GetFiles())
            {
                file.Delete();
            }
            foreach (DirectoryInfo dir in di.GetDirectories())
            {
                dir.Delete(true);
            }
        }
Exemple #10
0
        /// <summary>
        /// The operation which will clean all the remnant files and maps from
        /// the device.
        /// </summary>
        /// <param name="options">The options object which contains extra information
        /// which helps during the exeuction of this modus.</param>
        public static void Start(CleanOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            Logger.Log(I_StartProc_Clean);
            if (options.CleanSettings)
            {
                CleanFiles();
            }
            CleanDirectories();
            Logger.Log(I_EndProc_Clean);
        }
 public void Run(MantisDatabase db, CleanOptions options, TaskDataStore store)
 {
     try
     {
         using (var cmd = db.CreateCommand())
         {
             cmd.CommandText = $"SELECT value FROM {db.Table(MantisTable.config)} WHERE config_id = 'database_version'";
             var vr = cmd.ExecuteScalar();
             LogService.Info("Mantis database version is " + vr?.ToString() ?? "");
         }
     }
     catch (Exception e)
     {
         throw new TaskFailedException(false, "Connection test failed: " + e.Message);
     }
 }
        public static async Task <Launch> CleanLaunchAsync(
            this ICakeContext context,
            Service service,
            Launch launch,
            CleanOptions options)
        {
            var message = $"Before cleaning total tests in launch with id = {launch.Id} equals {launch.Statistics.Executions.Total}";

            context.Log.Write(Verbosity.Diagnostic, LogLevel.Debug, message);

            var afterClean = await new LaunchCleaner(service, options).CleanAsync(launch).ConfigureAwait(false);

            message = $"Cleaning launch with id = {launch.Id} successfully completed." +
                      $" Total tests =  {afterClean.Statistics.Executions.Total}";

            context.Log.Write(Verbosity.Diagnostic, LogLevel.Debug, message);
            return(afterClean);
        }
Exemple #13
0
//        ConfigWatcher m_config;
//        const int m_letterNum = 26;

//        /// <summary>
//        /// Initializes a new instance of this class.
//        /// </summary>
//        public Letters()
//        {
//            Reset();
//        }

//        /// <summary>
//        /// Reset the object's letters.
//        /// </summary>
//        public void Reset()
//        {
//            ClearCounts();
//            ClearFrequencies();
//        }

//        /// <summary>
//        /// Clear out the current count values
//        /// </summary>
//        private void ClearCounts()
//        {
//            m_letterCount = new int[m_letterNum];
//            m_prevLetterCount = new int[m_letterNum][];
//            m_nextLetterCount = new int[m_letterNum][];
//            for (int i = 0; i < m_letterNum; i++)
//            {
//                m_prevLetterCount[i] = new int[m_letterNum];
//                m_nextLetterCount[i] = new int[m_letterNum];
//            }
//        }

//        /// <summary>
//        /// Clear out the current frequency values
//        /// </summary>
//        private void ClearFrequencies()
//        {
//            m_letterFrequencies = new float[m_letterNum];
//            m_prevLetterFreqencies = new float[m_letterNum][];
//            m_nextLetterFreqencies = new float[m_letterNum][];
//            for (int i = 0; i < m_letterNum; i++)
//            {
//                m_prevLetterFreqencies[i] = new float[m_letterNum];
//                m_nextLetterFreqencies[i] = new float[m_letterNum];
//            }
//        }

//        /// <summary>
//        /// Returns the letter frequencies for the letters.
//        /// </summary>
//        /// <returns>An array of frequencies representing a-z.</returns>
//        public float[] GetLetterFrequencies()
//        {
//            return m_letterFrequencies;
//        }

//        /// <summary>
//        /// Reads in letter frequencies from an config file.
//        /// </summary>
//        public void LoadLetterFrequencies()
//        {
//            //int letter;
//            m_letterFrequencies = new float[m_letterNum];

//            if (m_config == null)
//            {
//                m_config = new ConfigWatcher();
//                m_config.Changed += new EventHandler<ConfigChangedEventArgs>(m_config_Changed);
//            }

//            LoadLettersFromConfig();

//            //XmlDocument xDOM = new XmlDocument();
//            //xDOM.Load(@"statistics.xml");

//            //XmlNodeList nodelist = xDOM.SelectNodes("FREQUENCY/LETTERS/LETTER");

//            //XmlAttribute xAttr;
//            //foreach (XmlNode node in nodelist)
//            //{
//            //    xAttr = (XmlAttribute)node.Attributes.GetNamedItem("name");
//            //    letter = (int)xAttr.Value.ToCharArray()[0] % 'A';
//            //    xAttr = (XmlAttribute)node.Attributes.GetNamedItem("value");
//            //    m_letterFrequencies[letter] = float.Parse(xAttr.Value, m_culture);
//            //}
//            // TODO: Prev/Next letter frequencies

//            return;
//        }

//        void m_config_Changed(object sender, ConfigChangedEventArgs e)
//        {
//            LoadLettersFromConfig();
//        }

//        private void LoadLettersFromConfig()
//        {
//            foreach (UsefulConfigLetter letter in m_config.Config.Letters)
//            {
//                m_letterFrequencies[char.ToUpper(letter.Name[0], m_culture) % 'A'] = letter.Frequency;
//            }
//        }

//        /// <summary>
//        /// Reads in letters from some text.
//        /// </summary>
//        /// <param name="text">The text from which to read the letters from.</param>
//        public void ReadText(string text)
//        {
//            if (text == null)
//            {
//                throw new ArgumentNullException("text");
//            }

//            char letter;
//            char previousLetter;
//            char nextLetter;

//            //Clear out the current values
//            ClearFrequencies();

//            //Get First letter
////			cLetter = char.ToUpper(TextString[0]);

//            previousLetter = char.MinValue;
//            letter = char.ToUpper(text[0], m_culture);

//            //Get the rest of the text
//            for (int i = 1 ; i < text.Length ; i++)
//            {
//                nextLetter = char.ToUpper(text[i], m_culture);

//                //Add to stats
//                AddToLetterCount(letter, previousLetter, nextLetter);

//                //Shuffle letters for next read
//                previousLetter = letter;
//                letter = nextLetter;
//            }

//            //This will be for the last letter

//            AddToLetterCount(letter, previousLetter, char.MinValue);

//            //Calculate the frequency percentages
//            //Call objStrings.CopyArray(MyLetters.FrequencyPercent, objCrypt.CalcFrequencyPercentages(MyLetters.Frequency))
//            m_letterFrequencies = Statistics.CalcFrequencyPercentages(m_letterCount);
//            m_prevLetterFreqencies = Statistics.CalcFreqPercentages(m_prevLetterCount);
//            m_nextLetterFreqencies = Statistics.CalcFreqPercentages(m_nextLetterCount);
//        }

//        ///// <summary>
//        /////
//        ///// </summary>
//        ///// <param name="Letter"></param>
//        //private void AddToLetterCount(char Letter)
//        //{
//        //    AddToLetterCount(Letter, char.MinValue, char.MinValue);
//        //}

//        /// <summary>
//        /// Add a letter to the letter's frequency count.
//        /// </summary>
//        /// <param name="letter">The letter to add to.</param>
//        /// <param name="previousLetter">Letter that comes before this letter.</param>
//        /// <param name="nextLetter">Letter that comes after this letter.</param>
//        private void AddToLetterCount(char letter, char previousLetter, char nextLetter)
//        {
//            if (char.IsLetter(letter))
//            {
//                m_letterCount[char.ToUpper(letter, m_culture) % 'A']++;

//                if (char.IsLetter(previousLetter))
//                {
//                    //Add letter to previous letter spread
//                    m_prevLetterCount[char.ToUpper(letter, m_culture) % 'A'][char.ToUpper(previousLetter, new CultureInfo("en-GB")) % 'A']++;
//                }

//                if (char.IsLetter(nextLetter))
//                {
//                    //Add letter to next letter spread
//                    m_nextLetterCount[char.ToUpper(letter, m_culture) % 'A'][char.ToUpper(nextLetter, new CultureInfo("en-GB")) % 'A']++;
//                }
//            }
//        }

        /// <summary>
        /// Cleans a dirty string by making it uppercase and removing any non-letters.
        /// </summary>
        /// <param name="dirty">The dirty string to clean.</param>
        /// <param name="alphabet">The unicode alphabet to check the dirty letter is in.</param>
        /// <param name="options"></param>
        /// <returns>The clean string.</returns>
        public static char Clean(char dirty, Alphabets alphabet, CleanOptions options)
        {
            // Check to make sure the letter is in the specified alphabet
            if (Alphabet.GetAlphabetLetters(alphabet).Contains(dirty))
            {
                if ((options & CleanOptions.ToUpper) == CleanOptions.ToUpper)
                {
                    return(char.ToUpper(dirty));
                }
                else
                {
                    return(dirty);
                }
            }
            else
            {
                return('\0');
            }
        }
        public static async Task <Launch> MergeLaunchesWithCleaningAsync(
            this ICakeContext context,
            Service service,
            Launch cleanable,
            Launch notCleanable,
            CleanOptions cleanOptions,
            MergeOptions mergeOptions = null)
        {
            var cleaner = new ForciblyTerminatingLaunchCleaner(
                new LaunchCleaner(service, cleanOptions),
                service);

            var launch = await new CleanableLaunchMerger(new LaunchMerger(service, mergeOptions), cleaner)
                         .MergeAsync(cleanable, notCleanable)
                         .ConfigureAwait(false);

            var message = $"Merging launches with cleaning with id = {cleanable.Id} and id = {notCleanable.Id} successfully completed";

            context.Log.Write(Verbosity.Diagnostic, LogLevel.Debug, message);

            return(launch);
        }
        protected override void ExecuteCommand(MantisDatabase db, DbCommand cmd, CleanOptions options, TaskDataStore store)
        {
            // delete all users which are not referenced anymore
            List <int> userids = db.ReadList <int>($"SELECT DISTINCT reporter_id FROM {db.Table(MantisTable.bugnote)}");

            userids.Union(db.ReadList <int>($"SELECT DISTINCT user_id FROM {db.Table(MantisTable.bug_file)}"));
            userids.Union(db.ReadList <int>($"SELECT DISTINCT user_id FROM {db.Table(MantisTable.bug_history)}"));
            userids.Union(db.ReadList <int>($"SELECT DISTINCT user_id FROM {db.Table(MantisTable.bug_monitor)}"));
            userids.Union(db.ReadList <int>($"SELECT DISTINCT user_id FROM {db.Table(MantisTable.bug_revision)}"));
            userids.Union(db.ReadList <int>($"SELECT DISTINCT reporter_id FROM {db.Table(MantisTable.bug)}"));
            userids.Union(db.ReadList <int>($"SELECT DISTINCT handler_id FROM {db.Table(MantisTable.bug)}"));
            userids.Union(db.ReadList <int>($"SELECT DISTINCT user_id FROM {db.Table(MantisTable.bug_tag)}"));
            userids.Union(db.ReadList <int>($"SELECT DISTINCT user_id FROM {db.Table(MantisTable.category)}"));
            userids.Union(db.ReadList <int>($"SELECT DISTINCT user_id FROM {db.Table(MantisTable.config)}"));
            userids.Union(db.ReadList <int>($"SELECT DISTINCT user_id FROM {db.Table(MantisTable.filters)}"));
            userids.Union(db.ReadList <int>($"SELECT DISTINCT poster_id FROM {db.Table(MantisTable.news)}"));
            userids.Union(db.ReadList <int>($"SELECT DISTINCT user_id FROM {db.Table(MantisTable.project_file)}"));
            userids.Union(db.ReadList <int>($"SELECT DISTINCT user_id FROM {db.Table(MantisTable.project_user_list)}"));
            userids.Union(db.ReadList <int>($"SELECT DISTINCT user_id FROM {db.Table(MantisTable.sponsorship)}"));
            userids.Union(db.ReadList <int>($"SELECT DISTINCT user_id FROM {db.Table(MantisTable.tag)}"));
            userids.Union(db.ReadList <int>($"SELECT DISTINCT user_id FROM {db.Table(MantisTable.user_profile)}"));

            // remove all users which are not referenced anymore
            db.DeleteMatching("users", $"DELETE FROM {db.Table(MantisTable.user)} WHERE id NOT IN @@ids", userids);
            db.DeleteMatching("user profiles", $"DELETE FROM {db.Table(MantisTable.user_profile)} WHERE user_id NOT IN @@ids", userids);

            // Remove confidential/personal user data
            cmd.CommandText = $"UPDATE {db.Table(MantisTable.user)} SET email='redacted',password='******',login_count=0,lost_password_request_count=0,failed_login_count=0,cookie_string=CONCAT('redacted_', id),last_visit=0,date_created=0";
            int count = cmd.ExecuteNonQuery();

            LogService.Info($"Removed personal data from all remaining {count} user profiles");

            // delete personal data
            db.DeleteAll("user preferences", MantisTable.user_pref);
            db.DeleteAll("user print preferences", MantisTable.user_print_pref);
        }
        protected override void ExecuteCommand(MantisDatabase db, DbCommand cmd, CleanOptions options, TaskDataStore store)
        {
            // get the id of the project to keep
            cmd.CommandText = $"SELECT id, name FROM {db.Table(MantisTable.project)} WHERE name IN @@projectnames";
            cmd.AddArrayParameters("@@projectnames", options.ProjectNamesToKeep);

            List <int> keepIds = new List <int>();

            using (var dr = cmd.ExecuteReader())
            {
                while (dr.Read())
                {
                    keepIds.Add(dr.Get <int>("id"));
                    LogService.Info($"Project '{dr.Get<String>("name")}' with id {dr.Get<int>("id")} will be kept");
                }
            }

            if (options.ProjectNamesToKeep.Count() != keepIds.Count)
            {
                throw new TaskFailedException("Not all mentioned projects werde found in the database");
            }

            store.Set(DataKey.KeepProjectIDs, keepIds);
        }
 public void Run(MantisDatabase db, CleanOptions options, TaskDataStore store)
 {
     ExecuteCommand(db, db.CreateCommand(), options, store);
 }
Exemple #18
0
        protected override void ExecuteCommand(MantisDatabase db, DbCommand cmd, CleanOptions options, TaskDataStore store)
        {
            List <int> projectids = db.ReadList <int>($"SELECT id FROM {db.Table(MantisTable.project)}");

            db.DeleteMatching("categories", $"DELETE FROM {db.Table(MantisTable.category)} WHERE project_id NOT IN @@ids", projectids);
        }
Exemple #19
0
 public CleanCommandMock(CleanOptions options)
     : base(options)
 {
 }
Exemple #20
0
		private static int RunClean(CleanOptions options)
		{
			var solution = LoadSolution(options);

			var console = new ProgramConsole();

			IProject project = null;

			if (options.Project != null)
			{
				project = FindProject(solution, options.Project);
			}
			else
			{
				project = solution.StartupProject;
			}

			if (project != null)
			{
				project.ToolChain.Clean(console, project).Wait();
			}
			else
			{
				console.WriteLine("Nothing to clean.");
			}

			return 1;
		}
 protected abstract void ExecuteCommand(MantisDatabase db, DbCommand cmd, CleanOptions options, TaskDataStore store);
Exemple #22
0
        static int RunClean(CleanOptions options)
        {
            var solution = LoadSolution(options);

            var gccSettings = new ToolchainSettings();
            gccSettings.ToolChainLocation = @"c:\vestudio\appdata\repos\GCCToolchain\bin";
            gccSettings.IncludePaths.Add("arm-none-eabi\\include\\c++\\4.9.3");
            gccSettings.IncludePaths.Add("arm-none-eabi\\include\\c++\\4.9.3\\arm-none-eabi\\thumb");
            gccSettings.IncludePaths.Add("lib\\gcc\\arm-none-eabi\\4.9.3\\include");

            var toolchain = new GccToolChain(gccSettings);

            var console = new ProgramConsole();

            var project = FindProject(solution, options.Project);

            if (project != null)
            {
                toolchain.Clean(console, project).Wait();
            }
            else
            {
                console.WriteLine("Nothing to clean.");
            }

            return 1;
        }