コード例 #1
0
        private void Window_Initialized(object sender, EventArgs e)
        {
            string version = Assembly.GetExecutingAssembly().GetName().Version.ToString(3);
            string build   = Assembly.GetExecutingAssembly().GetName().Version.Revision.ToString("0000");

            labelAboutVersion.Content      = "Version " + version;
            AboutVersionLabel.Content      = "Version " + version;
            AboutVersionBuildLabel.Content = "Build " + build;

            if (Logger.LogDebug)
            {
                AboutVersionBuildLabel.Visibility = System.Windows.Visibility.Visible;
                this.Title += " DEBUG";
            }

            try
            {
                this.addInManager   = new AddInManager(this);
                this.networkManager = new NetworkManager(this.addInManager);
                this.networkManager.NetworkSwitched += new EventHandler <NetworkSwitchedEventArgs>(networkManager_NetworkSwitched);
                this.networkManager.RedetectNetworkStatusChanged += new EventHandler <RedetectNetworkStatusChangeEventArgs>(networkManager_RedetectNetworkStatusChanged);

                InitTaskbarIconAndContextMenu();
                InitActions();

                UpdateJumplist();
            }
            catch (AddInLoaderException)
            {
                MessageBox.Show(String.Format(LanguageResources.AddInLoadError, version), "Proxy Switcher", MessageBoxButton.OK, MessageBoxImage.Stop);
                Application.Current.Shutdown(501);
            }
        }
コード例 #2
0
ファイル: App.cs プロジェクト: ppittle/LBi.LostDoc
 public static void Initialize(CompositionContainer container,
                               ContentManager contentManager,
                               AddInManager addInManager,
                               NotificationManager notifications,
                               TraceListener listener)
 {
     Instance = new App(container, contentManager, addInManager, notifications, listener);
 }
コード例 #3
0
 public void AddIns(string ID)
 {
     if (HttpContext.Current.Request.HttpMethod == "POST")
     {
         AddInManager.CreateAddInAppDomain(ID);
         AddInManager.LoadAddInDll(ID, "");
     }
 }
コード例 #4
0
ファイル: App.cs プロジェクト: ppittle/LBi.LostDoc
 public static void Initialize(CompositionContainer container, 
                               ContentManager contentManager, 
                               AddInManager addInManager, 
                               NotificationManager notifications, 
                               TraceListener listener)
 {
     Instance = new App(container, contentManager, addInManager, notifications, listener);
 }
コード例 #5
0
ファイル: App.cs プロジェクト: ppittle/LBi.LostDoc
 private App(CompositionContainer container,
             ContentManager contentManager,
             AddInManager addInManager,
             NotificationManager notifications,
             TraceListener listener)
 {
     this.Container     = container;
     this.Content       = contentManager;
     this.AddIns        = addInManager;
     this.Notifications = notifications;
     this.TraceListner  = listener;
 }
コード例 #6
0
ファイル: App.cs プロジェクト: ppittle/LBi.LostDoc
 private App(CompositionContainer container, 
             ContentManager contentManager, 
             AddInManager addInManager, 
             NotificationManager notifications, 
             TraceListener listener)
 {
     this.Container = container;
     this.Content = contentManager;
     this.AddIns = addInManager;
     this.Notifications = notifications;
     this.TraceListner = listener;
 }
コード例 #7
0
        /// <summary>
        /// Updates version info in Add-In page.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        private void VersionUpdate(object sender, UpdateInfoEventArguments e)
        {
            AddInManager om = new AddInManager();

            try
            {
                om.NewAddInVersionAvailableAsync(e.Guid, e.Version, e.AddressUri, e.UpdateClassification);
            }
            catch (Exception exception)
            {
                Trace.TraceError(exception.ToString());
            }
        }
コード例 #8
0
 public void AddAddIn(string ID, string Path)
 {
     try
     {
         Path = "G:\\Project\\NET\\DynamicDllLoad\\Plug-inDll\\bin\\Debug\\Plug-inDll.dll";
         AddInManager.CreateAddInAppDomain(ID);
         AddInManager.LoadAddInDll(ID, Path);
         HttpContext.Current.Response.Write("加载成功!");
     }
     catch (Exception ex)
     {
         HttpContext.Current.Response.Write(ex.Message);
     }
 }
