예제 #1
0
        void ChangeToDefinitionEH(object sender, EventArgs e)
        {
            LoggerSAP.Log("Changing element ({0},{1}) to definition.", _row, _column);
            BaseCrosswordElement bce = ElementsFactory.SAP.CreateObject(Definition.ObjectType, _crossword, _column, _row);

            _crossword.SubstituteCrosswordElement(bce, _column, _row);
        }
예제 #2
0
파일: Program.cs 프로젝트: aperwe/Cerberus
 /// <summary>
 /// Displays general introduction of the tool.
 /// </summary>
 private void IntroduceYourself()
 {
     LoggerSAP.Log("{0} ({1})", ExeName, ExeID); //Introduce yourself
     LoggerSAP.Log("Product created on May 2009. Support alias: {0}.", Settings.Default.SupportDetails);
     LoggerSAP.Log("Product specification: {0}", Settings.Default.DocumentationLink);
     LoggerSAP.Log();
 }
예제 #3
0
 void DefinitionSetEH(object sender, EventArgs e)
 {
     LoggerSAP.Log("Finished entering the definition.");
     _def.DefinitionChangedEvt += new EventHandler(DefinitionSetEH2);
     _def.definicja             = _tb.Text;
     _tb.Dispose();
 }
 /// <summary>
 /// Registers known crossword element types with <see cref="ElementsFactory"/>.
 /// </summary>
 public static void RegisterKnownElementTypes()
 {
     LoggerSAP.Log("Registering known crossword element types.");
     ElementsFactory.SAP.RegisterConstructor(Letter.ObjectType, Letter.ctor);
     ElementsFactory.SAP.RegisterConstructor(EmptyElement.ObjectType, EmptyElement.ctor);
     ElementsFactory.SAP.RegisterConstructor(Definition.ObjectType, Definition.ctor);
 }
예제 #5
0
        void PossibleWordAddedEH(object sender, EventArgs e)
        {
            LoggerSAP.Log("Finished entering a possible word.");
            string newWord = _tb.Text;

            _tb.Dispose();
            AddPossibleWord(newWord);
        }
예제 #6
0
 public void Cleanup()
 {
     if (_osleBotRedirectedLogger == null)
     {
         return;
     }
     LoggerSAP.UnregisterLogger(_osleBotRedirectedLogger);
     _osleBotRedirectedLogger = null;
 }
예제 #7
0
            private void CreateMeshNode(CSVMeshNode.CSVMeshNodeTemplate csvLine)
            {
                CSVMeshNode newNode = new CSVMeshNode(csvLine, _container);

                _container.semaphore.WaitOne();
                _container.nodeList.Add(newNode);
                _container.semaphore.Release();
                LoggerSAP.Log("Created mesh node named {0} (with {1} dimensions) from it's template.", newNode._name, newNode._x.rank);
            }
예제 #8
0
파일: Program.cs 프로젝트: aperwe/Cerberus
 private void DisableConsoleLogger()
 {
     if (_consoleLogger == null)
     {
         return;
     }
     LoggerSAP.UnregisterLogger(_consoleLogger);
     _consoleLogger = null;
 }
예제 #9
0
 internal Context()
 {
     //Create the context thread that will run until this class is not destroyed.
     LoggerSAP.Log("Creating ALIContext.");
     contextThread = new Thread(new ParameterizedThreadStart(ContextThreadEntryPoint));
     contextThread.IsBackground = true;                       //Set this thread as background
     contextThread.Name         = "ALIContext";               //Name the thread so that we can identify it later.
     contextThread.Priority     = ThreadPriority.BelowNormal; //Lower the priority of the thread.
     contextThread.Start(this);
 }
예제 #10
0
 void AssignLetterEH(object sender, EventArgs e)
 {
     LoggerSAP.Log("Assigning letter.");
     _tb           = new TextBox();
     _tb.Parent    = _wControl;
     _tb.Leave    += new EventHandler(LetterSetEH);
     _tb.MaxLength = 1;
     _tb.Focus();
     _tb.Text = letter;
 }
예제 #11
0
 void AddPossibleWordClickedEH(object sender, EventArgs e)
 {
     LoggerSAP.Log("Adding possible word to ({0},{1}) definition.", _row, _column);
     _tb          = new TextBox();
     _tb.Location = _wControl.Location;
     _tb.Parent   = _wControl.Parent;
     _tb.Leave   += new EventHandler(PossibleWordAddedEH);
     _tb.Focus();
     _tb.BringToFront();
 }
