public ActionResult AddAnotherModule()
        {
            var desktop = this.GetDesktop();

            desktop.RemoveModule("add1-module");
            DesktopModule m = new DesktopModule
            {
                ModuleID = "dyn-mod",
                Shortcut = new DesktopShortcut
                {
                    Name = "Dynamic Module"
                },

                Launcher = new Ext.Net.MenuItem
                {
                    Text = "Dynamic module"
                },

                Window =
                {
                    new Window
                    {
                        Title           = "Dynamic Window",
                        Width           = 300,
                        Height          = 300,
                        DefaultRenderTo = Ext.Net.DefaultRenderTo.Form,
                        Icon            = Icon.ApplicationAdd
                    }
                },

                AutoRun = true
            };

            desktop.AddModule(m);

            return(this.Direct());
        }
Ejemplo n.º 2
0
        private static void PrintILToNativeOffsetAlternative(ClrMethod method, IList <string> lines)
        {
            DesktopModule module = (DesktopModule)@method.Type.Module;

            if (!module.IsPdbLoaded)
            {
                // Have to load the Pdb, if it's not already loaded!!
                string val = module.TryDownloadPdb(null);
                if (val != null)
                {
                    module.LoadPdb(val);
                }
            }

            foreach (var location in module.GetSourceLocationsForMethod(@method.MetadataToken))
            {
                ILOffsetSourceLocation ILLocation = location;
                var ilMaps = @method.ILOffsetMap.Where(il => il.ILOffset == ILLocation.ILOffset);
                Console.WriteLine("{0:X8} -> {1}:{2}",
                                  location.ILOffset,
                                  Path.GetFileName(location.SourceLocation.FilePath),
                                  location.SourceLocation.LineNumber);
                Console.WriteLine("  " + String.Join("\n  ",
                                                     ilMaps.Select(
                                                         ilMap =>
                                                         String.Format("[{0:X8}-{1:X8} ({2:X8}-{3:X8})] ILOffset: {4:X2}",
                                                                       ilMap.StartAddress - @method.NativeCode,
                                                                       ilMap.EndAddress - @method.NativeCode,
                                                                       ilMap.StartAddress, ilMap.EndAddress, ilMap.ILOffset))));
                var indent = 7;
                Console.WriteLine("{0,6}:{1}", location.SourceLocation.LineNumber, lines[location.SourceLocation.LineNumber - 1]);
                Console.WriteLine(new string(' ', location.SourceLocation.ColStart - 1 + indent) +
                                  new string('*', location.SourceLocation.ColEnd - location.SourceLocation.ColStart));
            }
            Console.WriteLine();
        }