コード例 #9
0
 public AddInDlg(AddInManager addins)
 {
     this.InitializeComponent();
     this.AddInList.ListViewItemSorter = (IComparer) new ListViewSorter();
     this.CompList.ListViewItemSorter  = (IComparer) new ListViewSorter();
     foreach (IAddIn addIn in addins.AddIns)
     {
         Assembly     assembly     = Assembly.GetAssembly(addIn.GetType());
         ListViewItem listViewItem = this.AddInList.Items.Add(addIn.Name);
         listViewItem.SubItems.Add(assembly.GetName().Version.ToString());
         listViewItem.SubItems.Add(assembly.Location);
         listViewItem.ImageIndex = 0;
         listViewItem.Tag        = (object)addIn;
     }
     this.AddInList.Items[0].Selected = true;
 }
コード例 #10
0
 public void LoadAddIn(List <AddIn> AddIns)
 {
     try
     {
         foreach (AddIn current in AddIns)
         {
             if (current.AppDomainStatus == 1)
             {
                 string text = ConfigurationManager.AppSettings["AddInPath"].ToString() + "\\" + current.ControllerName + "\\";
                 if (!Directory.Exists(text))
                 {
                     throw new Exception("插件路径错误:" + text);
                 }
                 AddInManager.CreateAddInAppDomain(current.ControllerName);
                 AddInManager.LoadAddInDll(current.ControllerName, text + current.DllName);
             }
         }
     }
     catch (Exception ex)
     {
         Log.log(ex.ToString());
     }
 }
コード例 #11
0
 public void Unload(string ID)
 {
     try
     {
         if (AddInManager.AppDomains.ContainsKey(ID))
         {
             AddInManager.UnloadAddIn(ID);
             AddInManager.AppDomains.Remove(ID);
             if (AddInManager.Loaders.ContainsKey(ID))
             {
                 AddInManager.Loaders.Remove(ID);
             }
             HttpContext.Current.Response.Write("插件域 " + ID + " 卸载成功!");
         }
         else
         {
             HttpContext.Current.Response.Write("插件域 " + ID + " 并未加载!");
         }
     }
     catch (Exception ex)
     {
         HttpContext.Current.Response.Write(ex.Message);
     }
 }
