5 // Cesar Lopez Nataren (cesar@ciencias.unam.mx)
7 // (C) 2003, Cesar Lopez Nataren
11 using System.Reflection;
12 using System.Security.Policy;
13 using System.Threading;
14 using Microsoft.JScript;
15 using Microsoft.JScript.Vsa;
17 namespace Microsoft.Vsa {
19 public abstract class BaseVsaEngine : IVsaEngine {
21 private const int ROOT_MONIKER_MAX_SIZE = 256;
22 private bool monikerAlreadySet;
23 private string rootMoniker;
28 private bool siteAlreadySet;
31 private bool namespaceNotSet;
32 private bool supportDebug;
33 private bool generateDebugInfo;
34 protected bool compiled;
37 private bool initNewCalled;
39 private IVsaSite site;
40 private IVsaItems items;
42 // its default value has to be "JScript"
43 private string language;
45 private string version;
47 private Assembly assembly;
48 private Evidence evidence;
50 private string rootNamespace;
52 // FIXME: must set vars to proper values
53 internal BaseVsaEngine ()
56 public BaseVsaEngine (string language, string version, bool supportDebug)
58 this.language = language;
60 // FIXME: I think we must ensure that version it's
61 // compliant with versionformat Major.Minor.Build.Revision.
62 // Not sure about what Exception throw.
63 this.version = version;
65 this.supportDebug = supportDebug;
67 this.rootMoniker = "";
70 this.compiled = false;
73 this.lcid = Thread.CurrentThread.CurrentCulture.LCID;
76 this.rootNamespace = "";
77 this.namespaceNotSet = true;
79 this.initNewCalled = false;
80 this.generateDebugInfo = false;
83 this.siteAlreadySet = false;
86 public System._AppDomain AppDomain {
87 get { throw new NotImplementedException (); }
88 set { throw new NotImplementedException (); }
91 // FIXME: research if we can use "get" Evidence when: running and busy.
92 public Evidence Evidence {
95 throw new VsaException (VsaError.EngineClosed);
96 else if (!initNewCalled)
97 throw new VsaException (VsaError.EngineNotInitialized);
104 throw new VsaException (VsaError.EngineClosed);
106 throw new VsaException (VsaError.EngineRunning);
108 throw new VsaException (VsaError.EngineBusy);
109 else if (!initNewCalled)
110 throw new VsaException (VsaError.EngineNotInitialized);
116 public string ApplicationBase {
117 get { throw new NotImplementedException (); }
118 set { throw new NotImplementedException (); }
121 public Assembly Assembly {
124 throw new VsaException (VsaError.EngineClosed);
126 throw new VsaException (VsaError.EngineNotRunning);
128 throw new VsaException (VsaError.EngineBusy);
135 // FIXME: research if we can "get" it when running and busy.
136 // FIXME: when do we throw VsaException with
137 // VsaError set to DebugInfoNotSupported?
139 public bool GenerateDebugInfo {
142 throw new VsaException (VsaError.EngineClosed);
143 else if (!initNewCalled)
144 throw new VsaException (VsaError.EngineNotInitialized);
146 return generateDebugInfo;
151 throw new VsaException (VsaError.EngineClosed);
153 throw new VsaException (VsaError.EngineRunning);
155 throw new VsaException (VsaError.EngineBusy);
156 else if (!initNewCalled)
157 throw new VsaException (VsaError.EngineNotInitialized);
158 else if (!supportDebug)
159 throw new VsaException (VsaError.DebugInfoNotSupported);
161 generateDebugInfo = value;
165 public bool IsCompiled {
170 throw new VsaException (VsaError.EngineClosed);
172 throw new VsaException (VsaError.EngineBusy);
173 else if (!initNewCalled)
174 throw new VsaException (VsaError.EngineNotInitialized);
181 // FIXME: Research if we can "set" it when running
182 public bool IsDirty {
185 throw new VsaException (VsaError.EngineClosed);
192 throw new VsaException (VsaError.EngineClosed);
194 throw new VsaException (VsaError.EngineBusy);
195 else if (!initNewCalled)
196 throw new VsaException (VsaError.EngineNotInitialized);
202 public bool IsRunning {
205 throw new VsaException (VsaError.EngineClosed);
207 throw new VsaException (VsaError.EngineBusy);
208 else if (!initNewCalled)
209 throw new VsaException (VsaError.EngineNotInitialized);
215 public IVsaItems Items {
218 throw new VsaException (VsaError.EngineClosed);
220 throw new VsaException (VsaError.EngineBusy);
221 else if (!initNewCalled)
222 throw new VsaException (VsaError.EngineNotInitialized);
224 items = new VsaItems ((VsaEngine) this);
230 public string Language {
233 throw new VsaException (VsaError.EngineClosed);
235 throw new VsaException (VsaError.EngineBusy);
236 else if (!initNewCalled)
237 throw new VsaException (VsaError.EngineNotInitialized);
243 // FIXME: research when LCIDNotSupported gets thrown.
247 throw new VsaException (VsaError.EngineClosed);
249 throw new VsaException (VsaError.EngineBusy);
250 else if (!initNewCalled)
251 throw new VsaException (VsaError.EngineNotInitialized);
253 throw new VsaException (VsaError.EngineRunning);
260 throw new VsaException (VsaError.EngineClosed);
262 throw new VsaException (VsaError.EngineBusy);
263 else if (!initNewCalled)
264 throw new VsaException (VsaError.EngineNotInitialized);
266 throw new VsaException (VsaError.EngineRunning);
273 // FIXME: we must throw VsaException, VsaError set to EngineNameInUse
274 // when setting and name is already in use.
278 throw new VsaException (VsaError.EngineClosed);
280 throw new VsaException (VsaError.EngineBusy);
281 else if (!initNewCalled)
282 throw new VsaException (VsaError.EngineNotInitialized);
284 throw new VsaException (VsaError.EngineRunning);
291 throw new VsaException (VsaError.EngineClosed);
293 throw new VsaException (VsaError.EngineBusy);
294 else if (!initNewCalled)
295 throw new VsaException (VsaError.EngineNotInitialized);
297 throw new VsaException (VsaError.EngineRunning);
303 // FIXME: We have to check - when setting - that the moniker
304 // is not already in use.
305 public string RootMoniker {
308 throw new VsaException (VsaError.EngineClosed);
310 throw new VsaException (VsaError.EngineBusy);
316 if (monikerAlreadySet)
317 throw new VsaException (VsaError.RootMonikerAlreadySet);
319 throw new VsaException (VsaError.EngineClosed);
321 throw new VsaException (VsaError.EngineBusy);
323 MonikerState state = ValidateRootMoniker (value);
326 case MonikerState.Valid:
328 monikerAlreadySet = true;
331 case MonikerState.Invalid:
332 throw new VsaException (VsaError.RootMonikerInvalid);
334 case MonikerState.ProtocolInvalid:
335 throw new VsaException (VsaError.RootMonikerProtocolInvalid);
341 internal static MonikerState ValidateRootMoniker (string n)
343 if (n == null || n == "" || n.Length > ROOT_MONIKER_MAX_SIZE)
344 return MonikerState.Invalid;
347 Uri uri = new Uri (n);
348 string protocol = uri.Scheme;
350 if (protocol == "http" || protocol == "file" ||
351 protocol == "ftp" || protocol == "gopher" ||
352 protocol == "https" || protocol == "mailto")
353 return MonikerState.ProtocolInvalid;
355 return MonikerState.Valid;
357 } catch (UriFormatException e) {
358 return MonikerState.Invalid;
363 // FIXME: we must check - when setting - that the value is a valid
364 // namespace (research what does that mean :-)). If not the case
365 // VsaException must be thrown, set to VsaError.NamespaceInvalid
366 public string RootNamespace {
369 throw new VsaException (VsaError.EngineClosed);
371 throw new VsaException (VsaError.EngineBusy);
372 else if (!initNewCalled)
373 throw new VsaException (VsaError.EngineNotInitialized);
375 throw new VsaException (VsaError.EngineRunning);
377 return rootNamespace;
382 throw new VsaException (VsaError.EngineClosed);
384 throw new VsaException (VsaError.EngineBusy);
385 else if (!initNewCalled)
386 throw new VsaException (VsaError.EngineNotInitialized);
388 throw new VsaException (VsaError.EngineRunning);
390 rootNamespace = value;
391 namespaceNotSet = false;
395 public IVsaSite Site {
398 throw new VsaException (VsaError.EngineClosed);
400 throw new VsaException (VsaError.EngineBusy);
401 else if (!monikerAlreadySet)
402 throw new VsaException (VsaError.RootMonikerNotSet);
408 if (!monikerAlreadySet)
409 throw new VsaException (VsaError.RootMonikerNotSet);
410 else if (siteAlreadySet)
411 throw new VsaException (VsaError.SiteAlreadySet);
413 throw new VsaException (VsaError.EngineClosed);
415 throw new VsaException (VsaError.EngineBusy);
416 else if (value == null)
417 throw new VsaException (VsaError.SiteInvalid);
420 siteAlreadySet = true;
425 // Version Format: Major.Minor.Revision.Build
427 public string Version {
430 throw new VsaException (VsaError.EngineClosed);
432 throw new VsaException (VsaError.EngineBusy);
433 else if (!initNewCalled)
434 throw new VsaException (VsaError.EngineNotInitialized);
440 public virtual void Close ()
445 throw new VsaException (VsaError.EngineClosed);
447 throw new VsaException (VsaError.EngineBusy);
455 // Count that AssemblyExpected exception may be thrown.
457 public virtual bool Compile ()
460 throw new VsaException (VsaError.EngineClosed);
462 throw new VsaException (VsaError.EngineBusy);
464 throw new VsaException (VsaError.EngineEmpty);
466 throw new VsaException (VsaError.EngineRunning);
467 else if (!initNewCalled)
468 throw new VsaException (VsaError.EngineNotInitialized);
469 else if (namespaceNotSet)
470 throw new VsaException (VsaError.RootNamespaceNotSet);
475 public virtual object GetOption (string name)
480 opt = GetSpecificOption (name);
481 } catch (VsaException e) {
487 protected abstract object GetSpecificOption (string name);
489 protected abstract void SetSpecificOption (string name, object val);
491 public virtual void InitNew ()
494 throw new VsaException (VsaError.EngineClosed);
496 throw new VsaException (VsaError.EngineBusy);
497 else if (initNewCalled)
498 throw new VsaException (VsaError.EngineInitialized);
499 else if (!monikerAlreadySet)
500 throw new VsaException (VsaError.RootMonikerNotSet);
501 else if (!siteAlreadySet)
502 throw new VsaException (VsaError.SiteNotSet);
504 initNewCalled = true;
507 public virtual void LoadSourceState (IVsaPersistSite site)
509 throw new NotImplementedException ();
512 public virtual void Reset ()
515 throw new VsaException (VsaError.EngineClosed);
517 throw new VsaException (VsaError.EngineBusy);
519 throw new VsaException (VsaError.EngineNotRunning);
525 public virtual void RevokeCache ()
527 throw new NotImplementedException ();
530 public virtual void Run ()
533 throw new VsaException (VsaError.EngineClosed);
535 throw new VsaException (VsaError.EngineBusy);
537 throw new VsaException (VsaError.EngineRunning);
538 else if (!monikerAlreadySet)
539 throw new VsaException (VsaError.RootMonikerNotSet);
540 else if (!siteAlreadySet)
541 throw new VsaException (VsaError.SiteNotSet);
542 else if (namespaceNotSet)
543 throw new VsaException (VsaError.RootNamespaceNotSet);
548 public virtual void SetOption (string name, object value)
553 public virtual void SaveCompiledState (out byte [] pe, out byte [] debugInfo)
555 throw new NotImplementedException ();
558 public virtual void SaveSourceState (IVsaPersistSite site)
560 throw new NotImplementedException ();
563 public abstract bool IsValidIdentifier (string ident);
565 internal bool Closed {
566 get { return closed; }
569 internal bool Running {
570 get { return running; }
577 internal bool InitNewCalled {
578 get { return initNewCalled; }
579 set { initNewCalled = value; }
583 public class BaseVsaSite : IVsaSite {
585 public virtual byte [] Assembly {
586 get { throw new NotImplementedException (); }
589 public virtual byte [] DebugInfo {
590 get { throw new NotImplementedException (); }
593 public virtual void GetCompiledState (out byte [] pe, out byte [] debugInfo)
595 throw new NotImplementedException ();
598 public virtual object GetEventSourceInstance (string itemName, string eventSourceName)
600 throw new NotImplementedException ();
603 public virtual object GetGlobalInstance (string name)
605 throw new NotImplementedException ();
608 public virtual void Notify (string notify, object optional)
610 throw new NotImplementedException ();
613 public virtual bool OnCompilerError (IVsaError error)
615 throw new NotImplementedException ();
620 public abstract class BaseVsaStartup {
622 public void SetSite (IVsaSite site)
624 throw new NotImplementedException ();
627 public abstract void Startup ();
629 public abstract void Shutdown ();
632 internal enum MonikerState {