예제 #12
0
        /// <summary>
        /// Builds a flat list of files under the specified path (under enlistment location) that match the specified filter.
        /// These can be the files that can be processed by OSLEBot engine.
        /// </summary>
        /// <param name="relativePath">Path under enlistment location to look for files.</param>
        /// <param name="fileType">One of the file types supported by enlistment.</param>
        public IEnumerable <ConfigItem> GetFiles(string relativePath, LcxType fileType)
        {
            var retVal = new List <ConfigItem>();

            if (!IsDetected)
            {
                throw new EnlistmentException("Cannot get files because enlistment location is unknown.");
            }

            var searchPath    = Path.Combine(Location, relativePath);
            var searchPattern = GetFileExtensionFromType(fileType);
            var rawProjects   = Directory.GetFiles(searchPath, "*.snt", SearchOption.AllDirectories);

            LoggerSAP.Trace("{0} projects identified under {1}.", rawProjects.Length, searchPath);
            foreach (var project in rawProjects)
            {
                var projectSentinelFile = new FileInfo(project);
                var projectName         = projectSentinelFile.Directory.Name;
                var projectDirectory    = projectSentinelFile.DirectoryName;

                var rawLanguages = Directory.GetFiles(projectDirectory, ".language", SearchOption.AllDirectories);
                foreach (var language in rawLanguages)
                {
                    var languageSentinelFile = new FileInfo(language);
                    var languageName         = languageSentinelFile.Directory.Name;
                    var languageDirectory    = languageSentinelFile.DirectoryName;

                    var rawLocGroups = Directory.GetFiles(languageDirectory, ".locgroup", SearchOption.AllDirectories);
                    foreach (var locGroup in rawLocGroups)
                    {
                        var locGroupSentinelFile = new FileInfo(locGroup);
                        var locGroupName         = locGroupSentinelFile.Directory.Name;
                        var locGroupDirectory    = locGroupSentinelFile.DirectoryName;

                        var rawInput = Directory.GetFiles(locGroupDirectory, searchPattern, SearchOption.AllDirectories);

                        foreach (var inputFile in rawInput) //These are possible input files for OSLEBot (*.lcl files).
                        {
                            var fileObject = new FileInfo(inputFile);

                            var inputConfig = new ConfigItem
                            {
                                Project      = projectName,
                                Language     = languageName,
                                LocGroup     = locGroupName,
                                File         = fileObject.Name,
                                PhysicalPath = fileObject.FullName,
                            };
                            retVal.Add(inputConfig);
                        }
                    }
                }
            }
            return(retVal);
        }
예제 #13
0
        /// <summary>
        /// Validates the filter entries to ensure that they do not contain any entries that are not in <paramref name="data"/> collection.
        /// For a filter to be valid, it ought to itemize only such entries that actually exist in the filtered data set.
        /// </summary>
        /// <param name="filter">Filter entries that should be validated against actual data.</param>
        /// <param name="data">Entries to validate the filter against.</param>
        /// <param name="filterId">Desciptive name of what the filter contains. used to log warning message about the invalid entries. For example 'language'.</param>
        /// <returns>True if filter is valid. False if the filter contains at least one invalid entry.</returns>
        protected bool ValidateFilterAgainstData(IEnumerable <string> filter, IEnumerable <string> data, string filterId)
        {
            var invalidEntries = filter.Where(item => !data.Any(d => d.Equals(item, StringComparison.OrdinalIgnoreCase)));

            if (invalidEntries.Count() > 0)
            {
                LoggerSAP.Warning("Invalid {0} filter item(s): {1}", filterId, string.Join(" ,", invalidEntries.ToArray()));
                return(false);
            }
            return(true);
        }
예제 #14
0
 /// <summary>
 /// Sets dimensions for the crossword.
 /// </summary>
 /// <param name="columns">Number of crossword columns.</param>
 /// <param name="rows">Numer of crossword rows.</param>
 public void SetDimensions(int columns, int rows)
 {
     _columns = columns;
     _rows    = rows;
     if (_letters != null)
     {
         LoggerSAP.Log("Array of letter not empty. Deleting it.");
     }
     LoggerSAP.Log("Allocating new array of base crossword elements.");
     _letters = new BaseCrosswordElement[_columns, _rows];
 }
