Пример #1
0
 public static void ReturnNamedResourceAsWebPage(HttpMessage httpMessage, ISocketProxy socketProxy)
 {
     string destinationUrl = httpMessage.Headers.DestinationUrl().Substring(1);
     var resourceStream = new ResourceReader().GetResource(destinationUrl);
     var bytes = resourceStream.ReadFully();
     socketProxy.SendWebPage(Encoding.ASCII.GetString(bytes));
 }
Пример #2
0
        public static void ReadResource(int numberOfLeadingBytes)
        {
            var buffer = new byte[4096];
            using (var ms2 = new MemoryStream(buffer, true))
            {
                ms2.Write(new byte[numberOfLeadingBytes], 0, numberOfLeadingBytes);
                using (var rw = GenerateResourceStream(s_dict, ms2))
                {
                    //Rewind to begining of stream

                    ms2.Seek(numberOfLeadingBytes, SeekOrigin.Begin);

                    var reder = new ResourceReader(ms2);

                    var s_found_list = new List<string>();
                    foreach (DictionaryEntry entry in reder)
                    {
                        string key = (string)entry.Key;
                        string value = (string)entry.Value;
                        string found = s_dict[key];
                        Assert.True(string.Compare(value, found) == 0, "expected: " + value + ", but got : " + found);
                        s_found_list.Add(key);
                    }

                    Assert.True(s_found_list.Count == s_dict.Count);
                }
            }
        }
        public void CanBuildTemplate()
        {
            var templateText = new ResourceReader().GetTextResource("CacheList.html");
            var parser = new MainPageTemplateParser(null, templateText, new List<CacheRecord>());

            var message = parser.GenerateContent();

            Console.WriteLine(message);

            Assert.That(message.Length, Is.GreaterThan(0));
        }
Пример #4
0
Файл: test.cs Проект: mono/gert
	static int Main ()
	{
		string resXFile = Path.Combine (AppDomain.CurrentDomain.BaseDirectory,
			"Resources.resources");
		ResourceReader rr = new ResourceReader (resXFile);
		int i = 0;
		foreach (DictionaryEntry de in rr) {
			Bitmap bmp = null;
			switch (i) {
			case 0:
				if ("VIA vzw" != (string) de.Key)
					return 1;
				bmp = (Bitmap) de.Value;
#if NET_2_0
				if (bmp.Height != 32)
					return 2;
				if (bmp.Width != 32)
					return 3;
#else
				if (bmp.Height != 96)
					return 2;
				if (bmp.Width != 96)
					return 3;
#endif
				break;
			case 1:
				if ("dbs" != (string) de.Key)
					return 4;
				bmp = (Bitmap) de.Value;
				if (bmp.Height != 16)
					return 5;
				if (bmp.Width != 16)
					return 6;
				break;
			default:
				return 1;
			}
			i++;
		}
		if (i != 2)
			return 2;
		return 0;
	}
Пример #5
0
        private object ReadResources(string name)
        {
            string resName = "%RESNAME%";

            using (Stream s = Asm.GetManifestResourceStream(resName))
            {
                using (ResourceReader rr = new ResourceReader(s))
                {
                    IDictionaryEnumerator en = rr.GetEnumerator();

                    while (en.MoveNext())
                    {
                        if ((string)en.Key == name)
                        {
                            return(en.Value);
                        }
                    }
                }
            }
            return(null);
        }
Пример #6
0
 /// <summary>
 /// 读取 资源文件信息.
 /// </summary>
 /// <param name="resName"></param>
 public void DisplayHello(String resName)
 {
     try
     {
         ResourceReader        reader = new ResourceReader(resName + ".resource");
         IDictionaryEnumerator dict   = reader.GetEnumerator();
         while (dict.MoveNext())
         {
             String s = (String)dict.Key;
             if (s == "Hello")
             {
                 Console.WriteLine(dict.Value);
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         Console.WriteLine(ex.StackTrace);
     }
 }
        public static string[] GetResourceNames()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            string   resName  = assembly.GetName()
                                .Name + ".g.resources";

            using (Stream stream = assembly.GetManifestResourceStream(resName))
            {
                if (stream == null)
                {
                    return(new string[0]);
                }

                using (ResourceReader reader = new ResourceReader(stream))
                {
                    return(reader.Cast <DictionaryEntry>()
                           .Select(entry => (string)entry.Key)
                           .ToArray());
                }
            }
        }
Пример #8
0
        string GetStringFromResource(ResourceReader reader, string name)
        {
            Stream s = null;

            foreach (DictionaryEntry de in reader)
            {
                if ((string)de.Key == name)
                {
                    s = (Stream)de.Value;
                }
            }

            if (s == null)
            {
                return(null);
            }

            byte [] buff = new byte [s.Length];
            s.Read(buff, 0, buff.Length);
            return(Encoding.Unicode.GetString(buff, 0, buff.Length));
        }
Пример #9
0
        private void button1_Click(object sender, EventArgs e)
        {
            var resourceStream = typeof(Form1)
                                 .Assembly.GetManifestResourceStream("WinFormsCharts.Form1.resources");

            using (System.Resources.ResourceReader resReader = new ResourceReader(resourceStream))
            {
                var dictEnumerator = resReader.GetEnumerator();
                while (dictEnumerator.MoveNext())
                {
                    var ent = dictEnumerator.Entry;
                    if (ent.Key as string == "$this.Text")
                    {
                        string resFormName = ent.Value as string;
                    }
                    // chartSelector1.Items.Add(new ChartDropDownItem($"{ent.Key}", ent.Value as Bitmap));
                    //imageList1.Images.Add($"{ent.Key}", ent.Value as Bitmap);
                    //listView1.Items.Add(new ListViewItem($"{ent.Key}", $"{ent.Key}"));
                }
            }
        }
Пример #10
0
        void ProcessXmlNodeResourceFinal()
        {
            foreach (KeyValuePair <string, List <string> > keyvaluepair in _dicResourcesKeyBuffer)
            {
                using (IResourceReader reader = new ResourceReader(
                           Path.Combine(PathService.CL_Resources_Folder, keyvaluepair.Key)))
                {
                    /// 枚举资源文件所有对象
                    IDictionaryEnumerator iden = reader.GetEnumerator();
                    while (iden.MoveNext())
                    {
                        int index = keyvaluepair.Value.IndexOf(iden.Key.ToString());

                        if (keyvaluepair.Value.Contains(iden.Key.ToString()))
                        {
                            _imgList.Add(iden.Key.ToString(), (Image)iden.Value);
                        }
                    }
                }
            }
        }
Пример #11
0
        void DecryptAllAssemblies()
        {
            if (assemblyResource == null)
            {
                return;
            }
            var resourceSet = ResourceReader.Read(resourceModule, assemblyResource.CreateReader());

            foreach (var resourceElement in resourceSet.ResourceElements)
            {
                if (resourceElement.ResourceData.Code != ResourceTypeCode.ByteArray)
                {
                    throw new ApplicationException("Invalid resource");
                }
                var  resourceData = (BuiltInResourceData)resourceElement.ResourceData;
                var  assemblyData = Decrypt((byte[])resourceData.Data);
                var  theModule    = ModuleDefMD.Load(assemblyData);
                bool isMain       = resourceElement.Name == entryPointAssemblyKey;
                assemblyInfos.Add(new AssemblyInfo(assemblyData, DeobUtils.GetExtension(theModule.Kind), theModule.Assembly.FullName, theModule.Assembly.Name.String, isMain));
            }
        }
        public async Task <ActionResult <BoilerplateViewModel> > Get([FromQuery] string key)
        {
            var boilerPlate = await _boilerPlateRepository.GetAll()
                              .Where(x => x.Key == key)
                              .FirstOrDefaultAsync();

            if (boilerPlate == null)
            {
                return(NotFound());
            }

            var response = new BoilerplateViewModel {
                Key     = key,
                Title   = boilerPlate.Title,
                Content = boilerPlate.Content.StartsWith("resource:") ?
                          await ResourceReader.ReadResource($"{boilerPlate.Content.Split(':')[1]}.html", true) :
                          boilerPlate.Content
            };

            return(response);
        }
Пример #13
0
        public void InitializeDetails()
        {
            try
            {
                int i = 0;

                DetailsAddOrUpdate("MODE", 0, "Mode", "", ResourceReader.GetString("Offline"));
                DetailsAddOrUpdate("TU", 0, "TU", "", "");
                DetailsAddOrUpdate("CMD", 0, "Task", "", "");
                DetailsAddOrUpdate("SENS", 0, "Sensors", "", "");
                if (Model != null && (Model as Conveyor).ConveyorInfo != null && (Model as Conveyor).ConveyorInfo.SensorList != null)
                {
                    (Model as Conveyor).ConveyorInfo.SensorList.ForEach(s => DetailsAddOrUpdate(string.Format("SENS_{0}", i++), 4, s.Description, s.Reference, false));
                }
            }
            catch (Exception e)
            {
                _warehouse.AddEvent(Database.Event.EnumSeverity.Error, Database.Event.EnumType.Exception, e.Message);
                throw new Exception(string.Format("{0}.{1}: {2}", this.GetType().Name, (new StackTrace()).GetFrame(0).GetMethod().Name, e.Message));
            }
        }
Пример #14
0
        public static string LoadResourceData(string key)
        {
            //string apPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Properties/Resources.resx");
            var nav = string.Empty;
            var rd  = new ResourceReader(
                System.Web.Hosting.HostingEnvironment.MapPath(@"~\Properties\Resources.resource"));

            if (rd == null)
            {
                return(string.Empty);
            }
            string resType = string.Empty;

            byte[] valOut;
            rd.GetResourceData("NavCategory", out resType, out valOut);
            if (valOut != null)
            {
                nav = System.Text.Encoding.UTF8.GetString(valOut);
            }
            return(nav);
        }
Пример #15
0
        private BitmapImage GetImage()
        {
            Assembly DynamicTools = Assembly.LoadFile(DynUtils.g_DynamicPath);
            var      stream       = DynamicTools.GetManifestResourceStream(DynamicTools.GetName().Name + ".g.resources");

            if (stream != null)
            {
                var resourceReader = new ResourceReader(stream);

                foreach (DictionaryEntry resource in resourceReader)
                {
                    if (resource.Key.ToString().Contains("bulb"))
                    {
                        var uri = new Uri("/" + DynamicTools.GetName().Name + ";component/" + resource.Key.ToString(), UriKind.Relative);
                        return(new BitmapImage(uri));
                    }
                }
            }

            return(null);
        }
Пример #16
0
        private static object?ReadValue(ResourceReader reader, int dataPos, bool isString, out ResourceLocator locator)
        {
            object?          value;
            ResourceTypeCode typeCode;

            // Normally calling LoadString or LoadObject requires
            // taking a lock.  Note that in this case, we took a
            // lock before calling this method.
            if (isString)
            {
                value    = reader.LoadString(dataPos);
                typeCode = ResourceTypeCode.String;
            }
            else
            {
                value = reader.LoadObject(dataPos, out typeCode);
            }

            locator = new ResourceLocator(dataPos, ResourceLocator.CanCache(typeCode) ? value : null);
            return(value);
        }
Пример #17
0
        public Query GetProcedureQuery(Sql8rServer server, Sql8rDatabase database, Sql8rProcedure procedure)
        {
            string sql = ResourceReader.GetResourceSql("SQL8r.Logic.SqlServer.Queries.UI.EditProcedure.sql");

            string dbSQL = string.Format(sql, database.Name, procedure.ObjectId);

            var dtTables = new DataTable("Tables")
            {
                Locale = CultureInfo.InvariantCulture
            };
            var sdaTables = new SqlDataAdapter(dbSQL, ConnectionString);

            sdaTables.Fill(dtTables);

            DataRow drDatabase = dtTables.Rows[0];

            string def   = drDatabase["definition"].ToString();
            var    query = new Query(_settings, server.Name, database.Name, def);

            return(query);
        }
Пример #18
0
        /// <summary>
        /// Получает список ресурсов указанного именного файла ресурсов.
        /// </summary>
        /// <param name="Stream"></param>
        /// <returns></returns>
        public static AssemblyResources Load(FileStream Stream)
        {
            Dictionary <String, Object> _list = new Dictionary <String, Object>();

            using (ResourceReader RR = new ResourceReader(Stream))
            {
                IDictionaryEnumerator _resources = RR.GetEnumerator();
                while (_resources.MoveNext())
                {
                    _list.Add(_resources.Key.ToString(), _resources.Value);
                }

                RR.Close();
                RR.Dispose();
            }

            Stream.Close();
            Stream.Dispose();

            return(new AssemblyResources(_list));
        }
Пример #19
0
        public void Bug81759()
        {
            MemoryStream ms = new MemoryStream();

            using (ResourceReader xr = new ResourceReader(
                       TestResourceHelper.GetFullPathOfResource("Test/resources/bug81759.resources"))) {
                ResourceWriter rw = new ResourceWriter(ms);
                foreach (DictionaryEntry de in xr)
                {
                    rw.AddResource((string)de.Key, de.Value);
                }
                rw.Close();
            }
            ResourceReader rr = new ResourceReader(new MemoryStream(ms.ToArray()));

            foreach (DictionaryEntry de in rr)
            {
                Assert.AreEqual("imageList.ImageSize", de.Key as string, "#1");
                Assert.AreEqual("Size", de.Value.GetType().Name, "#2");
            }
        }
Пример #20
0
        protected override void LoadChildren()
        {
            EmbeddedResource er = this.Resource as EmbeddedResource;

            if (er != null)
            {
                Stream s = er.GetResourceStream();
                s.Position = 0;
                ResourceReader reader;
                try {
                    reader = new ResourceReader(s);
                }
                catch (ArgumentException) {
                    return;
                }
                foreach (DictionaryEntry entry in reader.Cast <DictionaryEntry>().OrderBy(e => e.Key.ToString()))
                {
                    ProcessResourceEntry(entry);
                }
            }
        }
Пример #21
0
        static LanguageSelector()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(LanguageSelector), new FrameworkPropertyMetadata(typeof(LanguageSelector)));
            var assembly = typeof(LanguageSelector).Assembly;
            var names    = assembly.GetManifestResourceNames();
            var match    = names.Single(x => x.EndsWith(".g.resources"));

            using (var reader = new ResourceReader(assembly.GetManifestResourceStream(match)))
            {
                var flags      = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                var enumerator = reader.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    var flag = (string)enumerator.Key;
                    Debug.Assert(flag != null, "flag == null");
                    flags.Add(System.IO.Path.GetFileNameWithoutExtension(flag), flag);
                }

                FlagNameResourceMap = flags;
            }
        }