コード例 #12
0
ファイル: Global.asax.cs プロジェクト: ppittle/LBi.LostDoc
        protected void Application_Start()
        {
            // TODO maybe put this somewhere else (not in global.asax)
            // TODO maybe move all of this into the App class with "IAppConfig"

            // initialize logger
            TraceListener traceListener =
                new TextWriterTraceListener(Path.Combine(AppConfig.LogPath, 
                                                         string.Format("repository_{0:yyyy'-'MM'-'dd__HHmmss}.log", 
                                                                       DateTime.Now)));

            // TODO introduce flags/settings for controlling logging levels, but for now include everything
            traceListener.Filter = new EventTypeFilter(SourceLevels.All);

            traceListener.TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime;

            Web.TraceSources.Content.Listeners.Add(traceListener);
            Web.TraceSources.AddInManager.Listeners.Add(traceListener);
            Repository.TraceSources.ContentManagerSource.Listeners.Add(traceListener);
            Repository.TraceSources.ContentSearcherSource.Listeners.Add(traceListener);

            // this might be stupid, but it fixes things for iisexpress
            Directory.SetCurrentDirectory(HostingEnvironment.ApplicationPhysicalPath);

            // set up add-in system
            AddInSource officalSource = new AddInSource("Official LostDoc repository add-in feed", 
                                                        AppConfig.AddInRepository, 
                                                        isOfficial: true);

            // intialize MEF

            // core 'add-ins'
            var currentAssembly = Assembly.GetExecutingAssembly();
            var assemblyName = currentAssembly.GetName();
            string corePackageId = assemblyName.Name;
            string corePackageVersion = assemblyName.Version.ToString();
            AggregateCatalog catalog = new AggregateCatalog();

            // load other sources from site-settings (not config)
            AddInRepository repository = new AddInRepository(officalSource);
            AddInManager addInManager = new AddInManager(repository, 
                                                         AppConfig.AddInInstallPath, 
                                                         AppConfig.AddInPackagePath);

            // when the catalog changes, discover and route all ApiControllers
            catalog.Changed += (sender, args) => this.UpdateWebApiRegistry(args);

            //// TODO for debugging only
            //Debugger.Break();
            //Debugger.Launch();

            // now register core libs
            catalog.Catalogs.Add(new AddInCatalog(new ApplicationCatalog(), corePackageId, corePackageVersion));

            // hook event so that installed add-ins get registered in the catalog, if composition occurs after this fires
            // or if recomposition is enabled, no restart should be requried
            addInManager.Installed +=
                (sender, args) => catalog.Catalogs.Add(new AddInCatalog(new DirectoryCatalog(args.InstallationPath), 
                                                                        args.Package.Id, 
                                                                        args.Package.Version));

            // delete and redeploy all installed packages, this will trigger the Installed event ^
            // this acts as a crude "remove/overwrite plugins that were in use when un/installed" hack
            addInManager.Restore();

            // create container
            CompositionContainer container = new CompositionContainer(catalog);

            // set up template resolver
            var lazyProviders = container.GetExports<IFileProvider>(ContractNames.TemplateProvider);
            var realProviders = lazyProviders.Select(lazy => lazy.Value);
            TemplateResolver templateResolver = new TemplateResolver(realProviders.ToArray());

            // load template
            Template template = new Template(container);
            template.Load(templateResolver, AppConfig.Template);

            // set up content manager
            ContentManager contentManager = new ContentManager(new ContentSettings
                                                                   {
                                                                       ContentPath = AppConfig.ContentPath, 
                                                                       // TODO make this configurable
                                                                       IgnoreVersionComponent = VersionComponent.Patch, 
                                                                       RepositoryPath = AppConfig.RepositoryPath, 
                                                                       Template = template
                                                                   });

            // set up notifaction system
            NotificationManager notifications = new NotificationManager();

            // initialize app-singleton
            App.Initialize(container, contentManager, addInManager, notifications, traceListener);

            // MVC init
            AreaRegistration.RegisterAllAreas();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            // inject our custom IControllerFactory for the Admin interface
            IControllerFactory oldControllerFactory = ControllerBuilder.Current.GetControllerFactory();
            IControllerFactory newControllerFactory = new AddInControllerFactory(AdministrationAreaRegistration.Name, 
                                                                                 container, 
                                                                                 oldControllerFactory);
            ControllerBuilder.Current.SetControllerFactory(newControllerFactory);

            // TODO figure out if we actually need this
            // hook in our MEF based IHttpController instead of the default one
            //GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerTypeResolver), new AddInHttpControllerTypeResolver(App.Instance.Container));
        }