예제 #15
0
 /// <summary>
 /// The base constructor takes care of creating the threaded mesh for you.
 /// </summary>
 protected AbstractThreadedMesh()
 {
     //Create the context thread that will run until this class is not destroyed.
     LoggerSAP.Log("Creating abstract mesh.");
     semaphore  = new Semaphore(1, 1, _nextSemaphoreId()); //Unique name for the semaphore.
     meshThread = new Thread(new ParameterizedThreadStart(DefaultSafeThreadStarter));
     meshThread.IsBackground = true;                       //Set this thread as background
     meshThread.Name         = _nextSemaphoreId();         //Name the thread so that we can identify it later.
     meshThread.Priority     = ThreadPriority.BelowNormal; //Lower the priority of the thread.
     meshThread.Start(this);
 }
예제 #16
0
 void AssignDefinitionEH(object sender, EventArgs e)
 {
     LoggerSAP.Log("Assigning definition.");
     _tb          = new TextBox();
     _tb.Location = _wControl.Location;
     _tb.Parent   = _wControl.Parent;
     _tb.Leave   += new EventHandler(DefinitionSetEH);
     _tb.Focus();
     _tb.Text = _def.definicja;
     _tb.BringToFront();
 }
예제 #17
0
 /// <summary>
 /// Loads data from the disk database (file or SQL) as in-memory data for manipulation.
 /// </summary>
 private void LoadDataFromDatabase(DataSet database, string cerberusConfigPath)
 {
     try
     {
         database.ReadXml(cerberusConfigPath);
     }
     catch (Exception e)
     {
         LoggerSAP.Critical("Failed to load Cerberus Configuration from: {0}. Exception: {1}, message: {2}", cerberusConfigPath, e.ToString(), e.Message);
         throw;
     }
 }
예제 #18
0
 public override void DrawCrossword()
 {
     LoggerSAP.Log("Drawing crossword.");
     if (_parent != null)
     {
         LoggerSAP.Log("Parent control set. Should draw.");
         LoggerSAP.Log("Parent: {0}, dimensions: [{1}, {2}].", _parent, _columns, _rows);
     }
     else
     {
         LoggerSAP.Log("Parent control not set. Nothing to draw.");
     }
 }
예제 #19
0
 private void AddPossibleWord(string newWord)
 {
     if (newWord.Length > 0)
     {
         if (_def.propozycje.Contains(newWord.ToLowerInvariant()))
         {
             LoggerSAP.Log("Word {0} is already contained.", newWord);
         }
         else
         {
             _def.propozycje.Add(newWord.ToLowerInvariant());
         }
     }
 }
예제 #20
0
        /// <summary>
        /// Processes one entry from the node queue (if the queue is non-empty).
        /// </summary>
        /// <param name="newNodeQueue">Queue that is to be processed.</param>
        /// <returns>True if the queue needs more processing.</returns>
        private bool ProcessNodeQueue(Queue <MeshNode.MeshNodeTemplate> newNodeQueue)
        {
            if (newNodeQueue.Count == 0)
            {
                return(false);                         //Nothing to process
            }
            semaphore.WaitOne();
            MeshNode newNode = new MeshNode(newNodeQueue.Dequeue(), this);

            nodeList.Add(newNode);
            LoggerSAP.Log("Created mesh node named {0} (with {1} dimensions) from it's template.", newNode._name, newNode._x.rank);
            semaphore.Release();
            return(true);
        }
예제 #21
0
파일: Program.cs 프로젝트: aperwe/Cerberus
 /// <summary>
 /// Shows usage to the command line.
 /// <para/>This is invoked when invalid command line is specified.
 /// </summary>
 private void ShowUsage()
 {
     LoggerSAP.Log("Usage:");
     LoggerSAP.Log("{0} [-l <ll-cc> [-l <ll-cc>[...]]] [-p <project> [-p <project> [...]]] [-m <mode>]", ExeName);
     LoggerSAP.Log("Where ll-cc is a language identfier, for example 'de-DE'");
     LoggerSAP.Log("      project is a project identifier, for example 'word'.");
     LoggerSAP.Log("      mode is one of {'locgroups', 'projects', 'centralized'}.");
     LoggerSAP.Log("         locgroups   - standalone mode with one instance of OSLEBot created per every locgroup.");
     LoggerSAP.Log("         projects    - standalone mode with one instance of OSLEBot created per every project.");
     LoggerSAP.Log("         centralized - same as 'projects' mode, but information about which checks are enabled for each {language, project} is obtained from a database.");
     LoggerSAP.Log("Sample command line: {0} -l fr-FR -l de-DE -p word -p mso", ExeName);
     LoggerSAP.Log("                     {0} -l fr-FR -m centralized", ExeName);
     LoggerSAP.Log("Without parameters, all files in enlistment are scanned and {0} runs in standalone mode.", ExeName);
 }