Пример #22
0
        private static object GetResource(string name, string key)
        {
            Assembly asm = Assembly.GetEntryAssembly();

            using (Stream s = asm.GetManifestResourceStream(name))
            {
                using (ResourceReader rr = new ResourceReader(s))
                {
                    IDictionaryEnumerator en = rr.GetEnumerator();

                    while (en.MoveNext())
                    {
                        if (en.Key is string && (string)en.Key == key)
                        {
                            return(en.Value);
                        }
                    }
                }
            }
            throw new Exception();
        }
Пример #23
0
        public static void ReadResource1()
        {
            using (var ms2 = new MemoryStream())
            {
                using (var rw = GenerateResourceStream(s_dict, ms2))
                {
                    //Rewind to beginning of stream

                    ms2.Seek(0L, SeekOrigin.Begin);

                    var reader = new ResourceReader(ms2);

                    var s_found_key   = new List <string>();
                    var s_found_value = new List <string>();
                    var enume         = reader.GetEnumerator();

                    while (enume.MoveNext())
                    {
                        s_found_key.Add((string)enume.Key);
                        s_found_value.Add((string)enume.Value);
                    }
                    enume.Reset();
                    int i = 0;
                    while (enume.MoveNext())
                    {
                        string key       = s_found_key[i];
                        string found_key = (string)enume.Key;

                        string value       = s_found_key[i];
                        string found_value = (string)enume.Key;
                        i++;
                        Assert.True(string.Compare(key, found_key) == 0, "expected: " + key + ", but got : " + found_key);
                        Assert.True(string.Compare(value, found_value) == 0, "expected: " + value + ", but got : " + found_value);
                    }


                    Assert.True(s_found_key.Count == s_dict.Count);
                }
            }
        }
Пример #24
0
        public void copyFiles()
        {
            using (
                var msData =
                    (UnmanagedMemoryStream)
                    Assembly.GetExecutingAssembly().GetManifestResourceStream("updateSystemDotNet.Setup.setup.package")) {
                using (var resReader = new ResourceReader(msData)) {
                    //Dateimap einlesen
                    var    xmlMap  = new XmlDocument();
                    byte[] mapData = null;
                    string tempString;
                    resReader.GetResourceData("map", out tempString, out mapData);
                    using (var msMap = new MemoryStream(mapData)) {
                        using (var srMap = new StreamReader(msMap, Encoding.UTF8)) {
                            xmlMap.Load(srMap);
                        }
                    }

                    int totalFiles  = (xmlMap.SelectNodes("Files/File").Count);
                    int currentFile = 0;

                    //Dateien verarbeiten
                    foreach (XmlNode fileNode in xmlMap.SelectNodes("Files/File"))
                    {
                        byte[] compressedFileData = null;
                        resReader.GetResourceData(fileNode.SelectSingleNode("Id").InnerText, out tempString, out compressedFileData);
                        writeCompressedFile(
                            compressedFileData,
                            fileNode.SelectSingleNode("Directory").InnerText,
                            fileNode.SelectSingleNode("Filename").InnerText);

                        currentFile++;
                        if (fileProgressChanged != null)
                        {
                            fileProgressChanged(this, new ProgressChangedEventArgs(Percent(currentFile, totalFiles), null));
                        }
                    }
                }
            }
        }
Пример #25
0
        public string this[string propertyName]
        {
            get
            {
                try
                {
                    string validationResult = String.Empty;
                    if (ValidationEnabled)
                    {
                        switch (propertyName)
                        {
                        case "ID":
                            if (_dbservicewms.CountPlaceIDs(ID) == 0 || ID.Length == 0)
                            {
                                validationResult = ResourceReader.GetString("ERR_LOC_RANGE");
                            }
                            break;

                        case "FrequencyClass":
                            if (FrequencyClass < 0 || (FrequencyClass == 0 && ID.StartsWith("W")))
                            {
                                validationResult = ResourceReader.GetString("ERR_RANGE");
                            }
                            break;
                        }
                    }
                    Validator.AddOrUpdate(propertyName, validationResult == String.Empty);
                    AllPropertiesValid = Validator.IsValid();
                    return(validationResult);
                }
                catch (Exception e)
                {
                    _warehouse.AddEvent(Database.Event.EnumSeverity.Error, Database.Event.EnumType.Exception,
                                        string.Format("{0}.{1}: {2}", this.GetType().Name, (new StackTrace()).GetFrame(0).GetMethod().Name, e.Message));
                    Validator.AddOrUpdate(propertyName, false);
                    AllPropertiesValid = Validator.IsValid();
                    return(ResourceReader.GetString("ERR_EXCEPTION"));
                }
            }
        }
Пример #26
0
        public string this[string propertyName]
        {
            get
            {
                try
                {
                    string validationResult = String.Empty;
                    if (ValidationEnabled)
                    {
                        switch (propertyName)
                        {
                        case "ID":
                            if (AddEnabled && _dbservicewms.CountBoxIDs(ID) != 0 || ID.Length == 0)
                            {
                                validationResult = ResourceReader.GetString("ERR_BOXID_EXISTS");
                            }
                            break;

                        case "SKUID":
                            if (_dbservicewms.FindSKUID(SKUID) == null || SKUID == null || SKUID.Length == 0)
                            {
                                validationResult = ResourceReader.GetString("ERR_SKUID_NONE");
                            }
                            break;
                        }
                    }
                    Validator.AddOrUpdate(propertyName, validationResult == String.Empty);
                    AllPropertiesValid = Validator.IsValid();
                    return(validationResult);
                }
                catch (Exception e)
                {
                    _warehouse.AddEvent(Database.Event.EnumSeverity.Error, Database.Event.EnumType.Exception,
                                        string.Format("{0}.{1}: {2}", this.GetType().Name, (new StackTrace()).GetFrame(0).GetMethod().Name, e.Message));
                    Validator.AddOrUpdate(propertyName, false);
                    AllPropertiesValid = Validator.IsValid();
                    return(ResourceReader.GetString("ERR_EXCEPTION"));
                }
            }
        }
