Skip to content

Commit 05a5b3e

Browse files
committed
Add UIShell OSGi source code.
1 parent d85b87d commit 05a5b3e

File tree

258 files changed

+15560
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

258 files changed

+15560
-0
lines changed

BundleEventArgs.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace UIShell.OSGi
2+
{
3+
using System;
4+
5+
public abstract class BundleEventArgs : EventArgs
6+
{
7+
internal BundleEventArgs(IBundle bundle)
8+
{
9+
if (bundle == null)
10+
{
11+
throw new ArgumentNullException();
12+
}
13+
Bundle = bundle;
14+
}
15+
16+
public IBundle Bundle { get; private set; }
17+
}
18+
}
19+

BundleException.cs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace UIShell.OSGi
2+
{
3+
using System;
4+
using System.Runtime.Serialization;
5+
6+
public class BundleException : Exception
7+
{
8+
public BundleException()
9+
{
10+
}
11+
12+
public BundleException(string message)
13+
: base(message)
14+
{
15+
}
16+
17+
protected BundleException(SerializationInfo info, StreamingContext context)
18+
: base(info, context)
19+
{
20+
}
21+
22+
public BundleException(string message, Exception innerException)
23+
: base(message, innerException)
24+
{
25+
}
26+
}
27+
}
28+

BundleInitializedState.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace UIShell.OSGi
2+
{
3+
public enum BundleInitializedState
4+
{
5+
Installed,
6+
Active
7+
}
8+
}
9+

BundleLazyActivatedEventArgs.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace UIShell.OSGi
2+
{
3+
public class BundleLazyActivatedEventArgs : BundleEventArgs
4+
{
5+
internal BundleLazyActivatedEventArgs(IBundle bundle)
6+
: base(bundle)
7+
{
8+
}
9+
}
10+
}
11+

BundleRuntime.cs

+213
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
namespace UIShell.OSGi
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Threading;
6+
using Core;
7+
using Core.Service;
8+
using Utility;
9+
10+
public class BundleRuntime : IDisposable
11+
{
12+
private bool _isDisposed;
13+
private bool _started;
14+
private volatile BundleRuntimeState _state;
15+
16+
public int BundleClassLoaderCacheSize { get; set; }
17+
18+
public bool EnableBundleClassLoaderCache { get; set; }
19+
20+
public bool EnableGlobalAssemblyFeature { get; set; }
21+
22+
public IFramework Framework { get; private set; }
23+
24+
public static BundleRuntime Instance { get; internal set; }
25+
26+
internal IServiceManager ServiceManager => Framework.ServiceContainer;
27+
28+
public string[] StartArgs { get; private set; }
29+
30+
public BundleRuntimeState State
31+
{
32+
get { return _state; }
33+
private set { _state = value; }
34+
}
35+
36+
public BundleRuntime()
37+
: this(new string[] { "Plugins" })
38+
{
39+
}
40+
41+
public BundleRuntime(string pluginsPath)
42+
: this(new string[] { pluginsPath })
43+
{
44+
}
45+
46+
public BundleRuntime(string[] pluginsPathList)
47+
{
48+
BundleClassLoaderCacheSize = 50;
49+
if (Instance != null)
50+
{
51+
throw new Exception(Messages.SingletonOSGiAllowed);
52+
}
53+
if ((pluginsPathList == null) || (pluginsPathList.Length == 0))
54+
{
55+
throw new Exception(Messages.AtLeastOnePluginsPathMustBeSpecified);
56+
}
57+
var framework = new Framework
58+
{
59+
Options = new FrameworkOptions(pluginsPathList)
60+
};
61+
Framework = framework;
62+
Instance = this;
63+
}
64+
65+
public void AddService<ServiceInterface>(object serviceInstance)
66+
{
67+
Framework.AddSystemService(typeof(ServiceInterface), new object[] { serviceInstance });
68+
}
69+
70+
public void AddService(Type serviceInterface, object serviceInstance)
71+
{
72+
Framework.AddSystemService(serviceInterface, new object[] { serviceInstance });
73+
}
74+
75+
public static void Dispose()
76+
{
77+
if (Instance != null)
78+
{
79+
if (Instance._started)
80+
{
81+
Instance.Stop();
82+
}
83+
Instance = null;
84+
}
85+
}
86+
87+
public T GetFirstOrDefaultService<T>()
88+
{
89+
if (ServiceManager != null)
90+
{
91+
return ServiceManager.GetFirstOrDefaultService<T>();
92+
}
93+
return default(T);
94+
}
95+
96+
public object GetFirstOrDefaultService(string serviceTypeName)
97+
{
98+
if (ServiceManager != null)
99+
{
100+
return ServiceManager.GetFirstOrDefaultService(serviceTypeName);
101+
}
102+
return null;
103+
}
104+
105+
public object GetFirstOrDefaultService(Type serviceType)
106+
{
107+
if (ServiceManager != null)
108+
{
109+
return ServiceManager.GetFirstOrDefaultService(serviceType);
110+
}
111+
return null;
112+
}
113+
114+
public List<T> GetService<T>()
115+
{
116+
if (ServiceManager != null)
117+
{
118+
return ServiceManager.GetService<T>();
119+
}
120+
return null;
121+
}
122+
123+
public List<object> GetService(string serviceTypeName)
124+
{
125+
if (ServiceManager != null)
126+
{
127+
return ServiceManager.GetService(serviceTypeName);
128+
}
129+
return null;
130+
}
131+
132+
public List<object> GetService(Type serviceType)
133+
{
134+
if (ServiceManager != null)
135+
{
136+
return ServiceManager.GetService(serviceType);
137+
}
138+
return null;
139+
}
140+
141+
public void RemoveService<ServiceInterface>(object serviceInstance)
142+
{
143+
Framework.RemoveSystemService(typeof(ServiceInterface), serviceInstance);
144+
}
145+
146+
public void RemoveService(Type serviceInterface, object serviceInstance)
147+
{
148+
Framework.RemoveSystemService(serviceInterface, serviceInstance);
149+
}
150+
151+
public void Start()
152+
{
153+
if (Thread.CurrentThread.Name == null)
154+
{
155+
Thread.CurrentThread.Name = "FrameworkThread";
156+
}
157+
Start(null);
158+
}
159+
160+
public void Start(string[] args)
161+
{
162+
if (!_started)
163+
{
164+
StartArgs = args;
165+
State = BundleRuntimeState.Starting;
166+
try
167+
{
168+
Framework.Start();
169+
State = BundleRuntimeState.Started;
170+
_started = true;
171+
}
172+
catch (Exception exception)
173+
{
174+
State = BundleRuntimeState.Stopped;
175+
_started = false;
176+
FileLogUtility.Error(Messages.StartTheFrameworkFailed);
177+
FileLogUtility.Error(exception);
178+
}
179+
}
180+
}
181+
182+
public void Stop()
183+
{
184+
if (_started)
185+
{
186+
State = BundleRuntimeState.Stopping;
187+
try
188+
{
189+
Framework.Stop();
190+
}
191+
catch (Exception exception)
192+
{
193+
FileLogUtility.Error(Messages.StopTheFrameworkFailed);
194+
FileLogUtility.Error(exception);
195+
}
196+
State = BundleRuntimeState.Stopped;
197+
_started = false;
198+
}
199+
}
200+
201+
void IDisposable.Dispose()
202+
{
203+
if (!_isDisposed)
204+
{
205+
Dispose();
206+
GC.SuppressFinalize(this);
207+
State = BundleRuntimeState.Disposed;
208+
_isDisposed = true;
209+
}
210+
}
211+
}
212+
}
213+

