void RegenerateEmbeddedResource(ModuleDef module)
        {
            EnsureChildrenFiltered();
            var outStream = new MemoryStream();
            var resources = new ResourceElementSet();

            foreach (ResourceElementTreeNode child in Children)
            {
                resources.Add(child.ResourceElement);
            }
            ResourceWriter.Write(module, outStream, resources);
            this.r = new EmbeddedResource(r.Name, outStream.ToArray(), r.Attributes);
        }
Exemple #2
0
        void RegenerateEmbeddedResource(ModuleDef module)
        {
            TreeNode.EnsureChildrenLoaded();
            var outStream = new MemoryStream();
            var resources = new ResourceElementSet();

            foreach (ResourceElementNode child in TreeNode.DataChildren)
            {
                resources.Add(child.ResourceElement);
            }
            ResourceWriter.Write(module, outStream, resources);
            Resource = new EmbeddedResource(Resource.Name, outStream.ToArray(), Resource.Attributes);
        }
        public byte[] Convert()
        {
            var resources = new ResourceElementSet();

            foreach (var info in infos)
            {
                resources.Add(Convert(info));
            }

            var memStream = new MemoryStream();

            ResourceWriter.Write(module, memStream, resources);
            return(memStream.ToArray());
        }
Exemple #4
0
        public void Save(string path)
        {
            //write the resources to the module
            using (var ms = new MemoryStream()) {
                ResourceWriter.Write(_module, ms, _elementSet);
                _module.Resources[0] = new EmbeddedResource(ResourceName, ms.ToArray());
            }

            //save module
            _module.Write(path);

            //TODO: something proper
            MessageBox.Show("Written!");
        }
        public void WritesResourceToDisk()
        {
            string   resourceName = "licence";
            Assembly assembly     = Assembly.GetExecutingAssembly();

            string[] resources = assembly.GetManifestResourceNames();
            Assert.IsFalse(resources.Length == 0);
            Assert.IsTrue(new List <string>(resources).Contains(resourceName));

            string output = Path.Combine(Path.GetTempPath(), "licence.txt");

            output = pathChecker.GetUnusedFilePath(output);

            Assert.IsFalse(File.Exists(output));
            rw.Write(resourceName, assembly, output);
            Assert.IsTrue(File.Exists(output));

            string contents = File.ReadAllText(output);

            Assert.IsTrue(contents.StartsWith(" GNU GENERAL PUBLIC LICENSE"));
            Assert.IsTrue(contents.EndsWith("<http://www.gnu.org/philosophy/why-not-lgpl.html>."));

            File.Delete(output);
        }
        void RegenerateEmbeddedResource(ModuleDef module)
        {
            TreeNode.EnsureChildrenLoaded();
            var outStream = new MemoryStream();
            var resources = new ResourceElementSet();

            foreach (DocumentTreeNodeData child in TreeNode.DataChildren)
            {
                var resourceElement = ResourceElementNode.GetResourceElement(child);
                if (resourceElement is null)
                {
                    throw new InvalidOperationException();
                }
                resources.Add(resourceElement);
            }

            ResourceWriter.Write(module, outStream, resources);
            Resource = new EmbeddedResource(Resource.Name, outStream.ToArray(), Resource.Attributes);
        }
        internal override void Write(ResourceWriter writer)
        {
            if (RawData != null)
            {
                writer.Write(RawData);
                return;
            }

            if (Version > 0x1104950)
            {
                writer.WriteInt32(( int )Flags);
            }

            writer.WriteResourceList(Animations);
            writer.WriteResourceList(BlendAnimations);

            if (Flags.HasFlag(AnimationPackFlags.Flag4))
            {
                writer.WriteResource(ExtraData);
            }
        }
