예제 #1
0
        internal LocalApplication(
            IComponentDirectory parentDirectory,
            ApplicationDesc application,
            Guid instanceGuid,
            ulong instanceNumber)
        {
            this.instanceGuid   = instanceGuid;
            this.instanceNumber = instanceNumber;

            string iname = application.Name + " " + instanceGuid.ToString();

            this.applicationDescriptor = application;

            localDirectory = new ComponentDirectory(parentDirectory, iname);

            localDirectory.Register(
                new Instance(
                    localDirectory.GetInstance <DatabaseManager>().Find("/"), "WorkingDirectory"));

            localDirectory.Register(new Instance(this, "Process"));

            foreach (IComponentProvider provider in application.Components)
            {
                localDirectory.Register(provider);
            }
        }
        public IApplicationInstance Run(string path, string verb, string[] args)
        {
            ApplicationDesc app = null;

            try
            {
                app = databaseManager.Find <ApplicationDesc>(path).Object;
            }
            catch (Exception)
            {
            }

            if (app == null)
            {
                throw new Exception(
                          String.Format(
                              "There is no application present at: '{0}'", path));
            }

            LocalApplication application = new LocalApplication(
                this.componentDirectory,
                app, Guid.NewGuid(), NewInstanceNumber(app));

            application.Callback = this;
            applicationInstances.Add(application);



            application.Start(verb, args);

            return(application);
        }
예제 #3
0
        public void Init(ApplicationDesc desc)
        {
            // set icon
            if (!string.IsNullOrEmpty(desc.Win32_IconFileName))
            {
                using (var s = this.GetType().Assembly.GetManifestResourceStream(desc.Win32_IconFileName))
                {
                    if (s == null)
                    {
                        Debug.ThrowError("WinFormApplication", "Cannot find icon file.\nYou must use this nameing convention: {MyAppNam}.IconFileName.png");
                    }
                    Bitmap bmp = new Bitmap(s);
                    this.Icon = Icon.FromHandle(bmp.GetHicon());
                }
            }

            theEvent = new ApplicationEvent();

            base.Name = desc.Name;
            base.Text = desc.Name;
            var frame = desc.FrameSize;

            if (frame.Width == 0 || frame.Height == 0)
            {
                frame = (IPlatform.Singleton.ScreenSize.ToVector2() / 1.5f).ToSize2();
            }
            base.ClientSize = new System.Drawing.Size(frame.Width, frame.Height);

            switch (desc.StartPosition)
            {
            case ApplicationStartPositions.Default: StartPosition = FormStartPosition.WindowsDefaultLocation; break;

            case ApplicationStartPositions.CenterCurrentScreen: StartPosition = FormStartPosition.CenterScreen; break;
            }

            switch (desc.Type)
            {
            case ApplicationTypes.Box:
                FormBorderStyle = FormBorderStyle.None; break;

            case ApplicationTypes.Frame:
                FormBorderStyle = FormBorderStyle.FixedDialog;
                MaximizeBox     = false;
                break;

            case ApplicationTypes.FrameSizable:
                FormBorderStyle = FormBorderStyle.Sizable; break;
            }

            base.FormClosing += winFormClosing;
            base.Shown       += winFormShown;

            MouseMove  += mouseMoveEvent;
            MouseDown  += mouseDownEvent;
            MouseUp    += mouseUpEvent;
            KeyDown    += keyDownEvent;
            KeyUp      += keyUpEvent;
            MouseWheel += scrollEvent;
        }