コード例 #13
0
        public ActionResult AddInDomain(string ID)
        {
            HttpRequest  request = HttpContext.Current.Request;
            ActionResult result;

            try
            {
                SqlHelper sqlHelper = new SqlHelper();
                DataTable dataTable = sqlHelper.ExecuteDataTable("select * from T_AddIn where f_id = " + ID, new SqlParameter[0]);
                if (dataTable != null && dataTable.Rows.Count > 0)
                {
                    string        appDomainName = dataTable.Rows[0]["F_AppDomain_Name"].ToString();
                    string        description   = dataTable.Rows[0]["F_Description"].ToString();
                    string        status        = dataTable.Rows[0]["F_Status"].ToString();
                    List <object> list          = new List <object>();
                    if (!AddInManager.AppDomains.ContainsKey(appDomainName))
                    {
                        result = this.RazorEngineView(new
                        {
                            ID            = ID,
                            AppDomainName = appDomainName,
                            Description   = description,
                            Status        = status,
                            Controllers   = list
                        });
                    }
                    else
                    {
                        if (AddInManager.Loaders[appDomainName] == null)
                        {
                            AddInManager.CreateAddInAppDomain(appDomainName);
                            AddIn.Common.Log.Write("创建新的代理类。");
                        }
                        try
                        {
                            foreach (IController current in AddInManager.Loaders[appDomainName].GetControllers())
                            {
                                List <object> list2 = new List <object>();
                                foreach (IAction current2 in current.Actions)
                                {
                                    List <object> list3 = new List <object>();
                                    foreach (IParameter current3 in current2.Parameters)
                                    {
                                        var item = new
                                        {
                                            ParameterName = current3.ParameterName,
                                            ParameterType = current3.ParameterType.Name
                                        };
                                        list3.Add(item);
                                    }
                                    var item2 = new
                                    {
                                        ActionName  = current2.ActionName,
                                        ReturnType  = current2.ReturnType.Name,
                                        HttpMethod  = current2.HttpMethod,
                                        Description = current2.Description,
                                        Parameters  = list3
                                    };
                                    list2.Add(item2);
                                }
                                var item3 = new
                                {
                                    ControllerName = current.ControllerName,
                                    Actions        = list2
                                };
                                list.Add(item3);
                            }
                        }
                        catch (Exception ex)
                        {
                            AddInWebApp.Common.Log.log(ex.ToString());
                        }
                        result = this.RazorEngineView(new
                        {
                            ID            = ID,
                            AppDomainName = appDomainName,
                            Description   = description,
                            Status        = status,
                            Controllers   = list
                        });
                    }
                }
                else
                {
                    result = this.Json(new
                    {
                        errcode = 0,
                        errmsg  = "OK",
                        msgdoc  = string.Concat(new object[]
                        {
                            "http://",
                            request.Url.Host,
                            ":",
                            request.Url.Port,
                            "/AddInsDomain/help/doc"
                        })
                    }, JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception ex2)
            {
                result = this.Json(new
                {
                    errcode = -1,
                    errmsg  = ex2.Message,
                    msgdoc  = string.Concat(new object[]
                    {
                        "http://",
                        request.Url.Host,
                        ":",
                        request.Url.Port,
                        "/AddInsDomain/help/doc"
                    })
                }, JsonRequestBehavior.AllowGet);
            }
            return(result);
        }
コード例 #14
0
 public void Find()
 {
     AddInManager.Update();
     AddInManager.Find();
 }
コード例 #15
0
 public void Update()
 {
     AddInManager.Update();
 }
コード例 #16
0
        private static void thread_CheckForNewVersion()
        {
            string local_version_string = get_installed_version();
            bool   _updateavailable     = false;
            bool   success;

            string remote_version_string = "0.0.0.0";
            string remote_url            = "http://code.google.com/p/for-the-record-to-lights-out/";
            string remote_name           = "";
            string xml_string            = "";

            //
            // The following block checks the latest version given in the remote file
            //

            //
            // Use the first line for production @ googlecode, and the second line for testing @ dropbox
            // Googlecode is not a good place to host. Better use dropbox
            // ** Github is even better!
            //
            //Uri latest_version_xml = new Uri("http://for-the-record-to-lights-out.googlecode.com/files/FTR2LO_Vail_latest_version.xml");
            //Uri latest_version_xml = new Uri("https://dl.dropbox.com/u/11034559/FTR2LightsOut/FTR2LO_Vail_latest_version.xml");
            Uri       latest_version_xml = new Uri("https://raw.github.com/jayrockk/ArgusTV-to-Lights-Out/master/ATV2LO_latest_version.xml");
            WebClient client             = null;

            try
            {
                client     = new WebClient();
                xml_string = client.DownloadString(latest_version_xml);
            }
            catch (Exception)
            {
                //MessageBox.Show("Exception " + ex.ToString());
            }
            finally
            {
                if (client != null)
                {
                    ((IDisposable)client).Dispose();
                }
            }

            XmlReader reader = null;

            try
            {
                reader = XmlReader.Create(new StringReader(xml_string));

                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        switch (reader.Name)
                        {
                        case "name":
                            reader.Read();
                            remote_name = reader.Value;
                            break;

                        case "latest_version":
                            reader.Read();
                            remote_version_string = reader.Value;
                            break;

                        case "url":
                            reader.Read();
                            remote_url = reader.Value;
                            break;
                        }
                    }
                }
            }
            catch (Exception)
            {
                //MessageBox.Show("Exception " + ex.ToString());
            }

            /*finally
             * {
             *  if (client != null)
             *      ((IDisposable)client).Dispose();
             * }*/

            //
            // compare local and remote version, and set applicationinfrastructure if remote version is newer
            //
            Version local_version;

            success = Version.TryParse(local_version_string, out local_version);

            Version remote_version;

            success = Version.TryParse(remote_version_string, out remote_version);

            if (remote_version.CompareTo(local_version) > 0)
            {
                _updateavailable = true;
            }


            //taken from http://forum.home-server-blog.de/viewtopic.php?f=31&t=13785
            if (_updateavailable)
            {
                var addinMgr = new AddInManager();
                addinMgr.NewAddInVersionAvailable(
                    new Guid("9b190a4e-3657-4770-8939-75a1f65ceaab"), //<Id> from AddIn.xml
                    new Version(remote_version_string),
                    new Uri(remote_url),
                    UpdateClassification.Update);
            }
        }