Exemple #8
0
        protected override void WriteCore(ResourceWriter writer)
        {
            if (RawData != null)
            {
                writer.Write(RawData);
                return;
            }

            if (Version > 0x1104950)
            {
                writer.WriteInt32(( int )Flags);
            }

            writer.WriteResourceList(Animations);
            writer.WriteResourceList(BlendAnimations);

            if (Flags.HasFlag(AnimationPackFlags.Bit2))
            {
                writer.WriteResource(Bit29Data);
            }
        }
        public static void Build(string fullPath, string outputPath)
        {
            var mod = new ModuleDefUser(ModuleName, null, ModuleDefMD.Load(typeof(void).Module).Assembly.ToAssemblyRef())
            {
                Kind = ModuleKind.Dll
            };

            var ass = new AssemblyDefUser(AssemblyName, Version.Parse("1.0.0.0"));

            ass.Modules.Add(mod);

            //get resourceset
            var set = new ResourceElementSet();

            foreach (ResourceElement re in FileFormatHelper.GetResourceElements(fullPath))
            {
                set.Add(re);
            }

            //write set to byte[] and add to module resources
            using (var ms = new MemoryStream()) {
                ResourceWriter.Write(mod, ms, set);
                mod.Resources.Add(new EmbeddedResource(Resources, ms.ToArray(), ManifestResourceAttributes.Private));
            }

            //create store type
            TypeDef store = new TypeDefUser(Namespace, ResourceStore, mod.CorLibTypes.Object.TypeDefOrRef)
            {
                Attributes = TypeAttributes.Public | TypeAttributes.BeforeFieldInit
            };

            //add the type to the module
            mod.Types.Add(store);

            //add code
            BuildStore(mod, ref store);

            //write module
            mod.Write(Path.Combine(outputPath, "osu!ui-rebuilt.dll"));
        }
        void Rename(TypeDef type, EmbeddedResource resource)
        {
            newNames.Clear();
            resource.Data.Position = 0;
            var resourceSet = ResourceReader.Read(module, resource.Data);
            var renamed     = new List <RenameInfo>();

            foreach (var elem in resourceSet.ResourceElements)
            {
                if (nameChecker.IsValidResourceKeyName(elem.Name))
                {
                    newNames.Add(elem.Name, true);
                    continue;
                }

                renamed.Add(new RenameInfo(elem, GetNewName(elem)));
            }

            if (renamed.Count == 0)
            {
                return;
            }

            Rename(type, renamed);

            var outStream = new MemoryStream();

            ResourceWriter.Write(module, outStream, resourceSet);
            var newResource   = new EmbeddedResource(resource.Name, outStream.ToArray(), resource.Attributes);
            int resourceIndex = module.Resources.IndexOf(resource);

            if (resourceIndex < 0)
            {
                throw new ApplicationException("Could not find index of resource");
            }
            module.Resources[resourceIndex] = newResource;
        }
