-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
에러 있음 빌드 안됨
- Loading branch information
s2quake
committed
May 3, 2018
1 parent
ced6808
commit e870796
Showing
57 changed files
with
2,218 additions
and
128 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
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
79 changes: 79 additions & 0 deletions
79
common/Ntreev.Crema.Javascript.Sharing/Methods/AddDataBaseEventListenerMethod.cs
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//Released under the MIT License. | ||
// | ||
//Copyright (c) 2018 Ntreev Soft co., Ltd. | ||
// | ||
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
//documentation files (the "Software"), to deal in the Software without restriction, including without limitation the | ||
//rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit | ||
//persons to whom the Software is furnished to do so, subject to the following conditions: | ||
// | ||
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the | ||
//Software. | ||
// | ||
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | ||
//WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
//COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
//OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
using Ntreev.Crema.Services; | ||
using System; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.Composition; | ||
using System.Text; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
using Jint.Native; | ||
|
||
namespace Ntreev.Crema.Javascript.Methods | ||
{ | ||
[Export(typeof(IScriptMethod))] | ||
[PartCreationPolicy(CreationPolicy.NonShared)] | ||
class AddDataBaseEventListenerMethod : ScriptMethodBase | ||
{ | ||
private readonly ICremaHost cremaHost; | ||
private readonly CremaDataBaseEventListenerBase[] eventListeners; | ||
private CremaDataBaseEventListenerContext eventListenerContext; | ||
|
||
[ImportingConstructor] | ||
public AddDataBaseEventListenerMethod(ICremaHost cremaHost, [ImportMany]IEnumerable<CremaDataBaseEventListenerBase> eventListeners) | ||
{ | ||
this.cremaHost = cremaHost; | ||
this.eventListeners = eventListeners.ToArray(); | ||
} | ||
|
||
protected override Delegate CreateDelegate() | ||
{ | ||
return new Action<CremaDataBaseEvents, CremaDataBaseEventListener>(this.AddDataBaseEventListener); | ||
} | ||
|
||
protected override void OnInitialized() | ||
{ | ||
base.OnInitialized(); | ||
} | ||
|
||
protected override void OnDisposed() | ||
{ | ||
base.OnDisposed(); | ||
this.eventListenerContext?.Dispose(); | ||
} | ||
|
||
private void AddDataBaseEventListener(CremaDataBaseEvents eventName, CremaDataBaseEventListener listener) | ||
{ | ||
if (this.Context.Properties.ContainsKey(typeof(CremaDataBaseEventListenerContext)) == false) | ||
{ | ||
this.eventListenerContext = new CremaDataBaseEventListenerContext(this.cremaHost, this.eventListeners); | ||
this.Context.Properties[typeof(CremaDataBaseEventListenerContext)] = this.eventListenerContext; | ||
} | ||
|
||
if (this.eventListenerContext != null) | ||
{ | ||
this.eventListenerContext.AddEventListener(eventName, listener); | ||
} | ||
else | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
common/Ntreev.Crema.Javascript.Sharing/Methods/CremaDataBaseEventListener.cs
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Ntreev.Crema.Javascript.Methods | ||
{ | ||
delegate void CremaDataBaseEventListener(string dataBaseName, IDictionary<string, object> e); | ||
} |
108 changes: 108 additions & 0 deletions
108
common/Ntreev.Crema.Javascript.Sharing/Methods/CremaDataBaseEventListenerBase.cs
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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using Ntreev.Crema.Services; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Linq; | ||
using Ntreev.Crema.ServiceModel; | ||
|
||
namespace Ntreev.Crema.Javascript.Methods | ||
{ | ||
abstract class CremaDataBaseEventListenerBase | ||
{ | ||
private readonly CremaDataBaseEvents eventName; | ||
private readonly Dictionary<IDataBase, List<CremaDataBaseEventListener>> dataBases = new Dictionary<IDataBase, List<CremaDataBaseEventListener>>(); | ||
//private readonly Dictionary<int, CremaDataBaseEventListener> hashes = new Dictionary<int, CremaDataBaseEventListener>(); | ||
|
||
protected CremaDataBaseEventListenerBase(CremaDataBaseEvents eventName) | ||
{ | ||
this.eventName = eventName; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
foreach (var item in this.dataBases) | ||
{ | ||
this.OnUnsubscribe(item.Key); | ||
} | ||
this.dataBases.Clear(); | ||
} | ||
|
||
public int Subscribe(IDataBase dataBase, CremaDataBaseEventListener listener) | ||
{ | ||
if (this.dataBases.ContainsKey(dataBase) == false) | ||
{ | ||
this.dataBases[dataBase] = new List<CremaDataBaseEventListener>(); | ||
} | ||
var listenerList = this.dataBases[dataBase]; | ||
if (listenerList.Any() == false) | ||
{ | ||
this.OnSubscribe(dataBase); | ||
} | ||
listenerList.Add(listener); | ||
return listener.GetHashCode(); | ||
} | ||
|
||
public void Unsubscribe(IDataBase dataBase, CremaDataBaseEventListener listener) | ||
{ | ||
var listenerList = this.dataBases[dataBase]; | ||
|
||
for (var i = 0; i < listenerList.Count; i++) | ||
{ | ||
if (this.GetHashCode(listenerList[i]) == this.GetHashCode(listener)) | ||
{ | ||
listenerList.RemoveAt(i); | ||
break; | ||
} | ||
} | ||
if (listenerList.Any() == false) | ||
{ | ||
this.OnUnsubscribe(dataBase); | ||
this.dataBases.Remove(dataBase); | ||
} | ||
} | ||
|
||
public CremaDispatcher Dispatcher | ||
{ | ||
get; set; | ||
} | ||
|
||
public CremaDataBaseEvents EventName => this.eventName; | ||
|
||
protected void Invoke(IDictionary<string, object> properties) | ||
{ | ||
this.Dispatcher.InvokeAsync(() => | ||
{ | ||
foreach (var item in this.dataBases) | ||
{ | ||
//item.Invoke(properties); | ||
} | ||
}); | ||
} | ||
|
||
protected abstract void OnSubscribe(IDataBase dataBase); | ||
|
||
protected abstract void OnUnsubscribe(IDataBase dataBase); | ||
|
||
//private void DataBase_Unloaded(object sender, EventArgs e) | ||
//{ | ||
// if (sender is IDataBase dataBase) | ||
// { | ||
// var listenerList = this.dataBases[dataBase]; | ||
// foreach (var item in listenerList) | ||
// { | ||
// this.hashes.Remove(item.GetHashCode()); | ||
// } | ||
// this.dataBases.Remove(dataBase); | ||
// } | ||
//} | ||
|
||
private int GetHashCode(CremaDataBaseEventListener listener) | ||
{ | ||
if (listener.Target is System.Runtime.CompilerServices.Closure c) | ||
{ | ||
return c.Constants[0].GetHashCode(); | ||
} | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
Oops, something went wrong.