コード例 #17
0
ファイル: Global.asax.cs プロジェクト: ppittle/LBi.LostDoc
        protected void Application_Start()
        {
            // TODO maybe put this somewhere else (not in global.asax)
            // TODO maybe move all of this into the App class with "IAppConfig"

            // initialize logger
            TraceListener traceListener =
                new TextWriterTraceListener(Path.Combine(AppConfig.LogPath,
                                                         string.Format("repository_{0:yyyy'-'MM'-'dd__HHmmss}.log",
                                                                       DateTime.Now)));

            // TODO introduce flags/settings for controlling logging levels, but for now include everything
            traceListener.Filter = new EventTypeFilter(SourceLevels.All);

            traceListener.TraceOutputOptions = TraceOptions.ThreadId | TraceOptions.DateTime;

            Web.TraceSources.Content.Listeners.Add(traceListener);
            Web.TraceSources.AddInManager.Listeners.Add(traceListener);
            Repository.TraceSources.ContentManagerSource.Listeners.Add(traceListener);
            Repository.TraceSources.ContentSearcherSource.Listeners.Add(traceListener);

            // this might be stupid, but it fixes things for iisexpress
            Directory.SetCurrentDirectory(HostingEnvironment.ApplicationPhysicalPath);

            // set up add-in system
            AddInSource officalSource = new AddInSource("Official LostDoc repository add-in feed",
                                                        AppConfig.AddInRepository,
                                                        isOfficial: true);

            // intialize MEF

            // core 'add-ins'
            var              currentAssembly    = Assembly.GetExecutingAssembly();
            var              assemblyName       = currentAssembly.GetName();
            string           corePackageId      = assemblyName.Name;
            string           corePackageVersion = assemblyName.Version.ToString();
            AggregateCatalog catalog            = new AggregateCatalog();

            // load other sources from site-settings (not config)
            AddInRepository repository   = new AddInRepository(officalSource);
            AddInManager    addInManager = new AddInManager(repository,
                                                            AppConfig.AddInInstallPath,
                                                            AppConfig.AddInPackagePath);

            // when the catalog changes, discover and route all ApiControllers
            catalog.Changed += (sender, args) => this.UpdateWebApiRegistry(args);

            //// TODO for debugging only
            //Debugger.Break();
            //Debugger.Launch();

            // now register core libs
            catalog.Catalogs.Add(new AddInCatalog(new ApplicationCatalog(), corePackageId, corePackageVersion));

            // hook event so that installed add-ins get registered in the catalog, if composition occurs after this fires
            // or if recomposition is enabled, no restart should be requried
            addInManager.Installed +=
                (sender, args) => catalog.Catalogs.Add(new AddInCatalog(new DirectoryCatalog(args.InstallationPath),
                                                                        args.Package.Id,
                                                                        args.Package.Version));

            // delete and redeploy all installed packages, this will trigger the Installed event ^
            // this acts as a crude "remove/overwrite plugins that were in use when un/installed" hack
            addInManager.Restore();

            // create container
            CompositionContainer container = new CompositionContainer(catalog);

            // set up template resolver
            var lazyProviders = container.GetExports <IFileProvider>(ContractNames.TemplateProvider);
            var realProviders = lazyProviders.Select(lazy => lazy.Value);
            TemplateResolver templateResolver = new TemplateResolver(realProviders.ToArray());

            // load template
            Template template = new Template(container);

            template.Load(templateResolver, AppConfig.Template);

            // set up content manager
            ContentManager contentManager = new ContentManager(new ContentSettings
            {
                ContentPath = AppConfig.ContentPath,
                // TODO make this configurable
                IgnoreVersionComponent = VersionComponent.Patch,
                RepositoryPath         = AppConfig.RepositoryPath,
                Template = template
            });

            // set up notifaction system
            NotificationManager notifications = new NotificationManager();

            // initialize app-singleton
            App.Initialize(container, contentManager, addInManager, notifications, traceListener);

            // MVC init
            AreaRegistration.RegisterAllAreas();
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            // inject our custom IControllerFactory for the Admin interface
            IControllerFactory oldControllerFactory = ControllerBuilder.Current.GetControllerFactory();
            IControllerFactory newControllerFactory = new AddInControllerFactory(AdministrationAreaRegistration.Name,
                                                                                 container,
                                                                                 oldControllerFactory);

            ControllerBuilder.Current.SetControllerFactory(newControllerFactory);

            // TODO figure out if we actually need this
            // hook in our MEF based IHttpController instead of the default one
            //GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerTypeResolver), new AddInHttpControllerTypeResolver(App.Instance.Container));
        }
