示例#1
0
 public void OnDestroy()
 {
     try
     {
         try
         {
             if (sensationCoreInterop_ != null)
             {
                 sensationCoreInterop_.uhsclRelease(sensationCoreInstancePtr_);
                 sensationCoreInterop_     = null;
                 SensationCore.Instance    = null;
                 sensationCoreInstancePtr_ = default(IntPtr);
             }
         }
         catch
         {
             ReleaseEmitter();
             sensationCoreInterop_.uhsclRelease(sensationCoreInstancePtr_);
             sensationCoreInterop_     = null;
             SensationCore.Instance    = null;
             sensationCoreInstancePtr_ = default(IntPtr);
         }
     }
     catch (Exception e)
     {
         UCA.Logger.LogInfo("Exception when destroying SensationCore: " + e);
     }
 }
示例#2
0
 private void ApplySearchPath(ISensationCoreInterop interop, IntPtr sclInstance, string path)
 {
     if (!setSearchPaths_.Contains(path))
     {
         interop.uhsclAddSearchPath(sclInstance, path);
         setSearchPaths_.Add(path);
     }
 }
示例#3
0
        public LogStreamReader(ISensationCoreInterop sensationCoreInterop)
        {
            uhsclGetLogInfoMessageBufferSize_     = sensationCoreInterop.uhsclGetLogInfoMessageBufferSize;
            uhsclGetLogInfoMessageBufferAndClear_ = sensationCoreInterop.uhsclGetLogInfoMessageBufferAndClear;

            uhsclGetLogWarningMessageBufferSize_     = sensationCoreInterop.uhsclGetLogWarningMessageBufferSize;
            uhsclGetLogWarningMessageBufferAndClear_ = sensationCoreInterop.uhsclGetLogWarningMessageBufferAndClear;

            uhsclGetLogErrorMessageBufferSize_     = sensationCoreInterop.uhsclGetLogErrorMessageBufferSize;
            uhsclGetLogErrorMessageBufferAndClear_ = sensationCoreInterop.uhsclGetLogErrorMessageBufferAndClear;
        }
示例#4
0
        public void CreateSensationCore(ISensationCoreInterop SensationCoreInterop = null)
        {
            try
            {
                if (SensationCore.Instance == null)
                {
                    if (SensationCoreInterop == null)
                    {
                        sensationCoreInterop_ = new SensationCoreInterop();
                        sensationCoreInterop_ = new LockDecorator(sensationCoreInterop_);
                        sensationCoreInterop_ = new ThrowOnErrorDecorator(sensationCoreInterop_);
                        sensationCoreInterop_ = new ForwardLogMessagesDecorator(sensationCoreInterop_, new LogStreamReader(sensationCoreInterop_));
                    }
                    else
                    {
                        sensationCoreInterop_ = SensationCoreInterop;
                    }
                    sensationCoreInstancePtr_ = sensationCoreInterop_.uhsclCreate();
                    if (sensationCoreInstancePtr_ == default(IntPtr))
                    {
                        throw new Exception("Failed to initialise SensationCore library");
                    }

                    foreach (var method in onSensationCoreInitializeUserMethods_)
                    {
                        try
                        {
                            method.Invoke(null, null);
                        }
                        catch (Exception ex)
                        {
                            UCA.Logger.LogWarning("Failed executing OnSensationCoreInitialize Method : " + method.Name + "\n" + ex.InnerException ?? ex.Message);
                        }
                    }

                    pythonSearchPaths_.ResetApplied();
                    pythonSearchPaths_.Apply(sensationCoreInterop_, sensationCoreInstancePtr_);
                    pythonSearchPaths_.DisplayWarningIfNoSearchPathsAreValid();

                    Instance = this;
                    if (Application.isPlaying)
                    {
                        UCA.Logger.LogInfo("SensationCore Successfully Created");
                    }
                }
            }
            catch (Exception e)
            {
                UCA.Logger.LogInfo("Exception creating SensationCore: " + e);
            }
        }
示例#5
0
        public void Apply(ISensationCoreInterop interop, IntPtr sclInstance)
        {
            ApplySearchPath(interop, sclInstance, DefaultSearchPath);
            foreach (var path in AdditionalSearchPaths)
            {
                ApplySearchPath(interop, sclInstance, path);
            }

            LoadPythonModulesInPath(interop, sclInstance, DefaultSearchPath);
            foreach (var path in AdditionalSearchPaths)
            {
                LoadPythonModulesInPath(interop, sclInstance, path);
            }
        }
示例#6
0
 private void LoadPythonModulesInPath(ISensationCoreInterop interop, IntPtr sclInstance, string path)
 {
     if (Directory.Exists(path))
     {
         foreach (string file in System.IO.Directory.GetFiles(path))
         {
             if (Path.GetExtension(file) == ".py")
             {
                 var module = Path.GetFileNameWithoutExtension(file);
                 Console.Error.Write("Loading " + module + " ... ");
                 try
                 {
                     interop.uhsclImportPythonModule(sclInstance, module);
                     Console.Error.WriteLine("success");
                 }
                 catch
                 {
                     Console.Error.WriteLine("failed");
                 }
             }
         }
     }
 }
 public InteropDecoratorTemplate(ISensationCoreInterop interop)
 {
     interop_ = interop;
 }
示例#8
0
 public ThrowOnErrorDecorator(ISensationCoreInterop interop)
 {
     interop_ = interop;
 }
示例#9
0
 public ForwardLogMessagesDecorator(ISensationCoreInterop interop, ILogStreamReader logStreamReader)
 {
     interop_         = interop;
     logStreamReader_ = logStreamReader;
 }
示例#10
0
 public LockDecorator(ISensationCoreInterop interop)
 {
     interop_ = interop;
 }