private bool SyncResultedInError(ILfProject project, string syncResult, string errorString, ProcessingState.SendReceiveStates?newState = null) { var line = LfMergeBridgeServices.GetLineContaining(syncResult, errorString); if (!string.IsNullOrEmpty(line)) { if (line.Contains("Exception")) { IEnumerable <string> stackTrace = LfMergeBridgeServices.GetLineAndStackTraceContaining(syncResult, errorString); Logger.Error(String.Join(Environment.NewLine, stackTrace)); // We want entire stack trace logged as a single log entry, so don't use Logger.LogMany() } else { Logger.Error(line); } if (newState.HasValue) { if (newState.Value == ProcessingState.SendReceiveStates.HOLD) { // When going on hold, do so via the new PutOnHold() function so we record an error message project.State.PutOnHold("Error during synchronize of {0}: {1}", project.ProjectCode, line); } else { project.State.SRState = newState.Value; } } return(true); } return(false); }
protected override void DoRun(ILfProject project) { // TODO: These checks might be overkill; consider removing some of them Logger.Debug("FdoToMongo: starting"); FwProject fwProject = project.FieldWorksProject; if (fwProject == null) { Logger.Error("Can't find FieldWorks project {0}", project.ProjectCode); return; } Logger.Debug("FdoToMongo: getting cache"); _cache = fwProject.Cache; if (_cache == null) { Logger.Error("Can't find cache for FieldWorks project {0}", project.ProjectCode); return; } Logger.Debug("FdoToMongo: serviceLocator"); _servLoc = _cache.ServiceLocator; if (_servLoc == null) { Logger.Error("Can't find service locator for FieldWorks project {0}", project.ProjectCode); return; } _lexiconConverter = new ConvertFdoToMongoLexicon(project, Logger, _connection); _lexiconConverter.RunConversion(); }
protected virtual void InitialTransferToMongoAfterClone(ILfProject project) { Logger.Notice("Initial transfer to mongo after clone"); project.IsInitialClone = true; Actions.Action.GetAction(ActionNames.TransferFdoToMongo).Run(project); project.IsInitialClone = false; }
public ConvertMongoToLcmComments(IMongoConnection conn, ILfProject proj, ILogger logger, IProgress progress) { _conn = conn; _project = proj; _logger = logger; _progress = progress; }
public virtual string GetSyncUri(ILfProject project) { string uri = project.LanguageDepotProjectUri; string serverPath = uri.StartsWith("http://") ? uri.Replace("http://", "") : uri; return "http://*****:*****@" + serverPath + "/" + HttpUtilityFromMono.UrlEncode(project.LanguageDepotProject.Identifier); }
public IMongoDatabase GetProjectDatabase(ILfProject project) { var mockDb = new Mock <IMongoDatabase>(); // SO much easier than implementing the 9 public methods for a manual stub of IMongoDatabase! // TODO: Add appropriate mock functions if needed return(mockDb as IMongoDatabase); }
public override void PreRun(ILfProject project) { _currentProject = project; if (!File.Exists(Settings.GetStateFileName(_currentProject.ProjectCode))) { _currentProject.State.SRState = ProcessingState.SendReceiveStates.CLONING; } }
public ConvertFdoToMongoOptionList ConvertOptionListFromFdo(ILfProject project, string listCode, ICmPossibilityList fdoOptionList, bool updateMongoList = true) { LfOptionList lfExistingOptionList = _conn.GetLfOptionListByCode(project, listCode); var converter = new ConvertFdoToMongoOptionList(lfExistingOptionList, _wsEn, listCode, _env.Logger, _cache.WritingSystemFactory); LfOptionList lfChangedOptionList = converter.PrepareOptionListUpdate(fdoOptionList); if (updateMongoList) _conn.UpdateRecord(project, lfChangedOptionList, listCode); return new ConvertFdoToMongoOptionList(lfChangedOptionList, _wsEn, listCode, _env.Logger, _cache.WritingSystemFactory); }
public static void DisposeFwProject(ILfProject project) { var lfProject = project as LanguageForgeProject; if (lfProject != null && lfProject._fieldWorksProject != null) { lfProject._fieldWorksProject.Dispose(); lfProject._fieldWorksProject = null; } }
public ConvertLcmToMongoComments(IMongoConnection conn, ILfProject proj, ILogger logger, IProgress progress, MongoProjectRecordFactory factory) { _conn = conn; _project = proj; _servLoc = proj.FieldWorksProject.ServiceLocator; _logger = logger; _progress = progress; _factory = factory; }
public LfOptionList GetLfOptionListByCode(ILfProject project, string listCode) { LfOptionList result; if (!_storedLfOptionLists.TryGetValue(listCode, out result)) { result = null; } return(result); }
public DateTime?GetLastSyncedDate(ILfProject project) { DateTime?result = null; if (_storedLastSyncDate.TryGetValue(project.ProjectCode, out result)) { return(result); } return(null); }
public bool SetLastSyncedDate(ILfProject project, DateTime?newSyncedDate) { _storedLastSyncDate[project.ProjectCode] = newSyncedDate; // Also update on the fake project record, since EnsureCloneAction looks at the project record to check its initial-clone logic if (_projectRecordFactory != null) { MongoProjectRecord projectRecord = _projectRecordFactory.Create(project); projectRecord.LastSyncedDate = newSyncedDate; } return(true); }
private void ReportNoSuchBranchFailure(ILfProject project, string cloneLocation, string cloneResult, string line, ProcessingState.ErrorCodes errorCode) { var clonePath = GetActualClonePath(cloneLocation, line); if (Directory.Exists(clonePath)) { Directory.Delete(clonePath, true); } CloneResultedInError(project, cloneResult, "no such branch", true, errorCode); }
public ConvertLcmToMongoOptionList ConvertOptionListFromLcm(ILfProject project, string listCode, ICmPossibilityList lcmOptionList, bool updateMongoList = true) { LfOptionList lfExistingOptionList = _conn.GetLfOptionListByCode(project, listCode); var converter = new ConvertLcmToMongoOptionList(lfExistingOptionList, _wsEn, listCode, _env.Logger, _cache.WritingSystemFactory); LfOptionList lfChangedOptionList = converter.PrepareOptionListUpdate(lcmOptionList); if (updateMongoList) { _conn.UpdateRecord(project, lfChangedOptionList, listCode); } return(new ConvertLcmToMongoOptionList(lfChangedOptionList, _wsEn, listCode, _env.Logger, _cache.WritingSystemFactory)); }
private ConvertFdoToMongoOptionList ConvertOptionListFromFdo(ILfProject project, string listCode, ICmPossibilityList fdoOptionList, bool updateMongoList = true) { LfOptionList lfExistingOptionList = Connection.GetLfOptionListByCode(project, listCode); var converter = new ConvertFdoToMongoOptionList(lfExistingOptionList, _wsEn, listCode, Logger, ServiceLocator.WritingSystemFactory); LfOptionList lfChangedOptionList = converter.PrepareOptionListUpdate(fdoOptionList); if (updateMongoList) { Connection.UpdateRecord(project, lfChangedOptionList, listCode); } return(new ConvertFdoToMongoOptionList(lfChangedOptionList, _wsEn, listCode, Logger, ServiceLocator.WritingSystemFactory)); }
public bool SetCustomFieldConfig(ILfProject project, Dictionary <string, LfConfigFieldBase> lfCustomFieldList) { if (lfCustomFieldList == null) { _storedCustomFieldConfig = new Dictionary <string, LfConfigFieldBase>(); } else { // _storedCustomFieldConfig = lfCustomFieldList; // This would assign a reference; we want to clone instead, in case unit tests further modify this dict _storedCustomFieldConfig = new Dictionary <string, LfConfigFieldBase>(lfCustomFieldList); // Cloning better simulates writing to Mongo } return(true); }
protected virtual bool CloneRepo(ILfProject project, string projectFolderPath, out string cloneResult) { var chorusHelper = MainClass.Container.Resolve<ChorusHelper>(); var options = new Dictionary<string, string> { { "fullPathToProject", projectFolderPath }, { "languageDepotRepoName", project.LanguageDepotProject.Identifier }, { "fdoDataModelVersion", FdoCache.ModelVersion }, { "languageDepotRepoUri", chorusHelper.GetSyncUri(project) }, { "user", "Language Forge"} }; return LfMergeBridge.LfMergeBridge.Execute("Language_Forge_Clone", Progress, options, out cloneResult); }
public virtual MongoProjectRecord Create(ILfProject project) { if (project == null) return null; if (Connection == null) return null; IMongoDatabase db = Connection.GetMainDatabase(); IMongoCollection<MongoProjectRecord> coll = db.GetCollection<MongoProjectRecord>(MagicStrings.LfCollectionNameForProjectRecords); MongoProjectRecord record = coll.Find(proj => proj.ProjectCode == project.ProjectCode) .Limit(1).FirstOrDefault(); return record; }
public bool SetInputSystems(ILfProject project, Dictionary <string, LfInputSystemRecord> inputSystems, List <string> vernacularWss, List <string> analysisWss, List <string> pronunciationWss) { foreach (var ws in inputSystems.Keys) { _storedInputSystems[ws] = inputSystems[ws]; } if (project.IsInitialClone) { // TODO: Update field input systems too? } return(true); }
public IEnumerable <TDocument> GetRecords <TDocument>(ILfProject project, string collectionName) { switch (collectionName) { case MagicStrings.LfCollectionNameForLexicon: return((IEnumerable <TDocument>)GetLfLexEntries()); case MagicStrings.LfCollectionNameForOptionLists: return((IEnumerable <TDocument>)GetLfOptionLists()); default: List <TDocument> empty = new List <TDocument>(); return(empty.AsEnumerable()); } }
//private ConvertFdoToMongoOptionList _convertAnthroCodesOptionList; public ConvertFdoToMongoLexicon(ILfProject lfProject, ILogger logger, IMongoConnection connection, IProgress progress, MongoProjectRecordFactory projectRecordFactory) { LfProject = lfProject; Logger = logger; Connection = connection; Progress = progress; ProjectRecordFactory = projectRecordFactory; FwProject = LfProject.FieldWorksProject; Cache = FwProject.Cache; ServiceLocator = FwProject.ServiceLocator; _wsEn = ServiceLocator.WritingSystemFactory.GetWsFromStr("en"); // Reconcile writing systems from FDO and Mongo Dictionary <string, LfInputSystemRecord> lfWsList = FdoWsToLfWs(); #if FW8_COMPAT List <string> VernacularWss = ServiceLocator.LanguageProject.CurrentVernacularWritingSystems.Select(ws => ws.Id).ToList(); List <string> AnalysisWss = ServiceLocator.LanguageProject.CurrentAnalysisWritingSystems.Select(ws => ws.Id).ToList(); List <string> PronunciationWss = ServiceLocator.LanguageProject.CurrentPronunciationWritingSystems.Select(ws => ws.Id).ToList(); #else List <string> VernacularWss = ServiceLocator.LanguageProject.CurrentVernacularWritingSystems.Select(ws => ws.LanguageTag).ToList(); List <string> AnalysisWss = ServiceLocator.LanguageProject.CurrentAnalysisWritingSystems.Select(ws => ws.LanguageTag).ToList(); List <string> PronunciationWss = ServiceLocator.LanguageProject.CurrentPronunciationWritingSystems.Select(ws => ws.LanguageTag).ToList(); #endif Connection.SetInputSystems(LfProject, lfWsList, VernacularWss, AnalysisWss, PronunciationWss); ListConverters = new Dictionary <string, ConvertFdoToMongoOptionList>(); ListConverters[GrammarListCode] = ConvertOptionListFromFdo(LfProject, GrammarListCode, ServiceLocator.LanguageProject.PartsOfSpeechOA); ListConverters[SemDomListCode] = ConvertOptionListFromFdo(LfProject, SemDomListCode, ServiceLocator.LanguageProject.SemanticDomainListOA, updateMongoList: false); ListConverters[AcademicDomainListCode] = ConvertOptionListFromFdo(LfProject, AcademicDomainListCode, ServiceLocator.LanguageProject.LexDbOA.DomainTypesOA); ListConverters[LocationListCode] = ConvertOptionListFromFdo(LfProject, LocationListCode, ServiceLocator.LanguageProject.LocationsOA); ListConverters[UsageTypeListCode] = ConvertOptionListFromFdo(LfProject, UsageTypeListCode, ServiceLocator.LanguageProject.LexDbOA.UsageTypesOA); ListConverters[SenseTypeListCode] = ConvertOptionListFromFdo(LfProject, SenseTypeListCode, ServiceLocator.LanguageProject.LexDbOA.SenseTypesOA); ListConverters[AnthroCodeListCode] = ConvertOptionListFromFdo(LfProject, AnthroCodeListCode, ServiceLocator.LanguageProject.AnthroListOA); ListConverters[StatusListCode] = ConvertOptionListFromFdo(LfProject, StatusListCode, ServiceLocator.LanguageProject.StatusOA); _convertCustomField = new ConvertFdoToMongoCustomField(Cache, ServiceLocator, logger); foreach (KeyValuePair <string, ICmPossibilityList> pair in _convertCustomField.GetCustomFieldParentLists()) { string listCode = pair.Key; ICmPossibilityList parentList = pair.Value; if (!ListConverters.ContainsKey(listCode)) { ListConverters[listCode] = ConvertOptionListFromFdo(LfProject, listCode, parentList); } } }
protected virtual bool CloneRepo(ILfProject project, string projectFolderPath, out string cloneResult) { var chorusHelper = MainClass.Container.Resolve <ChorusHelper>(); var options = new Dictionary <string, string> { { "fullPathToProject", projectFolderPath }, { "languageDepotRepoName", project.LanguageDepotProject.Identifier }, { "fdoDataModelVersion", FdoCache.ModelVersion }, { "languageDepotRepoUri", chorusHelper.GetSyncUri(project) }, { "user", "Language Forge" }, { "deleteRepoIfNoSuchBranch", "false" }, { "onlyRepairRepo", RepoAlreadyExists(projectFolderPath) ? "true" : "false" } }; return(LfMergeBridge.LfMergeBridge.Execute("Language_Forge_Clone", Progress, options, out cloneResult)); }
public override MongoProjectRecord Create(ILfProject project) { var sampleConfig = BsonSerializer.Deserialize <LfProjectConfig>(SampleData.jsonConfigData); // TODO: Could we use a Mock to do this instead? MongoProjectRecord record; if (_projectRecords.TryGetValue(project.ProjectCode, out record)) { return(record); } else { record = new MongoProjectRecord { Id = new ObjectId(), InputSystems = new Dictionary <string, LfInputSystemRecord>() { { "en", new LfInputSystemRecord { Abbreviation = "Eng", Tag = "en", LanguageName = "English", IsRightToLeft = false } }, { "fr", new LfInputSystemRecord { // this should probably be a three-letter abbreviation like Fre, // but since our test data has the two letter abbreviation for this ws // we have to stick with it so that we don't introduce an unwanted // change. Abbreviation = "fr", Tag = "fr", LanguageName = "French", IsRightToLeft = false } }, }, InterfaceLanguageCode = "en", LanguageCode = "fr", ProjectCode = project.ProjectCode, ProjectName = project.ProjectCode, SendReceiveProjectIdentifier = project.ProjectCode, Config = sampleConfig }; _projectRecords.Add(project.ProjectCode, record); return(record); } }
public bool CreateCustomFieldsConfigViews(ILfProject project, Dictionary <string, LfConfigFieldBase> lfCustomFieldList, Dictionary <string, string> lfCustomFieldTypes, bool isTest) { var customFieldSpecs = new List <CustomFieldSpec>(); foreach (string lfCustomFieldName in lfCustomFieldList.Keys) { customFieldSpecs.Add(new CustomFieldSpec(lfCustomFieldName, _fieldNameToFieldType[lfCustomFieldName])); } var lfproxy = MainClass.Container.Resolve <ILanguageForgeProxy>(); string output = lfproxy.UpdateCustomFieldViews(project.ProjectCode, customFieldSpecs, isTest); if (string.IsNullOrEmpty(output) || output == "false") { return(false); } return(true); }
public virtual string GetSyncUri(ILfProject project) { var settings = MainClass.Container.Resolve <LfMergeSettings>(); if (!string.IsNullOrEmpty(settings.LanguageDepotRepoUri)) { return(settings.LanguageDepotRepoUri); } var uriBldr = new UriBuilder(project.LanguageDepotProjectUri) { UserName = Username, Password = System.Environment.GetEnvironmentVariable("LANGUAGE_DEPOT_TRUST_TOKEN") ?? Password, Path = HttpUtility.UrlEncode(project.LanguageDepotProject.Identifier) }; return(uriBldr.Uri.ToString()); }
public virtual string GetSyncUri(ILfProject project) { var settings = MainClass.Container.Resolve <LfMergeSettings>(); if (!string.IsNullOrEmpty(settings.LanguageDepotRepoUri)) { return(settings.LanguageDepotRepoUri); } var uriBldr = new UriBuilder(project.LanguageDepotProjectUri) { UserName = Username, Password = Password, Path = HttpUtilityFromMono.UrlEncode(project.LanguageDepotProject.Identifier) }; return(uriBldr.Uri.ToString()); }
protected override bool CloneRepo(ILfProject project, string projectFolderPath, out string cloneResult) { if (_projectExists) { Directory.CreateDirectory(projectFolderPath); Directory.CreateDirectory(Path.Combine(projectFolderPath, ".hg")); File.WriteAllText(Path.Combine(projectFolderPath, ".hg", "hgrc"), "blablabla"); cloneResult = string.Format("Clone success: new clone created on branch '' in folder {0}", projectFolderPath); return(true); } if (_throwAuthorizationException) { throw new Chorus.VcsDrivers.Mercurial.RepositoryAuthorizationException(); } throw new Exception("Just some arbitrary exception"); }
public virtual MongoProjectRecord Create(ILfProject project) { if (project == null) { return(null); } if (Connection == null) { return(null); } IMongoDatabase db = Connection.GetMainDatabase(); IMongoCollection <MongoProjectRecord> coll = db.GetCollection <MongoProjectRecord>(MagicStrings.LfCollectionNameForProjectRecords); MongoProjectRecord record = coll.Find(proj => proj.ProjectCode == project.ProjectCode) .Limit(1).FirstOrDefault(); return(record); }
protected override void DoRun(ILfProject project) { _lfProject = project; _projectRecord = _projectRecordFactory.Create(_lfProject); if (_projectRecord == null) { Logger.Warning("No project named {0}", _lfProject.ProjectCode); Logger.Warning("If we are unit testing, this may not be an error"); return; } _lfProjectConfig = _projectRecord.Config; if (_lfProjectConfig == null) { return; } if (project.FieldWorksProject == null) { Logger.Error("Failed to find the corresponding FieldWorks project!"); return; } if (project.FieldWorksProject.IsDisposed) { Logger.Warning("Project {0} is already disposed; this shouldn't happen", project.ProjectCode); } _cache = project.FieldWorksProject.Cache; if (_cache == null) { Logger.Error("Failed to find the LCM cache!"); return; } _servLoc = _cache.ServiceLocator; if (_servLoc == null) { Logger.Error("Failed to find the service locator; giving up."); return; } var converter = new ConvertMongoToLcmLexicon(Settings, project, Logger, Progress, _connection, _projectRecord, EntryCounts); converter.RunConversion(); }
private bool CloneResultedInError(ILfProject project, string cloneResult, string errorString, bool isRecoverableError, ProcessingState.ErrorCodes errorCode) { var line = LfMergeBridgeServices.GetLineContaining(cloneResult, errorString); if (string.IsNullOrEmpty(line)) { return(false); } var errorType = isRecoverableError ? "Recoverable error" : "Error"; Logger.Error("{2} during initial clone of {0}: {1}", project.ProjectCode, line, errorType); project.State.SetErrorState(isRecoverableError ? ProcessingState.SendReceiveStates.ERROR : ProcessingState.SendReceiveStates.HOLD, errorCode, "{2} during initial clone of {0}: {1}", project.ProjectCode, line, errorType); return(true); }
public void Run(ILfProject project) { Logger.Notice("Action.{0} started", Name); PreRun(project); if (project.State.SRState == ProcessingState.SendReceiveStates.HOLD) { Logger.Notice("LFMerge on hold"); return; } project.State.SRState = StateForCurrentAction; try { DoRun(project); } catch (Exception e) { // An exception during initial clone means we'll want to // perform an initial clone next time this project is run if (project.IsInitialClone) { project.State.SRState = ProcessingState.SendReceiveStates.CLONING; } else if (project.State.SRState != ProcessingState.SendReceiveStates.HOLD && project.State.SRState != ProcessingState.SendReceiveStates.ERROR) { Logger.Error("Got exception. State going to IDLE"); project.State.SRState = ProcessingState.SendReceiveStates.IDLE; } Logger.Error("LfMerge exiting due to {1} exception in Action.{0} ({2})", Name, e.GetType(), e.Message); if (ExceptionLogging.Client != null) // can be null when running unit tests { ExceptionLogging.Client.Notify(e, Bugsnag.Payload.HandledState.ForHandledException()); } throw; } Logger.Notice("Action.{0} finished", Name); }
protected override void DoRun(ILfProject project) { // TODO: Some of these checks might be overkill; consider removing some of them Logger.Debug("MongoToFdo: starting"); _lfProject = project; _projectRecord = _projectRecordFactory.Create(_lfProject); if (_projectRecord == null) { Logger.Warning("No project named {0}", _lfProject.ProjectCode); Logger.Warning("If we are unit testing, this may not be an error"); return; } _lfProjectConfig = _projectRecord.Config; if (_lfProjectConfig == null) return; if (project.FieldWorksProject == null) { Logger.Error("Failed to find the corresponding FieldWorks project!"); return; } if (project.FieldWorksProject.IsDisposed) Logger.Warning("Project {0} is already disposed; this shouldn't happen", project.ProjectCode); _cache = project.FieldWorksProject.Cache; if (_cache == null) { Logger.Error("Failed to find the FDO cache!"); return; } _servLoc = _cache.ServiceLocator; if (_servLoc == null) { Logger.Error("Failed to find the service locator; giving up."); return; } var converter = new ConvertMongoToFdoLexicon(Settings, project, Logger, _connection, _projectRecord); converter.RunConversion(); }
protected override void DoRun(ILfProject project) { // TODO: These checks might be overkill; consider removing some of them if (project == null) { Logger.Error("Project was null in TransferFdoToMongoAction.DoRun"); return; } Logger.Debug("TransferFdoToMongoAction: locating FieldWorks project"); FwProject fwProject = project.FieldWorksProject; if (fwProject == null) { Logger.Error("Can't find FieldWorks project {0}", project.ProjectCode); return; } Logger.Debug("TransferFdoToMongoAction: locating FieldWorks project cache"); _cache = fwProject.Cache; if (_cache == null) { Logger.Error("Can't find cache for FieldWorks project {0}", project.ProjectCode); return; } Logger.Debug("TransferFdoToMongoAction: connecting to FieldWorks service locator"); _servLoc = _cache.ServiceLocator; if (_servLoc == null) { Logger.Error("Can't find service locator for FieldWorks project {0}", project.ProjectCode); return; } Logger.Debug("TransferFdoToMongoAction: setting up lexicon converter"); _lexiconConverter = new ConvertFdoToMongoLexicon(project, Logger, _connection, Progress, _projectRecordFactory); Logger.Debug("TransferFdoToMongoAction: about to run lexicon conversion"); _lexiconConverter.RunConversion(); Logger.Debug("TransferFdoToMongoAction: successful transfer; setting last-synced date"); _connection.SetLastSyncedDate(project, DateTime.UtcNow); }
public bool CreateCustomFieldsConfigViews(ILfProject project, Dictionary<string, LfConfigFieldBase> lfCustomFieldList) { return CreateCustomFieldsConfigViews(project, lfCustomFieldList, false); }
protected override void DoRun(ILfProject project) { }
private bool CloneResultedInError(ILfProject project, string cloneResult, string errorString) { var line = LfMergeBridgeServices.GetLineContaining(cloneResult, errorString); if (!string.IsNullOrEmpty(line)) { Logger.Error(line); project.State.SRState = ProcessingState.SendReceiveStates.HOLD; return true; } return false; }
public override void PreRun(ILfProject project) { _currentProject = project; if (!File.Exists(Settings.GetStateFileName(_currentProject.ProjectCode))) _currentProject.State.SRState = ProcessingState.SendReceiveStates.CLONING; }
/// <summary> /// Ensures a Send/Receive project from Language Depot is properly /// cloned into the WebWork directory for LfMerge. /// A project will be cloned if: /// 1) The LfMerge state file doesn't exist OR /// 2) The current LfMerge state is ProcessingState.SendReceiveStates.CLONING OR /// 3) The project directory is empty /// </summary> /// <param name="project">LF Project.</param> protected override void DoRun(ILfProject project) { try { // Check if an initial clone needs to be performed if (File.Exists(Settings.GetStateFileName(project.ProjectCode)) && (project.State.SRState != ProcessingState.SendReceiveStates.CLONING)) { return; } Logger.Notice("Initial clone for project {0}", project.ProjectCode); // Since we're in here, the previous clone was not finished, so remove and start over var cloneLocation = project.ProjectDir; if (Directory.Exists(cloneLocation)) { Logger.Notice("Cleaning out previous failed clone at {0}", cloneLocation); Directory.Delete(cloneLocation, true); } project.State.SRState = ProcessingState.SendReceiveStates.CLONING; string cloneResult; if (!CloneRepo(project, cloneLocation, out cloneResult)) { Logger.Error(cloneResult); return; } if (CloneResultedInError(project, cloneResult, "clone is not a FLEx project") || CloneResultedInError(project, cloneResult, "no such branch") || CloneResultedInError(project, cloneResult, "new repository with no commits") || CloneResultedInError(project, cloneResult, "clone has higher model")) { return; } var line = LfMergeBridgeServices.GetLineContaining(cloneResult, "new clone created on branch"); Require.That(!string.IsNullOrEmpty(line), "Looks like the clone was not successful, but we didn't get an understandable error"); // Dig out actual clone path from 'line'. const string folder = "folder '"; var folderIndex = line.IndexOf(folder, StringComparison.InvariantCulture); if (folderIndex >= 0) { var actualClonePath = line.Substring(folderIndex + folder.Length) .TrimEnd('.').TrimEnd('\''); Require.That(cloneLocation == actualClonePath, "Something changed in LfMergeBridge so that we cloned in a different directory"); } InitialTransferToMongoAfterClone(project); } catch (Exception e) { if (e.GetType().Name == "ArgumentOutOfRangeException" && e.Message == "Cannot update to any branch.") { project.State.SRState = ProcessingState.SendReceiveStates.HOLD; throw; } if (e.GetType().Name == "RepositoryAuthorizationException") { Logger.Error("Initial clone authorization exception"); project.State.SRState = ProcessingState.SendReceiveStates.HOLD; throw; } Logger.Error("Got {0} exception trying to clone: {1}", e.GetType(), e.Message); throw; } }
protected override void InitialTransferToMongoAfterClone(ILfProject project) { // We don't want to do this for these tests, but we still want to set the state project.State.SRState = ProcessingState.SendReceiveStates.SYNCING; }
/// <summary> /// Ensures a Send/Receive project from Language Depot is properly /// cloned into the WebWork directory for LfMerge.Core. /// A project will be cloned if: /// 1) The LfMerge state file doesn't exist OR /// 2) The current LfMerge state is ProcessingState.SendReceiveStates.CLONING OR /// 3) The project directory is empty /// </summary> /// <param name="project">LF Project.</param> protected override void DoRun(ILfProject project) { try { // Check if an initial clone needs to be performed if (File.Exists(Settings.GetStateFileName(project.ProjectCode)) && project.State.SRState != ProcessingState.SendReceiveStates.CLONING && File.Exists(project.FwDataPath)) { return; } var cloneLocation = project.ProjectDir; if (RepoAlreadyExists(cloneLocation)) { Logger.Notice("Repairing clone of project {0}", project.ProjectCode); } else { Logger.Notice("Initial clone for project {0}", project.ProjectCode); } project.State.SRState = ProcessingState.SendReceiveStates.CLONING; string cloneResult; if (!CloneRepo(project, cloneLocation, out cloneResult)) { Logger.Error(cloneResult); return; } if (CloneResultedInError(project, cloneResult, "clone is not a FLEx project", true, ProcessingState.ErrorCodes.NoFlexProject) || CloneResultedInError(project, cloneResult, "new repository with no commits", true, ProcessingState.ErrorCodes.EmptyProject) || CloneResultedInError(project, cloneResult, "clone has higher model", true, ProcessingState.ErrorCodes.ProjectTooNew) || CloneResultedInError(project, cloneResult, "LfMergeBridge starting S/R handler from directory", false, ProcessingState.ErrorCodes.Unspecified)) { return; } string line = LfMergeBridgeServices.GetLineContaining(cloneResult, "no such branch"); if (!string.IsNullOrEmpty(line)) { const string modelString = "Highest available model '"; var index = line.IndexOf(modelString, StringComparison.Ordinal); if (index < 0) { ReportNoSuchBranchFailure(project, cloneLocation, cloneResult, line, ProcessingState.ErrorCodes.UnspecifiedBranchError); return; } var cloneModelVersion = line.Substring(index + modelString.Length, 7); if (int.Parse(cloneModelVersion) < int.Parse(MagicStrings.MinimalModelVersion)) { ReportNoSuchBranchFailure(project, cloneLocation, cloneResult, line, ProcessingState.ErrorCodes.ProjectTooOld); Logger.Error("Error during initial clone of '{0}': " + "clone model version '{1}' less than minimal supported model version '{2}'.", project.ProjectCode, cloneModelVersion, MagicStrings.MinimalModelVersion); return; } Logger.Info(line); ChorusHelper.SetModelVersion(cloneModelVersion); } else { ChorusHelper.SetModelVersion(FdoCache.ModelVersion); line = LfMergeBridgeServices.GetLineContaining(cloneResult, "new clone created on branch"); Require.That(!string.IsNullOrEmpty(line), "Looks like the clone was not successful, but we didn't get an understandable error"); // verify clone path GetActualClonePath(cloneLocation, line); if (MongoProjectHasUserDataOrHasBeenSynced()) { // If the local Mercurial repo was deleted but the Mongo database is still there, // then there might be data in Mongo that we still need, in which case we should NOT // skip the syncing step. So do nothing, so that we'll fall through to the SYNCING state. } else { InitialTransferToMongoAfterClone(project); Logger.Notice("Initial clone completed; setting state to CLONED"); project.State.SRState = ProcessingState.SendReceiveStates.CLONED; } } } catch (Exception e) { switch (e.GetType().Name) { case "ArgumentOutOfRangeException": if (e.Message == "Cannot update to any branch.") { project.State.SetErrorState(ProcessingState.SendReceiveStates.ERROR, ProcessingState.ErrorCodes.UnspecifiedBranchError, "Error during initial clone of {0}: {1}", project.ProjectCode, e); return; } break; case "RepositoryAuthorizationException": Logger.Error("Initial clone of {0}: authorization exception", project.ProjectCode); project.State.SetErrorState(ProcessingState.SendReceiveStates.ERROR, ProcessingState.ErrorCodes.Unauthorized, "Error during initial clone of {0}: authorization exception from remote repository", project.ProjectCode); return; } Logger.Error("Got {0} exception trying to clone {1}: {2}", e.GetType(), project.ProjectCode, e.Message); throw; } }
public bool CreateCustomFieldsConfigViews(ILfProject project, Dictionary<string, LfConfigFieldBase> lfCustomFieldList, bool isTest) { var customFieldSpecs = new List<CustomFieldSpec>(); foreach (string lfCustomFieldName in lfCustomFieldList.Keys) { customFieldSpecs.Add(new CustomFieldSpec(lfCustomFieldName, _fieldNameToFieldType[lfCustomFieldName])); } var lfproxy = MainClass.Container.Resolve<ILanguageForgeProxy>(); string output = lfproxy.UpdateCustomFieldViews(project.ProjectCode, customFieldSpecs, isTest); if (string.IsNullOrEmpty(output) || output == "false") return false; return true; }