Exemplo n.º 1
0
 protected virtual void AddExtractedResourceOutput(ResourceConfigItem resource, byte[] code)
 {
     if (resource.Load ?? true)
     {
         Emitter.AddOutputItem(Outputs.ResourcesForHtml, resource.Name, code, TranslatorOutputKind.Resource, location: resource.Output);
     }
 }
Exemplo n.º 2
0
        protected virtual void AddLocaleOutput(EmbeddedResource resource, string outputPath)
        {
            var fileName = resource.Name.Substring(LocalesPrefix.Length);

            if (!string.IsNullOrWhiteSpace(AssemblyInfo.LocalesOutput))
            {
                outputPath = Path.Combine(outputPath, AssemblyInfo.LocalesOutput);
            }

            var content = ReadEmbeddedResource(resource);

            Emitter.AddOutputItem(Outputs.Locales, fileName, new StringBuilder(content), TranslatorOutputKind.Locale, location: outputPath);
        }
Exemplo n.º 3
0
        protected virtual void AddReferencedOutput(string outputPath, AssemblyDefinition assembly, H5ResourceInfo resource, string fileName, Func <string, string> preHandler = null)
        {
            Logger.ZLogTrace("Adding referenced output " + resource.Name);

            var currentAssembly = GetAssemblyNameForResource(assembly);

            var combinedResource = (resource.Parts != null && resource.Parts.Length > 0);

            TranslatorOutputItemContent content = null;

            if (combinedResource)
            {
                Logger.ZLogTrace("The resource contains parts");

                var contentBuffer = new StringBuilder();
                var needNewLine   = false;
                var noConsole     = AssemblyInfo.Console.Enabled != true;
                var fileHelper    = new FileHelper();

                foreach (var part in resource.Parts)
                {
                    Logger.ZLogTrace("Handling part " + part.Assembly + " " + part.ResourceName);

                    bool needPart = true;

                    System.Reflection.AssemblyName partAssemblyName = null;

                    if (part.Assembly != null)
                    {
                        partAssemblyName = GetAssemblyNameFromResource(part.Assembly);

                        if (noConsole &&
                            partAssemblyName.Name == H5_ASSEMBLY &&
                            (string.Compare(part.Name, H5ConsoleName, true) == 0 ||
                             string.Compare(part.Name, fileHelper.GetMinifiedJSFileName(H5ConsoleName), true) == 0)
                            )
                        {
                            // Skip H5 console resource
                            needPart = false;

                            Logger.ZLogTrace("Skipping this part as it is H5 Console and the Console option disabled");
                        }
                        else
                        {
                            var partContentName = GetExtractedResourceName(part.Assembly, part.Name);
                            needPart = ExtractedScripts.Add(partContentName);

                            if (!needPart)
                            {
                                Logger.ZLogTrace("Skipping this part as it is already added");
                            }
                        }
                    }

                    if (needPart)
                    {
                        if (needNewLine)
                        {
                            NewLine(contentBuffer);
                        }

                        string partContent      = null;
                        var    resourcePartName = part.ResourceName;

                        if (partAssemblyName == null)
                        {
                            Logger.ZLogTrace("Using assembly " + assembly.FullName + " to search resource part " + resourcePartName);

                            partContent = ReadEmbeddedResource(assembly, resourcePartName, true, preHandler).Item2;
                        }
                        else
                        {
                            var partAssembly = References
                                               .Where(x => x.Name.Name == partAssemblyName.Name)
                                               .OrderByDescending(x => x.Name.Version)
                                               .FirstOrDefault();

                            if (partAssembly == null)
                            {
                                Logger.ZLogWarning("Did not find assembly for resource part {0} by assembly name {1}. Skipping this item!", resourcePartName, partAssemblyName.Name);
                                continue;
                            }

                            if (partAssembly.Name.Version != partAssemblyName.Version)
                            {
                                Logger.ZLogInformation("Found different assembly version (higher) {0} for resource part {1} from {2}", partAssembly.FullName, resourcePartName, assembly.FullName);
                            }
                            else
                            {
                                Logger.ZLogTrace("Found exact assembly version {0} for resource part {1}.", partAssembly.FullName, resourcePartName);
                            }

                            var resourcePartFound = false;

                            try
                            {
                                partContent       = ReadEmbeddedResource(partAssembly, resourcePartName, true, preHandler).Item2;
                                resourcePartFound = true;
                            }
                            catch (InvalidOperationException)
                            {
                                Logger.ZLogTrace("Did not find resource part {0} in {1}. Will try to find it by short name {2}", resourcePartName, partAssembly.FullName, part.Name);
                            }

                            if (!resourcePartFound)
                            {
                                try
                                {
                                    partContent       = ReadEmbeddedResource(partAssembly, part.Name, true, preHandler).Item2;
                                    resourcePartFound = true;
                                }
                                catch (InvalidOperationException)
                                {
                                    Logger.ZLogTrace("Did not find resource part {0} in {1}", part.Name, partAssembly.FullName);
                                }

                                if (!resourcePartFound)
                                {
                                    if (partAssembly.Name.Version != partAssemblyName.Version)
                                    {
                                        var partAssemblyExactVersion = References
                                                                       .Where(x => x.FullName == partAssemblyName.FullName)
                                                                       .FirstOrDefault();

                                        if (partAssemblyExactVersion != null)
                                        {
                                            Logger.ZLogTrace("Trying to find it in the part's assembly by long name {0}", part.Name);

                                            try
                                            {
                                                partContent       = ReadEmbeddedResource(partAssemblyExactVersion, resourcePartName, true, preHandler).Item2;
                                                resourcePartFound = true;
                                            }
                                            catch (InvalidOperationException)
                                            {
                                                Logger.ZLogTrace("Did not find resource part {0} in {1}. Will try to find it by short name {2}", resourcePartName, partAssemblyExactVersion.FullName, part.Name);
                                            }

                                            if (!resourcePartFound)
                                            {
                                                try
                                                {
                                                    partContent       = ReadEmbeddedResource(partAssemblyExactVersion, part.Name, true, preHandler).Item2;
                                                    resourcePartFound = true;
                                                }
                                                catch (InvalidOperationException)
                                                {
                                                    Logger.ZLogTrace("Did not find resource part {0} in {1}. Will try to find it by the resource's assembly by long name {2} ", part.Name, partAssemblyExactVersion.FullName, resourcePartName);
                                                }
                                            }
                                        }
                                    }

                                    if (!resourcePartFound)
                                    {
                                        partContent       = ReadEmbeddedResource(assembly, resourcePartName, true, preHandler).Item2;
                                        resourcePartFound = true;
                                    }
                                }
                            }
                        }

                        contentBuffer.Append(partContent);

                        needNewLine = true;
                    }
                }

                content = contentBuffer;
            }
            else
            {
                var readAsString = FileHelper.IsJS(fileName) || preHandler != null;

                var notCombinedResource = ReadEmbeddedResource(assembly, resource.Name, readAsString, preHandler);

                if (readAsString)
                {
                    content = notCombinedResource.Item2;
                }
                else
                {
                    content = notCombinedResource.Item1;
                }
            }

            ExtractedScripts.Add(GetExtractedResourceName(currentAssembly, resource.Name));

            Emitter.AddOutputItem(Outputs.References, fileName, content, TranslatorOutputKind.Reference, location: outputPath, assembly: currentAssembly);
        }