예제 #22
0
 /// <summary>
 /// Loads data from the disk database (file or SQL) as in-memory data for manipulation.
 /// </summary>
 private void LoadDataFromDatabase(DataSet database)
 {
     if (Enlistment.IsDetected)
     {
         var myHomeDir    = Enlistment.CerberusHomeDir;
         var dataFilePath = new FileInfo(Path.Combine(myHomeDir, "Configuration.xml"));
         if (dataFilePath.Exists)
         {
             LoggerSAP.Trace("Loading data from Configuration.xml");
             database.ReadXml(dataFilePath.FullName);
         }
         else
         {
             LoggerSAP.Warning("No Cerberus database found. Check enablement information is not available.");
         }
     }
 }
예제 #23
0
        private void ReadInput()
        {
            //Start reading our file.
            LoggerSAP.Log("Reading in: {0}...", _csvEdbFileName);
            MyStreamReader sr = new MyStreamReader(_csvEdbFileName);
            string         csvLine;
            int            lineCount = 0;

            while (!sr.EndOfStream)
            {
                csvLine = sr.ReadLine(); lineCount++;
                AddNode(new CSVMeshNode.CSVMeshNodeTemplate(csvLine)); //No need to explicitly wait for semaphore, because AddNode() already does this.
                Thread.SpinWait(1);                                    //Give away a little of processor time.
            }
            sr.Close();
            LoggerSAP.Log("Finished reading {0} ({1} entries).", _csvEdbFileName, lineCount);
        }
예제 #24
0
        /// <summary>
        /// The entry point for the context thread.
        /// </summary>
        /// <param name="threadParamObj"></param>
        private void ContextThreadEntryPoint(object threadParamObj)
        {
            LoggerSAP.Log(string.Format("ALIContext thread has started. Thread name: {0}", Thread.CurrentThread.Name));
            Context threadParam = (Context)threadParamObj;

            while (threadParam.isActive) //Message loop
            {
                //Do some useful work here
                LoggerSAP.Log("Context working...");
                Thread.Sleep(5000);
                if (threadParam.meshTest == null)
                {
                    threadParam.meshTest = new Test();
                }
            }
            LoggerSAP.Log(string.Format("ALIContext thread has finished. Thread name: {0}", Thread.CurrentThread.Name));
        }
예제 #25
0
 /// <summary>
 /// Provides catching top-level exceptions from the thread, so that the application doesn't crash
 /// when specific thread doesn't catch all it's exceptions.
 /// </summary>
 /// <param name="threadParamObj">Object from ParametrizedThreadStart. It is ourselves, actually.</param>
 private void DefaultSafeThreadStarter(object threadParamObj)
 {
     try
     {
         string className = GetType().Name;
         LoggerSAP.Log("{0} ({1}) thread was born.", Thread.CurrentThread.Name, className);
         Thread.Sleep(2); //Wait for the framework to initialize 'this' object. Without this wait, members assigned to in constructor may not be initialized.
         AbstractThreadedMesh param = (AbstractThreadedMesh)threadParamObj;
         MeshThreadEntryPoint(param);
         LoggerSAP.Log("{0} ({1}) thread has died.", Thread.CurrentThread.Name, className);
     }
     catch (Exception ex)
     {
         LoggerSAP.Log("The '{0} thread didn't catch its exception. The thread has died. Exception message: {1}.",
                       Thread.CurrentThread.Name,
                       ex.Message);
     }
 }
