/** * @brief preload a compressed audio file * @details the compressed audio will be decode to wave, then write into an * internal buffer in SimpleaudioEngine */ /// <summary> /// Load the sound effect found with the given path. The sound effect is only loaded one time and the /// effect is cached as an instance of EffectPlayer. /// </summary> public void PreloadEffect(string pszFilePath) { if (_NoAudioHardware) { return; } if (string.IsNullOrEmpty(pszFilePath)) { return; } int nId = pszFilePath.GetHashCode(); lock (SharedList) { if (SharedList.ContainsKey(nId)) { return; } } try { CCEffectPlayer eff = new CCEffectPlayer(); eff.Open(FullPath(pszFilePath), nId); SharedList[nId] = eff; } catch (NoAudioHardwareException ex) { _NoAudioHardware = true; CCLog.Log(ex.ToString()); } }
public int PlayEffect(int fxid, bool bLoop) { if (_NoAudioHardware) { return(-1); } lock (SharedList) { try { if (SharedList.ContainsKey(fxid)) { SharedList[fxid].Play(bLoop); if (bLoop) { _LoopedSounds[fxid] = fxid; } } } catch (Exception ex) { CCLog.Log("Unexpected exception while playing a SoundEffect: {0}", fxid); CCLog.Log(ex.ToString()); } } return(fxid); }
/// <summary> /// Play the sound effect with the given path and optionally set it to lopo. /// </summary> /// <param name="pszFilePath">The path to the sound effect file.</param> /// <param name="bLoop">True if the sound effect will play continuously, and false if it will play then stop.</param> /// <returns></returns> public int PlayEffect(string pszFilePath, bool bLoop) { int nId = pszFilePath.GetHashCode(); PreloadEffect(pszFilePath); lock (SharedList) { try { if (SharedList.ContainsKey(nId)) { SharedList[nId].Play(bLoop); if (bLoop) { _LoopedSounds[nId] = nId; } } } catch (Exception ex) { CCLog.Log("Unexpected exception while playing a SoundEffect: {0}", pszFilePath); CCLog.Log(ex.ToString()); } } return(nId); }
public void PauseEffect(int fxid) { if (_NoAudioHardware) { return; } try { if (SharedList.ContainsKey(fxid)) { SharedList[fxid].Pause(); } } catch (NoAudioHardwareException ex) { CCLog.Log("NoAudioHardware! while playing a SoundEffect: {0}", fxid); CCLog.Log(ex.ToString()); _NoAudioHardware = true; } catch (Exception ex) { CCLog.Log("Unexpected exception while playing a SoundEffect: {0}", fxid); CCLog.Log(ex.ToString()); } }
public void StopAllEffects() { if (_NoAudioHardware) { return; } List <CCEffectPlayer> l = new List <CCEffectPlayer>(); lock (SharedList) { try { l.AddRange(SharedList.Values); SharedList.Clear(); } catch (Exception ex) { CCLog.Log("Unexpected exception while stopping all effects."); CCLog.Log(ex.ToString()); } } foreach (CCEffectPlayer p in l) { p.Stop(); } }
public void AcquireReadWriteLocksReadWriteBlocks() { var name = Guid.NewGuid().ToString(); using (var sma = new SharedList <byte>(name, 10)) { using (var smr = new SharedList <byte>(name)) { // Acquire write lock sma.AcquireWriteLock(); // Should block (and fail to reset write signal) Assert.False(smr.AcquireReadLock(10)); sma.ReleaseWriteLock(); smr.AcquireReadLock(); // Should block (and fail to reset read signal) Assert.False(sma.AcquireWriteLock(10)); smr.ReleaseReadLock(); } } }
public PhysicEngine(SharedList pList) { this._sharedList = pList; this._forces.Add(new Vector3(0f, 0f, 0.01f)); //_sharedList.getParticles().Add(new Particle(new Vector3(1f, 0f, 0f), new Vector3(1f, 0f, 0f))); //Test-Particle }
public void MethodsThrowAfterDisposed(Action <SharedList <string> > methodCall) { var d = new SharedList <string>(LockingStrategy); d.Dispose(); methodCall.Invoke(d); }
public void DoubleDispose() { var d = new SharedList <string>(LockingStrategy); d.Dispose(); d.Dispose(); }
public void TryAdd() { const string value = "value"; var sharedList = new SharedList <string>(LockingStrategy); bool doInsert = false; using (ISharedCollectionLock l = sharedList.GetReadLock()) { if (!sharedList.Contains(value)) { doInsert = true; } } if (doInsert) { using (ISharedCollectionLock l = sharedList.GetWriteLock()) { if (!sharedList.Contains(value)) { sharedList.Add(value); } } } CollectionAssert.AreEqual(new List <string> { value }, sharedList.BackingList); }
private SharedList <T> InitSharedList <T>(T value) { var list = new SharedList <T>(LockingStrategy); list.BackingList.Add(value); return(list); }
public void MethodsThrowAfterDisposed(Action <SharedList <string> > methodCall) { var d = new SharedList <string>(this.LockingStrategy); d.Dispose(); Assert.Throws <ObjectDisposedException>(() => methodCall.Invoke(d)); }
public int PlayEffect(string filename, bool loop = false) { int nId = filename.GetHashCode(); PreloadEffect(filename); lock (SharedList) { try { if (SharedList.ContainsKey(nId)) { SharedList[nId].Play(loop); if (loop) { loopedSounds[nId] = nId; } } } catch (Exception ex) { CCLog.Log("Unexpected exception while playing a SoundEffect: {0}", filename); CCLog.Log(ex.ToString()); } } return(nId); }
public SharedList CreateSharedList(SharedList model) { var entityEntry = _context.SharedLists.Add(model); _context.SaveChanges(); return(entityEntry.Entity); }
public void IndexerOutOfRangeThrowsException() { var name = Guid.NewGuid().ToString(); using (var sma = new SharedList <int>(name, 10)) { bool exceptionThrown = false; try { sma[-1] = 0; } catch (ArgumentOutOfRangeException) { exceptionThrown = true; } Assert.True(exceptionThrown); exceptionThrown = false; IList <int> a = sma; try { a[-1] = 0; } catch (ArgumentOutOfRangeException) { exceptionThrown = true; } Assert.True(exceptionThrown); try { exceptionThrown = false; sma[sma.Length] = 0; } catch (ArgumentOutOfRangeException) { exceptionThrown = true; } Assert.True(exceptionThrown); try { exceptionThrown = false; a[a.Count] = 0; } catch (ArgumentOutOfRangeException) { exceptionThrown = true; } Assert.True(exceptionThrown); } }
public SharedBucketList(int bucketSize = 16) { Buckets = new SharedList[bucketSize]; for (var i = 0; i < bucketSize; i++) { Buckets[i] = new SharedList(); } }
// Gets the list items such as the negative keywords of a negative keyword list. private async Task <IList <SharedListItem> > GetListItemsBySharedListAsync(SharedList sharedList) { var request = new GetListItemsBySharedListRequest { SharedList = sharedList }; return((await Service.CallAsync((s, r) => s.GetListItemsBySharedListAsync(r), request)).ListItems); }
public void DisposedWriteLockDeniesWrite() { var sharedList = new SharedList <string>(this.LockingStrategy); ISharedCollectionLock l = sharedList.GetWriteLock(); l.Dispose(); Assert.Throws <WriteLockRequiredException>(() => sharedList[0] = "foo"); }
public void DisposedWriteLockDeniesRead() { var d = new SharedList <string>(this.LockingStrategy); ISharedCollectionLock l = d.GetWriteLock(); l.Dispose(); Assert.Throws <ReadLockRequiredException>(() => d.Contains("foo")); }
public DrawEngine(GraphicsDevice pGraphicsDevice, ContentManager pContentManager, Camera pCamera,SharedList pList) { this._camera = pCamera; this._graphicsDevice = pGraphicsDevice; this._contentManager = pContentManager; this._sharedList = pList; _spriteBatch = new SpriteBatch(this._graphicsDevice); _font = _contentManager.Load<SpriteFont>("font/FPSFont"); }
public void DisposedWriteLockDeniesRead() { var d = new SharedList <string>(LockingStrategy); ISharedCollectionLock l = d.GetWriteLock(); l.Dispose(); d.Contains("foo"); }
public void CanGetAnotherLockAfterDisposingLock() { var d = new SharedList <string>(LockingStrategy); ISharedCollectionLock l = d.GetReadLock(); l.Dispose(); l = d.GetReadLock(); l.Dispose(); }
public void DisposedWriteLockDeniesWrite() { var sharedList = new SharedList <string>(LockingStrategy); ISharedCollectionLock l = sharedList.GetWriteLock(); l.Dispose(); sharedList[0] = "foo"; }
public DrawEngine(GraphicsDevice pGraphicsDevice, ContentManager pContentManager, SharedList pList) { this._graphicsDevice = pGraphicsDevice; this._contentManager = pContentManager; this._sharedList = pList; _spriteBatch = new SpriteBatch(this._graphicsDevice); _font = _contentManager.Load <SpriteFont>("font/FPSFont"); _instancing = new Instancing(_graphicsDevice, _contentManager, _sharedList); }
// Deletes list items such as negative keywords from the corresponding list. private async Task <IList <BatchError> > DeleteListItemsFromSharedListAsync( IList <long> listItemIds, SharedList sharedList) { var request = new DeleteListItemsFromSharedListRequest { ListItemIds = listItemIds, SharedList = sharedList }; return((await Service.CallAsync((s, r) => s.DeleteListItemsFromSharedListAsync(r), request)).PartialErrors); }
public bool DeleteSharedList(SharedList model) { var entity = _context.SharedLists.FirstOrDefault(sl => sl.Id == model.Id); if (entity != null) { _context.SharedLists.Remove(entity); _context.SaveChanges(); return(true); } return(false); }
// Adds list items such as negative keywords to the corresponding list. private async Task <AddListItemsToSharedListResponse> AddListItemsToSharedListAsync( IList <SharedListItem> listItems, SharedList sharedList) { var request = new AddListItemsToSharedListRequest { ListItems = listItems, SharedList = sharedList }; return(await Service.CallAsync((s, r) => s.AddListItemsToSharedListAsync(r), request)); }
private void InvokeSkinEvents(SkinEventType skinEventType) { SharedList <SkinEventListener> list = ((NaiveLockingList <SkinEventListener>)DotNetNukeContext.Current.SkinEventListeners).SharedList; using (list.GetReadLock()) { foreach (var listener in list.Where(x => x.EventType == skinEventType)) { listener.SkinEvent.Invoke(this, new SkinEventArgs(this)); } } }
public bool UpdateSharedList(SharedList model) { var updatingEntity = _context.SharedLists.FirstOrDefault(sl => sl.Id == model.Id); if (updatingEntity != null) { updatingEntity.Update(model); _context.Entry(updatingEntity).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); return(true); } return(false); }
public void IListIsReadOnly() { var name = Guid.NewGuid().ToString(); using (var sma = new SharedList <int>(name, 10)) { sma[0] = 3; sma[4] = 10; IList <int> a = sma; Assert.True(a.IsReadOnly); } }
/** * @brief Release the shared Engine object * @warning It must be called before the application exit, or a memroy leak will be casued. */ public void End() { SharedMusic.Close(); lock (SharedList) { foreach (var kvp in SharedList) { kvp.Value.Close(); } SharedList.Clear(); } }
public void TwoDictsShareALockWriteTest() { ILockStrategy ls = new ReaderWriterLockStrategy(); var d1 = new SharedList <string>(ls); var d2 = new SharedList <string>(ls); using (ISharedCollectionLock readLock = d1.GetReadLock()) { using (ISharedCollectionLock writeLock = d2.GetWriteLock()) { //do nothing } } }
public static void LoadFromXmlFile(this Dictionary<int, SharedList<ParameterRewriteAction>> actions, string fileName, int portalId, bool portalSpecific, ref List<string> messages) { if (messages == null) { messages = new List<string>(); } if (File.Exists(fileName)) { var rdr = new XmlTextReader(fileName); while (rdr.Read()) { switch (rdr.NodeType) { case XmlNodeType.Element: if (rdr.Name == "parameterRewrite") { string portalIdRaw = rdr.GetAttribute("portalId"); int rulePortalId = -1; int actionCount = 0; if (portalIdRaw != null) { Int32.TryParse(portalIdRaw, out rulePortalId); } if (rulePortalId == portalId || rulePortalId == -1 || portalId == -1 || portalSpecific) { //now set up the action string tabIdRaw = rdr.GetAttribute("tabIds"); string tabNames = rdr.GetAttribute("tabNames"); string name = rdr.GetAttribute("name"); string fromSiteRootRaw = rdr.GetAttribute("fromSiteRoot"); bool fromSiteRoot; bool.TryParse(fromSiteRootRaw, out fromSiteRoot); List<int> tabIds = XmlHelpers.TabIdsFromAttributes(tabIdRaw, tabNames, portalId, ref messages); foreach (int tabId in tabIds) { var action = new ParameterRewriteAction { LookFor = rdr.GetAttribute("lookFor"), RewriteTo = rdr.GetAttribute("rewriteTo"), Name = name, TabId = tabId }; if (fromSiteRoot) { action.ForSiteRoot = true; action.TabId = -3; } else { //older rule specified tabid -3 meant site root action.ForSiteRoot = tabId == -3; } action.PortalId = portalId; SharedList<ParameterRewriteAction> tabActionCol; if (actions.ContainsKey(action.TabId)) { tabActionCol = actions[action.TabId]; } else { tabActionCol = new SharedList<ParameterRewriteAction>(); actions.Add(action.TabId, tabActionCol); } tabActionCol.Add(action); actionCount++; } messages.Add(name + " rewrite actions added:" + actionCount.ToString()); } } break; case XmlNodeType.EndElement: break; } } rdr.Close(); } else { messages.Add("Filename does not exist:" + fileName); } }
static CoreScheduler() { var lockStrategy = new ReaderWriterLockStrategy(LockRecursionPolicy.SupportsRecursion); ScheduleQueue = new SharedList<ScheduleItem>(lockStrategy); ScheduleInProgress = new SharedList<ScheduleHistoryItem>(lockStrategy); }
// Gets the list items such as the negative keywords of a negative keyword list. private async Task<IList<SharedListItem>> GetListItemsBySharedListAsync(SharedList sharedList) { var request = new GetListItemsBySharedListRequest { SharedList = sharedList }; return (await Service.CallAsync((s, r) => s.GetListItemsBySharedListAsync(r), request)).ListItems; }
// Deletes list items such as negative keywords from the corresponding list. private async Task<IList<BatchError>> DeleteListItemsFromSharedListAsync( IList<long> listItemIds, SharedList sharedList) { var request = new DeleteListItemsFromSharedListRequest { ListItemIds = listItemIds, SharedList = sharedList }; return (await Service.CallAsync((s, r) => s.DeleteListItemsFromSharedListAsync(r), request)).PartialErrors; }
// Adds list items such as negative keywords to the corresponding list. private async Task<AddListItemsToSharedListResponse> AddListItemsToSharedListAsync( IList<SharedListItem> listItems, SharedList sharedList) { var request = new AddListItemsToSharedListRequest { ListItems = listItems, SharedList = sharedList }; return (await Service.CallAsync((s, r) => s.AddListItemsToSharedListAsync(r), request)); }
/// <summary> /// Scans the collection of Rewrite Parameter rules, and rewrites the parameters if a match is found /// </summary> /// <param name="newUrl"></param> /// <param name="tabKeyVal"></param> /// <param name="urlParms"></param> /// <param name="isSiteRoot"></param> /// <param name="urlAction"></param> /// <param name="rewriteParms"></param> /// <param name="parentTraceId"></param> /// <returns>The new Url with the parameters rewritten onto the end of hte old Url</returns> internal static string RewriteParameters(string newUrl, string tabKeyVal, string[] urlParms, bool isSiteRoot, UrlAction urlAction, out bool rewriteParms, Guid parentTraceId) { string result = newUrl; rewriteParms = false; //get the actions from the cache var messages = new List<string>(); Dictionary<int, SharedList<ParameterRewriteAction>> rewriteActions = CacheController.GetParameterRewrites(urlAction.PortalId, ref messages, parentTraceId); if (messages == null) { messages = new List<string>(); } try { if (rewriteActions != null && rewriteActions.Count > 0) { SharedList<ParameterRewriteAction> tabRewrites = null; var tabIdRegex = new Regex(@"(?:\?|\&)tabid\=(?<tabid>[\d]+)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); Match tabMatch = tabIdRegex.Match(newUrl); if (tabMatch.Success) { string rawTabId = tabMatch.Groups["tabid"].Value; int tabId; if (Int32.TryParse(rawTabId, out tabId)) { if (rewriteActions.ContainsKey(tabId)) { //find the right set of rewrite actions for this tab tabRewrites = rewriteActions[tabId]; } } } if (rewriteActions.ContainsKey(AllTabsRewrite)) //-1 means 'all tabs' - rewriting across all tabs { //initialise to empty collection if there are no specific tab rewrites if (tabRewrites == null) { tabRewrites = new SharedList<ParameterRewriteAction>(); } //add in the all rewrites SharedList<ParameterRewriteAction> allRewrites = rewriteActions[AllTabsRewrite]; foreach (ParameterRewriteAction rewrite in allRewrites) { tabRewrites.Add(rewrite); //add the 'all' range to the tab range } } if (isSiteRoot && rewriteActions.ContainsKey(SiteRootRewrite)) { //initialise to empty collection if there are no specific tab rewrites if (tabRewrites == null) { tabRewrites = new SharedList<ParameterRewriteAction>(); } SharedList<ParameterRewriteAction> siteRootRewrites = rewriteActions[SiteRootRewrite]; foreach (ParameterRewriteAction rewrite in siteRootRewrites) { tabRewrites.Add(rewrite); //add the site root rewrites to the collection } } //get the parms as a string string parms = string.Join("/", urlParms); if (tabRewrites != null && tabRewrites.Count > 0) { //process each one until a match is found foreach (ParameterRewriteAction rewrite in tabRewrites) { string lookFor = rewrite.LookFor; //debugInfo += " lookFor:" + lookFor; var parmRegex = new Regex(lookFor, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); //check the match, if a match found, do the replacement if (parmRegex.IsMatch(parms)) { //rewrite the parameter string sendTo = rewrite.RewriteTo; string parmsOriginal = parms; //replace hte parameter with the rewrite string parms = parmRegex.Replace(parms, sendTo); messages.Add(rewrite.Name + " rewrite match (" + parmsOriginal + "), replaced to : " + parms); //makes sure the newUrl has got a trailing ampersand or a ? to start the query string if (newUrl.Contains("?")) { if (newUrl.EndsWith("&") == false) { newUrl += "&"; } } else //need to start the querystring off (592: allow for custom rewrites on site root) { newUrl += "?"; } //makes sure the new parms string hasn't got a starting ampersand if (parms.StartsWith("&")) { parms = parms.Substring(1); } //parameters are added to the back fo the newUrl newUrl += parms; //it's a rewrite, all right rewriteParms = true; result = newUrl; urlAction.CustomParmRewrite = true; break; } messages.Add(rewrite.Name + " rewrite not matched (" + parms + ")"); } } } } catch (Exception ex) { Services.Exceptions.Exceptions.LogException(ex); string error = "Exception: " + ex.Message + "\n" + ex.StackTrace; messages.Add(error); } finally { //post messages to debug output urlAction.DebugMessages.AddRange(messages); } return result; }