Пример #27
0
        private static IReadOnlyList <int> FillStrings(IDictionary <int, IDictionary <string, string> > strings, Stream resStream, string prefix)
        {
            var locales     = new List <int>();
            var regexString = _resNameRegex;

            if (!String.IsNullOrEmpty(prefix))
            {
                if (!prefix.EndsWith(_resSeparator))
                {
                    prefix += _resSeparator;
                }

                regexString = Regex.Escape(prefix) + _resNameRegex;
            }

            var regex = new Regex(regexString, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

            using (var resReader = new ResourceReader(resStream))
            {
                foreach (var(name, stream) in resReader.Cast <DictionaryEntry>().Select(de => (de.Key as string, de.Value as Stream)))
                {
                    var match = regex.Match(name);

                    if (match.Success)
                    {
                        try
                        {
                            var lcid = new CultureInfo(match.Groups[1].Value).LCID;
                            locales.Add(lcid);
                            strings[lcid] = GetStringsFromJson(stream);
                        }
                        catch (CultureNotFoundException)
                        {
                        }
                    }
                }
            }

            return(locales.AsReadOnly());
        }
Пример #28
0
        internal SecondaryFrame(SettlementView settlementView, Vector2 topLeftPosition, string textureAtlas) :
            base("SecondaryFrame")
        {
            _gameConfigCache = CallContext <GameConfigCache> .GetData("GameConfigCache");

            Size     = new PointI(556, 741);
            Position = topLeftPosition.ToPointI();

            SettlementView = settlementView;

            var pairs = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("textureName1", $"{textureAtlas}.frame_main"),
                new KeyValuePair <string, string>("textureName2", $"{textureAtlas}.frame2_whole"),
                new KeyValuePair <string, string>("textureName3", $"{textureAtlas}.frame_bottom"),
                new KeyValuePair <string, string>("position1", $"{Convert.ToInt32(topLeftPosition.X)};{Convert.ToInt32(topLeftPosition.Y)}"),
                new KeyValuePair <string, string>("size1", $"{Size.X};{Size.Y}")
            };

            var spec = ResourceReader.ReadResource("PhoenixGamePresentation.Views.SettlementViewComposite.SecondaryFrameControls.txt", Assembly.GetExecutingAssembly());

            Controls = ControlCreator.CreateFromSpecification(spec, pairs);

            var buildingsView = new BuildingsView("buildingsView", settlementView, textureAtlas);
            var frmBuildings  = Controls["frmSecondary.frmBuildings"];

            frmBuildings.AddControl(buildingsView, Alignment.TopCenter);

            var slots10  = new DynamicSlots("slots20", $"{textureAtlas}.slot", new PointI(515, 65), 5, 2, 10.0f);
            var frmUnits = Controls["frmSecondary.frmUnits"];

            frmUnits.AddControl(slots10, Alignment.TopLeft, Alignment.TopLeft, new PointI(0, 5));
            CreateUnitLabels(slots10);

            var slots5   = new DynamicSlots("slots2", $"{textureAtlas}.slot", new PointI(515, 65), 5, 1, 10.0f);
            var frmOther = Controls["frmSecondary.frmOther"];

            frmOther.AddControl(slots5, Alignment.TopLeft, Alignment.TopLeft, new PointI(0, 5));
            CreateOtherLabels(slots5);
        }
Пример #29
0
        static Words()
        {
            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(ResourceId))
                using (var rr = new ResourceReader(stream))
                {
                    var rre = rr.GetEnumerator();

                    while (rre.MoveNext())
                    {
                        if ((string)rre.Key == DictFile)
                        {
                            // https://github.com/microsoft/msbuild/issues/2221
                            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
                                RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                            {
                                _words = new List <string>();
                                var fPathInter = (rre.Value as string).Split(';')[0].Split('\\');
                                if (fPathInter[0] != ".." || fPathInter[1] != "resources")
                                {
                                    throw new InvalidDataException();
                                }
                                var fPath = Path.Combine("Resources", fPathInter[fPathInter.Length - 1]);
                                using (var fStream = new FileStream(fPath, FileMode.Open))
                                    using (var sr = new StreamReader(fStream))
                                    {
                                        string nextLine = null;
                                        while ((nextLine = sr.ReadLine()) != null)
                                        {
                                            _words.Add(nextLine);
                                        }
                                    }
                            }
                            else
                            {
                                _words = new List <string>((rre.Value as string).Split(new char[] { '\n' }));
                            }
                        }
                    }
                }
        }
Пример #30
0
        public static void Read_resources_withobject()
        {
            //The following byte array corresponds to
            //rw.AddResource("name1", "value1");
            //rw.AddResource("name2", (object)bytearray);
            //rw.AddResource("name3", "value3");

            byte[] _RefBuffer12 = new byte[] { 206, 202, 239, 190, 1, 0, 0, 0, 145, 0, 0, 0, 108, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 101, 115, 111, 117, 114, 99, 101, 82, 101, 97, 100, 101, 114, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44, 32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108, 105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 98, 55, 55, 97, 53, 99, 53, 54, 49, 57, 51, 52, 101, 48, 56, 57, 35, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 117, 110, 116, 105, 109, 101, 82, 101, 115, 111, 117, 114, 99, 101, 83, 101, 116, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 80, 65, 68, 80, 65, 68, 80, 208, 41, 193, 10, 209, 41, 193, 10, 211, 41, 193, 10, 15, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 249, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 49, 0, 0, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 50, 0, 8, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 51, 0, 30, 1, 0, 0, 1, 6, 118, 97, 108, 117, 101, 49, 32, 17, 1, 0, 0, 206, 202, 239, 190, 1, 0, 0, 0, 145, 0, 0, 0, 108, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 101, 115, 111, 117, 114, 99, 101, 82, 101, 97, 100, 101, 114, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44, 32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108, 105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 98, 55, 55, 97, 53, 99, 53, 54, 49, 57, 51, 52, 101, 48, 56, 57, 35, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 117, 110, 116, 105, 109, 101, 82, 101, 115, 111, 117, 114, 99, 101, 83, 101, 116, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 80, 65, 68, 80, 65, 68, 80, 208, 41, 193, 10, 209, 41, 193, 10, 211, 41, 193, 10, 15, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 249, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 49, 0, 0, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 50, 0, 8, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 51, 0, 16, 0, 0, 0, 1, 6, 118, 97, 108, 117, 101, 49, 1, 6, 118, 97, 108, 117, 101, 50, 1, 6, 118, 97, 108, 117, 101, 51, 1, 6, 118, 97, 108, 117, 101, 51 };


            Dictionary <string, object> s_dict_expected = new Dictionary <string, object>
            {
                { "name1", "value1" },
                { "name2", new byte[] {
                      206, 202, 239, 190, 1, 0, 0, 0, 145, 0, 0, 0, 108, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 101, 115, 111, 117, 114, 99, 101, 82, 101, 97, 100, 101, 114, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44, 32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108, 105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 98, 55, 55, 97, 53, 99, 53, 54, 49, 57, 51, 52, 101, 48, 56, 57, 35, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 117, 110, 116, 105, 109, 101, 82, 101, 115, 111, 117, 114, 99, 101, 83, 101, 116, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 80, 65, 68, 80, 65, 68, 80, 208, 41, 193, 10, 209, 41, 193, 10, 211, 41, 193, 10, 15, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 249, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 49, 0, 0, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 50, 0, 8, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 51, 0, 16, 0, 0, 0, 1, 6, 118, 97, 108, 117, 101, 49, 1, 6, 118, 97, 108, 117, 101, 50, 1, 6, 118, 97, 108, 117, 101, 51
                  } },
                { "name3", "value3" }
            };

            using (var ms2 = new MemoryStream(_RefBuffer12))
            {
                using (var rw = new ResourceReader(ms2))
                {
                    ms2.Seek(0L, SeekOrigin.Begin);

                    var reader = new ResourceReader(ms2);

                    var s_found_list = new List <string>();

                    foreach (DictionaryEntry entry in reader)
                    {
                        string key      = (string)entry.Key;
                        object actual   = entry.Value;
                        object expected = s_dict_expected[key];
                        Assert.Equal(expected, actual);
                        s_found_list.Add(key);
                    }
                }
            }
        }
Пример #31
0
        public string this[string propertyName]
        {
            get
            {
                try
                {
                    string validationResult = String.Empty;
                    if (ValidationEnabled)
                    {
                        switch (propertyName)
                        {
                        case "TaskSegment":
                            if (TaskSegment < EnumSimpleCommandSegmentTask.Reset)
                            {
                                validationResult = ResourceReader.GetString("ERR_TASK");
                            }
                            break;

                        case "Segment":
                            if (!Segments.Any(p => p == Segment))
                            {
                                validationResult = ResourceReader.GetString("ERR_SEGMENT");
                            }
                            break;
                        }
                    }
                    Validator.AddOrUpdate(propertyName, validationResult == String.Empty);
                    AllPropertiesValid = Validator.IsValid();
                    return(validationResult);
                }
                catch (Exception e)
                {
                    _warehouse.AddEvent(Database.Event.EnumSeverity.Error, Database.Event.EnumType.Exception,
                                        string.Format("{0}.{1}: {2}", this.GetType().Name, (new StackTrace()).GetFrame(0).GetMethod().Name, e.Message));
                    Validator.AddOrUpdate(propertyName, false);
                    AllPropertiesValid = Validator.IsValid();
                    return(ResourceReader.GetString("ERR_EXCEPTION"));
                }
            }
        }
