public static TaskMemoryRepository CreateOrLoadTaskMemoryRepository(string projectName, string settingsDirectory)
        {
            var path = System.IO.Path.Combine(settingsDirectory, projectName + FileExtensionWithDot);
            TaskMemoryRepository repo = null;

            if (File.Exists(path))
            {
                try
                {
                    var x = new XmlSerializer(typeof(TaskMemoryRepository));
                    using (FileStream stream = File.OpenRead(path))
                    {
                        repo = x.Deserialize(stream) as TaskMemoryRepository;
                    }
                }
                catch (Exception error)
                {
                    Palaso.Reporting.Logger.WriteEvent("Error trying to read task memory: " + error.Message);
                    //now just make a new one, this is the kind of data we can through away
                }
            }

            if (repo == null)
            {
                repo = new TaskMemoryRepository();
            }
            repo.Path = path;
            return(repo);
        }
        protected WordGatheringTaskBase(ITaskConfiguration config,
                                        LexEntryRepository lexEntryRepository,
                                        ViewTemplate viewTemplate,
                                        TaskMemoryRepository taskMemoryRepository)
            : base(config,
                   lexEntryRepository, taskMemoryRepository)
        {
            if (viewTemplate == null)
            {
                throw new ArgumentNullException("viewTemplate");
            }

            _viewTemplate             = viewTemplate;
            _lexicalFormWritingSystem =
                viewTemplate.GetDefaultWritingSystemForField(Field.FieldNames.EntryLexicalForm.ToString());

            var glossField = _viewTemplate.GetField(LexSense.WellKnownProperties.Gloss);

            if (glossField == null)
            {
                _glossMeaningField = false;
            }
            else
            {
                _glossMeaningField = glossField.IsMeaningField;
            }
        }
Exemple #3
0
        public TaskBase(ITaskConfiguration config,
                        LexEntryRepository lexEntryRepository,
                        TaskMemoryRepository taskMemoryRepository)
        {
            if (config.Label == null)
            {
                throw new ArgumentNullException("label");
            }
            if (config.LongLabel == null)
            {
                throw new ArgumentNullException("longLabel");
            }
            if (config.Description == null)
            {
                throw new ArgumentNullException("description");
            }
            if (config.RemainingCountText == null)
            {
                throw new ArgumentNullException("remainingCountText");
            }
            if (config.ReferenceCountText == null)
            {
                throw new ArgumentNullException("referenceCountText");
            }
            if (lexEntryRepository == null)
            {
                throw new ArgumentNullException("lexEntryRepository");
            }
            _lexEntryRepository = lexEntryRepository;
            _taskMemory         = taskMemoryRepository.FindOrCreateSettingsByTaskId(config.TaskName);

            // convert any amount of whitespace to one space
            Regex rgx = new Regex("\\s+");

            _label              = rgx.Replace(config.Label.Trim(), " ");
            _longLabel          = rgx.Replace(config.LongLabel.Trim(), " ");
            _description        = rgx.Replace(config.Description.Trim(), " ");
            _remainingCountText = rgx.Replace(config.RemainingCountText.Trim(), " ");
            _referenceCountText = rgx.Replace(config.ReferenceCountText.Trim(), " ");
            _isPinned           = config.IsPinned;

//            _cachePath = WeSayWordsProject.Project.PathToCache;
//            _cacheFilePath = Path.Combine(_cachePath, MakeSafeName(Label + ".cache"));
//
//            ReadCacheFile();

            _remainingCount = _taskMemory.Get("RemainingCount", CountNotComputed);
            _referenceCount = _taskMemory.Get("ReferenceCount", CountNotComputed);
        }
Exemple #4
0
        protected WordGatheringTaskBase(ITaskConfiguration config,
                                        LexEntryRepository lexEntryRepository,
                                        ViewTemplate viewTemplate,
                                        TaskMemoryRepository taskMemoryRepository)
            : base(config,
                   lexEntryRepository, taskMemoryRepository)
        {
            if (viewTemplate == null)
            {
                throw new ArgumentNullException("viewTemplate");
            }

            _viewTemplate             = viewTemplate;
            _lexicalFormWritingSystem =
                viewTemplate.GetDefaultWritingSystemForField(Field.FieldNames.EntryLexicalForm.ToString());
        }