public void UpdateData(IRepositoryInfoCacheData data) { var now = DateTimeOffset.Now; var isUpdated = false; if (!Nullable.Equals(currentGitRemote, data.CurrentGitRemote)) { currentGitRemote = data.CurrentGitRemote ?? GitRemote.Default; isUpdated = true; } if (!Nullable.Equals(currentGitBranch, data.CurrentGitBranch)) { currentGitBranch = data.CurrentGitBranch ?? GitBranch.Default; isUpdated = true; } if (!Nullable.Equals(currentConfigRemote, data.CurrentConfigRemote)) { currentConfigRemote = data.CurrentConfigRemote ?? ConfigRemote.Default; isUpdated = true; } if (!Nullable.Equals(currentConfigBranch, data.CurrentConfigBranch)) { currentConfigBranch = data.CurrentConfigBranch ?? ConfigBranch.Default; isUpdated = true; } SaveData(now, isUpdated); }
public object Execute(ConfigBranch config, object context) { if (context == null) throw new ArgumentNullException("context"); SPListItem item = null; var properties = context as SPItemEventProperties; if (properties != null) { item = properties.ListItem; } if (context.GetType() == typeof (SPListItem)) { item = context as SPListItem; } var duplicatePluginConfig = ConfigBranch.GetInstance<DuplicatePluginConfig>(config); return DuplicateValues(item, duplicatePluginConfig); }
public IList<KeyValuePair<bool, string>> Test(ConfigBranch config, object context) { throw new NotImplementedException(); }
public object Execute(ConfigBranch branch, object context) { if (context == null) throw new ArgumentNullException("context"); var config = ConfigBranch.GetInstance<LinkedLookupConfig>(branch); SPItemEventProperties props = null; SPEventReceiverType eventType; SPSite site; SPWeb web; SPList list; SPListItem item; #region Load properties if (context is SPItemEventProperties) { props = context as SPItemEventProperties; eventType = props.EventType; site = props.Site; web = props.Web; list = props.List; item = props.ListItem; } else if (context is SPListItem) // pro castecne ucely debugu { item = context as SPListItem; eventType = SPEventReceiverType.ItemDeleting; site = item.Web.Site; web = item.Web; list = item.ParentList; } else { log.LogError("Incorrect context"); return null; } #endregion for (int i = 0; i < config.LinkedLookup.Count; i++) { LinkedLookupSettings settings = config.LinkedLookup[i]; try { using (SPWeb localWeb = site.OpenW(settings.LocalWeb, true)) { if (localWeb.ID == web.ID) { SPList localList = localWeb.OpenList(settings.LocalList, true); if (localList.ID == list.ID) // mame konfiguraci na zpracovavanou polozku a jdem dal { log.LogInfo("RUNNING LinkedLookup at " + localList.DefaultViewUrlNoAspx() + " on item " + item.ID); SPField localField = localList.OpenField(settings.LocalField, true); Guid lookupWebId = ( (SPFieldLookup) localField ).LookupWebId; Guid lookupListId = new Guid(( (SPFieldLookup) localField ).LookupList); item.Web.Site.RunElevated(delegate(SPSite elevatedSite) { using (SPWeb remoteWeb = elevatedSite.OpenW(lookupWebId, true)) { SPList remoteList = remoteWeb.OpenList(settings.RemoteList, true); SPField remoteField = remoteList.OpenField(settings.RemoteField, true); string localLookupValue = ""; string oldLookup = ""; List<int> oldItems = new List<int>(); //ID polozek, ktere v remote lookupu byly driv List<int> newItems = new List<int>(); // ID polozek, ktere v remote lookupu maji byt po zmene try { if (eventType == SPEventReceiverType.ItemDeleting) { oldLookup = ( item[localField.InternalName] ?? "" ).ToString().Trim(); localLookupValue = oldLookup; } else if (( eventType == SPEventReceiverType.ItemAdded || eventType == SPEventReceiverType.ItemUpdating )) { oldLookup = ( item[localField.InternalName] ?? "" ).ToString().Trim(); localLookupValue = (props.AfterProperties[localField.InternalName] ?? "").ToString().Trim(); } if (settings.Force) { localLookupValue = oldLookup; oldLookup = ""; } // staré vazby v lokálním lookupu, které budeme chtít prověřit a případně smazat if (eventType == SPEventReceiverType.ItemDeleting || eventType == SPEventReceiverType.ItemUpdating) { if (oldLookup != "") { oldItems = oldLookup.GetLookupIndexes().ToList(); } } // nové vazby v lokálním lookupu, plus zajištění, že nesmažeme něco, co má zůstat navázané // !!! POZOR, pokud je lookup schovany z editFormu pomoci Advanced Field Modifications, bude v AfterProperties prazdny - max. jde pouzit skryti radku ve formu javascriptem if (( eventType == SPEventReceiverType.ItemAdded || eventType == SPEventReceiverType.ItemUpdating )) { newItems = localLookupValue.GetLookupIndexes().ToList(); } List<int> addItems = newItems.Where(id => !oldItems.Contains(id)).ToList(); List<int> removeItems = oldItems.Where(id => !newItems.Contains(id)).ToList(); if (removeItems.Count > 0) { //if (config.DebugOn()) Tools.Log(props, config, "Clearing old - items " + removeItems.JoinStrings(", ")); ClearOld(settings, item.ID, removeItems, remoteField, remoteList); } if (addItems.Count > 0) { //if (config.DebugOn()) Tools.Log(props, config, "Adding new - items " + addItems.JoinStrings(", ")); AddNew(settings, props, addItems, remoteField, remoteList); } // if (removeItems.Count == 0 && addItems.Count == 0 && config.DebugOn()) Tools.Log(props, config, "LinkedLookupReceiver - no changes written"); } catch (Exception exc) { log.LogException(exc); } } return null; }); } } } } catch (Exception exc) { log.LogException(exc); } } return "OK"; }
public void Repository() { var repository = LoadRepository(); var repositoryManager = Substitute.For <IRepositoryManager>(); var repositoryListener = Substitute.For <IRepositoryListener>(); repositoryListener.AttachListener(repository, repositoryEvents); var origin = new ConfigRemote { Name = "origin", Url = "https://github.com/someUser/someRepo.git" }; var remotes = new[] { origin }; var remoteDictionary = remotes.ToDictionary(remote => remote.Name); var masterOriginBranch = new ConfigBranch { Name = "master", Remote = origin }; var branches = new[] { masterOriginBranch, new ConfigBranch { Name = "features/feature-1", Remote = origin } }; var branchDictionary = branches.ToDictionary(branch => branch.Name); var remoteBranches = new[] { new ConfigBranch { Name = "master", Remote = origin }, new ConfigBranch { Name = "features/feature-1", Remote = origin }, new ConfigBranch { Name = "features/feature-2", Remote = origin } }; var remoteBranchDictionary = remoteBranches .GroupBy(branch => branch.Remote.Value.Name) .ToDictionary(grouping => grouping.Key, grouping => grouping.ToDictionary(branch => branch.Name)); repository.Initialize(repositoryManager); string expectedBranch = null; repository.OnCurrentBranchChanged += branch => { expectedBranch = branch; }; string expectedRemote = null; repository.OnCurrentRemoteChanged += remote => { expectedRemote = remote; }; repositoryManager.OnLocalBranchListUpdated += Raise.Event <Action <Dictionary <string, ConfigBranch> > >(branchDictionary); repositoryEvents.OnLocalBranchListChanged.WaitOne(repositoryEventsTimeout).Should().BeTrue("OnLocalBranchListChanged not raised"); repositoryManager.OnRemoteBranchListUpdated += Raise.Event <Action <Dictionary <string, ConfigRemote>, Dictionary <string, Dictionary <string, ConfigBranch> > > >(remoteDictionary, remoteBranchDictionary); repositoryEvents.OnRemoteBranchListChanged.WaitOne(repositoryEventsTimeout).Should().BeTrue("OnRemoteBranchListChanged not raised"); repositoryManager.OnCurrentBranchUpdated += Raise.Event <Action <ConfigBranch?> >(masterOriginBranch); repositoryManager.OnCurrentRemoteUpdated += Raise.Event <Action <ConfigRemote?> >(origin); repositoryEvents.OnCurrentBranchChanged.WaitOne(repositoryEventsTimeout).Should().BeTrue("OnCurrentBranchChanged not raised"); repositoryEvents.OnCurrentRemoteChanged.WaitOne(repositoryEventsTimeout).Should().BeTrue("OnCurrentRemoteChanged not raised"); repositoryEvents.OnRepositoryInfoChanged.WaitOne(repositoryEventsTimeout).Should().BeTrue("OnRepositoryInfoChanged not raised"); expectedBranch.Should().Be("master"); expectedRemote.Should().Be("origin"); }