Пример #32
0
        public string this[string propertyName]
        {
            get
            {
                try
                {
                    string validationResult = String.Empty;
                    if (ValidationEnabled)
                    {
                        switch (propertyName)
                        {
                        case "Destination":
                            if (_dbservicewms.FindPlaceID(Destination) == null)
                            {
                                validationResult = ResourceReader.GetString("ERR_DESTINATION");
                            }
                            break;

                        case "ReleaseTime":
                            if (ReleaseTime < SqlDateTime.MinValue.Value || ReleaseTime >= SqlDateTime.MaxValue.Value)
                            {
                                validationResult = ResourceReader.GetString("ERR_RANGE");
                            }
                            break;
                        }
                    }
                    Validator.AddOrUpdate(propertyName, validationResult == String.Empty);
                    AllPropertiesValid = Validator.IsValid();
                    return(validationResult);
                }
                catch (Exception e)
                {
                    _warehouse.AddEvent(Database.Event.EnumSeverity.Error, Database.Event.EnumType.Exception,
                                        string.Format("{0}.{1}: {2}", this.GetType().Name, (new StackTrace()).GetFrame(0).GetMethod().Name, e.Message));
                    Validator.AddOrUpdate(propertyName, false);
                    AllPropertiesValid = Validator.IsValid();
                    return(ResourceReader.GetString("ERR_EXCEPTION"));
                }
            }
        }
Пример #33
0
        public void Load()
        {
            string    scriptName;
            string    className;
            AGIScript agiScript;

            if (mapping == null)
            {
                mapping = new Hashtable();
            }
            lock (mapping)
            {
                mapping.Clear();
                try
                {
                    ResourceReader rr = new ResourceReader(AppDomain.CurrentDomain.BaseDirectory + resourceName);
                    foreach (DictionaryEntry de in rr)
                    {
                        scriptName = (string)de.Key;
                        className  = (string)de.Value;
                        agiScript  = CreateAGIScriptInstance(className);
                        if (mapping.Contains(scriptName))
                        {
                            throw new AGIException(String.Format("Duplicate mapping name '{0}' in file {1}", scriptName, resourceName));
                        }
                        mapping.Add(scriptName, agiScript);
#if LOGGER
                        logger.Info("Added mapping for '" + scriptName + "' to class " + agiScript.GetType().FullName);
#endif
                    }
                }
                catch (Exception ex)
                {
#if LOGGER
                    logger.Error("Resource bundle '" + resourceName + "' is missing.");
#endif
                    throw ex;
                }
            }
        }
        public Resource(Assembly assembly, string resourcePath, string projectSourcePath)
        {
            AssemblyName = assembly.GetName().Name;
            FileInfo fileInfo = new FileInfo(assembly.Location);

            AssemblyLastModified = fileInfo.LastWriteTime;
            ResourcePath         = resourcePath;
            if (!string.IsNullOrWhiteSpace(projectSourcePath))
            {
                var filename = GetFileNameFromProjectSourceDirectory(assembly, resourcePath, projectSourcePath);

                if (filename != null) //means that the source file was found, or a copy was in the web apps folders
                {
                    GetCacheDependency = utcStart => new CacheDependency(filename, utcStart);
                    GetStream          = () => File.OpenRead(filename);
                    return;
                }
            }
            GetCacheDependency = utcStart => new CacheDependency(assembly.Location);


            GetStream = () =>
            {
                var assemblyName   = assembly.GetName().Name;
                var resourceSource = assemblyName + ".g.resources";
                var resourceStream = assembly.GetManifestResourceStream(resourceSource);
                if (resourceStream != null)
                {
                    var stream = new ResourceReader(resourceStream);
                    foreach (DictionaryEntry resource in stream)
                    {
                        if (resource.Key.ToString() == resourcePath)
                        {
                            return((Stream)resource.Value);
                        }
                    }
                }
                return(null);
            };
        }
        private IHttpHandler FindHandler(HttpContext context)
        {
            var reader = new ResourceReader();
            var requestTypeName = GetRequestTypeName(context).ToLowerInvariant();
            var requestResourceName = GetRequestResourceName(requestTypeName, context.Request);

            switch (requestTypeName)
            {
                case "js":
                    return new JavaScriptHandler(reader, requestResourceName);
                case "css":
                    return new CssHandler(reader);
                case "jpg":
                case "gif":
                case "png":
                case "anyimage":    //testing only
                    return new ImageHandler(reader, requestResourceName);
                case "delete":
                    return new DeleteItemHandler(requestResourceName, new MainPageHandler(reader)); //not too happy about a GET doing this, but ok for now.
                default:
                    return new MainPageHandler(reader);
                    //return new DefaultHttpHandler(); TODO: when you get bored, wtf is DefaultHttpHandler
            }
        }
        /**
         * Standard procedure to compile resources:
         * 1. Get an AppDomain correspondint to the Classloader.
         * 2. Create an assembly in the given appdomain
         * 3. Create a type for each resource, given the className (resourceName), contents
              (pReader.getBytes(resourceName)), and the AppDomain.
         * 4.  Write the compiled types to the store.
         */
        public override CompilationResult compile(
            string[] pResourceNames,
            ResourceReader pReader,
            ResourceStore pStore,
            ClassLoader pClassLoader
            )
        {
            int OFFSETCONSTANT = 8;
            Type[] types = new Type[pResourceNames.Length];
            string[] contents = new string[pResourceNames.Length];
            CodeSnippetCompileUnit[] units = new CodeSnippetCompileUnit[pResourceNames.Length];
            for (int i = 0; i < types.Length; i++)
            {
                string resourceName = pResourceNames[i].Replace('.','/')+".java";
                byte[] byteArray = pReader.getBytes(resourceName);
                string fileContents = this.StringFromBytes(byteArray);
                units[i] = new CodeSnippetCompileUnit(fileContents.Replace("cli.", ""));
                if (fileContents.Contains("public static void consequence"))
                {
                    object[] info = this.GetLinePragmaInfo(fileContents,OFFSETCONSTANT);
                    if(info != null)
                        units[i].LinePragma = new CodeLinePragma(info[0] as string, (int)info[1]);
                }
            }

            CodeDomProvider provider = GetProvider();
            CompilerParameters compilerParameters = new CompilerParameters();
            compilerParameters.GenerateInMemory = true;
            compilerParameters.IncludeDebugInformation = true;

            //            compilerParameters.OutputAssembly = pResourceNames[i].Substring(pResourceNames[i].LastIndexOf('.') + 1);

            int count = 0;
            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {

               if (assembly.FullName.StartsWith("CompiledRules"))
                {
                    try
                    {
                        File.Delete(assembly.Location);
                    }
                    catch (System.Exception e)
                    {
                        count++;
                    }
                }
                else
                {
                    compilerParameters.ReferencedAssemblies.Add(assembly.Location);
                }

            }

            compilerParameters.OutputAssembly = "CompiledRules" + count + ".dll";

            CompilerResults results = provider.CompileAssemblyFromDom
                //(compilerParameters, contents);
                (compilerParameters, units);

            Collection problems = new ArrayList();

            DotnetPackageCompilationData pcData = (DotnetPackageCompilationData)
                ((PackageStore)pStore).getPackageCompilationData();

            MemoryStream stream = new MemoryStream(1024);
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(stream, results.CompiledAssembly);

            for (int i = 0; i < types.Length; i++)
            {
                string resourceName = pResourceNames[i];
                pcData.write(resourceName, new object[]{results.CompiledAssembly, stream.GetBuffer()});

            }
            CompilationProblem[] result = new CompilationProblem[problems.size()];
            return new CompilationResult(result);
        }
 public bool runTest()
   {
   Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   String strValue = String.Empty;
   IDictionaryEnumerator idic;
   try
     {
     ResourceWriter resWriter;
     ResourceReader resReader;
     Stream stream = null;
     MemoryStream ms;
     FileStream fs;
     if(File.Exists(Environment.CurrentDirectory+"\\Co5445.resources"))
       File.Delete(Environment.CurrentDirectory+"\\Co5445.resources");
     strLoc = "Loc_20xcy";
     stream = null;
     iCountTestcases++;
     try {
     resWriter = new ResourceWriter(stream);
     iCountErrors++;
     printerr( "Error_29vc8! ArgumentNullException expected");
     } catch ( ArgumentNullException aExc) {
     } catch ( Exception exc) {
     iCountErrors++;
     printerr( "Error_10s9x! ArgumentNullException expected , got exc=="+exc.ToString());
     }
     strLoc = "Loc_3f98d";
     new FileStream("Co5445.resources", FileMode.Create).Close();
     fs = new FileStream("Co5445.resources", FileMode.Open, FileAccess.Read, FileShare.None);
     iCountTestcases++;
     try {
     resWriter = new ResourceWriter(fs);
     iCountErrors++;
     printerr( "Error_2c88s! ArgumentException expected");
     } catch (ArgumentException aExc) {
     } catch ( Exception exc) {
     iCountErrors++;
     printerr( "Error_2x0zu! ArgumentException expected, got exc=="+exc.ToString());
     }
     strLoc = "Loc_f0843";
     ms = new MemoryStream();
     resWriter = new ResourceWriter(ms);
     resWriter.AddResource("Harrison", "Ford");
     resWriter.AddResource("Mark", "Hamill");
     resWriter.Generate();
     ms.Position = 0;
     resReader = new ResourceReader(ms);
     idic = resReader.GetEnumerator();
     idic.MoveNext();
     iCountTestcases++;
     if(!idic.Value.Equals("Ford"))
       {
       iCountErrors++;
       printerr( "Error_2d0s9 Expected==Ford, value=="+idic.Value.ToString());
       }
     idic.MoveNext();
     iCountTestcases++;
     if(!idic.Value.Equals("Hamill"))
       {
       iCountErrors++;
       printerr( "Error_2ce80 Expected==Hamill, value=="+idic.Value.ToString());
       }
     strLoc = "Loc_20984";
     iCountTestcases++;
     if(idic.MoveNext())
       {
       iCountErrors++;
       printerr( "Error_f4094! Should have hit the end of the stream already");
       }
     fs.Close();
     strLoc = "Loc_04853fd";
     if(File.Exists(Environment.CurrentDirectory+"\\Co5445.resources"))
       File.Delete(Environment.CurrentDirectory+"\\Co5445.resources");
     } catch (Exception exc_general ) {
     ++iCountErrors;
     Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general.ToString());
     }
   if ( iCountErrors == 0 )
     {
     Console.WriteLine( "paSs. "+s_strTFName+" ,iCountTestcases=="+iCountTestcases.ToString());
     return true;
     }
   else
     {
     Console.WriteLine("FAiL! "+s_strTFName+" ,iCountErrors=="+iCountErrors.ToString()+" , BugNums?: "+s_strActiveBugNums );
     return false;
     }
   }
