Пример #1
0
        /// <summary>
        /// Called when the ViewModel is ready to be presented
        /// </summary>
        /// <returns></returns>
        public Task Initialize(bool forceInitialize = false)
        {
            lock (_initializationLock)
            {
                _logger?.Log(_eventsSource, $"ViewModel {__Name} initializing", LogRecordTypes.Debug);
                bool skip = IsInitialized && !forceInitialize;
                IsInitialized = true;
                if (skip)
                {
                    _logger?.Log(_eventsSource, $"ViewModel {__Name} is initialized skipping initialization", LogRecordTypes.Debug);
                    return(completedTask);
                }
            }

            return(Task.Run(OnInitialization).ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    var initializationException = new InitializationException(_eventsSource, t.Exception);
                    LogError(_eventsSource, initializationException);
                    _logger.Log(_eventsSource, $"Failed to initialize ViewModel {__Name} .", LogRecordTypes.Error);
                }

                RefreshValidationRules();
                PropertyChanged += PropertyChangedHandler;
                IsBusy = false;
                OnInitialized(this);
            }));
        }
Пример #2
0
        public void initializePlugins()
        {
            if(_initialized)
            {
                InitializationException ex = new InitializationException();
                ex.reason = "plug-ins already initialized";
                throw ex;
            }

            //
            // Invoke initialize() on the plug-ins, in the order they were loaded.
            //
            ArrayList initializedPlugins = new ArrayList();
            try
            {
                foreach(PluginInfo p in _plugins)
                {
                    try
                    {
                        p.plugin.initialize();
                    }
                    catch(PluginInitializationException ex)
                    {
                        throw ex;
                    }
                    catch(System.Exception ex)
                    {
                        PluginInitializationException e = new PluginInitializationException(ex);
                        e.reason = "plugin `" + p.name + "' initialization failed";
                        throw e;
                    }
                    initializedPlugins.Add(p.plugin);
                }
            }
            catch(System.Exception)
            {
                //
                // Destroy the plug-ins that have been successfully initialized, in the
                // reverse order.
                //
                initializedPlugins.Reverse();
                foreach(Plugin p in initializedPlugins)
                {
                    try
                    {
                        p.destroy();
                    }
                    catch(System.Exception)
                    {
                        // Ignore.
                    }
                }
                throw;
            }

            _initialized = true;
        }
        public void SerializeDeserialize2()
        {
            try
            {
                InitializationException.Throw("message", null);
            }
            catch (InitializationException e)
            {
                using (MemoryStream memStream = new MemoryStream())
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(memStream, e);
                    memStream.Position = 0;

                    InitializationException e2 = (InitializationException)formatter.Deserialize(memStream);

                    Assert.AreEqual(e.Message, e2.Message);
                }
            }
        }