예제 #4
0
        /// <summary>
        /// Sets up the bridge in the new appdomain
        /// </summary>
        /// <param name="parentDirectory">Parent component directory</param>
        /// <param name="app">Application descriptor</param>
        /// <param name="guid">Application instance GUID</param>
        /// <param name="appInstance">Self application instance to link into the directory</param>
        internal void Setup(IComponentDirectory parentDirectory, ApplicationDesc app, Guid guid, IApplicationInstance appInstance, IAssemblyLoader xassemblyLoader)
        {
            assemblyLoader = xassemblyLoader;

            string iname = app.Name + " " + guid;

            // Console.Out.WriteLine("Creating process: {0}", iname);
            AppDomain.CurrentDomain.TypeResolve     += new ResolveEventHandler(CurrentDomain_TypeResolve);
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            this.directory = new ComponentDirectory(parentDirectory, iname);
            this.directory.Register(
                new Instance(
                    this.directory.GetInstance <DatabaseManager>().Find("/")));

            IComponentProvider appProvider = null;

            /** register self as process **/
            this.directory.Register(
                new Instance(appInstance, "Self"));

            /*******************************************************************************************
            * TODO: SECURITY: this is where we would re-register views of already registered (kernel)
            * providers to shadow the originals
            *******************************************************************************************/

            foreach (IComponentProvider provider in app.Components)
            {
                this.directory.Register(provider);

                if (provider.MatchedName == app.ApplicationComponent)
                {
                    appProvider = provider;
                }
            }

            if (appProvider == null)
            {
                throw new Exception(
                          String.Format(
                              "The application {0} cannot be set up because the application component was not found",
                              app.Name));
            }

            this.appInstance = this.directory.GetInstance(appProvider.MatchedName) as IApplicationBase;

            if (app == null)
            {
                throw new Exception(
                          String.Format(
                              "The application {0} cannot be set up because the application component cannot be instantiated",
                              app.Name));
            }

            /* a-ok */
        }
예제 #5
0
        public void Init(ApplicationDesc desc)
        {
            // set icon
            if (!string.IsNullOrEmpty(desc.Win32_IconFileName))
            {
                using (var s = this.GetType().Assembly.GetManifestResourceStream(desc.Win32_IconFileName))
                {
                    if (s == null) Debug.ThrowError("WinFormApplication", "Cannot find icon file.\nYou must use this nameing convention: {MyAppNam}.IconFileName.png");
                    Bitmap bmp = new Bitmap(s);
                    this.Icon = Icon.FromHandle(bmp.GetHicon());
                }
            }

            theEvent = new ApplicationEvent();

            base.Name = desc.Name;
            base.Text = desc.Name;
            var frame = desc.FrameSize;
            if (frame.Width == 0 || frame.Height == 0) frame = (IPlatform.Singleton.ScreenSize.ToVector2() / 1.5f).ToSize2();
            base.ClientSize = new System.Drawing.Size(frame.Width, frame.Height);

            switch (desc.StartPosition)
            {
                case ApplicationStartPositions.Default: StartPosition = FormStartPosition.WindowsDefaultLocation; break;
                case ApplicationStartPositions.CenterCurrentScreen: StartPosition = FormStartPosition.CenterScreen; break;
            }

            switch (desc.Type)
            {
                case ApplicationTypes.Box:
                    FormBorderStyle = FormBorderStyle.None; break;

                case ApplicationTypes.Frame:
                    FormBorderStyle = FormBorderStyle.FixedDialog;
                    MaximizeBox = false;
                    break;

                case ApplicationTypes.FrameSizable:
                    FormBorderStyle = FormBorderStyle.Sizable; break;
            }

            base.FormClosing += winFormClosing;
            base.Shown += winFormShown;

            MouseMove += mouseMoveEvent;
            MouseDown += mouseDownEvent;
            MouseUp += mouseUpEvent;
            KeyDown += keyDownEvent;
            KeyUp += keyUpEvent;
            MouseWheel += scrollEvent;
        }
        private ulong NewInstanceNumber(ApplicationDesc app)
        {
            List <IApplicationInstance> instances = this.applicationInstances.FindAll(
                delegate(IApplicationInstance instance)
            {
                return(instance.ApplicationInfo.Id == app.Id);
            });

            ulong instanceNumber = 0;

            if (instances.Count > 0)
            {
                instanceNumber = instances[instances.Count - 1].InstanceNumber + 1;
            }

            return(instanceNumber);
        }