Пример #38
0
 public MainPageHandler(ResourceReader resourceReader)
     : base(resourceReader)
 {
 }
Пример #39
0
 public JavaScriptHandler(ResourceReader reader, string resourceName)
     : base(reader)
 {
     _resourceName = resourceName;
 }
Пример #40
0
Файл: View.cs Проект: dfr0/moon
	public override Widget GetView ()
	{
		if (box != null)
			return box;

		// Create ui
		box = new VBox (false, 10);
		store = new ListStore (typeof (string), typeof (string), typeof (object));
		tree = new TreeView ();
		tree.Model = store;
		tree.AppendColumn ("Name", new CellRendererText (), "text", 0);
		tree.AppendColumn ("Type", new CellRendererText (), "text", 1);
		tree.HeadersVisible = true;
		tree.CursorChanged += HandleCursorChanged;
		scrolled_tree = new ScrolledWindow ();
		scrolled_tree.Add (tree);
		box.PackStart (scrolled_tree, true, true, 0);

		// Load resources
		EmbeddedResource embed = resource as EmbeddedResource;
		if (embed != null) {
			using (MemoryStream stream = new MemoryStream (embed.GetResourceData ())) {
				using (ResourceReader reader = new ResourceReader (stream)) {
					foreach (DictionaryEntry obj in reader) {
						store.AppendValues (obj.Key.ToString (), obj.Value.GetType ().FullName, obj.Value);
					}
				}
			}
		} else {
			Console.WriteLine ("Don't know how to handle a resource whose type is {0}", resource.GetType ().FullName);
		}

		return box;
	}
Пример #41
0
        public static void Exception_Corrupted_resources1()
        {
            byte[] _RefBuffer12 = new byte[] { 206, 202, 239, 190, 1, 0, 0, 0, 145, 0, 0, 0, 108, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 101, 115, 111, 117, 114, 99, 101, 82, 101, 97, 100, 101, 114, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44, 32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108, 105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 98, 55, 55, 97, 53, 99, 53, 54, 49, 57, 51, 52, 101, 48, 56, 57, 35, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 117, 110, 116, 105, 109, 101, 82, 101, 115, 111, 117, 114, 99, 101, 83, 101, 116, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 80, 65, 68, 80, 65, 68, 80, 208, 41, 193, 10, 209, 41, 193, 10, 211, 41, 193, 10, 15, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 249, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 49, 0, 0, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 50, 0, 8, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 51, 0, 16, 0, 0, 0, 1, 6, 118, 97, 108, 117, 101, 49, 1, 6, 118, 97, 108, 117, 101, 50, 1};
            using (var ms2 = new MemoryStream(_RefBuffer12))
            {
                using (var reader = new ResourceReader(ms2))
                {
                    var s_found_list = new List<DictionaryEntry>();
                    Assert.Throws<BadImageFormatException>(() =>
                    {
                        var enume = reader.GetEnumerator();

                        while (enume.MoveNext())
                        {
                            s_found_list.Add(enume.Entry);
                        }

                    });
                }
            }
        }
Пример #42
0
    /// <remarks>
    /// Builds ResAsm files out of resource files
    /// </remarks>
    static void Disassemble(string pattern)
    {
        string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), pattern);
        foreach (string file in files) {

            Hashtable resources = new Hashtable();
            int       length    = 0;
            // read resource files into the hashtable
            switch (Path.GetExtension(file).ToUpper()) {
                case ".RESX":
                    ResXResourceReader rx = new ResXResourceReader(file);
                    IDictionaryEnumerator n = rx.GetEnumerator();
                    while (n.MoveNext())
                        if (!resources.ContainsKey(n.Key)) {
                            length = Math.Max(length, n.Key.ToString().Length);
                            resources.Add(n.Key, n.Value);
                        }

                    rx.Close();
                break;
                case ".RESOURCES":
                    ResourceReader rr = new ResourceReader(file);
                    foreach (DictionaryEntry entry in rr) {
                        if (!resources.ContainsKey(entry.Key)) {
                            length = Math.Max(length, entry.Key.ToString().Length);
                            resources.Add(entry.Key, entry.Value);
                        }
                    }
                    rr.Close();
                break;
            }

            // write the hashtable to the resource file
            string fname  = Path.GetFileNameWithoutExtension(file);
            string path   = fname + "-data";
            StreamWriter writer = File.CreateText(fname + ".res");

            writer.Write("# this file was automatically generated by ResAsm\r\n\r\n");
            foreach (DictionaryEntry entry in resources) {
                // strings are put directly into the resasm format
                if (entry.Value is string) {
                    writer.Write(entry.Key.ToString() + "=\"" + ConvertIllegalChars(entry.Value.ToString()) + "\"\r\n");
                } else {
                    // all other files are referenced as a file and the filename
                    // is saved in the resasm format, the files need to be generated.
                    string extension  = "";
                    string outputname = path + '\\' + entry.Key.ToString();
                    if (entry.Value is Icon) {
                        extension = ".ico";
                        if (!Directory.Exists(path))
                            Directory.CreateDirectory(path);
                        ((Icon)entry.Value).Save(File.Create(outputname + extension));
                    } else if (entry.Value is Image) {
                        // all bitmaps are saved in the png format
                        extension = ".png";
                        if (!Directory.Exists(path))
                            Directory.CreateDirectory(path);
                        ((Image)entry.Value).Save(outputname + extension, ImageFormat.Png);
                    } else {
                        Console.WriteLine("can't save " + entry.Key + " unknown format.");
                        continue;
                    }
                    writer.Write(entry.Key.ToString().PadRight(length) + " = " + outputname + extension + "\r\n");
                }
            }
            writer.Close();
        }
    }