コード例 #18
0
        public ActionResult Unload()
        {
            HttpRequest  request = HttpContext.Current.Request;
            ActionResult result;

            try
            {
                string  value = request.Form["Params"];
                dynamic param = JsonConvert.DeserializeObject(value);

                string    appDomainID   = param.AppDomainID;
                SqlHelper sqlHelper     = new SqlHelper();
                DataTable dataTable     = sqlHelper.ExecuteDataTable("select * from T_AddIn where F_ID =" + appDomainID, new SqlParameter[0]);
                string    appDomianName = (dataTable != null && dataTable.Rows.Count > 0) ? dataTable.Rows[0]["F_AppDomain_Name"].ToString() : "";
                if (appDomianName != "")
                {
                    if (AddInManager.AppDomains.ContainsKey(appDomianName))
                    {
                        AddInManager.UnloadAddIn(appDomianName);
                        AddInManager.AppDomains.Remove(appDomianName);
                        if (AddInManager.Loaders.ContainsKey(appDomianName))
                        {
                            AddInManager.Loaders.Remove(appDomianName);
                        }
                        sqlHelper.ExecuteNonQuery("update T_AddIn set F_Status = 0 where F_ID=" + appDomainID, new SqlParameter[0]);
                        result = this.Json(new
                        {
                            errcode = 0,
                            errmsg  = "OK",
                            msgdoc  = string.Concat(new object[]
                            {
                                "http://",
                                request.Url.Host,
                                ":",
                                request.Url.Port,
                                "/AddInsDomain/help/doc"
                            })
                        }, JsonRequestBehavior.DenyGet);
                    }
                    else
                    {
                        result = this.Json(new
                        {
                            errcode = 40003,
                            errmsg  = "尝试卸载未加载的插件域!",
                            msgdoc  = string.Concat(new object[]
                            {
                                "http://",
                                request.Url.Host,
                                ":",
                                request.Url.Port,
                                "/AddInsDomain/help/doc"
                            })
                        }, JsonRequestBehavior.DenyGet);
                    }
                }
                else
                {
                    result = this.Json(new
                    {
                        errcode = 40004,
                        errmsg  = "参数错误:ID!",
                        msgdoc  = string.Concat(new object[]
                        {
                            "http://",
                            request.Url.Host,
                            ":",
                            request.Url.Port,
                            "/AddInsDomain/help/doc"
                        })
                    }, JsonRequestBehavior.DenyGet);
                }
            }
            catch (Exception ex)
            {
                Log.log(ex.ToString());
                result = this.Json(new
                {
                    errcode = -1,
                    errmsg  = ex.Message,
                    msgdoc  = string.Concat(new object[]
                    {
                        "http://",
                        request.Url.Host,
                        ":",
                        request.Url.Port,
                        "/AddInsDomain/help/doc"
                    })
                }, JsonRequestBehavior.DenyGet);
            }
            return(result);
        }