BundleRuntimeState.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace UIShell.OSGi
2+
{
3+
public enum BundleRuntimeState
4+
{
5+
Starting,
6+
Started,
7+
Stopping,
8+
Stopped,
9+
Disposed
10+
}
11+
}
12+

BundleStartOptions.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace UIShell.OSGi
2+
{
3+
using System;
4+
5+
[Serializable]
6+
public enum BundleStartOptions
7+
{
8+
Transient,
9+
General
10+
}
11+
}
12+

BundleState.cs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace UIShell.OSGi
2+
{
3+
using System;
4+
5+
[Serializable]
6+
public enum BundleState
7+
{
8+
Installed,
9+
Resolved,
10+
Starting,
11+
Active,
12+
Stopping,
13+
Uninstalled
14+
}
15+
}
16+

BundleStateChangedEventArgs.cs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace UIShell.OSGi
2+
{
3+
public class BundleStateChangedEventArgs : BundleEventArgs
4+
{
5+
internal BundleStateChangedEventArgs(BundleState previousState, BundleState currentState, IBundle bundle)
6+
: base(bundle)
7+
{
8+
PreviousState = previousState;
9+
CurrentState = currentState;
10+
}
11+
12+
public override string ToString()
13+
{
14+
return $"Bundle:{Bundle},PreviousState:{PreviousState},CurrentState:{CurrentState}";
15+
}
16+
17+
public BundleState CurrentState { get; private set; }
18+
19+
public BundleState PreviousState { get; private set; }
20+
}
21+
}
22+

BundleStopOptions.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace UIShell.OSGi
2+
{
3+
public enum BundleStopOptions
4+
{
5+
Transient,
6+
General
7+
}
8+
}
9+

BundleType.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace UIShell.OSGi
2+
{
3+
public enum BundleType
4+
{
5+
Fragment,
6+
Host
7+
}
8+
}
9+

0 commit comments

Comments
 (0)