Пример #43
0
        public static void ReadV1Resources()
        {
            //NOte: The below ByteStream was generated by V1 framework resource writer from the below dictionary
            byte[] _RefBuffer1 = new byte[] { 206, 202, 239, 190, 1, 0, 0, 0, 88, 0, 0, 0, 41, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 101, 115, 111, 117, 114, 99, 101, 82, 101, 97, 100, 101, 114, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 45, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 117, 110, 116, 105, 109, 101, 82, 101, 115, 111, 117, 114, 99, 101, 83, 101, 116, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 1, 0, 0, 0, 12, 0, 0, 0, 1, 0, 0, 0, 23, 83, 121, 115, 116, 101, 109, 46, 83, 116, 114, 105, 110, 103, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 129, 56, 148, 171, 124, 133, 198, 205, 9, 176, 129, 210, 193, 133, 199, 216, 245, 127, 11, 239, 60, 90, 212, 15, 202, 130, 229, 15, 241, 187, 198, 30, 88, 117, 120, 32, 253, 221, 196, 54, 242, 213, 88, 62, 206, 25, 176, 106, 0, 0, 0, 0, 47, 0, 0, 0, 108, 0, 0, 0, 153, 0, 0, 0, 216, 0, 0, 0, 255, 0, 0, 0, 76, 1, 0, 0, 155, 1, 0, 0, 186, 1, 0, 0, 251, 1, 0, 0, 62, 2, 0, 0, 129, 2, 0, 0, 146, 3, 0, 0, 42, 65, 0, 114, 0, 103, 0, 95, 0, 73, 0, 110, 0, 118, 0, 97, 0, 108, 0, 105, 0, 100, 0, 77, 0, 101, 0, 109, 0, 98, 0, 101, 0, 114, 0, 73, 0, 110, 0, 102, 0, 111, 0, 0, 0, 0, 0, 56, 73, 0, 110, 0, 118, 0, 97, 0, 108, 0, 105, 0, 100, 0, 79, 0, 112, 0, 95, 0, 71, 0, 101, 0, 116, 0, 73, 0, 100, 0, 68, 0, 105, 0, 102, 0, 102, 0, 70, 0, 114, 0, 111, 0, 109, 0, 77, 0, 101, 0, 109, 0, 73, 0, 100, 0, 59, 0, 0, 0, 40, 65, 0, 114, 0, 103, 0, 95, 0, 69, 0, 110, 0, 117, 0, 109, 0, 78, 0, 111, 0, 116, 0, 67, 0, 108, 0, 111, 0, 110, 0, 101, 0, 97, 0, 98, 0, 108, 0, 101, 0, 136, 0, 0, 0, 58, 65, 0, 114, 0, 103, 0, 95, 0, 84, 0, 97, 0, 114, 0, 103, 0, 101, 0, 116, 0, 78, 0, 111, 0, 116, 0, 86, 0, 97, 0, 108, 0, 105, 0, 100, 0, 70, 0, 111, 0, 114, 0, 73, 0, 82, 0, 101, 0, 102, 0, 108, 0, 101, 0, 99, 0, 116, 0, 170, 0, 0, 0, 34, 65, 0, 114, 0, 103, 0, 95, 0, 71, 0, 101, 0, 116, 0, 77, 0, 101, 0, 116, 0, 104, 0, 78, 0, 111, 0, 116, 0, 70, 0, 110, 0, 100, 0, 214, 0, 0, 0, 72, 78, 0, 111, 0, 116, 0, 83, 0, 117, 0, 112, 0, 112, 0, 111, 0, 114, 0, 116, 0, 101, 0, 100, 0, 95, 0, 65, 0, 100, 0, 100, 0, 105, 0, 110, 0, 103, 0, 77, 0, 101, 0, 116, 0, 104, 0, 115, 0, 78, 0, 111, 0, 116, 0, 83, 0, 117, 0, 112, 0, 112, 0, 111, 0, 114, 0, 116, 0, 101, 0, 100, 0, 35, 1, 0, 0, 74, 78, 0, 111, 0, 116, 0, 83, 0, 117, 0, 112, 0, 112, 0, 111, 0, 114, 0, 116, 0, 101, 0, 100, 0, 95, 0, 65, 0, 100, 0, 100, 0, 105, 0, 110, 0, 103, 0, 70, 0, 105, 0, 101, 0, 108, 0, 100, 0, 115, 0, 78, 0, 111, 0, 116, 0, 83, 0, 117, 0, 112, 0, 112, 0, 111, 0, 114, 0, 116, 0, 101, 0, 100, 0, 81, 1, 0, 0, 26, 77, 0, 105, 0, 115, 0, 115, 0, 105, 0, 110, 0, 103, 0, 77, 0, 101, 0, 109, 0, 98, 0, 101, 0, 114, 0, 126, 1, 0, 0, 60, 73, 0, 110, 0, 118, 0, 97, 0, 108, 0, 105, 0, 100, 0, 67, 0, 97, 0, 115, 0, 116, 0, 95, 0, 81, 0, 73, 0, 70, 0, 111, 0, 114, 0, 69, 0, 110, 0, 117, 0, 109, 0, 86, 0, 97, 0, 114, 0, 70, 0, 97, 0, 105, 0, 108, 0, 101, 0, 100, 0, 145, 1, 0, 0, 62, 73, 0, 110, 0, 118, 0, 97, 0, 108, 0, 105, 0, 100, 0, 79, 0, 112, 0, 95, 0, 73, 0, 110, 0, 118, 0, 97, 0, 108, 0, 105, 0, 100, 0, 78, 0, 101, 0, 119, 0, 69, 0, 110, 0, 117, 0, 109, 0, 86, 0, 97, 0, 114, 0, 105, 0, 97, 0, 110, 0, 116, 0, 198, 1, 0, 0, 62, 65, 0, 114, 0, 103, 0, 95, 0, 79, 0, 98, 0, 106, 0, 101, 0, 99, 0, 116, 0, 78, 0, 111, 0, 116, 0, 86, 0, 97, 0, 108, 0, 105, 0, 100, 0, 70, 0, 111, 0, 114, 0, 77, 0, 101, 0, 116, 0, 104, 0, 111, 0, 100, 0, 73, 0, 110, 0, 102, 0, 111, 0, 11, 2, 0, 0, 32, 65, 0, 114, 0, 103, 0, 95, 0, 78, 0, 111, 0, 65, 0, 99, 0, 99, 0, 101, 0, 115, 0, 115, 0, 83, 0, 112, 0, 101, 0, 99, 0, 58, 2, 0, 0, 0, 57, 84, 104, 101, 32, 115, 112, 101, 99, 105, 102, 105, 101, 100, 32, 109, 101, 109, 98, 101, 114, 32, 105, 110, 102, 111, 32, 105, 115, 32, 110, 111, 116, 32, 118, 97, 108, 105, 100, 32, 102, 111, 114, 32, 116, 104, 105, 115, 32, 73, 82, 101, 102, 108, 101, 99, 116, 46, 0, 75, 84, 104, 101, 32, 68, 73, 83, 80, 73, 68, 32, 114, 101, 116, 117, 114, 110, 101, 100, 32, 102, 114, 111, 109, 32, 71, 101, 116, 73, 68, 115, 79, 102, 78, 97, 109, 101, 115, 32, 105, 115, 32, 100, 105, 102, 102, 101, 114, 101, 110, 116, 32, 102, 114, 111, 109, 32, 116, 104, 101, 32, 99, 97, 99, 104, 101, 100, 32, 68, 73, 83, 80, 73, 68, 46, 0, 32, 84, 104, 101, 32, 101, 110, 117, 109, 101, 114, 97, 116, 111, 114, 32, 105, 115, 32, 110, 111, 116, 32, 99, 108, 111, 110, 101, 97, 98, 108, 101, 46, 0, 42, 84, 104, 101, 32, 116, 97, 114, 103, 101, 116, 32, 105, 115, 32, 110, 111, 116, 32, 118, 97, 108, 105, 100, 32, 102, 111, 114, 32, 116, 104, 105, 115, 32, 73, 82, 101, 102, 108, 101, 99, 116, 46, 0, 75, 67, 97, 110, 110, 111, 116, 32, 103, 101, 116, 32, 116, 104, 101, 32, 118, 97, 108, 117, 101, 32, 102, 111, 114, 32, 116, 104, 101, 32, 112, 114, 111, 112, 101, 114, 116, 121, 32, 105, 110, 102, 111, 32, 115, 105, 110, 99, 101, 32, 105, 116, 32, 100, 111, 101, 115, 32, 110, 111, 116, 32, 104, 97, 118, 101, 32, 97, 32, 103, 101, 116, 116, 101, 114, 46, 0, 44, 73, 68, 105, 115, 112, 97, 116, 99, 104, 69, 120, 32, 100, 111, 101, 115, 32, 110, 111, 116, 32, 115, 117, 112, 112, 111, 114, 116, 32, 97, 100, 100, 105, 110, 103, 32, 109, 101, 116, 104, 111, 100, 115, 46, 0, 43, 73, 68, 105, 115, 112, 97, 116, 99, 104, 69, 120, 32, 100, 111, 101, 115, 32, 110, 111, 116, 32, 115, 117, 112, 112, 111, 114, 116, 32, 97, 100, 100, 105, 110, 103, 32, 102, 105, 101, 108, 100, 115, 46, 0, 17, 77, 101, 109, 98, 101, 114, 32, 110, 111, 116, 32, 102, 111, 117, 110, 100, 46, 0, 51, 81, 73, 32, 102, 111, 114, 32, 73, 69, 110, 117, 109, 86, 65, 82, 73, 65, 78, 84, 32, 102, 97, 105, 108, 101, 100, 32, 111, 110, 32, 116, 104, 101, 32, 117, 110, 109, 97, 110, 97, 103, 101, 100, 32, 115, 101, 114, 118, 101, 114, 46, 0, 67, 86, 97, 114, 105, 97, 110, 116, 32, 114, 101, 116, 117, 114, 110, 101, 100, 32, 102, 114, 111, 109, 32, 73, 110, 118, 111, 107, 101, 40, 41, 32, 111, 110, 32, 109, 101, 109, 98, 101, 114, 32, 68, 73, 83, 80, 73, 68, 95, 78, 69, 87, 69, 78, 85, 77, 32, 105, 115, 32, 105, 110, 118, 97, 108, 105, 100, 46, 0, 45, 84, 104, 101, 32, 111, 98, 106, 101, 99, 116, 32, 105, 115, 32, 110, 111, 116, 32, 118, 97, 108, 105, 100, 32, 102, 111, 114, 32, 116, 104, 105, 115, 32, 109, 101, 116, 104, 111, 100, 32, 105, 110, 102, 111, 46, 0, 68, 77, 117, 115, 116, 32, 115, 112, 101, 99, 105, 102, 121, 32, 98, 105, 110, 100, 105, 110, 103, 32, 102, 108, 97, 103, 115, 32, 100, 101, 115, 99, 114, 105, 98, 105, 110, 103, 32, 116, 104, 101, 32, 105, 110, 118, 111, 107, 101, 32, 111, 112, 101, 114, 97, 116, 105, 111, 110, 32, 114, 101, 113, 117, 105, 114, 101, 100, 46, };

            Dictionary<string, string> s_dictv1 = new Dictionary<string, string>
             {
                { "Arg_InvalidMemberInfo","The specified member info is not valid for this IReflect."},
                {"InvalidOp_GetIdDiffFromMemId","The DISPID returned from GetIDsOfNames is different from the cached DISPID."},
                {"Arg_EnumNotCloneable","The enumerator is not cloneable."},
                {"Arg_TargetNotValidForIReflect","The target is not valid for this IReflect."},
                {"Arg_GetMethNotFnd","Cannot get the value for the property info since it does not have a getter."},
                {"NotSupported_AddingMethsNotSupported","IDispatchEx does not support adding methods."},
                {"NotSupported_AddingFieldsNotSupported","IDispatchEx does not support adding fields."},
                {"MissingMember","Member not found."},
                {"InvalidCast_QIForEnumVarFailed","QI for IEnumVARIANT failed on the unmanaged server."},
                {"InvalidOp_InvalidNewEnumVariant","Variant returned from Invoke() on member DISPID_NEWENUM is invalid."},
                {"Arg_ObjectNotValidForMethodInfo","The object is not valid for this method info."},
                {"Arg_NoAccessSpec","Must specify binding flags describing the invoke operation required."}

             };

            using (var ms2 = new MemoryStream(_RefBuffer1))
            {
                using (var rw = new ResourceReader(ms2))
                {
                    //Rewind to begining of stream

                    ms2.Seek(0L, SeekOrigin.Begin);

                    var reder = new ResourceReader(ms2);

                    var s_found_list = new List<string>();
                    foreach (DictionaryEntry entry in reder)
                    {
                        string key = (string)entry.Key;
                        string value = (string)entry.Value;
                        string found = s_dictv1[key];
                        Assert.True(string.Compare(value, found) == 0, "expected: " + value + ", but got : " + found);
                        s_found_list.Add(key);
                    }

                    Assert.True(s_found_list.Count == s_dictv1.Count);
                }

            }
        }