コード例 #19
0
        //public void AddIns()
        //{
        //    if (HttpContext.Current.Request.HttpMethod == "GET")
        //    {
        //        string html = "<ul>";
        //        foreach (var domain in AddInManager.AppDomains)
        //        {
        //            html += "<li><span>" + domain.Key + "</span><ul>";

        //            foreach (var c in AddInManager.Loaders[domain.Key].Controllers)
        //            {
        //                html += "<li><span>" + c.ControllerName + "</span><ul>";
        //                foreach (var a in c.Actions)
        //                {
        //                    html += "<li><span>" + a.ActionName + "():" + a.ReturnType.Name + "</span><ul>";

        //                    foreach (var p in a.Parameters)
        //                    {
        //                        html += "<li>" + p.ParameterName + ":" + p.ParameterType.Name + "</li>";
        //                    }
        //                    html += "</ul></li>";
        //                }
        //                html += "</ul></li>";
        //            }
        //            html += "</ul></li>";
        //        }
        //        html += "</ul>";
        //        HttpContext.Current.Response.Write(html);
        //    }

        //}

        public ActionResult AddIns()
        {
            //if (HttpContext.Current.Request.HttpMethod == "GET")
            //{

            //    List<dynamic> models = new List<dynamic>();
            //    foreach (var domain in AddInManager.AppDomains)
            //    {
            //        //初始化动态类型
            //        dynamic model = new ExpandoObject();
            //        model.AddInDomain = domain.Key;

            //        //controllers 集合变量
            //        List<dynamic> controllers = new List<dynamic>();
            //        foreach (var c in AddInManager.Loaders[domain.Key].Controllers)
            //        {
            //            dynamic controller = new ExpandoObject();
            //            controller.ControllerName = c.ControllerName;
            //            List<dynamic> actions = new List<dynamic>();
            //            foreach (var a in c.Actions)
            //            {
            //                dynamic action = new ExpandoObject();
            //                action.ActionName = a.ActionName;
            //                action.ReturnType = a.ReturnType.Name;

            //                List<dynamic> parameters = new List<dynamic>();
            //                foreach (var p in a.Parameters)
            //                {
            //                    dynamic parameter = new ExpandoObject();
            //                    parameter.ParameterName = p.ParameterName;
            //                    parameter.ParameterType = p.ParameterType.Name;
            //                    parameters.Add(parameter);
            //                }
            //                action.Parameters = parameters;
            //                actions.Add(action);
            //            }
            //            controller.Actions = actions;
            //            controllers.Add(controller);
            //        }

            //        model.Controllers = controllers;
            //        models.Add(model);
            //    }
            //    //return VelocityView(models);
            //    return Json(models, JsonRequestBehavior.AllowGet);
            //}

            if (HttpContext.Current.Request.HttpMethod == "GET")
            {
                List <dynamic> models = new List <dynamic>();

                foreach (var domain in AddInManager.AppDomains)
                {
                    //初始化动态类型
                    dynamic model = new ExpandoObject();
                    model.AddInDomain = domain.Key;
                    //controllers 集合变量
                    List <dynamic> controllers  = new List <dynamic>();
                    var            _controllers = new { };

                    // 当Loader被回收 ,创建新的代理类。
                    if (AddInManager.Loaders[domain.Key] == null)
                    {
                        AddInManager.CreateAddInAppDomain(domain.Key);
                        AddIn.Common.Log.Write("创建新的代理类。");
                    }
                    try
                    {
                        foreach (var c in AddInManager.Loaders[domain.Key].GetControllers())
                        {
                            List <dynamic> actions = new List <dynamic>();
                            foreach (var a in c.Actions)
                            {
                                List <dynamic> parameters = new List <dynamic>();
                                foreach (var p in a.Parameters)
                                {
                                    var _parameter = new { ParameterName = p.ParameterName, ParameterType = p.ParameterType.Name };
                                    parameters.Add(_parameter);
                                }
                                var _action = new { ActionName = a.ActionName, ReturnType = a.ReturnType.Name, HttpMethod = a.HttpMethod, Description = a.Description, Parameters = parameters };
                                actions.Add(_action);
                            }
                            var _controller = new { ControllerName = c.ControllerName, Actions = actions };
                            controllers.Add(_controller);
                        }
                    }
                    catch (Exception e)
                    {
                        Common.Log.log(e.ToString());
                        //return VelocityView(e.ToString());
                        return(VelocityView(models));
                    }
                    var _model = new { AddInDomain = domain.Key, Controllers = controllers };
                    models.Add(_model);
                }

                return(VelocityView(models));
                //return Json(models, JsonRequestBehavior.AllowGet);
            }
            return(null);
        }