Ejemplo n.º 3
0
        private void RemoveObjects()
        {
            try
            {
                string loggedUser = Session["username"] as string;
#if DEBUG
                if (loggedUser == "DEVELOPER")
                {
                    return;
                }
#endif

                UsuarioLogic usuariologic = new UsuarioLogic();

                List <COCASJOL.DATAACCESS.privilegio> privs = usuariologic.GetPrivilegiosDeUsuario(loggedUser);

                XmlDocument doc = new XmlDocument();
                doc.Load(Server.MapPath(System.Configuration.ConfigurationManager.AppSettings.Get("privilegesXML")));

                XmlNodeList nodes = doc.SelectNodes("privilegios/privilege");

                DesktopShortcuts            listDS = this.MyDesktop.Shortcuts;
                DesktopModulesCollection    listDM = this.MyDesktop.Modules;
                ItemsCollection <Component> listIC = this.MyDesktop.StartMenu.Items;

                if (privs.Count == 0)
                {
                    listDS.Clear();
                    listDM.Clear();
                    listIC.Clear();
                }
                else
                {
                    foreach (XmlNode node in nodes)
                    {
                        XmlNode keyNode      = node.SelectSingleNode("key");
                        XmlNode moduleNode   = node.SelectSingleNode("module");
                        XmlNode shortcutNode = node.SelectSingleNode("shortcut");
                        XmlNode menuitemNode = node.SelectSingleNode("menuitem");

                        string key      = keyNode.InnerText.Replace("\t", "").Replace("\r\n", "").Replace("\n", "").Trim();
                        string module   = moduleNode.InnerText.Replace("\t", "").Replace("\r\n", "").Replace("\n", "").Trim();
                        string shortcut = shortcutNode.InnerText.Replace("\t", "").Replace("\r\n", "").Replace("\n", "").Trim();
                        string menuitem = menuitemNode.InnerText.Replace("\t", "").Replace("\r\n", "").Replace("\n", "").Trim();

                        var query = from p in privs.AsParallel()
                                    where p.PRIV_LLAVE == key
                                    select p;

                        if (query.Count() == 0)
                        {
                            for (int x = 0; x < listDS.Count; x++)
                            {
                                DesktopShortcut ds = listDS.ElementAt(x);

                                if (ds.ShortcutID == shortcut)
                                {
                                    listDS.Remove(ds);
                                }
                            }

                            for (int x = 0; x < listDM.Count; x++)
                            {
                                DesktopModule dm = listDM.ElementAt(x);

                                if (dm.ModuleID == module)
                                {
                                    listDM.Remove(dm);
                                }
                            }

                            for (int x = 0; x < listIC.Count; x++)
                            {
                                Component item = listIC.ElementAt(x);

                                if (item is Ext.Net.MenuItem)
                                {
                                    Ext.Net.MenuItem menuItem = (Ext.Net.MenuItem)item;

                                    if (menuItem.Menu.Count > 0)
                                    {
                                        MenuCollection menu = menuItem.Menu;

                                        for (int y = 0; y < menu.Primary.Items.Count; y++)
                                        {
                                            Component itm = menu.Primary.Items.ElementAt(y);
                                            if (itm.ID == menuitem)
                                            {
                                                menu.Primary.Items.Remove(itm);
                                            }
                                        }
                                    }

                                    if (menuItem.Menu.Primary.Items.Count == 0)
                                    {
                                        listIC.Remove(menuItem);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Fatal("Error fatal al remover objetos sin acceso.", ex);
                throw;
            }
        }
        /// <summary>
        /// Code from http://stackoverflow.com/questions/2057781/is-there-a-way-to-get-the-stacktraces-for-all-threads-in-c-like-java-lang-thre/24315960#24315960
        /// also see http://stackoverflow.com/questions/31633541/clrmd-throws-exception-when-creating-runtime/31745689#31745689
        /// </summary>
        public void PrintCodeForMethod(Benchmark benchmark, Process process, IBenchmarkLogger logger, bool printAssembly, bool printIL, bool printDiagnostics)
        {
            this.process = process;
            this.logger  = logger;

            //Method name format: "BenchmarkDotNet.Samples.Infra.RunFast()" (NOTE: WITHOUT the return type)
            var methodInfo = benchmark.Target.Method;

            fullTypeName = methodInfo.DeclaringType.FullName;

            var methodParams = string.Join(", ", methodInfo.GetParameters().Select(p => p.ParameterType.FullName));

            fullMethodName = $"{fullTypeName}.{methodInfo.Name}({methodParams})";

            logger?.WriteLine($"\nPrinting Code for Method: {fullMethodName}");
            logger?.WriteLine($"\nPrintAssembly={printAssembly}, PrintIL={printIL}");
            logger?.WriteLine($"Attaching to process {Path.GetFileName(process.MainModule.FileName)}, Pid={process.Id}");
            logger?.WriteLine($"Path {process.MainModule.FileName}");
            using (var dataTarget = DataTarget.AttachToProcess(process.Id, 5000, AttachFlag.NonInvasive))
            {
                var runtime = SetupClrRuntime(dataTarget);
                if (printDiagnostics)
                {
                    PrintRuntimeDiagnosticInfo(dataTarget, runtime);
                }

                if (printAssembly == false && printIL == false)
                {
                    return;
                }

                ClrType       @class  = runtime.GetHeap().GetTypeByName(fullTypeName);
                ClrMethod     @method = @class.Methods.Single(m => m.GetFullSignature() == fullMethodName);
                DesktopModule module  = (DesktopModule)@method.Type.Module;
                if (!module.IsPdbLoaded)
                {
                    string pdbLocation = module.TryDownloadPdb(null);
                    if (pdbLocation != null)
                    {
                        module.LoadPdb(pdbLocation);
                    }
                }

                logger?.WriteLine($"Module: {Path.GetFileName(module.Name)}");
                logger?.WriteLine($"Type: {method.Type.Name}");
                logger?.WriteLine($"Method: {method.Name}");

                // TODO work out why this returns locations inside OTHER methods, it's like it doesn't have an upper bound and just keeps going!?
                var ilOffsetLocations = module.GetSourceLocationsForMethod(@method.MetadataToken);

                string   filePath = null;
                string[] lines    = null;
                logger?.WriteLine("");
                for (int i = 0; i < ilOffsetLocations.Count; i++)
                {
                    var location = ilOffsetLocations[i];
                    var ilMaps   = @method.ILOffsetMap.Where(il => il.ILOffset == location.ILOffset).ToList();
                    if (ilMaps.Any() == false)
                    {
                        continue;
                    }

                    if (lines == null || location.SourceLocation.FilePath != filePath)
                    {
                        filePath = location.SourceLocation.FilePath;
                        lines    = File.ReadAllLines(filePath);
                        logger?.WriteLine($"Parsing file {Path.GetFileName(location.SourceLocation.FilePath)}");
                    }

                    PrintLocationAndILMapInfo(@method, location, ilMaps);
                    PrintSourceCode(lines, location);

                    if (printAssembly)
                    {
                        var debugControl = dataTarget.DebuggerInterface as IDebugControl;
                        PrintAssemblyCode(@method, ilMaps, runtime, debugControl);
                    }
                }
            }
        }
        public ActionResult AddAnotherModule()
        {
            var desktop = this.GetDesktop();
            desktop.RemoveModule("add1-module");
            DesktopModule m = new DesktopModule
            {
                ModuleID = "dyn-mod",
                Shortcut = new DesktopShortcut
                {
                    Name = "Dynamic Module"
                },

                Launcher = new Ext.Net.MenuItem
                {
                    Text = "Dynamic module"
                },

                Window =
                {
                    new Window
                    {
                        Title = "Dynamic Window",
                        Width = 300,
                        Height = 300,
                        DefaultRenderTo = Ext.Net.DefaultRenderTo.Form,
                        Icon = Icon.ApplicationAdd
                    }
                },

                AutoRun = true
            };

            desktop.AddModule(m);

            return this.Direct();
        }
Ejemplo n.º 6
0
        public ActionResult NewFolder(string FolderName, string type)
        {
            string FolderIcon = "FolderDefaultIcon";

            switch (type)
            {
            case "Default":
                FolderIcon = "FolderDefaultIcon";
                break;

            case "Shared":
                FolderIcon = "FolderSharedIcon";
                break;

            case "Course":
                FolderIcon = "FolderCourseIcon";
                break;

            case "Favourite":
                FolderIcon = "FolderFavouriteIcon";
                break;

            case "Images":
                FolderIcon = "FolderImagesIcon";
                break;

            case "Videos":
                FolderIcon = "FolderVideosIcon";
                break;

            case "MyPC":
                FolderIcon = "FolderVirtualUserHDDIcon";
                break;
            }
            AjaxResult r       = new AjaxResult();
            Desktop    desktop = X.GetCmp <Desktop>("Desktop1");
            var        folder  = new DesktopModule
            {
                ModuleID = FolderName,
                Shortcut = new DesktopShortcut
                {
                    Name    = FolderName,
                    IconCls = FolderIcon,
                    X       = "150",
                    Y       = "30"
                },
                //Launcher = new Ext.Net.MenuItem
                //{
                //    Text = "Dynamic module"
                //},
                Window =
                {
                    new Window
                    {
                        Title           = FolderName,
                        Width           = 500,
                        Height          = 500,
                        DefaultRenderTo = Ext.Net.DefaultRenderTo.Form,
                        Icon            = Icon.ApplicationAdd
                    }
                },
            };

            desktop.AddModule(folder);
            return(r);
        }