Пример #44
0
	public static int Unpack (string assembly, string pattern)
	{
		Assembly asm = null;
		try {
			asm = Assembly.LoadFile (assembly);
		} catch (Exception e) {
			Console.Error.WriteLine ("Unable to load assembly: {0}.", assembly);
			Console.Error.WriteLine (e);
			return 1;
		}

		string [] resources = asm.GetManifestResourceNames ();
	
		foreach (string resource in resources) {
			if (verbose)
				Console.WriteLine ("decompressing '{0}'", resource);

			ResourceReader reader = null;

			try {
				using (reader = new ResourceReader (asm.GetManifestResourceStream (resource))) {
				
					IDictionaryEnumerator id = reader.GetEnumerator (); 

					while (id.MoveNext ()) {
						string key = (string) id.Key;
						if (!Regex.IsMatch (key, pattern))
							continue;

						if (verbose)
							Console.WriteLine ("  stream: {0}", key);

						MemoryStream stream = id.Value as MemoryStream;
						if (stream == null) {
							Console.Error.WriteLine ("Item not stored as a MemoryStream. {0}", key);
							continue;
						}

						byte [] data = new byte [stream.Length];
						stream.Read (data, 0, data.Length);

						string dir = Path.GetDirectoryName (key);
						if (!String.IsNullOrEmpty (dir))
							Directory.CreateDirectory (dir);

						using (FileStream fs = File.OpenWrite (key)) {
							fs.Write (data, 0, data.Length);
						}
									      
					}
				}
			} catch (Exception e) {
				Console.WriteLine ("failed to decompress {0}, exception '{1}'.. skipping", resource, e.Message);
			}
		}

		return 0;
	}
Пример #45
0
        public static void Exception_EOF()
        {
            byte[] _RefBuffer12 = new byte[] { 206, 202, 239, 190, 1, 0, 0, 0, 145, 0, 0, 0, 108, 83, 121, 115, 116, 101, 109};
            using (var ms2 = new MemoryStream(_RefBuffer12))
            {
                Assert.Throws<BadImageFormatException>(() =>
                {
                    using (var rw = new ResourceReader(ms2))
                    {

                    }
                });
               
            }
        }
Пример #46
0
        public static void Exception_opening_opened_resources()
        {
            byte[] _RefBuffer12 = new byte[] { 206, 202, 239, 190, 1, 0, 0, 0, 145, 0, 0, 0, 108, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 101, 115, 111, 117, 114, 99, 101, 82, 101, 97, 100, 101, 114, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44, 32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108, 105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 98, 55, 55, 97, 53, 99, 53, 54, 49, 57, 51, 52, 101, 48, 56, 57, 35, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 117, 110, 116, 105, 109, 101, 82, 101, 115, 111, 117, 114, 99, 101, 83, 101, 116, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 80, 65, 68, 80, 65, 68, 80, 208, 41, 193, 10, 209, 41, 193, 10, 211, 41, 193, 10, 15, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 249, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 49, 0, 0, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 50, 0, 8, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 51, 0, 16, 0, 0, 0, 1, 6, 118, 97, 108, 117, 101, 49, 1, 6, 118, 97, 108, 117, 101, 50 };
            using (var ms2 = new MemoryStream(_RefBuffer12))
            {
                using (var rw = new ResourceReader(ms2))
                {

                   
                    Assert.Throws<ArgumentException>(() =>
                    {
                        var rr = new ResourceReader(ms2);
                    });
                }
            }
        }
Пример #47
0
        public static void Read_resources_withobject()
        {
            //The following byte array corresponds to  
            //rw.AddResource("name1", "value1");
            //rw.AddResource("name2", (object)bytearray);
            //rw.AddResource("name3", "value3");

            byte[] _RefBuffer12 = new byte[] { 206, 202, 239, 190, 1, 0, 0, 0, 145, 0, 0, 0, 108, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 101, 115, 111, 117, 114, 99, 101, 82, 101, 97, 100, 101, 114, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44, 32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108, 105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 98, 55, 55, 97, 53, 99, 53, 54, 49, 57, 51, 52, 101, 48, 56, 57, 35, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 117, 110, 116, 105, 109, 101, 82, 101, 115, 111, 117, 114, 99, 101, 83, 101, 116, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 80, 65, 68, 80, 65, 68, 80, 208, 41, 193, 10, 209, 41, 193, 10, 211, 41, 193, 10, 15, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 249, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 49, 0, 0, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 50, 0, 8, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 51, 0, 30, 1, 0, 0, 1, 6, 118, 97, 108, 117, 101, 49, 32, 17, 1, 0, 0, 206, 202, 239, 190, 1, 0, 0, 0, 145, 0, 0, 0, 108, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 101, 115, 111, 117, 114, 99, 101, 82, 101, 97, 100, 101, 114, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44, 32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108, 105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 98, 55, 55, 97, 53, 99, 53, 54, 49, 57, 51, 52, 101, 48, 56, 57, 35, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 117, 110, 116, 105, 109, 101, 82, 101, 115, 111, 117, 114, 99, 101, 83, 101, 116, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 80, 65, 68, 80, 65, 68, 80, 208, 41, 193, 10, 209, 41, 193, 10, 211, 41, 193, 10, 15, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 249, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 49, 0, 0, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 50, 0, 8, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 51, 0, 16, 0, 0, 0, 1, 6, 118, 97, 108, 117, 101, 49, 1, 6, 118, 97, 108, 117, 101, 50, 1, 6, 118, 97, 108, 117, 101, 51, 1, 6, 118, 97, 108, 117, 101, 51 };

            
           Dictionary<string, string> s_dict_expected = new Dictionary<string, string>{
                                                                           { "name1", "value1"},
                                                                           { "name2", null},
                                                                           { "name3", "value3"}
                                                                         };
            using (var ms2 = new MemoryStream(_RefBuffer12))
            {
                using (var rw = new ResourceReader(ms2))
                {

                    ms2.Seek(0L, SeekOrigin.Begin);

                    var reader = new ResourceReader(ms2);

                    var s_found_list = new List<string>();

                    foreach (DictionaryEntry entry in reader)
                    {
                        string key = (string)entry.Key;
                        string found = (string)entry.Value;
                        string value = s_dict_expected[key];
                        Assert.True(string.Compare(value, found) == 0, "expected: " + value + ", but got : " + found);
                        s_found_list.Add(key);
                    }
                

                }
            }
        }
Пример #48
0
        public static void ReadResource1()
        {

            using (var ms2 = new MemoryStream())
            {
                using (var rw = GenerateResourceStream(s_dict, ms2))
                {
                    //Rewind to begining of stream

                    ms2.Seek(0L, SeekOrigin.Begin);

                    var reader = new ResourceReader(ms2);

                    var s_found_key = new List<string>();
                    var s_found_value = new List<string>();
                    var enume = reader.GetEnumerator();

                    while (enume.MoveNext())
                    {
                        s_found_key.Add((string)enume.Key);
                        s_found_value.Add((string)enume.Value);
                    }
                    enume.Reset();
                    int i = 0;
                    while (enume.MoveNext())
                    {
                        string key = s_found_key[i];
                        string found_key = (string)enume.Key;

                        string value = s_found_key[i];
                        string found_value = (string)enume.Key;
                        i++;
                        Assert.True(string.Compare(key, found_key) == 0, "expected: " + key + ", but got : " + found_key);
                        Assert.True(string.Compare(value, found_value) == 0, "expected: " + value + ", but got : " + found_value);
                    }


                    Assert.True(s_found_key.Count == s_dict.Count);
                }
            }

        }
Пример #49
0
        public static void Exception_Enumerator_Value()
        {
            Assert.Throws<InvalidOperationException>(() =>
            {
                using (var ms2 = new MemoryStream())
                {
                    using (var rw = GenerateResourceStream(s_dict, ms2))
                    {
                        ms2.Seek(0L, SeekOrigin.Begin);
                        var rr1 = new ResourceReader(ms2);

                        IDictionaryEnumerator enumarator = rr1.GetEnumerator();
                        rr1.Dispose();
                        var shouldnotgethere = enumarator.Value;


                    }
                }
            });
        }
    private static bool ValidateResourceFile(string resFile, string outputDir, string sourceHash, int viewCount)
    {
        IDictionary<int, KeyValuePair<string, string>> resourceDictionary =
            new Dictionary<int, KeyValuePair<string, string>>();
        using (var resourceReader = new ResourceReader(Path.Combine(outputDir, resFile)))
        {
            // Create an IDictionaryEnumerator to iterate through the resources.
            IDictionaryEnumerator IDEnumerator = resourceReader.GetEnumerator();

            // Iterate through the resources and store it in dictionary
            foreach (DictionaryEntry d in resourceReader)
            {
                //The KeyValuePair to be Inserted into the dictionary, NEEDS TO BE CASTED!
                var valueToInsert = (KeyValuePair<string, string>)d.Value;

                //Populating Dictionary, Item, the key in the dictionary is turn into an integer
                resourceDictionary.Add(Int32.Parse(d.Key.ToString()), valueToInsert);
            }
            resourceReader.Close();
        }

        /*
         * This is commented out in the public file because this class is an internal MS class that EF uses to create it's hash.
         * I reflected on it, made it a public class, and included it in our internal process to validate that the views were
         * created correctly and the view hash matched the original EF hash.
         * I will not distribute MS source code so the simplest approach is to comment this section out.
         *
         * This code being commented out does not affect the output file, it's just a validation step.
         * */

        //var resourceHaser = new CompressingHashBuilder(new SHA256CryptoServiceProvider());
        //for (int i = 0; i < viewCount; i++)
        //{
        //   KeyValuePair<string, string> resourceValue = resourceDictionary[i];
        //   resourceHaser.AppendLine(resourceValue.Key);
        //   resourceHaser.AppendLine(resourceValue.Value);
        //}
        //string fileHash = resourceHaser.ComputeHash();
        //return sourceHash == fileHash;
        return true;
    }
 protected AbstractEmbeddedResourceHandler(ResourceReader resourceReader)
 {
     _ResourceReader = resourceReader;
 }
 public void CanGetEmbeddedResourceFromAssembly()
 {
     var reader = new ResourceReader();
     var text = reader.GetTextResource("CacheList.html");
     Assert.That(text, Is.Not.Empty);
 }