コード例 #20
0
        private static void thread_CheckForNewVersion()
        {
            string local_version_string = get_installed_version();
            bool _updateavailable = false;
            bool success;

            string remote_version_string = "0.0.0.0";
            string remote_url = "http://code.google.com/p/for-the-record-to-lights-out/";
            string remote_name = "";
            string xml_string = "";

            //
            // The following block checks the latest version given in the remote file
            //

            //
            // Use the first line for production @ googlecode, and the second line for testing @ dropbox
            // Googlecode is not a good place to host. Better use dropbox
            // ** Github is even better!
            //
            //Uri latest_version_xml = new Uri("http://for-the-record-to-lights-out.googlecode.com/files/FTR2LO_Vail_latest_version.xml");
            //Uri latest_version_xml = new Uri("https://dl.dropbox.com/u/11034559/FTR2LightsOut/FTR2LO_Vail_latest_version.xml");
            Uri latest_version_xml = new Uri("https://raw.github.com/jayrockk/ArgusTV-to-Lights-Out/master/ATV2LO_latest_version.xml");
            WebClient client = null;
            try
            {
                client = new WebClient();
                xml_string = client.DownloadString(latest_version_xml);
            }
            catch (Exception)
            {
                //MessageBox.Show("Exception " + ex.ToString());
            }
            finally
            {
                if (client != null)
                {
                    ((IDisposable)client).Dispose();
                }
            }

            XmlReader reader = null;
            try
            {
                reader = XmlReader.Create(new StringReader(xml_string));

                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        switch (reader.Name)
                        {
                            case "name":
                                reader.Read();
                                remote_name = reader.Value;
                                break;
                            case "latest_version":
                                reader.Read();
                                remote_version_string = reader.Value;
                                break;
                            case "url":
                                reader.Read();
                                remote_url = reader.Value;
                                break;
                        }
                    }
                }
            }
            catch (Exception)
            {
                //MessageBox.Show("Exception " + ex.ToString());
            }
            /*finally
            {
                if (client != null)
                    ((IDisposable)client).Dispose();
            }*/

            //
            // compare local and remote version, and set applicationinfrastructure if remote version is newer
            //
            Version local_version;
            success = Version.TryParse(local_version_string, out local_version);

            Version remote_version;
            success = Version.TryParse(remote_version_string, out remote_version);

            if (remote_version.CompareTo(local_version) > 0)
            {
                _updateavailable = true;
            }

            //taken from http://forum.home-server-blog.de/viewtopic.php?f=31&t=13785
            if (_updateavailable)
            {
                var addinMgr = new AddInManager();
                addinMgr.NewAddInVersionAvailable(
                   new Guid("9b190a4e-3657-4770-8939-75a1f65ceaab"), //<Id> from AddIn.xml
                   new Version(remote_version_string),
                   new Uri(remote_url),
                   UpdateClassification.Update);
            }
        }