private void textEmp_KeyUp(object sender, KeyEventArgs e) { if (!keyLocker.Contains(e.KeyData)) { keyLocker.Add(e.KeyData); try { lastKeyData = e.KeyData; if (lastEmployeeText != textEmp.Text && !(textEmp.Text.Length == 1 && Regex.IsMatch(textEmp.Text, "[A-Za-z]"))) { buttonSelect.Text = label + "..."; if ((lastKeyData != Keys.Delete) && (lastKeyData != Keys.Back) && lastKeyData != Keys.Down && lastKeyData != Keys.Up) { ParseEmployee(false); } } else if ((textEmp.Text.Length == 1 && Regex.IsMatch(textEmp.Text, "[A-Za-z]")) || (textEmp.Text.Length == 0)) { buttonSelect.Text = label + "..."; } lastEmployeeText = textEmp.Text; } catch (Exception ex) { ErrorShower.OnShowError(null, ex.Message, ""); } finally { keyLocker.Remove(e.KeyData); } } }
/// <summary> /// VScan calls WCF service to save data on the server. It's buffered operation. /// </summary> /// <param name="fileName"></param> /// <param name="data"></param> public void SaveData(string serverDirName, string fileName, byte[] data, string s1, string s2) { try { SecurityCheckThrow(s1, s2); RecordCallHistory("SaveData"); if (!FileLocks.Contains(serverDirName, StringComparer.InvariantCultureIgnoreCase)) { FileLocks.Add(serverDirName); } var uploadRootFolder = new DirectoryInfo(Global.Strings.UPLOADROOT); var serverDir = uploadRootFolder.Combine(serverDirName); serverDir.EnsureDirectory(); var finfo = serverDir.CombineFileName(fileName); using (var file = finfo.Open(FileMode.OpenOrCreate)) { file.Seek(file.Length, SeekOrigin.Begin); file.Write(data, 0, data.Length); } } catch (Exception ex) { throw new FaultException <MyApplicationFault>(new MyApplicationFault(), ex.Message); } }
/// <summary> /// Add a client to the server room /// </summary> /// <param name="client">Client to add</param> /// <returns>true if added and false if client already in the room</returns> public bool AddClient(ClientInfo client) { if (_clientList.Contains(client)) { return(false); } else { _clientList.Add(client); return(true); } }
public void CollectFanArt(Guid mediaItemId, IDictionary <Guid, IList <MediaItemAspect> > aspects) { if (_checkCache.Contains(mediaItemId)) { return; } Guid?seriesMediaItemId = null; Guid?seasonMediaItemId = null; IDictionary <Guid, string> actorMediaItems = new Dictionary <Guid, string>(); SingleMediaItemAspect videoAspect; List <string> actors = new List <string>(); if (MediaItemAspect.TryGetAspect(aspects, VideoAspect.Metadata, out videoAspect)) { IEnumerable <string> actorObjects = videoAspect.GetCollectionAttribute <string>(VideoAspect.ATTR_ACTORS); if (actorObjects != null) { actors.AddRange(actorObjects); } } IList <MultipleMediaItemAspect> relationAspects; if (MediaItemAspect.TryGetAspects(aspects, RelationshipAspect.Metadata, out relationAspects)) { foreach (MultipleMediaItemAspect relation in relationAspects) { if ((Guid?)relation[RelationshipAspect.ATTR_LINKED_ROLE] == SeriesAspect.ROLE_SERIES) { seriesMediaItemId = (Guid)relation[RelationshipAspect.ATTR_LINKED_ID]; } if ((Guid?)relation[RelationshipAspect.ATTR_LINKED_ROLE] == SeasonAspect.ROLE_SEASON) { seasonMediaItemId = (Guid)relation[RelationshipAspect.ATTR_LINKED_ID]; } if ((Guid?)relation[RelationshipAspect.ATTR_LINKED_ROLE] == PersonAspect.ROLE_ACTOR) { int?index = (int?)relation[RelationshipAspect.ATTR_RELATIONSHIP_INDEX]; if (index.HasValue && actors.Count > index.Value && index.Value >= 0) { actorMediaItems[(Guid)relation[RelationshipAspect.ATTR_LINKED_ID]] = actors[index.Value]; } } } } _checkCache.Add(mediaItemId); Task.Run(() => ExtractFanArt(mediaItemId, aspects, seriesMediaItemId, seasonMediaItemId, actorMediaItems)); }
private static void UpdateRestrictionsOnVersion(Item item) { if (inProcess.Contains(item.ID)) { return; } inProcess.Add(item.ID); try { Database db = Sitecore.Context.ContentDatabase; if (db != null && db.Name == "master") { Item project = db.GetItem(item[Data.ProjectFieldId]); if (project != null) { if (!item.Editing.IsEditing) { item.Editing.BeginEdit(); } item.Publishing.ValidFrom = ((DateField)project.Fields[Data.ProjectDetailsReleaseDate]).DateTime; item.Editing.EndEdit(); } } } finally { inProcess.Remove(item.ID); } }
public static async void Block([NotNull] string key, [NotNull] Func <Task> taskFactory) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (taskFactory == null) { throw new ArgumentNullException(nameof(taskFactory)); } if (Running.Contains(key)) { // block if running return; } Running.Add(key); try { await taskFactory(); } finally { Running.Remove(key); } }
private void textBoxPerson_KeyUp(object sender, KeyEventArgs e) { if (!keyLocker.Contains(e.KeyData)) { keyLocker.Add(e.KeyData); try { if (e.KeyData == Keys.Enter && textBoxPerson.Text.Length > 0) { if (InvokeRequired) { BeginInvoke((MethodInvoker)(Find)); } else { Find(); } } } catch (Exception ex) { Data.Env.WriteToLog(ex); } finally { keyLocker.Remove(e.KeyData); } } }
private void person_KeyUp(object sender, KeyEventArgs e) { if (!_keyLocker.Contains(e.KeyData)) { try { _keyLocker.Add(e.KeyData); lastKeyData = e.KeyData; if (e.KeyData != Keys.Enter) { if (lastPersonText != person.Text.Trim()) { if (comboPerson.DroppedDown) { comboPerson.DroppedDown = false; } buttonSelect.Text = Environment.StringResources.GetString("Search") + "..."; if (person.Text.Trim().Length > 0) { ParsePerson(lastKeyData == Keys.Delete || lastKeyData == Keys.Back || lastKeyData == Keys.OemMinus || lastKeyData == Keys.Space); } } } lastPersonText = person.Text; } catch (Exception ex) { Data.Env.WriteToLog(ex); } }
/** * Register an {@link EventListener} to notify when {@link Event}s are added * * @param listener the {@link EventListener} to register */ public void registerListener(EventListener listener) { if (!listeners.Contains(listener)) { listeners.Add(listener); } }
public void AddWindow(Display.Window window) { if (window == null) { throw new ArgumentNullException("window"); } if (windows.Contains(window)) { return; } if (windows.Count == 0) { _focusedWindow = window; Mouse.CurrentWindow = window; } window.GainedFocus += onFocused; window.KeyPressed += onKeyDown; window.KeyReleased += onKeyUp; window.MouseMoved += onMouseMove; window.MouseWheelScrolled += onMouseWheel; window.MouseButtonPressed += onMouseDown; window.MouseButtonReleased += onMouseUp; windows.Add(window); }
/** * Register an {@link AttackListener} to notify when {@link Attack}s are added * * @param listener the {@link AttackListener} to register */ public void registerListener(AttackListener listener) { if (!listeners.Contains(listener)) { listeners.Add(listener); } }
public void AddDisposableObj(IDisposable disposableObj) { if (!_objList.Contains(disposableObj)) { _objList.Add(disposableObj); } }
private void searchBox_KeyUp(object sender, KeyEventArgs e) { if (!keyLocker.Contains(e.KeyData)) { try { keyLocker.Add(e.KeyData); lastKeyData = e.KeyData; if (e.KeyData != Keys.Enter) { if (lastPersonText != searchBox.Text.Trim()) { if (showBox.DroppedDown) { showBox.DroppedDown = false; } buttonSearch.Text = buttonMainText + "..."; if (searchBox.Text.Trim().Length > 0) { ParsePerson(lastKeyData == Keys.Delete || lastKeyData == Keys.Back || lastKeyData == Keys.OemMinus || lastKeyData == Keys.Space); } } } lastPersonText = searchBox.Text; } catch (Exception ex) { Data.Env.WriteToLog(ex); } }
private static void MoveItemToState(Item item, String state) { if (inProcess.Contains(item.ID)) { return; } inProcess.Add(item.ID); try { Database db = Sitecore.Context.ContentDatabase; if (db != null && db.Name == "master") { Item project = db.GetItem(item[Data.ProjectFieldId]); if (project != null) { if (!item.Editing.IsEditing) { item.Editing.BeginEdit(); } item.Fields["__Workflow State"].Value = state; //final item.Editing.EndEdit(); } } } finally { inProcess.Remove(item.ID); } }
private void text_KeyUp(object sender, KeyEventArgs e) { if (!keyLocker.Contains(e.KeyData)) { keyLocker.Add(e.KeyData); try { if (e.KeyData == Keys.Enter) { Parse(); if (ID > 0) { text.SelectAll(); } } else if (text.Text != lastText) { ID = 0; } lastText = text.Text; } catch (Exception ex) { Data.Env.WriteToLog(ex); } finally { keyLocker.Remove(e.KeyData); } } }
public void Dispose() { if (observer != null && observers.Contains(observer)) { observers.Remove(observer); } }
private void textEmp_KeyUp(object sender, KeyEventArgs e) { if (keyLocker.Contains(e.KeyData)) { return; } keyLocker.Add(e.KeyData); try { string txt = textEmp.Text.Trim(); lastKeyData = e.KeyData; if (lastEmployeeText != textEmp.Text && !(textEmp.Text.Length == 1 && Regex.IsMatch(textEmp.Text, "[A-Za-z]"))) { if (e.KeyData == Keys.Enter) { if (findEmployeeID > 0) { OnFindEmployee(findEmployeeID); } else { parser.Parse(ref txt); if (txt.Length > 0 && parser.CandidateCount > 0) { OnFindEmployee((int)parser.CandidateEmployees[0]["КодСотрудника"]); } } } if ((lastKeyData != Keys.Delete) && (lastKeyData != Keys.Back) && e.KeyData != Keys.Down && e.KeyData != Keys.Up && e.KeyData != Keys.Space) { ParseEmployee(false); } else if (lastKeyData == Keys.Delete || lastKeyData == Keys.Back) { findEmployeeID = 0; if (comboBoxEmp.DroppedDown) { comboBoxEmp.DroppedDown = false; } if (textEmp.Text.Trim().Length == 0) { OnFindEmployee(0); } } } lastEmployeeText = textEmp.Text; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { keyLocker.Remove(e.KeyData); } }
/** * Register an {@link ResponseListener} to notify when {@link Response}s are added * * @param listener the {@link ResponseListener} to register */ public void registerListener(ResponseListener listener) { //if (! listeners.Contains(listener)) { if (!listeners.Contains(listener)) { listeners.Add(listener); } }
//private internal static void AddWindow(Window window) { if (windows.Contains(window)) { return; } windows.Add(window); }
public static bool HasService(Type type) { if (type == null) { return(false); } return(services.Contains(type)); }
public void CollectFanArt(Guid mediaItemId, IDictionary <Guid, IList <MediaItemAspect> > aspects) { if (_checkCache.Contains(mediaItemId)) { return; } Guid?albumMediaItemId = null; IDictionary <Guid, string> artistMediaItems = new Dictionary <Guid, string>(); SingleMediaItemAspect audioAspect; List <string> artists = new List <string>(); if (MediaItemAspect.TryGetAspect(aspects, AudioAspect.Metadata, out audioAspect)) { IEnumerable <string> artistObjects = audioAspect.GetCollectionAttribute <string>(AudioAspect.ATTR_ALBUMARTISTS); if (artistObjects != null) { artists.AddRange(artistObjects); } } IList <MultipleMediaItemAspect> relationAspects; if (MediaItemAspect.TryGetAspects(aspects, RelationshipAspect.Metadata, out relationAspects)) { foreach (MultipleMediaItemAspect relation in relationAspects) { if ((Guid?)relation[RelationshipAspect.ATTR_LINKED_ROLE] == AudioAlbumAspect.ROLE_ALBUM) { albumMediaItemId = (Guid)relation[RelationshipAspect.ATTR_LINKED_ID]; } if ((Guid?)relation[RelationshipAspect.ATTR_LINKED_ROLE] == PersonAspect.ROLE_ALBUMARTIST) { int?index = (int?)relation[RelationshipAspect.ATTR_RELATIONSHIP_INDEX]; if (index.HasValue && artists.Count > index.Value && index.Value >= 0) { artistMediaItems[(Guid)relation[RelationshipAspect.ATTR_LINKED_ID]] = artists[index.Value]; } } } } _checkCache.Add(mediaItemId); Task.Run(() => ExtractFanArt(mediaItemId, aspects, albumMediaItemId, artistMediaItems)); }
private void text_KeyUp(object sender, KeyEventArgs e) { if (!keyLocker.Contains(e.KeyData)) { try { if (e.KeyData == Keys.Enter) { text.Text = text.Text.Replace(System.Environment.NewLine, ""); DataRow[] drs = Parse(); if (drs != null && drs.Length == 1) { text.SelectAll(); } else { SelectDialog(); } } else if (text.Text != lastText) { if (e.KeyData == Keys.Delete || e.KeyData == Keys.Back) { Parse(false); } else { ParseAndSelectTail(); } } lastText = text.Text; } catch (Exception ex) { Data.Env.WriteToLog(ex); } finally { keyLocker.Remove(e.KeyData); } } }
public void CollectFanArt(Guid mediaItemId, IDictionary <Guid, IList <MediaItemAspect> > aspects) { if (_checkCache.Contains(mediaItemId)) { return; } _checkCache.Add(mediaItemId); Task.Run(() => ExtractFanArt(mediaItemId, aspects)); }
private void ListenerOnPeerConnectedEvent(NetPeer peer) { _logger.Information("NetworkServer: Client {@Id} connected", peer.Id); var networkClient = new NetworkClient(peer); if (!_clients.Contains(networkClient)) { _clients.Add(networkClient); } }
private bool IsDuplicate(string id) { if (_receivedCommentIds.Contains(id)) { return(true); } else { _receivedCommentIds.Add(id); return(false); } }
//public public void AddWindow(Window window) { if (window == null) { throw new ArgumentNullException("window"); } if (windows.Contains(window)) { return; } windows.Add(window); }
private void ProceedNode(TreeNode tNode) { var wNode = tNode as FolderTree.FolderNodes.WorkNodes.WorkNode; if (wNode == null) { return; } if (wNode.Checked) { if (!selected.Contains(wNode) || (grayed.Contains(wNode) && wNode.ForeColor == Color.FromKnownColor(KnownColor.ControlText))) { Environment.WorkDocData.AddDocToWorkFolder(docIDs, wNode.ID, wNode.Emp.ID); string docStr = DBDocString.Format(docIDs[0]); Environment.UndoredoStack.Add("AddDocToWork", Environment.StringResources.GetString("AddDocToWork"), string.Format(Environment.StringResources.GetString("UndoAddDocToWork"), docStr), string.Format(Environment.StringResources.GetString("RedoAddDocToWork"), docStr), UndoRedoCommands.UndoAddToWork, new object[] { docIDs[0], wNode.ID, wNode.Emp.ID }, wNode.Emp.ID); } } else { if (selected.Contains(wNode) || (grayed.Contains(wNode) && wNode.ForeColor == Color.FromKnownColor(KnownColor.ControlText))) { Environment.WorkDocData.RemoveDocFromWorkFolder(docIDs, wNode.ID, wNode.Emp.ID); } } foreach (TreeNode subNode in wNode.Nodes) { ProceedNode(subNode); } }
public void WhenUnsubscribe_ShouldBeDisposed() { var mock1 = new Mock<INotificationObserver<string>>(); var mock2 = new Mock<INotificationObserver<string>>(); var mock3 = new Mock<INotificationObserver<string>>(); var obs = new SynchronizedCollection<INotificationObserver<string>> {mock1.Object, mock2.Object, mock3.Object }; var unsub = new Unsubscriber(obs, mock2.Object); unsub.Dispose(); Assert.Equal(2, obs.Count); Assert.False(obs.Contains(mock2.Object)); }
public void WhenUnsubscribe_ShouldBeDisposed() { var mock1 = new Mock <INotificationObserver <string> >(); var mock2 = new Mock <INotificationObserver <string> >(); var mock3 = new Mock <INotificationObserver <string> >(); var obs = new SynchronizedCollection <INotificationObserver <string> > { mock1.Object, mock2.Object, mock3.Object }; var unsub = new Unsubscriber(obs, mock2.Object); unsub.Dispose(); Assert.Equal(2, obs.Count); Assert.False(obs.Contains(mock2.Object)); }
public Task RunBuild(RunBuild build) { Builds.Add(build); return(Task.Run(async() => { while (true) { if (!Builds.Contains(build)) { return Task.CompletedTask; } await Task.Delay(1000); } }, _cancellationToken)); }
protected override void OnFileChanged(object source, FileSystemEventArgs e) { if (Path.GetExtension(e.Name).ToLower() == ".xml" && _bMDXmlFiles.Contains(e.FullPath)) { _scanXML(e.FullPath); } Media m = (Media)_files.Values.FirstOrDefault(f => e.FullPath == f.FullPath); if (m != null) { if (m.IsVerified) { m.IsVerified = false; } } }
// This Unit test is based from full framework test public static void SynchronizedCollectionPublicMembersTest() { SynchronizedCollection<int> coll = new SynchronizedCollection<int>(); int size = 100; for (int i = 0; i < size; i++) coll.Add(i); Assert.True(coll.Count == size, string.Format("collection count was wrong! Expected: {0} got: {1}", size, coll.Count)); for (int i = 0; i < size; i++) { Assert.True(coll[i] == i, string.Format("coll element {0} was wrong! Expected: {1} got: {2} ", i, i, coll[i])); Assert.True(coll.IndexOf(i) == i, string.Format("coll IndexOf wasn't right! Expected: {0} got: {1}" , i, coll.IndexOf(i))); Assert.True(coll.Contains(i), string.Format("coll Contains failed to find the value {0}.", i)); } SynchronizedCollection<int> coll2 = new SynchronizedCollection<int>(new object(), new List<int>(coll)); for (int i = 0; i < size; i++) { Assert.True(coll2[i] == i, string.Format("coll2 element was wrong! expected: {0} got: {1} ", i, coll2[i])); } SynchronizedCollection<int> coll3 = new SynchronizedCollection<int>(new object(), 1, 2, 3, 4, 5 , 6); for (int i = 0; i < 5; i++) { Assert.True(coll3[i] == i + 1, string.Format("coll3 element {0} was wrong! expected: {1} got: {2}", i, i+1, coll3[i])); } int newValue = 80; coll3[5] = newValue; Assert.True(coll3[5] == newValue); IEnumerator <int> e = coll.GetEnumerator(); int n = 0; while (e.MoveNext()) { Assert.True(e.Current.Equals(n++), string.Format("Expected: {0}, got:{1}", n-1, e.Current)); } Assert.True(n == 100, string.Format("Expect number of elements: {0}, got:{1}", 100, n)); int[] array = new int[size + 1]; coll.CopyTo(array, 1); for (int i = 0; i < size; i++) { Assert.True(array[i + 1] == i, string.Format("After CopyTo, Element {0} was wrong! Expected: {1} got: {2}", i, i+1, array[i + 1])); } coll.Add(coll.Count); coll.Insert(0, -1); coll.RemoveAt(0); coll.Remove(coll.Count - 1); Assert.True(coll.Count == size, string.Format("Expect number of elements after modification: {0}, got: {1}", size, coll.Count)); for (int i = 0; i < size; i++) { Assert.True(coll[i] == i, string.Format("coll element was wrong after modification! Expected: {0} got: {1} ", i, coll[i])); } coll.Clear(); Assert.True(coll.Count == 0, string.Format("Clear operation failed!, expected: 0, actual {0}", coll.Count)); // Negative cases Assert.Throws<ArgumentNullException>("syncRoot", () => { new SynchronizedCollection<int>(null); }); Assert.Throws<ArgumentNullException>("list", () => { new SynchronizedCollection<int>(new object(), null); }); Assert.Throws<ArgumentNullException>("syncRoot", () => { new SynchronizedCollection<int>(null, new List<int>()); }); Assert.Throws<ArgumentNullException>("syncRoot", () => { new SynchronizedCollection<int>(null, 1, 2, 3, 4); }); Assert.Throws<ArgumentOutOfRangeException>(() => { coll[1000] = 5; }); Assert.Throws<ArgumentOutOfRangeException>(() => { coll[-1] = 5; }); Assert.Throws<ArgumentOutOfRangeException>(() => { coll.Insert(1000, 5); }); Assert.Throws<ArgumentOutOfRangeException>(() => { coll.Insert(-1, 5); }); Assert.False(coll.Remove(100000)); Assert.Throws<ArgumentOutOfRangeException>(() => { coll.RemoveAt(-1); }); Assert.Throws<ArgumentOutOfRangeException>(() => { coll.RemoveAt(10000); }); }