Пример #4
0
        //
        // Only for use by ObjectAdapterFactory
        //
        public ObjectAdapterI(Instance instance, Communicator communicator,
            ObjectAdapterFactory objectAdapterFactory, string name,
            RouterPrx router, bool noConfig)
        {
            instance_ = instance;
            _communicator = communicator;
            _objectAdapterFactory = objectAdapterFactory;
            _servantManager = new ServantManager(instance, name);
            _name = name;
            _incomingConnectionFactories = new List<IncomingConnectionFactory>();
            _publishedEndpoints = new List<EndpointI>();
            _routerEndpoints = new List<EndpointI>();
            _routerInfo = null;
            _directCount = 0;
            _noConfig = noConfig;

            if(_noConfig)
            {
                _id = "";
                _replicaGroupId = "";
                _reference = instance_.referenceFactory().create("dummy -t", "");
                _acm = instance_.serverACM();
                return;
            }

            Properties properties = instance_.initializationData().properties;
            List<string> unknownProps = new List<string>();
            bool noProps = filterProperties(unknownProps);

            //
            // Warn about unknown object adapter properties.
            //
            if(unknownProps.Count != 0 && properties.getPropertyAsIntWithDefault("Ice.Warn.UnknownProperties", 1) > 0)
            {
                StringBuilder message = new StringBuilder("found unknown properties for object adapter `");
                message.Append(_name);
                message.Append("':");
                foreach(string s in unknownProps)
                {
                    message.Append("\n    ");
                    message.Append(s);
                }
                instance_.initializationData().logger.warning(message.ToString());
            }

            //
            // Make sure named adapter has configuration.
            //
            if(router == null && noProps)
            {
                //
                // These need to be set to prevent warnings/asserts in the destructor.
                //
                state_ = StateDestroyed;
                instance_ = null;
                _incomingConnectionFactories = null;

                InitializationException ex = new InitializationException();
                ex.reason = "object adapter `" + _name + "' requires configuration";
                throw ex;
            }

            _id = properties.getProperty(_name + ".AdapterId");
            _replicaGroupId = properties.getProperty(_name + ".ReplicaGroupId");

            //
            // Setup a reference to be used to get the default proxy options
            // when creating new proxies. By default, create twoway proxies.
            //
            string proxyOptions = properties.getPropertyWithDefault(_name + ".ProxyOptions", "-t");
            try
            {
                _reference = instance_.referenceFactory().create("dummy " + proxyOptions, "");
            }
            catch(ProxyParseException)
            {
                InitializationException ex = new InitializationException();
                ex.reason = "invalid proxy options `" + proxyOptions + "' for object adapter `" + _name + "'";
                throw ex;
            }

            _acm = new ACMConfig(properties, communicator.getLogger(), _name + ".ACM", instance_.serverACM());

            {
                int defaultMessageSizeMax = instance.messageSizeMax() / 1024;
                int num = properties.getPropertyAsIntWithDefault(_name + ".MessageSizeMax", defaultMessageSizeMax);
                if(num < 1 || num > 0x7fffffff / 1024)
                {
                    _messageSizeMax = 0x7fffffff;
                }
                else
                {
                    _messageSizeMax = num * 1024; // Property is in kilobytes, _messageSizeMax in bytes
                }
            }

            try
            {
                int threadPoolSize = properties.getPropertyAsInt(_name + ".ThreadPool.Size");
                int threadPoolSizeMax = properties.getPropertyAsInt(_name + ".ThreadPool.SizeMax");
                if(threadPoolSize > 0 || threadPoolSizeMax > 0)
                {
                    _threadPool = new ThreadPool(instance_, _name + ".ThreadPool", 0);
                }

                if(router == null)
                {
                    router = RouterPrxHelper.uncheckedCast(
                        instance_.proxyFactory().propertyToProxy(_name + ".Router"));
                }
                if(router != null)
                {
                    _routerInfo = instance_.routerManager().get(router);
                    if(_routerInfo != null)
                    {
                        //
                        // Make sure this router is not already registered with another adapter.
                        //
                        if(_routerInfo.getAdapter() != null)
                        {
                            Ice.AlreadyRegisteredException ex = new Ice.AlreadyRegisteredException();
                            ex.kindOfObject = "object adapter with router";
                            ex.id = instance_.identityToString(router.ice_getIdentity());
                            throw ex;
                        }

                        //
                        // Add the router's server proxy endpoints to this object
                        // adapter.
                        //
                        EndpointI[] endpoints = _routerInfo.getServerEndpoints();
                        for(int i = 0; i < endpoints.Length; ++i)
                        {
                            _routerEndpoints.Add(endpoints[i]);
                        }
                        _routerEndpoints.Sort(); // Must be sorted.

                        //
                        // Remove duplicate endpoints, so we have a list of unique endpoints.
                        //
                        for(int i = 0; i < _routerEndpoints.Count-1;)
                        {
                            EndpointI e1 = _routerEndpoints[i];
                            EndpointI e2 = _routerEndpoints[i + 1];
                            if(e1.Equals(e2))
                            {
                                _routerEndpoints.RemoveAt(i);
                            }
                            else
                            {
                                ++i;
                            }
                        }

                        //
                        // Associate this object adapter with the router. This way,
                        // new outgoing connections to the router's client proxy will
                        // use this object adapter for callbacks.
                        //
                        _routerInfo.setAdapter(this);

                        //
                        // Also modify all existing outgoing connections to the
                        // router's client proxy to use this object adapter for
                        // callbacks.
                        //
                        instance_.outgoingConnectionFactory().setRouterInfo(_routerInfo);
                    }
                }
                else
                {
                    //
                    // Parse the endpoints, but don't store them in the adapter. The connection
                    // factory might change it, for example, to fill in the real port number.
                    //
                    List<EndpointI> endpoints =  parseEndpoints(properties.getProperty(_name + ".Endpoints"), true);
                    foreach(EndpointI endp in endpoints)
                    {
                        IncomingConnectionFactory factory = new IncomingConnectionFactory(instance, endp, this);
                        _incomingConnectionFactories.Add(factory);
                    }
                    if(endpoints.Count == 0)
                    {
                        TraceLevels tl = instance_.traceLevels();
                        if(tl.network >= 2)
                        {
                            instance_.initializationData().logger.trace(tl.networkCat, "created adapter `" + _name +
                                                                        "' without endpoints");
                        }
                    }

                    //
                    // Parse published endpoints.
                    //
                    _publishedEndpoints = parsePublishedEndpoints();
                }

                if(properties.getProperty(_name + ".Locator").Length > 0)
                {
                    setLocator(LocatorPrxHelper.uncheckedCast(
                        instance_.proxyFactory().propertyToProxy(_name + ".Locator")));
                }
                else
                {
                    setLocator(instance_.referenceFactory().getDefaultLocator());
                }
            }
            catch(LocalException)
            {
                destroy();
                throw;
            }
        }