예제 #26
0
        private void LoadDataFromDatabase(string dataFilePath)
        {
            var fileInfo = new FileInfo(dataFilePath);

            if (fileInfo.Exists)
            {
                //SetStatusBarItem(1, Properties.Resources.LoadingDataInDataInProgress);
                SetStatusBarItem(1, "Loading data from Configuration.xml");
                ConfiguratorApplication.Current.Database.ReadXml(dataFilePath);
                //SetStatusBarItem(1, Properties.Resources.LoadedData);
                SetStatusBarItem(1, "Loaded data from Configuration.xml");
            }
            else
            {
                //SetStatusBarItem(0, Properties.Resources.DataFileDoesNotExist);
                SetStatusBarItem(0, "Configuration data file cannot be located.");
                LoggerSAP.Error("Location of configuration data file is invalid: {0}", fileInfo.FullName);
            }
        }
예제 #27
0
        /// <summary>
        /// Reads information about all checks stored in the configuration database, including information about what items
        /// each check is enabled on, and transforms it into a strongly typed list of check config items that can be easily consumed
        /// by the caller to specify which input should be checked by which check.
        /// </summary>
        /// <param name="configuration">Configuration database</param>
        private static IList <CheckConfig> ReadCheckConfigsFromDatabase(CheckConfiguration configuration)
        {
            var checkConfigs = new List <CheckConfig>();
            var allChecks    = configuration.GetAllChecks();

            foreach (var check in allChecks)
            {
                bool isAllLangs = configuration.IsCheckGlobalForAllLanguages(check);
                IList <CultureInfo> enabledLangs = null;
                if (!isAllLangs)
                {
                    enabledLangs = configuration.GetLanguagesWithCheckEnabled(check).Select(lang => new CultureInfo(lang)).ToList();
                }

                bool           isAllProjects   = configuration.IsCheckGlobalForAllProjects(check);
                IList <string> enabledProjects = null;
                if (!isAllProjects)
                {
                    enabledProjects = configuration.GetProjectsWithCheckEnabled(check).ToList();
                }
                //Extra check for presence of physical file for this check.
                //If the file is not present, log a warning, and skip the check, but allow the executor to continue.
                var phycalFile = Environment.ExpandEnvironmentVariables(configuration.GetCheckFilePath(check));
                if (File.Exists(phycalFile))
                {
                    checkConfigs.Add(new CheckConfig(
                                         check,
                                         configuration.GetCheckFilePath(check),
                                         isAllLangs,
                                         enabledLangs,
                                         isAllProjects,
                                         enabledProjects,
                                         RuleContainerType.Source // we are hard-coding the type of rule to source files
                                         ));
                }
                else //The physical file does not exist. Log a warning
                {
                    LoggerSAP.Warning("Could not locate '{0}' file containing source code of {1} check. This check will be ignored.", configuration.GetCheckFilePath(check), check);
                }
            }
            return(checkConfigs);
        }
예제 #28
0
            private void CheckInputQueue()
            {
                _container.semaphore.WaitOne();
                int queueEntries = _container.newNodeQueue.Count;

                _container.semaphore.Release();
                if (queueEntries == 0)
                {
                    LoggerSAP.Log("Nothing to process. Going to sleep.");
                    sleepTime = 5000;
                }
                else
                {
                    LoggerSAP.Log("Wow, {0} csv entries to process! Getting down to it.", queueEntries);
                    _container.semaphore.WaitOne();
                    CSVMeshNode.CSVMeshNodeTemplate csvLine = (CSVMeshNode.CSVMeshNodeTemplate)_container.newNodeQueue.Dequeue();
                    _container.semaphore.Release();
                    CreateMeshNode(csvLine);
                }
            }
예제 #29
0
        public void OldEnableCheckForLanguage(string checkName, string languageName)
        {
            var languageRow = (from language in Languages
                               where language.Name == languageName
                               select language).Single();
            var checkRow = (from check in Checks
                            where check.Name == checkName
                            select check).Single();

            foreach (var lg in LocGroups)
            {
                try
                {
                    ConfigItems.AddConfigItemsRow(languageRow, checkRow, lg);
                }
                catch (ConstraintException ex)
                {
                    LoggerSAP.Trace(ex.Message);
                }
            }
        }
예제 #30
0
 /// <summary>
 /// Registers known crossword implementors with the factory.
 /// </summary>
 public static void RegisterKnownCrosswordTypes()
 {
     LoggerSAP.Log("Registering known crossword types.");
     UniversalFactory <string, Crossword> .SAP.RegisterConstructor("Jolka", Jolka.ctor);
 }