예제 #7
0
        private void DoInstall(InstallSource source, InstallDestination installDestination)
        {
            source.InstallEnvironment             = environment;
            installDestination.InstallEnvironment = environment;

            ApplicationDesc app = source.OpenForReading <ApplicationDesc>().Object;

            using (TypedStream <ApplicationDesc> appstream = installDestination.OpenForWriting <ApplicationDesc>())
            {
                appstream.Object = app;
            }

            /* register default bindings */
            foreach (string type in app.DefaultBindings.Keys)
            {
                documentManagement.RegisterDocumentUsage(
                    type, installDestination.ToString(), app.DefaultBindings[type]);
            }
        }
        public IApplicationInstance Run(string path, string verb, string[] args, IComponentDirectory environ)
        {
            ApplicationDesc app = null;

            try
            {
                app = databaseManager.Find <ApplicationDesc>(path).Object;
            }
            catch (Exception)
            {
            }

            if (app == null)
            {
                throw new Exception(
                          String.Format(
                              "There is no application present at: '{0}'", path));
            }

            ComponentDirectory localEnvironment = new ComponentDirectory(this.componentDirectory, path);

            foreach (IComponentProvider component in environ.RegisteredProviders)
            {
                localEnvironment.Register(component);
            }

            LocalApplication application = new LocalApplication(
                localEnvironment,
                app, Guid.NewGuid(), NewInstanceNumber(app));

            application.Callback = this;
            applicationInstances.Add(application);
            application.Start(verb, args);

            return(application);
        }
예제 #9
0
        /// <summary>
        /// Application instance that lives in a dedicated app domain
        /// </summary>
        /// <param name="parentDirectory"></param>
        /// <param name="application"></param>
        /// <param name="instanceGuid"></param>
        internal AppDomainApplication(
            IComponentDirectory parentDirectory,
            ApplicationDesc application,
            Guid instanceGuid,
            ulong instanceNumber)
        {
            this.instanceGuid   = instanceGuid;
            this.instanceNumber = instanceNumber;

            string iname = application.Name + " " + instanceGuid.ToString();

            appDomain = AppDomain.CreateDomain(iname);

            /* create instance and unwrap the caller so that all the stuff happens in its own domain */
            this.bridge = appDomain.CreateInstanceAndUnwrap(
                typeof(Bridge).Assembly.FullName,
                typeof(Bridge).FullName) as Bridge;

            this.applicationDescriptor = application;

            /* set up the instance */
            this.bridge.Setup(parentDirectory, application, instanceGuid, this, parentDirectory.GetInstance <IAssemblyLoader>());
            this.bridge.Callback = this;
        }
예제 #10
0
        private void CacheDeserialization()
        {
            Child.InstallEnvironment = environment;
            SerializableXmlDocument doc = Child.OpenForReading <SerializableXmlDocument>().Object;

            doc.Normalize();

            XmlElement node = doc.FirstChild.NextSibling as XmlElement;

            // assert root node
            if (node.Name != "Application")
            {
                throw new AbortInstallationException("Source is not an application descriptor");
            }

            // check version
            if (new Version(node.GetAttribute("xversion")) > new Version(1, 0, 0))
            {
                throw new AbortInstallationException("Application descriptor is of an incorrect version");
            }

            string          name = node.GetAttribute("name");
            Guid            id   = new Guid(node.GetAttribute("id"));
            string          rootComponentName = node.GetAttribute("root");
            DocumentSupport apptype           = (DocumentSupport)Enum.Parse(typeof(DocumentSupport), node.GetAttribute("type"));
            string          friendlyName      = node.GetAttribute("friendly");

            List <ConfiguredComponent> defs = new List <ConfiguredComponent>();

            /** ok, construct **/
            ApplicationDesc app = new ApplicationDesc(id, apptype, name, friendlyName);

            foreach (XmlNode firstNode in node.ChildNodes)
            {
                if (firstNode.Name == "Components")
                {
                    /* load all components */
                    foreach (XmlNode componentNode in firstNode.ChildNodes)
                    {
                        if (componentNode.Name.StartsWith("#"))
                        {
                            continue;
                        }

                        if (componentNode.Name != "Component")
                        {
                            throw new AbortInstallationException("Application description is not well-formed. Only Component nodes are allowed in the Components section");
                        }

                        defs.Add(new ConfiguredComponent(componentNode));
                    }
                }
                if (firstNode.Name == "Bindings")
                {
                    foreach (XmlNode bindingNode in firstNode.ChildNodes)
                    {
                        if (bindingNode.Name != "Binding")
                        {
                            continue;
                        }

                        app.DefaultBindings[((XmlElement)bindingNode).GetAttribute("Type")] =
                            Array.ConvertAll <string, string>(
                                ((XmlElement)bindingNode).GetAttribute("Verbs").Split(','),
                                delegate(string s) { return(s.Trim()); });
                    }
                }
            }

            app.Components           = defs.ToArray();
            app.ApplicationComponent = rootComponentName;

            applicationDescriptor = app;
        }