Exemple #11
0
 internal void Write(ResourceWriter writer)
 {
     writer.Write(( int )Type);
     writer.WriteResource(GetValue());
 }
        private void Import(BinaryReader reader, ImportFile file)
        {
            var targetDir = Path.ChangeExtension(file.TargetFilename, null);

            reader.ReadStruct <Header>(out var header);

            if (header.depth != 32)
            {
                throw new ImportException($"{header.depth} bit not supported");
            }

            var tags    = new List <Tag>();
            var frames  = new List <Frame>();
            var events  = new List <string>();
            var isEvent = false;
            var layers  = new List <Layer>();

            for (int i = 0; i < header.frames; i++)
            {
                reader.ReadStruct <FrameHeader>(out var frame);

                byte[] celData = null;
                events.Clear();

                for (int j = 0; j < frame.chunks; j++)
                {
                    var    size      = reader.ReadUInt32();
                    var    type      = reader.ReadUInt16();
                    var    next      = reader.BaseStream.Position + size - 6;
                    string layerName = null;

                    switch (type)
                    {
                    // Old palette chunk
                    case 0x0011:
                    case 0x0004:
                        break;

                    // Layer chunk
                    case 0x2004:
                    {
                        var flags           = reader.ReadUInt16();
                        var layerType       = reader.ReadUInt16();
                        var layerChildLevel = reader.ReadUInt16();
                        reader.BaseStream.Position += 4;
                        var blendMode = reader.ReadUInt16();
                        if (blendMode != 0)
                        {
                            throw new ImportException("Blend modes other than normal are not supported at this time");
                        }
                        var opacity = reader.ReadByte();
                        reader.BaseStream.Position += 3;
                        layerName = System.Text.Encoding.UTF8.GetString(reader.ReadBytes(reader.ReadUInt16()));

                        if (layerChildLevel == 0 && layerName.ToLower() == "events")
                        {
                            isEvent = true;
                        }
                        else if (isEvent && layerChildLevel == 0)
                        {
                            isEvent = false;
                        }

                        layers.Add(new Layer {
                                Name = layerName, IsEvent = isEvent
                            });

                        break;
                    }

                    // Cel chunk
                    case 0x2005:
                    {
                        var layerIndex = reader.ReadUInt16();
                        var x          = reader.ReadInt16();
                        var y          = reader.ReadInt16();
                        var opacity    = reader.ReadByte();
                        var celType    = reader.ReadUInt16();
                        reader.BaseStream.Position += 7;

                        if (layers[layerIndex].IsEvent)
                        {
                            events.Add(layers[layerIndex].Name.ToLower());
                            break;
                        }

                        if (opacity != 255)
                        {
                            throw new ImportException("opacity not implemented");
                        }

//                            if (layerIndex != 0)
//                              throw new ImportException("layers not implemented");

                        switch (celType)
                        {
                        case 0: throw new ImportException("raw cels are not supported");

                        case 1: throw new ImportException("linked cels are not supported");

                        case 2:
                        {
                            var w = reader.ReadUInt16();
                            var h = reader.ReadUInt16();

                            reader.ReadUInt16();

                            using (var deflate = new DeflateStream(reader.BaseStream, CompressionMode.Decompress, true))
                            {
                                try
                                {
                                    var data = new byte[header.width * header.height * 4];
                                    for (int yy = 0; yy < h; yy++)
                                    {
                                        deflate.Read(data, x * 4 + (yy + y) * header.width * 4, w * 4);
                                    }

                                    if (celData == null)
                                    {
                                        celData = data;
                                    }
                                    else
                                    {
                                        MergeFrame(data, celData);
                                    }
                                }
                                catch
                                {
                                    throw new ImportException("cel data corrupt");
                                }
                            }

                            break;
                        }
                        }
                        break;
                    }

                    // Cel extra chunk
                    case 0x2006:
                        break;

                    // Color profile chunk
                    case 0x2007:
                        break;

                    // Mask chunk
                    case 0x2016:
                        break;

                    // Path chunk
                    case 0x2017:
                        break;

                    // Frame Tags Chunk
                    case 0x2018:
                    {
                        var tagCount = reader.ReadUInt16();
                        reader.BaseStream.Position += 8;

                        for (var tagIndex = 0; tagIndex < tagCount; tagIndex++)
                        {
                            var fromFrame = reader.ReadUInt16();
                            var toFrame   = reader.ReadUInt16();
                            var loopDir   = reader.ReadByte();

                            if (loopDir == 2)
                            {
                                throw new ImportException("Ping-Pong loop direction not implemented");
                            }

                            reader.BaseStream.Position += 12;

                            tags.Add(new Tag {
                                    from    = fromFrame,
                                    to      = toFrame,
                                    name    = System.Text.Encoding.UTF8.GetString(reader.ReadBytes(reader.ReadUInt16())),
                                    loopdir = loopDir
                                });
                        }
                        break;
                    }
                    }

                    reader.BaseStream.Position = next;
                }

                // Add the frame
                frames.Add(new Frame {
                    duration = frame.duration / 1000.0f,
                    name     = $"{file.Name}/{i}",
                    data     = celData,
                    events   = events.Count > 0 ? events.ToArray() : null
                });
            }

            if (frames.Count == 1 && tags.Count == 0)
            {
                if (Directory.Exists(targetDir))
                {
                    Directory.Delete(targetDir, true);
                }

                using (var writer = new ResourceWriter(File.Create(file.TargetFilename), typeof(Image)))
                {
                    writer.Write((short)header.width);
                    writer.Write((short)header.height);
                    writer.Write((byte)PixelFormat.R8G8B8A8);
                    writer.Write(Thickness.Empty);
                    writer.Write(frames[0].data, 0, frames[0].data.Length);
                }
            }
            else
            {
                if (File.Exists(file.TargetFilename))
                {
                    File.Delete(file.TargetFilename);
                }

                Directory.CreateDirectory(targetDir);

                for (var frameIndex = 0; frameIndex < frames.Count; frameIndex++)
                {
                    using (var writer = new ResourceWriter(File.Create(Path.Combine(file.TargetDirectory, $"{frames[frameIndex].name}.resource")), typeof(Image)))
                    {
                        writer.Write((short)header.width);
                        writer.Write((short)header.height);
                        writer.Write((byte)PixelFormat.R8G8B8A8);
                        writer.Write(Thickness.Empty);
                        writer.Write(frames[frameIndex].data, 0, frames[frameIndex].data.Length);
                    }
                }

                // If the file has tags then write each tag as an ImageAnimation in "name/Tag"
                foreach (var tag in tags)
                {
                    using (var writer = new ResourceWriter(File.Create(Path.Combine(Path.ChangeExtension(file.TargetFilename, null), $"{tag.name}.resource")), typeof(ImageAnimation)))
                    {
                        writer.Write(tag.to - tag.from + 1);
                        if (tag.loopdir == 0)
                        {
                            for (int i = tag.from; i <= tag.to; i++)
                            {
                                writer.Write(frames[i].name);
                                writer.Write(frames[i].duration);

                                if (frames[i].events != null)
                                {
                                    writer.Write((byte)frames[i].events.Length);
                                    for (int e = 0; e < frames[i].events.Length; e++)
                                    {
                                        writer.Write(frames[i].events[e]);
                                    }
                                }
                                else
                                {
                                    writer.Write((byte)0);
                                }
                            }
                        }
                        else
                        {
                            for (int i = tag.to; i >= tag.from; i--)
                            {
                                writer.Write(frames[i].name);
                                writer.Write(frames[i].duration);

                                if (frames[i].events != null)
                                {
                                    writer.Write((byte)frames[i].events.Length);
                                    for (int e = 0; e < frames[i].events.Length; e++)
                                    {
                                        writer.Write(frames[i].events[e]);
                                    }
                                }
                                else
                                {
                                    writer.Write((byte)0);
                                }
                            }
                        }
                    }
                }

                Directory.SetLastWriteTime(Path.ChangeExtension(file.TargetFilename, null), File.GetLastWriteTime(file.Filename));
            }
        }
        private List <GenerateResult> GenerateInternal(TemplateOption option, List <Table> tables, CodeGenerateHandler handler)
        {
            var result     = new List <GenerateResult>();
            var references = new List <Reference>();

            foreach (var table in tables)
            {
                references.AddRange(table.ForeignKeys);
            }

            var tparts = option.Partitions.Where(s => s.Loop == PartitionLoop.Tables).ToList();
            var nparts = option.Partitions.Where(s => s.Loop == PartitionLoop.None).ToList();
            var count  = tparts.Count * tables.Count + nparts.Count;
            var index  = 0;

            var calc = new Func <int, int>(i =>
            {
                return((int)((i / (count * 1.0)) * 100));
            });

            InitializeNamespaces();

            foreach (var table in tables)
            {
                var model = new { Tables = tables, References = references, Current = table, Profile = option.Profile };
                if (Processor.IsCancellationRequested())
                {
                    break;
                }

                foreach (var part in tparts)
                {
                    if (Processor.IsCancellationRequested())
                    {
                        break;
                    }

                    if (handler != null)
                    {
                        handler(table.Name, calc(++index));
                    }

                    var info    = new FileInfo(part.FilePath);
                    var content = ReplaceIncludeTemplate(info.DirectoryName, part.Content);
                    var code    = RazorEngine.Razor.Parse(content, model);
                    var r       = ProcessPartitionCodeFile(part, table, option.Profile, option, code);
                    if (r != null)
                    {
                        result.Add(r);
                    }
                }
            }

            foreach (var part in nparts)
            {
                if (Processor.IsCancellationRequested())
                {
                    break;
                }

                if (handler != null)
                {
                    handler("全局", calc(++index));
                }

                var model   = new { Tables = tables, References = references, Profile = option.Profile };
                var info    = new FileInfo(part.FilePath);
                var content = ReplaceIncludeTemplate(info.DirectoryName, part.Content);
                var code    = RazorEngine.Razor.Parse(content, model);
                var r       = ProcessPartitionCodeFile(part, null, option.Profile, option, code);
                if (r != null)
                {
                    result.Add(r);
                }
            }

            if (option.WriteToDisk)
            {
                ResourceWriter.Write(option.Template, option.OutputDirectory);
            }

            return(result);
        }
        public static void Main()
        {
            try
            {
                ResourceWriter rw = new ResourceWriter("Microsoft.VSDesigner.WMI.Res.resources");

                rw.AddResource("Microsoft.VSDesigner.WMI.closed_fol.bmp", System.Drawing.Image.FromFile("c:\\lab\\SE Nodes\\art\\closed_fol.bmp"));
                rw.AddResource("Microsoft.VSDesigner.WMI.open_fol.bmp", System.Drawing.Image.FromFile("c:\\lab\\SE Nodes\\art\\open_fol.bmp"));
                rw.AddResource("Microsoft.VSDesigner.WMI.class.bmp", Image.FromFile("c:\\lab\\SE Nodes\\art\\class.bmp"));
                rw.AddResource("Microsoft.VSDesigner.WMI.classassoc.bmp", Image.FromFile("c:\\lab\\SE Nodes\\art\\classassoc.bmp"));
                rw.AddResource("Microsoft.VSDesigner.WMI.abstr1.bmp", Image.FromFile("c:\\lab\\SE Nodes\\art\\abstr1.bmp"));
                rw.AddResource("Microsoft.VSDesigner.WMI.abstr2.bmp", Image.FromFile("c:\\lab\\SE Nodes\\art\\abstr2.bmp"));
                rw.AddResource("Microsoft.VSDesigner.WMI.abstr_assoc1.bmp", Image.FromFile("c:\\lab\\SE Nodes\\art\\abstr_assoc1.bmp"));
                rw.AddResource("Microsoft.VSDesigner.WMI.abstr_assoc2.bmp", Image.FromFile("c:\\lab\\SE Nodes\\art\\abstr_assoc2.bmp"));

                rw.AddResource("Microsoft.VSDesigner.WMI.ObjectViewer.bmp", Image.FromFile("c:\\lab\\SE Nodes\\art\\ObjectViewer.bmp"));
                rw.AddResource("Microsoft.VSDesigner.WMI.Events.bmp", Image.FromFile("c:\\lab\\SE Nodes\\art\\Events.bmp"));
                rw.AddResource("Microsoft.VSDesigner.WMI.EventsNew.bmp", Image.FromFile("c:\\lab\\SE Nodes\\art\\EventsNew.bmp"));
                rw.AddResource("Microsoft.VSDesigner.WMI.inst.bmp", Image.FromFile("c:\\lab\\SE Nodes\\art\\inst.bmp"));
                rw.AddResource("Microsoft.VSDesigner.WMI.ObjectViewerNew.bmp", Image.FromFile("c:\\lab\\SE Nodes\\art\\ObjectViewerNew.bmp"));

                rw.AddResource("Microsoft.VSDesigner.WMI.Start.ico", Image.FromFile("c:\\lab\\SE Nodes\\art\\Start.ico"));
                rw.AddResource("Microsoft.VSDesigner.WMI.Stop.ico", Image.FromFile("c:\\lab\\SE Nodes\\art\\Stop.ico"));
                rw.AddResource("Microsoft.VSDesigner.WMI.ErrorNode.ico", Image.FromFile("c:\\lab\\SE Nodes\\art\\ErrorNode.ico"));

                //generic
                rw.AddResource("WMISE_Cancel", "Cancel");
                rw.AddResource("WMISE_Exception", "Exception: {0}\n\rTrace: {1}");
                rw.AddResource("WMISE_SelectClassBtn", "Sele&ct class...");
                rw.AddResource("WMISE_SubscribeBtn", "Su&bscribe");
                rw.AddResource("WMISE_AddEventFilterCM", "&Add event filter...");
                rw.AddResource("WMISE_AddEventFilterLabel", "<Add event filter...>");
                rw.AddResource("WMISE_Seconds", "seconds");
                rw.AddResource("WMISE_OK", "OK");
                rw.AddResource("WMISE_NoDescr", "No description");
                rw.AddResource("WMISE_InvalidPath", "Invalid Object Path: {0}");

                //AssocGroupComponent.cs
                rw.AddResource("WMISE_AssocGroupClassPropertyDescr", "The name of the class to which the child nodes belong");
                rw.AddResource("WMISE_AssocGroupRolePropertyDescr", "The role of the child nodes in the relationship");
                rw.AddResource("WMISE_AssocGroupAssocPropertyDescr", "The name of the relationship class");

                //ExecuteMethodDialog.cs
                rw.AddResource("WMISE_ExecMethodDlg_Title", "Execute Method {0}.{1}");
                rw.AddResource("WMISE_ExecMethodDlg_ServerName", "Server: {0}");
                rw.AddResource("WMISE_ExecMethodDlg_NoInputParams", "No Input Parameters");
                rw.AddResource("WMISE_ExecMethodDlg_Execute", "Execute");
                rw.AddResource("WMISE_ExecMethodDlg_InputParameters", "Input Parameters");
                rw.AddResource("WMISE_ExecMethodDlg_OutputParameters", "Output Parameters");


                //ExtrinsicEventQueryDialog.cs
                rw.AddResource("WMISE_ExtrEventQueryDlg_Title", "Build Management Event Query");
                rw.AddResource("WMISE_ExtrEventQueryDlg_EventClassLbl", "Event class: ");

                //ExtrinsicEventQueryNode.cs
                rw.AddResource("WMISE_EventQueryStop", "Sto&p");
                rw.AddResource("WMISE_EventQueryStart", "S&tart");
                rw.AddResource("WMISE_EventQueryPurge", "P&urge");

                //ExtrinsicEventNode.cs
                rw.AddResource("WMISE_ExtrinsicEventNodeLbl", "Management Events");

                //IntrinsicEventQueryDialog.cs
                rw.AddResource("WMISE_IntrinsicEvent_Created", "Created");
                rw.AddResource("WMISE_IntrinsicEvent_Modified", "Modified");
                rw.AddResource("WMISE_IntrinsicEvent_Deleted", "Deleted");
                rw.AddResource("WMISE_IntrinsicEvent_Operated", "Created, Modified or Deleted");

                rw.AddResource("WMISE_IntrEventQueryDlg_Title", "Build Object Operation Event Query");
                rw.AddResource("WMISE_IntrEventQueryDlg_EventClassLbl", "Target class: ");

                rw.AddResource("WMISE_IntrEventQueryDlg_EventName", "Raise event when instance is: ");
                rw.AddResource("WMISE_IntrEventQueryDlg_PollingInterval", "Poll for events every: ");

                //IntrinsicEventNode.cs
                rw.AddResource("WMISE_IntrinsicEventNodeLbl", "Management Data Events");

                //SelectWMIClassTreeDialog.cs
                rw.AddResource("WMISE_ClassSelectorLbl", "Add Objects");
                rw.AddResource("WMISE_ClassSelectorLblSearch", "&Find class containing:");
                rw.AddResource("WMISE_ClassSelectorBtnSearch", "Find &Next");
                rw.AddResource("WMISE_ClassSelectorBtnAdd", "&Add  >>");
                rw.AddResource("WMISE_ClassSelectorBtnRemove", "<<  &Remove");
                rw.AddResource("WMISE_ClassSelectorSelClassesLbl", "Se&lected classes:");
                rw.AddResource("WMISE_ClassSelectorAskViewAll", "Do you want to add all classes in this namespace?");
                rw.AddResource("WMISE_ClassSelectorClassAlreadySelected", "Class {0} is already selected");
                rw.AddResource("WMISE_ClassSelectorDlgHelp", "This dialog allows you to select one or more Management classes. " +
                               "The objects belonging to these classes will be then added as nodes to the Server Explorer tree");


                //WMIClassesNode.cs
                rw.AddResource("WMISE_ClassesNode_AddClass", "&Add Objects...");
                rw.AddResource("WMISE_ClassesNode_AddClassLbl", "<Add Objects...>");
                rw.AddResource("WMISE_ClassesNodeLbl", "Management Data");

                //WMIClassNode.cs
                rw.AddResource("WMISE_ClassNode_CreateNewInstance", "Create &New Object...");
                rw.AddResource("WMISE_ClassNode_NewInstanceLbl", "<New {0}>");
                rw.AddResource("WMISE_ClassNode_RemovePrompt", "Are you sure you want to remove {0} from the view?");

                //WMIInstanceNode.cs
                rw.AddResource("WMISE_InstNode_SaveNewInstanceCM", "Save");

                //WMIObjectComponent.cs
                rw.AddResource("WMISE_ObjComp_PutFailed", "Could not save object {0}: {1}");


                //WMIObjectPropertyTable.cs
                rw.AddResource("WMISE_PropTable_ColumnName", "Name");
                rw.AddResource("WMISE_PropTable_ColumnType", "Type");
                rw.AddResource("WMISE_PropTable_ColumnValue", "Value");
                rw.AddResource("WMISE_PropTable_ColumnDescription", "Description");
                rw.AddResource("WMISE_PropTable_ColumnComparison", "Operator");
                rw.AddResource("WMISE_PropTable_ColumnIsKey", "Key");
                rw.AddResource("WMISE_PropTable_ColumnIsLocal", "Local");

                //namespace descriptions
                rw.AddResource("WMISE_NSDescription_Root", "The Root namespace is primarily designed to contain other namespaces. Typically, you should not use root to store your objects.");
                rw.AddResource("WMISE_NSDescription_Root_Default", "The Default namespace is the default location where objects are stored if a namespace has not been specified.");
                rw.AddResource("WMISE_NSDescription_Root_Cimv2", "The CIMV2 namespace contains the majority of information about the status and configuration of the local system.");
                rw.AddResource("WMISE_NSDescription_Root_Cimv2_Applications", "The Applications namespace contains management objects for many applications installed on the local system.");
                rw.AddResource("WMISE_NSDescription_Root_Cimv2_Applications_MicrosoftIE", "The MicrosoftIE namespace contains object for managing Internet Explorer on the local system.");
                rw.AddResource("WMISE_NSDescription_Root_Directory", "The Directory namespace contains objects for directory services such as the Active Directory.");
                rw.AddResource("WMISE_NSDescription_Root_Directory_Ldap", "The LDAP namespace contains Active Directory schema and data. You may use this namespace to browse the Active Directory information visible to the local machine.");
                rw.AddResource("WMISE_NSDescription_Root_Wmi", "The WMI namespace contains detailed data supplied by Windows Driver Model (WDM) drivers installed on the local system.");
                rw.AddResource("WMISE_NSDescription_Root_Microsoft_SQLServer", "The MicrosoftSQLServer namespace contains objects for managing SQL Server 7.0 and 2000 systems.");



                rw.Write();
                rw.Close();


                ResourceReader        reader  = new ResourceReader("Microsoft.VSDesigner.WMI.Res.resources");
                IDictionaryEnumerator enumRes = (IDictionaryEnumerator)((IEnumerable)reader).GetEnumerator();
                while (enumRes.MoveNext())
                {
                    Console.WriteLine();
                    Console.WriteLine("Name: {0}", enumRes.Key);
                    Console.WriteLine("Value: {0}", enumRes.Value);
                }
                reader.Close();
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
            }
        }
