Example #1
0
        public static XAssembly XFromReturnUrl(IQueryCollection query, X x)
        {
            XAssembly    xassembly = null;
            XType        xtype     = null;
            StringValues returnUrl;

            query.TryGetValue("ReturnUrl", out returnUrl);
            string url = returnUrl.ToString();

            if (url.EndsWith("/"))
            {
                url = url.TrimEnd('/');
            }
            if (url.StartsWith("/"))
            {
                url = url.TrimStart('/');
            }
            string[] path = url.Split("/");
            if (path.Length > 0)
            {
                string dll = path[0].Replace('-', '.');
                xtype = x.XGetType(dll + "." + dll + "," + dll);
                if (xtype != null)
                {
                    xassembly = xtype.XAssembly;
                }
            }
            return(xassembly);
        }
Example #2
0
        public static string GetDoc(XAssembly asm, IXSymbol symbol)
        {
            var    file = XSharpXMLDocTools.GetXmlDocFile(asm, null);
            string key  = null;

            if (symbol is IXTypeSymbol type)
            {
                key = type.XMLSignature;
            }
            else if (symbol is IXMemberSymbol member)
            {
                key = member.XMLSignature;
            }
            if (file == null)
            {
                return(null);
            }
            if (!string.IsNullOrEmpty(key))
            {
                uint   id  = 0;
                string xml = "";
                return(ThreadHelper.JoinableTaskFactory.Run(async delegate
                {
                    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                    StringBuilder sb = new StringBuilder();

                    var result = file.ParseMemberSignature(key, out id);
                    result = file.GetMemberXML(id, out xml);
                    var summary = GetSummary(xml, out var returns, out var remarks);
                    if (!string.IsNullOrWhiteSpace(summary))
                    {
                        sb.Append(addXml("summary", summary));
                    }
                    if (symbol is IXMemberSymbol member && member.Parameters.Count > 0)
                    {
                        var names = new List <string>();
                        var desc = new List <string>();
                        GetParameterInfo(file, xml, names, desc);
                        if (names.Count > 0 && desc.Count > 0 && names.Count == desc.Count)
                        {
                            for (int i = 0; i < names.Count; i++)
                            {
                                var temp = addXml("param", desc[i]);
                                temp = temp.Replace("<param>", $"<param name=\"{names[i]}\">");
                                sb.Append(temp);
                            }
                        }
                    }
                    if (!String.IsNullOrWhiteSpace(returns))
                    {
                        sb.Append(addXml("returns", returns));
                    }
                    if (!String.IsNullOrWhiteSpace(remarks))
                    {
                        sb.Append(addXml("remarks", remarks));
                    }
                    return sb.ToString();
                }));
Example #3
0
        protected static string XToKey(XAssembly xassembly)
        {
            string name = xassembly.XFullName;

            name = name.Split(",")[0];
            string key = name.Replace('.', '_');

            return(key);
        }
Example #4
0
        public static bool XAuthorize(XType xthis, XAssembly xassembly)
        {
            bool success = false;

            if (xthis.XAssembly.XFullName == xassembly.XFullName)
            {
                success = true;
            }
            return(success);
        }
Example #5
0
        public static IVsXMLMemberIndex GetXmlDocFile(XAssembly assembly, XProject project)
        {
            IVsXMLMemberIndex index = null;
            var location            = assembly.FileName;

            if (!string.IsNullOrWhiteSpace(location))
            {
                if (!_memberIndexes.TryGetValue(location, out index))
                {
                    _XMLMemberIndexService.CreateXMLMemberIndex(location, out index);
                    if (index != null)
                    {
                        _memberIndexes.Add(location, index);
                    }
                }
            }
            if (index == null && project != null)  // Sometimes we get a type in the Microsoft.Net folder and not the reference assemblies folder
            {
                string refasm = "";
                foreach (var asm in project.AssemblyReferences)
                {
                    if (asm.FullName == assembly.FullName)
                    {
                        refasm = asm.FileName;
                        break;
                    }
                    if (!string.IsNullOrEmpty(asm.FileName) && asm.FileName.EndsWith("System.DLL", StringComparison.OrdinalIgnoreCase))
                    {
                        if (assembly.FullName.Contains("mscorlib"))
                        {
                            refasm = Path.Combine(Path.GetDirectoryName(asm.FileName), "mscorlib.dll");
                            break;
                        }
                    }
                }

                if (refasm != location && !String.IsNullOrEmpty(refasm))
                {
                    if (!_memberIndexes.TryGetValue(refasm, out index))
                    {
                        _XMLMemberIndexService.CreateXMLMemberIndex(refasm, out index);
                        if (index != null)
                        {
                            if (!String.IsNullOrWhiteSpace(location))
                            {
                                _memberIndexes.Add(location, index);
                            }
                            _memberIndexes.Add(refasm, index);
                        }
                    }
                }
            }

            return(index);
        }
Example #6
0
 public static string XToString(XAssembly xassembly, IStringLocalizer xstring)
 {
     if (xstring != null)
     {
         string key   = XToKey(xassembly);
         string value = xstring[key];
         if (key != value)
         {
             return(value);
         }
     }
     return(XToString(xassembly.XFullName.Split(',')[0], xstring));
 }
Example #7
0
        public static XAssembly XFromRoute(RouteData route, X x)
        {
            XAssembly xassembly = null;
            string    dll       = (string)route.Values["assembly"];

            dll = dll.Replace('-', '.');
            XType xtype = x.XGetType(dll + "." + dll + "," + dll);

            if (xtype != null)
            {
                xassembly = xtype.XAssembly;
            }
            return(xassembly);
        }
Example #8
0
        public static XType XGetEntryType(XAssembly xassembly)
        {
            XType xtype = null;

            foreach (XType t in xassembly.XExportedTypes)
            {
                if (t.XName == t.XNamespace && t.XName == t.XAssembly.XFullName.Split(',')[0])
                {
                    xtype = t;
                    break;
                }
            }
            return(xtype);
        }
Example #9
0
        public async Task <IViewComponentResult> InvokeAsync(XAssembly xassembly, _XThisCache xthis)
        {
            _XAssemblyModel xmodel = new _XAssemblyModel();
            XType           xtype  = xthis.XThis.XGetType();
            List <XType>    xtypes = _XThisModel.XAuthorize(xtype, xassembly.XExportedTypes);
            Dictionary <string, List <string> > childNSs;
            Dictionary <string, List <XType> >  childTypes;

            XToHiearchyTypes(xtypes, out childNSs, out childTypes);
            xmodel.XNamespaces  = childNSs;
            xmodel.XTypes       = childTypes;
            xmodel.XInformation = _XAssemblyModel.XToAbout(xassembly, xthis.XString);
            xmodel.XString      = xthis.XString;
            return(View(xmodel));
        }
Example #10
0
        public static IStringLocalizer XToCache(XAssembly xassembly, IMemoryCache cache, ISession session, IStringLocalizerFactory factory)
        {
            AssemblyName     name            = new AssemblyName(xassembly.XFullName);
            string           baseName        = string.Format("{0}.Properties.Resources", name.Name);
            IStringLocalizer stringLocalizer = factory.Create(baseName, name.Name);
            _XStringModel    xstring         = new _XStringModel(stringLocalizer);
            string           key             = typeof(_XStringModel).FullName + "#" + xstring.GetHashCode();

            using (ICacheEntry entry = cache.CreateEntry(key))
            {
                entry.SetValue(xstring);
            }
            session.SetString("string", key);
            return(stringLocalizer);
        }
Example #11
0
        public static Dictionary <string, string> XToAbout(XAssembly assemly, IStringLocalizer xstring)
        {
            Dictionary <string, string> about = new Dictionary <string, string>();

            foreach (XAttribute xattr in assemly.XGetCustomAttributes())
            {
                if (xattr.XGetType().XName.StartsWith("Assembly") && xattr.XGetType().XName.EndsWith("Attribute") && xattr.XGetType().XNamespace == "System.Reflection")
                {
                    string attr = xattr.XGetType().XName;
                    attr = attr.Substring("Assembly".Length);
                    attr = attr.Substring(0, attr.Length - "Attribute".Length);
                    XPropertyInfo xprop = xattr.XGetType().XGetProperty(attr);
                    if (xprop != null && xprop.XIsStatic == false)
                    {
                        string v = _XStringModel.XToString(xprop.XGetValue(xattr), xstring);
                        about[attr] = v;
                    }
                }
            }
            return(about);
        }
Example #12
0
        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, XAssemblyAuthorizationRequirement requirement)
        {
            bool success = false;

            if (context.User != null && context.Resource is AuthorizationFilterContext authContext && authContext.ModelState.IsValid)
            {
                XAssembly xassembly = _XAssemblyModel.XFromRoute(authContext.RouteData, x);
                if (xassembly != null)
                {
                    _XThisCache xthis = _XThisModel.XAuthenticate(context.User, cache, authContext.HttpContext.Session);
                    if (xthis != null)
                    {
                        success = _XThisModel.XAuthorize(xthis.XThis.XGetType(), xassembly);
                    }
                }
            }
            if (success)
            {
                context.Succeed(requirement);
            }
            return(Task.CompletedTask);
        }
Example #13
0
 public AssemblyEntry(XAssembly metadata)
 {
     this.metadata = metadata;
     this.path     = this.metadata.Path;
     this.share    = this.metadata.Share;
 }
Example #14
0
        internal static XFile CreateFileForSystemType(XPETypeSymbol petype, XPESymbol element)
        {
            asmName = petype.Assembly;
            bool mustCreate = false;

            if (Semaphore == null)
            {
                // we create a semaphore file in the workfolder to make sure that if 2 copies of VS are running
                // that we will not delete the files from the other copy
                var tempFolder = Path.GetTempPath();
                tempFolder = Path.Combine(tempFolder, folderName);
                var semFile = Path.Combine(tempFolder, semName);
                // clean up files from previous run
                if (Directory.Exists(tempFolder))
                {
                    if (File.Exists(semFile))
                    {
                        try
                        {
                            File.Delete(semFile);
                            DeleteFolderRecursively(new DirectoryInfo(tempFolder));
                        }
                        catch
                        {
                            // if deletion fails, other copy of VS is running, so do not delete the folder
                        }
                    }
                }
                if (!Directory.Exists(tempFolder))
                {
                    Directory.CreateDirectory(tempFolder);
                }
                WorkFolder = tempFolder;
                if (!File.Exists(semFile))
                {
                    Semaphore = File.Create(semFile);
                }
            }
            var ns     = petype.Namespace + "." + petype.Assembly.Version;
            var name   = petype.Name;
            var nspath = Path.Combine(WorkFolder, ns);

            if (!Directory.Exists(nspath))
            {
                Directory.CreateDirectory(nspath);
            }
            var temp = Path.Combine(nspath, petype.Name) + ".prg";

            mustCreate = !File.Exists(temp);
            if (mustCreate)
            {
                VS.StatusBar.ShowMessageAsync("Generating reference source for " + petype.FullName).FireAndForget();
                VS.StatusBar.StartAnimationAsync(StatusAnimation.General).FireAndForget();
                var aLines = XClassCreator.Create(petype, LookupXml);
                File.WriteAllLines(temp, aLines, System.Text.Encoding.UTF8);
                File.SetAttributes(temp, FileAttributes.ReadOnly);
                VS.StatusBar.ClearAsync().FireAndForget();
                VS.StatusBar.EndAnimationAsync(StatusAnimation.General).FireAndForget();
            }
            var xFile = XSolution.AddOrphan(temp);

            return(xFile);
        }