Пример #53
0
 public Boolean runTest()
   {
   Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver " + s_strDtTmVer);
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc = "Loc_000oo";
   String strValue = String.Empty;
   Co5209AddResource_str_ubArr cc = new Co5209AddResource_str_ubArr();
   IDictionaryEnumerator idic;
   try {
   do
     {
     ResourceWriter resWriter;
     ResourceReader resReader;
     int statusBits = 0;
     int resultBits = 0;
     Byte[] ubArr = null;
     if(File.Exists(Environment.CurrentDirectory+"\\Co5209.resources"))
       File.Delete(Environment.CurrentDirectory+"\\Co5209.resources");
     strLoc = "Loc_204gh";
     resWriter = new ResourceWriter("Co5209.resources");
     strLoc = "Loc_209tj";
     try
       {
       iCountTestcases++;
       resWriter.AddResource(null, ubArr);
       iCountErrors++;
       printerr("Error_20fhs! Expected Exception not thrown");
       }
     catch (ArgumentException) {}
     catch (Exception exc)
       {
       iCountErrors++;
       printerr("Error_2t0jg! Unexpected exception exc=="+exc.ToString());
       }
     strLoc = "Loc_t4j80";
     ubArr = null;
     iCountTestcases++;
     try
       {
       resWriter.AddResource("key with null value", ubArr);
       }
     catch (Exception exc)
       {
       iCountErrors++;
       printerr("Error_59ufd! Unexpected exc=="+exc.ToString());
       }
     Byte[] ubArr1 = {(Byte)'v', (Byte)'a', (Byte)'l', (Byte)'u', (Byte)'e', (Byte)' ', (Byte)'1',};
     Byte[] ubArr2 = {(Byte)'v', (Byte)'a', (Byte)'l', (Byte)'u', (Byte)'e', (Byte)' ', (Byte)'2',};
     Byte[] ubArr3 = {(Byte)'v', (Byte)'a', (Byte)'l', (Byte)'u', (Byte)'e', (Byte)' ', (Byte)'3',};
     Byte[] ubArr4 = {(Byte)'v', (Byte)'a', (Byte)'l', (Byte)'u', (Byte)'e', (Byte)' ', (Byte)'4',};
     Byte[] ubArr5 = {(Byte)'v', (Byte)'a', (Byte)'l', (Byte)'u', (Byte)'e', (Byte)' ', (Byte)'5',};
     Byte[] ubArr6 = {(Byte)'v', (Byte)'a', (Byte)'l', (Byte)'u', (Byte)'e', (Byte)' ', (Byte)'6',};
     strLoc = "Loc_59ugd";
     resWriter.AddResource("key 1", ubArr1);
     resWriter.AddResource("key 2", ubArr2);
     resWriter.AddResource("key 3", ubArr3);
     resWriter.AddResource("key 4", ubArr4);
     resWriter.AddResource("key 5", ubArr5);
     resWriter.AddResource("key 6", ubArr6);
     strLoc = "Loc_230rj";
     iCountTestcases++;
     try
       {
       resWriter.AddResource("key 1", ubArr6);
       iCountErrors++;
       printerr("Error_2th8e! Names are not unique");
       }
     catch (ArgumentException) {}
     catch (Exception exc)
       {
       iCountErrors++;
       printerr("Error_298hg! Unexpected exception=="+exc.ToString());
       }
     resWriter.Generate();
     iCountTestcases++;
     if(!File.Exists(Environment.CurrentDirectory+"\\Co5209.resources"))
       {
       iCountErrors++;
       printerr("Error_23094! Expected file was not created");
       }
     resWriter.Close();
     strLoc = "Loc_30tud";
     resReader = new ResourceReader(Environment.CurrentDirectory+"\\Co5209.resources");
     strLoc = "Loc_0576cd";
     byte[] btTemp;
     Boolean fNotEqual;
     IDictionaryEnumerator resEnumerator = resReader.GetEnumerator();
     idic = resReader.GetEnumerator();
     while(idic.MoveNext())
       {
       if(idic.Key.Equals("key 1")) {
       btTemp = (byte[])idic.Value;
       fNotEqual = false;
       for(int i=0;i<btTemp.Length; i++) {
       if(btTemp[i]!=ubArr1[i])
	 fNotEqual = true;
       }
       if(!fNotEqual)
	 statusBits = statusBits | 0x1;
       } else if(idic.Key.Equals("key 2")) {
       btTemp = (byte[])idic.Value;
       fNotEqual = false;
       for(int i=0;i<btTemp.Length; i++) {
       if(btTemp[i]!=ubArr2[i])
	 fNotEqual = true;
       }
       if(!fNotEqual)
	 statusBits = statusBits | 0x2;
       } else if(idic.Key.Equals("key 3")) {
       btTemp = (byte[])idic.Value;
       fNotEqual = false;
       for(int i=0;i<btTemp.Length; i++) {
       if(btTemp[i]!=ubArr3[i])
	 fNotEqual = true;
       }
       if(!fNotEqual)
	 statusBits = statusBits | 0x4;
       } else if(idic.Key.Equals("key 4")) {
       btTemp = (byte[])idic.Value;
       fNotEqual = false;
       for(int i=0;i<btTemp.Length; i++) {
       if(btTemp[i]!=ubArr4[i])
	 fNotEqual = true;
       }
       if(!fNotEqual)
	 statusBits = statusBits | 0x8;
       } else if(idic.Key.Equals("key 5")) {
       btTemp = (byte[])idic.Value;
       fNotEqual = false;
       for(int i=0;i<btTemp.Length; i++) {
       if(btTemp[i]!=ubArr5[i])
	 fNotEqual = true;
       }
       if(!fNotEqual)
	 statusBits = statusBits | 0x10;
       } else if(idic.Key.Equals("key 6")) {
       btTemp = (byte[])idic.Value;
       fNotEqual = false;
       for(int i=0;i<btTemp.Length; i++) {
       if(btTemp[i]!=ubArr6[i])
	 fNotEqual = true;
       }
       if(!fNotEqual)
	 statusBits = statusBits | 0x20;
       }
       }
     resultBits = 0x1 | 0x2 | 0x4 | 0x8 | 0x10 | 0x20;
     iCountTestcases++;
     if(statusBits != resultBits)
       {
       iCountErrors++;
       printerr("Error_238fh! The names are incorrect, StatusBits=="+statusBits);
       }
     strLoc = "Loc_t0dds";
     iCountTestcases++;
     if(idic.MoveNext())
       {
       iCountErrors++;
       printerr("Error_2398r! , There shouldn't have been more elementes : GetValue=="+idic.Value);
       }
     resReader.Close();
     strLoc = "Loc_957fd";
     } while (false);
   } catch (Exception exc_general ) {
   ++iCountErrors;
   Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general=="+exc_general);
   }
   if ( iCountErrors == 0 )
     {
     Console.WriteLine( "paSs.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
     return true;
     }
   else
     {
     Console.WriteLine("FAiL!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
     return false;
     }
   }
Пример #54
0
        public static void Exception_incorrect_magic_number()
        {
            using (var ms2 = new MemoryStream())
            {
                using (var rw = GenerateResourceStream(s_dict, ms2))
                {
                    ms2.Seek(0L, SeekOrigin.Begin);
                    using (var bw = new BinaryWriter(ms2))
                    {
                        bw.Write(2000);//Our resource reader expects the ResourceManager magic number here

                        //  ms2.Seek(0L, SeekOrigin.Begin);
                        Assert.Throws<ArgumentException>(() =>
                        {
                            var resReader = new ResourceReader(ms2);
                        });
                    }
                }
            }
        }
Пример #55
0
 public static void ExceptionforResourceReaderNull()
 {
     Assert.Throws<ArgumentNullException>(() =>
     {
         MemoryStream ms2 = null;
         var rw = new ResourceReader(ms2);
     });
 }
Пример #56
0
        public static void ExceptionforResourceReaderDispose01()
        {
            Assert.Throws<InvalidOperationException>(() =>
            {
                using (var ms2 = new MemoryStream())
                {
                    using (var rw = GenerateResourceStream(s_dict, ms2))
                    {
                        ms2.Seek(0L, SeekOrigin.Begin);
                        var rr1 = new ResourceReader(ms2);

                        rr1.Dispose();
                        var s_found_list = new List<string>();
                        foreach (DictionaryEntry entry in rr1)
                        {
                            string key = (string)entry.Key;
                            string value = (string)entry.Value;
                            string found = s_dict[key];
                            Assert.True(string.Compare(value, found) == 0, "expected: " + value + ", but got : " + found);
                            s_found_list.Add(key);
                        }

                    }
                }
            });
        }
Пример #57
0
        public static void Exception_Corrupted_resources()
        {
            byte[] _RefBuffer12 = new byte[] { 206, 202, 239, 190, 1, 0, 0, 0, 145, 0, 0, 0, 108, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 101, 115, 111, 117, 114, 99, 101, 82, 101, 97, 100, 101, 114, 44, 32, 109, 115, 99, 111, 114, 108, 105, 98, 44, 32, 86, 101, 114, 115, 105, 111, 110, 61, 52, 46, 48, 46, 48, 46, 48, 44, 32, 67, 117, 108, 116, 117, 114, 101, 61, 110, 101, 117, 116, 114, 97, 108, 44, 32, 80, 117, 98, 108, 105, 99, 75, 101, 121, 84, 111, 107, 101, 110, 61, 98, 55, 55, 97, 53, 99, 53, 54, 49, 57, 51, 52, 101, 48, 56, 57, 35, 83, 121, 115, 116, 101, 109, 46, 82, 101, 115, 111, 117, 114, 99, 101, 115, 46, 82, 117, 110, 116, 105, 109, 101, 82, 101, 115, 111, 117, 114, 99, 101, 83, 101, 116, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 80, 65, 68, 80, 65, 68, 80, 208, 41, 193, 10, 209, 41, 193, 10, 211, 41, 193, 10, 15, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 249, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 49, 0, 0, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 50, 0, 8, 0, 0, 0, 10, 110, 0, 97, 0, 109, 0, 101, 0, 51, 0, 16, 0, 0, 0, 1, 6, 118, 97, 108, 117, 101, 49, 1, 6, 118, 97, 108, 117, 101, 50 };
            using (var ms2 = new MemoryStream(_RefBuffer12))
            {
                using (var reader = new ResourceReader(ms2))
                {

                    var s_found_list = new List<string>();
                    Assert.Throws<FormatException>(() =>
                    {
                        foreach (DictionaryEntry entry in reader)
                        {
                            string key = (string)entry.Key;
                            s_found_list.Add(key);
                        }
                    });
                }
            }
        }