Exemple #15
0
        private List <GenerateResult> GenerateInternal(TemplateOption option, List <Table> tables, CodeGenerateHandler handler)
        {
            var result   = new List <GenerateResult>();
            var _tables  = ProxyBuilder.Rebuild(tables);
            var _profile = ProxyBuilder.Rebuild(option.Profile);
            var _guids   = new GuidDispatcher();

            var _reference = new List <dynamic>();

            foreach (var table in _tables)
            {
                _reference.AddRange(table.ForeignKeys);
            }

            var assemblyList = option.DynamicAssemblies;

            assemblyList.AddRange(ProxyBuilder.GetAssemblyList());

            var path   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "templates\\T4");
            var host   = new TemplateHost(path, _tables, _reference, assemblyList, _guids);
            var engine = new Engine();

            host.Profile = _profile;

            var tparts = option.Partitions.Where(s => s.Loop == PartitionLoop.Tables).ToList();
            var nparts = option.Partitions.Where(s => s.Loop == PartitionLoop.None).ToList();

            var count = tparts.Count * tables.Count + nparts.Count;
            var index = 0;

            var calc = new Func <int, int>(i =>
            {
                return((int)((i / (count * 1.0)) * 100));
            });

            foreach (var table in _tables)
            {
                if (Processor.IsCancellationRequested())
                {
                    break;
                }

                foreach (var part in tparts)
                {
                    if (Processor.IsCancellationRequested())
                    {
                        break;
                    }

                    host.TemplateFile = part.FilePath;
                    if (handler != null)
                    {
                        handler(table.Name, calc(++index));
                    }

                    host.Current = table;
                    var content = engine.ProcessTemplate(part.Content, host);
                    var r       = ProcessPartitionCodeFile(part, host, table, _profile, option, content);
                    if (r != null)
                    {
                        result.Add(r);
                    }
                }
            }

            foreach (var part in nparts)
            {
                if (Processor.IsCancellationRequested())
                {
                    break;
                }

                if (handler != null)
                {
                    handler("全局", calc(++index));
                }

                host.TemplateFile = part.FilePath;
                var content = engine.ProcessTemplate(part.Content, host);
                var r       = ProcessPartitionCodeFile(part, host, null, _profile, option, content);
                if (r != null)
                {
                    result.Add(r);
                }
            }

            if (option.WriteToDisk)
            {
                ResourceWriter.Write(option.Template, option.Profile, option.OutputDirectory);
            }

            return(result);
        }