Пример #5
0
        /// <summary>
        /// Initialize OpenGL namespace static environment. This method shall be called before any other classes methods.
        /// </summary>
        public static void Initialize()
        {
            if (_Initialized)
            {
                return;                 // Already initialized
            }
            _Initialized = true;
#if !NETSTANDARD1_1
            // Optional initialization
            string envGlInit = Environment.GetEnvironmentVariable("OPENGL_NET_INIT");
            if (envGlInit != null && envGlInit == "NO")
            {
                return;
            }
#endif
            // Environment options
            LogComment("OpenGL.Net is initializing");

            // Loader function			OS API			GL API
            // ------------------------------------------------------
            // Supported platform: Windows
            // wglGetProcAddress		WGL				GL
            // wglGetProcAddress		WGL				GLES2+ (with WGL_create_context_es(2)?_profile_EXT)
            // eglGetProcAddress		EGL(Angle)		GLES2+
            // ------------------------------------------------------
            // Supported platform: Linux
            // glXGetProcAddress		GLX				GL
            // glXGetProcAddress		GLX				GLES2+ (with GLX_create_context_es(2)?_profile_EXT)
            // eglGetProcAddress		EGL				GLES2+
            // ------------------------------------------------------
            // Supported platform: Android
            // eglGetProcAddress		EGL				GL
            // eglGetProcAddress		EGL				GLES2+

            try {
#if !MONODROID
                // Determine whether use EGL as device context backend
                if (Egl.IsAvailable && Platform.CurrentPlatformId == Platform.Id.Linux && Glx.IsAvailable == false)
                {
                    Egl.IsRequired = true;
                }
#endif

                // Create native window for getting preliminary information on desktop systems
                // This instance will be used for creating contexts without explictly specify a window
                NativeWindow = DeviceContext.CreateHiddenWindow();

                // Create device context
                using (DeviceContext windowDevice = DeviceContext.Create()) {
                    // Create basic OpenGL context
                    IntPtr renderContext = windowDevice.CreateSimpleContext();
                    if (renderContext == IntPtr.Zero)
                    {
                        throw new NotImplementedException("unable to create a simple context");
                    }

                    // Make contect current
                    if (windowDevice.MakeCurrent(renderContext) == false)
                    {
                        throw new InvalidOperationException("unable to make current", windowDevice.GetPlatformException());
                    }

#if !MONODROID
                    // Reload platform function pointers, if required
                    if (Egl.IsRequired == false && Platform.CurrentPlatformId == Platform.Id.WindowsNT)
                    {
                        Wgl.BindAPI();
                    }
#endif

                    // Query OpenGL informations
                    string glVersion = GetString(StringName.Version);
                    _CurrentVersion = KhronosVersion.Parse(glVersion);

                    // Query OpenGL extensions (current OpenGL implementation, CurrentCaps)
                    _CurrentExtensions = new Extensions();
                    _CurrentExtensions.Query();
                    // Query platform extensions
                    windowDevice.QueryPlatformExtensions();
                    // Query OpenGL limits
                    _CurrentLimits = Limits.Query(CurrentVersion, _CurrentExtensions);

                    // Obtain current OpenGL Shading Language version
                    string glslVersion = null;

                    switch (_CurrentVersion.Api)
                    {
                    case KhronosVersion.ApiGl:
                        if (_CurrentVersion >= Version_200 || _CurrentExtensions.ShadingLanguage100_ARB)
                        {
                            glslVersion = GetString(StringName.ShadingLanguageVersion);
                        }
                        break;

                    case KhronosVersion.ApiGles2:
                        glslVersion = GetString(StringName.ShadingLanguageVersion);
                        break;
                    }

                    if (glslVersion != null)
                    {
                        _CurrentShadingVersion = GlslVersion.Parse(glslVersion, _CurrentVersion.Api);
                    }

                    // Vendor/Render information
                    _Vendor   = GetString(StringName.Vendor);
                    _Renderer = GetString(StringName.Renderer);

                    if (EnvDebug || EnvExperimental)
                    {
                        Debug.Assert(CurrentVersion != null && CurrentExtensions != null);
                        CheckExtensionCommands <Gl>(CurrentVersion, CurrentExtensions, EnvExperimental);
                    }

                    // Before deletion, make uncurrent
                    windowDevice.MakeCurrent(IntPtr.Zero);
                    // Detroy context
                    if (windowDevice.DeleteContext(renderContext) == false)
                    {
                        throw new InvalidOperationException("unable to delete OpenGL context");
                    }
                }

                LogComment("OpenGL.Net has been initialized");
            } catch (Exception excepton) {
                InitializationException = excepton;
                LogComment("Unable to initialize OpenGL.Net: {0}", InitializationException.ToString());
            }
        }
Пример #6
0
 protected void OnInitializationException(Exception ex)
 {
     InitializationException?.Invoke(ex);
 }