-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from AlmirKadric/feature/refactor
added namespaces for all mage sdk files
- Loading branch information
Showing
38 changed files
with
3,243 additions
and
3,167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,81 @@ | ||
using System; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
|
||
/// <summary> | ||
/// Async is a utility class which provides straight-forward, powerful functions for working with asynchronous C#. | ||
/// | ||
/// Async provides around 20 functions that include the usual 'functional' suspects (map, reduce, filter, each…) as well as | ||
/// some common patterns for asynchronous control flow (parallel, series, waterfall…). All these functions assume you follow | ||
/// the convention of providing a single callback as the last argument of your async function. | ||
/// </summary> | ||
public class Async { | ||
public static void each<T> (List<T> items, Action<T, Action<Exception>> fn, Action<Exception> cb) { | ||
if (items == null || items.Count == 0) { | ||
cb(null); | ||
return; | ||
} | ||
|
||
int currentItemI = 0; | ||
Action iterate = null; | ||
iterate = () => { | ||
if (currentItemI >= items.Count) { | ||
namespace Wizcorp.MageSDK.Utils { | ||
/// <summary> | ||
/// Async is a utility class which provides straight-forward, powerful functions for working with asynchronous C#. | ||
/// | ||
/// Async provides around 20 functions that include the usual 'functional' suspects (map, reduce, filter, each…) as well as | ||
/// some common patterns for asynchronous control flow (parallel, series, waterfall…). All these functions assume you follow | ||
/// the convention of providing a single callback as the last argument of your async function. | ||
/// </summary> | ||
public class Async { | ||
public static void each<T>(List<T> items, Action<T, Action<Exception>> fn, Action<Exception> cb) { | ||
if (items == null || items.Count == 0) { | ||
cb(null); | ||
return; | ||
} | ||
|
||
// Execute the given function on this item | ||
fn(items[currentItemI], (Exception error) => { | ||
// Stop iteration if there was an error | ||
if (error != null) { | ||
cb(error); | ||
int currentItemI = 0; | ||
Action iterate = null; | ||
iterate = () => { | ||
if (currentItemI >= items.Count) { | ||
cb(null); | ||
return; | ||
} | ||
|
||
// Continue to next item | ||
currentItemI++; | ||
iterate(); | ||
}); | ||
}; | ||
// Execute the given function on this item | ||
fn(items[currentItemI], (Exception error) => { | ||
// Stop iteration if there was an error | ||
if (error != null) { | ||
cb(error); | ||
return; | ||
} | ||
|
||
// Begin the iteration | ||
iterate (); | ||
} | ||
// Continue to next item | ||
currentItemI++; | ||
iterate(); | ||
}); | ||
}; | ||
|
||
public static void series (List<Action<Action<Exception>>> actionItems, Action<Exception> cb) { | ||
bool isEmpty = actionItems == null || actionItems.Count == 0; | ||
if (isEmpty) { | ||
cb(null); | ||
return; | ||
// Begin the iteration | ||
iterate(); | ||
} | ||
|
||
int currentItemI = 0; | ||
Action iterate = null; | ||
iterate = () => { | ||
if (currentItemI >= actionItems.Count) { | ||
public static void series(List<Action<Action<Exception>>> actionItems, Action<Exception> cb) { | ||
bool isEmpty = actionItems == null || actionItems.Count == 0; | ||
if (isEmpty) { | ||
cb(null); | ||
return; | ||
} | ||
|
||
// Shift an element from the list | ||
Action<Action<Exception>> actionItem = actionItems[currentItemI]; | ||
|
||
// Execute the given function on this item | ||
actionItem((Exception error) => { | ||
// Stop iteration if there was an error | ||
if (error != null) { | ||
cb(error); | ||
|
||
int currentItemI = 0; | ||
Action iterate = null; | ||
iterate = () => { | ||
if (currentItemI >= actionItems.Count) { | ||
cb(null); | ||
return; | ||
} | ||
|
||
// Continue to next item | ||
currentItemI++; | ||
iterate(); | ||
}); | ||
}; | ||
|
||
// Begin the iteration | ||
iterate (); | ||
// Shift an element from the list | ||
Action<Action<Exception>> actionItem = actionItems[currentItemI]; | ||
|
||
// Execute the given function on this item | ||
actionItem((Exception error) => { | ||
// Stop iteration if there was an error | ||
if (error != null) { | ||
cb(error); | ||
return; | ||
} | ||
|
||
// Continue to next item | ||
currentItemI++; | ||
iterate(); | ||
}); | ||
}; | ||
|
||
// Begin the iteration | ||
iterate(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,60 @@ | ||
using System; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
|
||
public class EventEmitter<T> { | ||
// | ||
private Dictionary<string, object> eventTags = new Dictionary<string, object>(); | ||
private EventHandlerList eventsList = new EventHandlerList(); | ||
namespace Wizcorp.MageSDK.Event { | ||
public class EventEmitter<T> { | ||
// | ||
private Dictionary<string, object> eventTags = new Dictionary<string, object>(); | ||
private EventHandlerList eventsList = new EventHandlerList(); | ||
|
||
// | ||
public void on(string eventTag, Action<object, T> handler) | ||
{ | ||
if (!eventTags.ContainsKey(eventTag)) { | ||
eventTags.Add(eventTag, new object()); | ||
// | ||
public void on(string eventTag, Action<object, T> handler) { | ||
if (!eventTags.ContainsKey(eventTag)) { | ||
eventTags.Add(eventTag, new object()); | ||
} | ||
|
||
eventsList.AddHandler(eventTags[eventTag], handler); | ||
} | ||
|
||
eventsList.AddHandler(eventTags[eventTag], handler); | ||
} | ||
// | ||
public void once(string eventTag, Action<object, T> handler) { | ||
Action<object, T> handlerWrapper = null; | ||
handlerWrapper = (object obj, T arguments) => { | ||
eventsList.RemoveHandler(eventTags[eventTag], handlerWrapper); | ||
handler(obj, arguments); | ||
}; | ||
|
||
// | ||
public void once(string eventTag, Action<object, T> handler) | ||
{ | ||
Action<object, T> handlerWrapper = null; | ||
handlerWrapper = (object obj, T arguments) => { | ||
eventsList.RemoveHandler(eventTags[eventTag], handlerWrapper); | ||
handler(obj, arguments); | ||
}; | ||
on(eventTag, handlerWrapper); | ||
} | ||
|
||
on(eventTag, handlerWrapper); | ||
} | ||
// | ||
public void emit(string eventTag, object sender, T arguments) { | ||
if (!eventTags.ContainsKey(eventTag)) { | ||
return; | ||
} | ||
|
||
// | ||
public void emit(string eventTag, object sender, T arguments) | ||
{ | ||
if (!eventTags.ContainsKey(eventTag)) { | ||
return; | ||
Action<object, T> execEventList = (Action<object, T>)eventsList[eventTags[eventTag]]; | ||
execEventList(sender, arguments); | ||
} | ||
|
||
Action<object, T> execEventList = (Action<object, T>)eventsList[eventTags[eventTag]]; | ||
execEventList(sender, arguments); | ||
} | ||
|
||
public void emit(string eventTag, T arguments) | ||
{ | ||
emit(eventTag, null, arguments); | ||
} | ||
public void emit(string eventTag, T arguments) { | ||
emit(eventTag, null, arguments); | ||
} | ||
|
||
// | ||
public void off(string eventTag, Action<object, T> handler) | ||
{ | ||
eventsList.RemoveHandler(eventTags[eventTag], handler); | ||
} | ||
// | ||
public void off(string eventTag, Action<object, T> handler) { | ||
eventsList.RemoveHandler(eventTags[eventTag], handler); | ||
} | ||
|
||
// | ||
public void removeAllListeners() | ||
{ | ||
// Destroy all event handlers | ||
eventsList.Dispose(); | ||
eventsList = new EventHandlerList(); | ||
// | ||
public void removeAllListeners() { | ||
// Destroy all event handlers | ||
eventsList.Dispose(); | ||
eventsList = new EventHandlerList(); | ||
|
||
// Destroy all event tags | ||
eventTags = new Dictionary<string, object>(); | ||
// Destroy all event tags | ||
eventTags = new Dictionary<string, object>(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.