/// <summary>
        /// <para>
        /// This method allows a generalized implementation of transfering
        /// a value from a
        /// <see cref="ResourceBuilder.ResourceAttributes"/>
        /// to a
        /// <see cref="MediaResource"/>
        /// object.
        /// </para>
        ///
        /// <para>
        /// Classes derived from the
        /// <see cref="ResourceBuilder.ResourceAttributes"/>
        /// class have fields, with names that match against fields in a
        /// <see cref="MediaResource"/>
        /// object.
        /// </para>
        /// </summary>
        /// <param name="attribName">name of the attribute to transfer</param>
        /// <param name="res">The
        /// <see cref="MediaResource"/>
        /// object to transfer to.
        /// </param>
        /// <param name="attribs">
        /// The
        /// <see cref="ResourceBuilder.ResourceAttributes"/>
        /// object to transfer from.
        /// </param>
        private static void TransferValue(string attribName, MediaResource res, ResourceAttributes attribs)
        {
            object val = null;

            System.Type type = attribs.GetType();
            FieldInfo   info = type.GetField(attribName);

            if (info != null)
            {
                val = info.GetValue(attribs);

                if (val != null)
                {
                    IValueType ivt = val as IValueType;

                    bool ok = true;
                    if (ivt != null)
                    {
                        ok = ivt.IsValid;
                    }
                    if (ok)
                    {
                        //res.m_Attributes[attribName] = val;
                        res[attribName] = val;
                    }
                }
            }
        }
Exemplo n.º 2
0
        void EmbedResourceFile(string name, string fileName, ResourceAttributes attribute)
        {
            if (resources != null)
            {
                MonoResource[] new_r = new MonoResource [resources.Length + 1];
                System.Array.Copy(resources, new_r, resources.Length);
                resources = new_r;
            }
            else
            {
                resources = new MonoResource [1];
            }
            int p = resources.Length - 1;

            resources [p].name  = name;
            resources [p].attrs = attribute;
            try {
                FileStream s   = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                long       len = s.Length;
                resources [p].data = new byte [len];
                s.Read(resources [p].data, 0, (int)len);
                s.Close();
            } catch {
            }
        }
Exemplo n.º 3
0
        private static void SerializeAttributesInCoral(ResourceAttributes attributes, CoralBody coral, Dictionary <string, CBORObject> dictionary, Uri uriRelative)
        {
            List <string> keys = new List <string>(attributes.Keys);

            keys.Sort();
            foreach (string name in keys)
            {
                if (!CoralsKeys.ContainsKey(name))
                {
                    continue;
                }

                List <string> values = new List <string>(attributes.GetValues(name));
                if (values.Count == 0)
                {
                    continue;
                }

                if (uriRelative != null && name == "anchor")
                {
                    List <string> newValues = new List <string>();
                    foreach (string val in values)
                    {
                        newValues.Add(new Uri(uriRelative, val).ToString());
                    }

                    values = newValues;
                }

                SerializeAttributeInCoral(name, values, coral, null);
            }
        }
Exemplo n.º 4
0
        internal Resource EDAMResource()
        {
            if (this.Data == null)
            {
                return(null);
            }

            Resource resource = new Resource();

            resource.Guid = this.Guid;
            if (resource.Guid == null && this.Data != null)
            {
                resource.Data          = new Data();
                resource.Data.BodyHash = this.DataHash;
                resource.Data.Size     = this.Data.Length;
                resource.Data.Body     = this.Data;
            }
            resource.Mime = this.MimeType;
            ResourceAttributes attributes = new ResourceAttributes();

            if (this.Filename != null)
            {
                attributes.FileName = this.Filename;
            }
            if (this.SourceUrl != null)
            {
                attributes.SourceURL = this.SourceUrl;
            }
            resource.Attributes = attributes;
            return(resource);
        }
Exemplo n.º 5
0
        private static void SerializeAttributes(ResourceAttributes attributes, StringBuilder sb, Uri uriRelative)
        {
            List <string> keys = new List <string>(attributes.Keys);

            keys.Sort();
            foreach (string name in keys)
            {
                List <string> values = new List <string>(attributes.GetValues(name));
                if (values.Count == 0)
                {
                    continue;
                }

                if (uriRelative != null && name == "anchor")
                {
                    List <string> newValues = new List <string>();
                    foreach (string val in values)
                    {
                        newValues.Add(new Uri(uriRelative, val).ToString());
                    }

                    values = newValues;
                }
                sb.Append(Separator);
                SerializeAttribute(name, values, sb);
            }
        }
Exemplo n.º 6
0
        public static void SerializeResourceInCoral(IResource resource, CoralBody coral,
                                                    Dictionary <string, CBORObject> dictionary,
                                                    ResourceAttributes otherAttributes = null, Uri uriRelative = null,
                                                    bool isEndPoint = false)
        {
            CBORObject obj = CBORObject.NewArray();
            CBORObject href;

            if (uriRelative == null)
            {
                href = Ciri.ToCbor(resource.Path + resource.Name);
            }
            else
            {
                href = Ciri.ToCbor(new Uri(uriRelative, resource.Path + resource.Name));
            }

            CoralBody body = new CoralBody();

            SerializeAttributesInCoral(resource.Attributes, body, dictionary, uriRelative);
            if (otherAttributes != null)
            {
                SerializeAttributesInCoral(otherAttributes, body, dictionary, uriRelative);
            }

            if (body.Length == 0)
            {
                body = null;
            }

            CoralItem item = new CoralLink(isEndPoint ? "http://coreapps.org/ref#rd-unit" : "http://coreapps.org/reef#rd-item", href, body);

            coral.Add(item);
        }
Exemplo n.º 7
0
        public static void SerializeResource(IResource resource, CBORObject cbor, Dictionary <string, CBORObject> dictionary,
                                             ResourceAttributes otherAttributes = null, Uri uriRelative = null)
        {
            CBORObject obj = CBORObject.NewMap();
            string     href;

            if (uriRelative == null)
            {
                href = resource.Path + resource.Name;
            }
            else
            {
                href = new Uri(uriRelative, resource.Path + resource.Name).ToString();
            }

            if (dictionary == null)
            {
                obj.Add("href", href);
            }
            else
            {
                obj.Add(1, href);
            }
            SerializeAttributes(resource.Attributes, obj, dictionary, uriRelative);
            if (otherAttributes != null)
            {
                SerializeAttributes(otherAttributes, obj, dictionary, uriRelative);
            }

            cbor.Add(obj);
        }
Exemplo n.º 8
0
        private void AddResourceFile(string name, string fileName, ResourceAttributes attribute, bool fileNeedsToExists)
        {
            check_name_and_filename(name, fileName, fileNeedsToExists);

            // Resource files are created/searched under the assembly storage
            // directory
            if (dir != null)
            {
                fileName = Path.Combine(dir, fileName);
            }

            if (resources != null)
            {
                MonoResource[] new_r = new MonoResource [resources.Length + 1];
                System.Array.Copy(resources, new_r, resources.Length);
                resources = new_r;
            }
            else
            {
                resources = new MonoResource [1];
            }
            int p = resources.Length - 1;

            resources [p].name     = name;
            resources [p].filename = fileName;
            resources [p].attrs    = attribute;
        }
Exemplo n.º 9
0
		/// <summary>
		/// Creates a resource, given a metadata block of values.
		/// </summary>
		/// <param name="attribs"></param>
		/// <returns></returns>
		public static MediaResource CreateResource(ResourceAttributes attribs)
		{
			MediaResource newRes = new MediaResource();
			SetCommonAttributes(newRes, attribs);

			return newRes;
		}
        /// <summary>
        /// Creates a resource, given a metadata block of values.
        /// </summary>
        /// <param name="attribs"></param>
        /// <returns></returns>
        public static MediaResource CreateResource(ResourceAttributes attribs)
        {
            MediaResource newRes = new MediaResource();

            SetCommonAttributes(newRes, attribs);

            return(newRes);
        }
        private void AddResourceFileNoLock(
            String name,
            String fileName,
            ResourceAttributes attribute)
        {
            BCLDebug.Log("DYNIL", "## DYNIL LOGGING: AssemblyBuilder.AddResourceFile( " + name + ", " + fileName + ")");

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), name);
            }
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            if (fileName.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), fileName);
            }
            if (!String.Equals(fileName, Path.GetFileName(fileName)))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_NotSimpleFileName"), "fileName");
            }

            m_assemblyData.CheckResNameConflict(name);
            m_assemblyData.CheckFileNameConflict(fileName);

            String fullFileName;

            if (m_assemblyData.m_strDir == null)
            {
                // If assembly directory is null, use current directory
                fullFileName = Path.Combine(Environment.CurrentDirectory, fileName);
            }
            else
            {
                // Form the full path given the directory provided by user
                fullFileName = Path.Combine(m_assemblyData.m_strDir, fileName);
            }

            // get the full path
            fullFileName = Path.GetFullPath(fullFileName);

            // retrieve just the file name
            fileName = Path.GetFileName(fullFileName);

            if (File.Exists(fullFileName) == false)
            {
                throw new FileNotFoundException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString(
                                                                  "IO.FileNotFound_FileName"),
                                                              fileName), fileName);
            }
            m_assemblyData.AddResWriter(new ResWriterData(null, null, name, fileName, fullFileName, attribute));
        }
Exemplo n.º 12
0
        public void AddResourceFile(string name, string fileName, ResourceAttributes attribs)
        {
            ResourceFile resfile = new ResourceFile();

            resfile.Name       = name;
            resfile.FileName   = fileName;
            resfile.Attributes = attribs;
            resourceFiles.Add(resfile);
        }
        private IResourceWriter DefineResourceNoLock(
            String name,
            String description,
            String fileName,
            ResourceAttributes attribute)
        {
            CodeAccessPermission.DemandInternal(PermissionType.ReflectionEmit);
            BCLDebug.Log("DYNIL", "## DYNIL LOGGING: AssemblyBuilder.DefineResource( " + name + ", " + fileName + ")");

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), name);
            }
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            if (fileName.Length == 0)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "fileName");
            }
            if (!String.Equals(fileName, Path.GetFileName(fileName)))
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_NotSimpleFileName"), "fileName");
            }

            m_assemblyData.CheckResNameConflict(name);
            m_assemblyData.CheckFileNameConflict(fileName);

            ResourceWriter resWriter;
            String         fullFileName;

            if (m_assemblyData.m_strDir == null)
            {
                // If assembly directory is null, use current directory
                fullFileName = Path.Combine(Environment.CurrentDirectory, fileName);
                resWriter    = new ResourceWriter(fullFileName);
            }
            else
            {
                // Form the full path given the directory provided by user
                fullFileName = Path.Combine(m_assemblyData.m_strDir, fileName);
                resWriter    = new ResourceWriter(fullFileName);
            }
            // get the full path
            fullFileName = Path.GetFullPath(fullFileName);

            // retrieve just the file name
            fileName = Path.GetFileName(fullFileName);

            m_assemblyData.AddResWriter(new ResWriterData(resWriter, null, name, fileName, fullFileName, attribute));
            return(resWriter);
        }
 internal ResWriterData(ResourceWriter resWriter, Stream memoryStream, string strName, string strFileName, string strFullFileName, ResourceAttributes attribute)
 {
     this.m_resWriter       = resWriter;
     this.m_memoryStream    = memoryStream;
     this.m_strName         = strName;
     this.m_strFileName     = strFileName;
     this.m_strFullFileName = strFullFileName;
     this.m_nextResWriter   = null;
     this.m_attribute       = attribute;
 }
 internal ResWriterData(ResourceWriter resWriter, Stream memoryStream, string strName, string strFileName, string strFullFileName, ResourceAttributes attribute)
 {
     this.m_resWriter = resWriter;
     this.m_memoryStream = memoryStream;
     this.m_strName = strName;
     this.m_strFileName = strFileName;
     this.m_strFullFileName = strFullFileName;
     this.m_nextResWriter = null;
     this.m_attribute = attribute;
 }
Exemplo n.º 16
0
		/// <summary>
		/// Creates a resource, given the contentUri and protocolInfo.
		/// </summary>
		/// <param name="contentUri"></param>
		/// <param name="protocolInfo"></param>
		/// <returns></returns>
		public static MediaResource CreateResource (string contentUri, string protocolInfo)
		{
			ResourceAttributes attribs = new ResourceAttributes();
			attribs.contentUri = contentUri;
			attribs.protocolInfo = CdsMetadataCaches.ProtocolInfoStrings.CacheThis(protocolInfo);

			MediaResource newRes = new MediaResource();
			SetCommonAttributes(newRes, attribs);

			return newRes;
		}
Exemplo n.º 17
0
        //------------------------------------------------------------
        // CResourceFileInfo Constructor
        //
        /// <summary></summary>
        /// <param name="info"></param>
        /// <param name="id"></param>
        /// <param name="embed"></param>
        /// <param name="vis"></param>
        //------------------------------------------------------------
        internal CResourceFileInfo(
            FileInfo info,
            string logname,
            bool embed,
            bool pub)
        {
            this.fileInfo    = info;
            this.LogicalName = logname;
            this.Embed       = embed;
            this.Access      = (pub ? ResourceAttributes.Public : ResourceAttributes.Private);

            this.searchName = fileInfo.FullName.ToLower();
        }
        /// <summary>
        /// Creates a resource, given the contentUri and protocolInfo.
        /// </summary>
        /// <param name="contentUri"></param>
        /// <param name="protocolInfo"></param>
        /// <returns></returns>
        public static MediaResource CreateResource(string contentUri, string protocolInfo)
        {
            ResourceAttributes attribs = new ResourceAttributes();

            attribs.contentUri   = contentUri;
            attribs.protocolInfo = CdsMetadataCaches.ProtocolInfoStrings.CacheThis(protocolInfo);

            MediaResource newRes = new MediaResource();

            SetCommonAttributes(newRes, attribs);

            return(newRes);
        }
Exemplo n.º 19
0
 public IResourceWriter DefineResource
     (String name, String description,
     ResourceAttributes attribute)
 {
     try
     {
         StartSync();
         // TODO
         return(null);
     }
     finally
     {
         EndSync();
     }
 }
Exemplo n.º 20
0
        public IResourceWriter DefineResource(string name, string description,
                                              string fileName, ResourceAttributes attribute)
        {
            IResourceWriter writer;

            // description seems to be ignored
            AddResourceFile(name, fileName, attribute, false);
            writer = new ResourceWriter(fileName);
            if (resource_writers == null)
            {
                resource_writers = new ArrayList();
            }
            resource_writers.Add(writer);
            return(writer);
        }
Exemplo n.º 21
0
        public void DefineManifestResource(string name, Stream stream, ResourceAttributes attribute)
        {
            ManifestResourceTable.Record rec = new ManifestResourceTable.Record();
            rec.Offset         = manifestResources.Position;
            rec.Flags          = (int)attribute;
            rec.Name           = this.Strings.Add(name);
            rec.Implementation = 0;
            this.ManifestResource.AddRecord(rec);
            manifestResources.Write(0);                 // placeholder for the length
            manifestResources.Write(stream);
            int savePosition = manifestResources.Position;

            manifestResources.Position = rec.Offset;
            manifestResources.Write(savePosition - (manifestResources.Position + 4));
            manifestResources.Position = savePosition;
        }
Exemplo n.º 22
0
        private static void SerializeAttributes(ResourceAttributes attributes, StringBuilder sb)
        {
            List <string> keys = new List <string>(attributes.Keys);

            keys.Sort();
            foreach (string name in keys)
            {
                List <string> values = new List <string>(attributes.GetValues(name));
                if (values.Count == 0)
                {
                    continue;
                }
                sb.Append(Separator);
                SerializeAttribute(name, values, sb);
            }
        }
Exemplo n.º 23
0
        private static void SerializeAttributes(ResourceAttributes attributes, CBORObject cbor, Dictionary <string, CBORObject> dictionary)
        {
            List <string> keys = new List <string>(attributes.Keys);

            keys.Sort();
            foreach (string name in keys)
            {
                List <string> values = new List <string>(attributes.GetValues(name));
                if (values.Count == 0)
                {
                    continue;
                }

                SerializeAttribute(name, values, cbor, dictionary);
            }
        }
 public void AddResourceFile(
     String name,
     String fileName,
     ResourceAttributes attribute)
 {
     CodeAccessPermission.DemandInternal(PermissionType.ReflectionEmit);
     if (m_assemblyData.m_isSynchronized)
     {
         lock (m_assemblyData)
         {
             AddResourceFileNoLock(name, fileName, attribute);
         }
     }
     else
     {
         AddResourceFileNoLock(name, fileName, attribute);
     }
 }
Exemplo n.º 25
0
        internal void EmbedResource(string name, byte[] blob, ResourceAttributes attribute)
        {
            if (resources != null)
            {
                MonoResource[] new_r = new MonoResource [resources.Length + 1];
                System.Array.Copy(resources, new_r, resources.Length);
                resources = new_r;
            }
            else
            {
                resources = new MonoResource [1];
            }
            int p = resources.Length - 1;

            resources [p].name  = name;
            resources [p].attrs = attribute;
            resources [p].data  = blob;
        }
 public IResourceWriter DefineResource(
     String name,
     String description,
     String fileName,
     ResourceAttributes attribute)
 {
     if (m_assemblyData.m_isSynchronized)
     {
         lock (m_assemblyData)
         {
             return(DefineResourceNoLock(name, description, fileName, attribute));
         }
     }
     else
     {
         return(DefineResourceNoLock(name, description, fileName, attribute));
     }
 }
Exemplo n.º 27
0
        public IResourceWriter DefineResource(string name, string description, ResourceAttributes attribute)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name == String.Empty)
            {
                throw new ArgumentException("name cannot be empty");
            }
            if (transient)
            {
                throw new InvalidOperationException("The module is transient");
            }
            if (!assemblyb.IsSave)
            {
                throw new InvalidOperationException("The assembly is transient");
            }
            ResourceWriter writer = new ResourceWriter(new MemoryStream());

            if (resource_writers == null)
            {
                resource_writers = new Hashtable();
            }
            resource_writers [name] = writer;

            // The data is filled out later
            if (resources != null)
            {
                MonoResource[] new_r = new MonoResource [resources.Length + 1];
                System.Array.Copy(resources, new_r, resources.Length);
                resources = new_r;
            }
            else
            {
                resources = new MonoResource [1];
            }
            int p = resources.Length - 1;

            resources [p].name  = name;
            resources [p].attrs = attribute;

            return(writer);
        }
Exemplo n.º 28
0
 public static void SerializeResource(IResource resource, StringBuilder sb, ResourceAttributes otherAttributes = null,
                                      Uri uriRelative = null)
 {
     sb.Append("<");
     if (uriRelative != null)
     {
         sb.Append(new Uri(uriRelative, resource.Path + resource.Name).ToString());
     }
     else
     {
         sb.Append(resource.Path)
         .Append(resource.Name);
     }
     sb.Append(">");
     SerializeAttributes(resource.Attributes, sb, uriRelative);
     if (otherAttributes != null)
     {
         SerializeAttributes(otherAttributes, sb, uriRelative);
     }
 }
Exemplo n.º 29
0
		/// <summary>
		/// Constructors use this method to set the properties of a resource.
		/// Programmers can use this method also, but the method is not
		/// guaranteed to be thread safe. As a general rule, programmers shouldn't
		/// be changing the values of resources after they've instantiated them.
		/// </summary>
		/// <param name="res"></param>
		/// <param name="attribs"></param>
		public static void SetCommonAttributes(MediaResource res, ResourceAttributes attribs)
		{
			res.ProtocolInfo = attribs.protocolInfo;
			res.ContentUri = attribs.contentUri.Trim();
			
			if ((attribs.importUri != null) && (attribs.importUri != ""))
			{
				res[T[_RESATTRIB.importUri]] = attribs.importUri;
			}

			TransferValue("bitrate", res, attribs);
			TransferValue("bitsPerSample", res, attribs);
			TransferValue("colorDepth", res, attribs);
			TransferValue("duration", res, attribs);
			TransferValue("nrAudioChannels", res, attribs);
			TransferValue("protection", res, attribs);
			TransferValue("resolution", res, attribs);
			TransferValue("sampleFrequency", res, attribs);
			TransferValue("size", res, attribs);
		}
        /// <summary>
        /// Constructors use this method to set the properties of a resource.
        /// Programmers can use this method also, but the method is not
        /// guaranteed to be thread safe. As a general rule, programmers shouldn't
        /// be changing the values of resources after they've instantiated them.
        /// </summary>
        /// <param name="res"></param>
        /// <param name="attribs"></param>
        public static void SetCommonAttributes(MediaResource res, ResourceAttributes attribs)
        {
            res.ProtocolInfo = attribs.protocolInfo;
            res.ContentUri   = attribs.contentUri.Trim();

            if ((attribs.importUri != null) && (attribs.importUri != ""))
            {
                res[T[_RESATTRIB.importUri]] = attribs.importUri;
            }

            TransferValue("bitrate", res, attribs);
            TransferValue("bitsPerSample", res, attribs);
            TransferValue("colorDepth", res, attribs);
            TransferValue("duration", res, attribs);
            TransferValue("nrAudioChannels", res, attribs);
            TransferValue("protection", res, attribs);
            TransferValue("resolution", res, attribs);
            TransferValue("sampleFrequency", res, attribs);
            TransferValue("size", res, attribs);
        }
Exemplo n.º 31
0
        public void DefineManifestResource(string name, Stream stream, ResourceAttributes attribute)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name == String.Empty)
            {
                throw new ArgumentException("name cannot be empty");
            }
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (transient)
            {
                throw new InvalidOperationException("The module is transient");
            }
            if (!assemblyb.IsSave)
            {
                throw new InvalidOperationException("The assembly is transient");
            }

            if (resources != null)
            {
                MonoResource[] new_r = new MonoResource [resources.Length + 1];
                System.Array.Copy(resources, new_r, resources.Length);
                resources = new_r;
            }
            else
            {
                resources = new MonoResource [1];
            }
            int p = resources.Length - 1;

            resources [p].name   = name;
            resources [p].attrs  = attribute;
            resources [p].stream = stream;
        }
Exemplo n.º 32
0
    public IEnumerator gatherResources(string resourceName)
    {
        if (!gatheringResource)
        {
            gatheringResource = true;
            ResourceAttributes closestResource = null;
            IEnumerator        coroutine       = null;

            if (resourceName.Equals("StoneDepot") && findClosestResource(stoneDepotsInRange) != null)
            {
                closestResource = findClosestResource(stoneDepotsInRange);
            }
            if (resourceName.Equals("Tree") && findClosestResource(treesInRange) != null)
            {
                closestResource = findClosestResource(treesInRange);
            }
            if (closestResource != null)
            {
                StartCoroutine(coroutine = closestResource.walkingToResource(this));
            }

            while (gatheringResource)
            {
                if (closestResource == null)
                {
                    break;
                }
                if (closestResource.getGatheringResourcesRunning() && this.getResourceBeingMined() != closestResource)
                {
                    StopCoroutine(coroutine);
                    break;
                }
                yield return(null);
            }
            gatheringResource = false;
        }
    }
Exemplo n.º 33
0
        public void AddResourceFile(string name, string file, ResourceAttributes attribute)
        {
            IResourceWriter rw = _myModule.DefineResource(Path.GetFileName(file), name, attribute);

            string ext = Path.GetExtension(file);

            if (String.Equals(ext, ".resources", StringComparison.OrdinalIgnoreCase))
            {
                ResourceReader rr = new ResourceReader(file);
                using (rr) {
                    System.Collections.IDictionaryEnumerator de = rr.GetEnumerator();

                    while (de.MoveNext())
                    {
                        string key = de.Key as string;
                        rw.AddResource(key, de.Value);
                    }
                }
            }
            else
            {
                rw.AddResource(name, File.ReadAllBytes(file));
            }
        }
Exemplo n.º 34
0
		public IResourceWriter DefineResource(string name, string description, string fileName, ResourceAttributes attribute)
		{
			// FXBUG we ignore the description, because there is no such thing

			string fullPath = fileName;
			if (dir != null)
			{
				fullPath = Path.Combine(dir, fileName);
			}
			ResourceWriter rw = new ResourceWriter(fullPath);
			ResourceFile resfile;
			resfile.Name = name;
			resfile.FileName = fileName;
			resfile.Attributes = attribute;
			resfile.Writer = rw;
			resourceFiles.Add(resfile);
			return rw;
		}
Exemplo n.º 35
0
		public void AddResourceFile(string name, string fileName, ResourceAttributes attribs)
		{
			ResourceFile resfile = new ResourceFile();
			resfile.Name = name;
			resfile.FileName = fileName;
			resfile.Attributes = attribs;
			resourceFiles.Add(resfile);
		}
Exemplo n.º 36
0
			public LinkedResource (string name, string file, bool isPrivate)
			{
				this.name = name;
				this.file = file;
				this.attribute = isPrivate ? ResourceAttributes.Private : ResourceAttributes.Public;
			}
Exemplo n.º 37
0
        private void AddResourceFileNoLock(
            String      name,
            String      fileName,
            ResourceAttributes attribute)
        {
            if (name == null)
                throw new ArgumentNullException("name");
            if (name.Length == 0)
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), name);
            if (fileName == null)
                throw new ArgumentNullException("fileName");
            if (fileName.Length == 0)
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), fileName);
            if (!String.Equals(fileName, Path.GetFileName(fileName)))
                throw new ArgumentException(Environment.GetResourceString("Argument_NotSimpleFileName"), "fileName");
            Contract.EndContractBlock();

            BCLDebug.Log("DYNIL", "## DYNIL LOGGING: AssemblyBuilder.AddResourceFile( " + name + ", " + fileName + ")");

            m_assemblyData.CheckResNameConflict(name);
            m_assemblyData.CheckFileNameConflict(fileName);

            String  fullFileName;

            if (m_assemblyData.m_strDir == null)
            {
                // If assembly directory is null, use current directory
                fullFileName = Path.Combine(Directory.GetCurrentDirectory(), fileName);
            }
            else
            {
                // Form the full path given the directory provided by user
                fullFileName = Path.Combine(m_assemblyData.m_strDir, fileName);
            }
            
            // get the full path
            fullFileName = Path.UnsafeGetFullPath(fullFileName);
            
            // retrieve just the file name
            fileName = Path.GetFileName(fullFileName);
            
            if (File.UnsafeExists(fullFileName) == false)
                throw new FileNotFoundException(Environment.GetResourceString(
                    "IO.FileNotFound_FileName",
                    fileName), fileName);
            m_assemblyData.AddResWriter( new ResWriterData( null, null, name, fileName, fullFileName, attribute) );
        }
Exemplo n.º 38
0
		private void AddResourceFile (string name, string fileName, ResourceAttributes attribute, bool fileNeedsToExists)
		{
			check_name_and_filename (name, fileName, fileNeedsToExists);

			// Resource files are created/searched under the assembly storage
			// directory
			if (dir != null)
				fileName = Path.Combine (dir, fileName);

			if (resources != null) {
				MonoResource[] new_r = new MonoResource [resources.Length + 1];
				System.Array.Copy(resources, new_r, resources.Length);
				resources = new_r;
			} else {
				resources = new MonoResource [1];
			}
			int p = resources.Length - 1;
			resources [p].name = name;
			resources [p].filename = fileName;
			resources [p].attrs = attribute;
		}
Exemplo n.º 39
0
        public void AddResourceFile(string name, string file, ResourceAttributes attribute)
        {
            IResourceWriter rw = _myModule.DefineResource(Path.GetFileName(file), name, attribute);

            string ext = Path.GetExtension(file);
            if(String.Equals(ext, ".resources", StringComparison.OrdinalIgnoreCase)) {
                ResourceReader rr = new ResourceReader(file);
                using (rr) {
                    System.Collections.IDictionaryEnumerator de = rr.GetEnumerator();

                    while (de.MoveNext()) {
                        string key = de.Key as string;
                        rw.AddResource(key, de.Value);
                    }
                }
            } else {
                rw.AddResource(name, File.ReadAllBytes(file));
            }
        }
Exemplo n.º 40
0
        public void DefineManifestResource(String name, Stream stream, ResourceAttributes attribute)
        {
            if (name == null)
                throw new ArgumentNullException("name");
            
            if (stream == null)
                throw new ArgumentNullException("stream");
            Contract.EndContractBlock();

            // Define embedded managed resource to be stored in this module

            lock(SyncRoot)
            {
                DefineManifestResourceNoLock(name, stream, attribute);
            }
        }
 private IResourceWriter DefineResourceNoLock(string name, string description, ResourceAttributes attribute)
 {
     if (this.IsTransient())
     {
         throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadResourceContainer"));
     }
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (name.Length == 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
     }
     if (!this.m_assemblyBuilder.IsPersistable())
     {
         throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadResourceContainer"));
     }
     this.m_assemblyBuilder.m_assemblyData.CheckResNameConflict(name);
     MemoryStream stream = new MemoryStream();
     ResourceWriter resWriter = new ResourceWriter(stream);
     ResWriterData data = new ResWriterData(resWriter, stream, name, string.Empty, string.Empty, attribute) {
         m_nextResWriter = this.m_moduleData.m_embeddedRes
     };
     this.m_moduleData.m_embeddedRes = data;
     return resWriter;
 }
 public void AddResourceFile(string name, string fileName, ResourceAttributes attribute)
 {
     lock (this.SyncRoot)
     {
         this.AddResourceFileNoLock(name, fileName, attribute);
     }
 }
 private void AddResourceFileNoLock(string name, string fileName, ResourceAttributes attribute)
 {
     string fullPath;
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (name.Length == 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), name);
     }
     if (fileName == null)
     {
         throw new ArgumentNullException("fileName");
     }
     if (fileName.Length == 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), fileName);
     }
     if (!string.Equals(fileName, Path.GetFileName(fileName)))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_NotSimpleFileName"), "fileName");
     }
     this.m_assemblyData.CheckResNameConflict(name);
     this.m_assemblyData.CheckFileNameConflict(fileName);
     if (this.m_assemblyData.m_strDir == null)
     {
         fullPath = Path.Combine(Environment.CurrentDirectory, fileName);
     }
     else
     {
         fullPath = Path.Combine(this.m_assemblyData.m_strDir, fileName);
     }
     fullPath = Path.GetFullPath(fullPath);
     fileName = Path.GetFileName(fullPath);
     if (!File.Exists(fullPath))
     {
         throw new FileNotFoundException(Environment.GetResourceString("IO.FileNotFound_FileName", new object[] { fileName }), fileName);
     }
     this.m_assemblyData.AddResWriter(new ResWriterData(null, null, name, fileName, fullPath, attribute));
 }
 public IResourceWriter DefineResource(string name, string description, string fileName, ResourceAttributes attribute)
 {
     lock (this.SyncRoot)
     {
         return this.DefineResourceNoLock(name, description, fileName, attribute);
     }
 }
 private IResourceWriter DefineResourceNoLock(string name, string description, string fileName, ResourceAttributes attribute)
 {
     ResourceWriter writer;
     string fullPath;
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (name.Length == 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), name);
     }
     if (fileName == null)
     {
         throw new ArgumentNullException("fileName");
     }
     if (fileName.Length == 0)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), "fileName");
     }
     if (!string.Equals(fileName, Path.GetFileName(fileName)))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_NotSimpleFileName"), "fileName");
     }
     this.m_assemblyData.CheckResNameConflict(name);
     this.m_assemblyData.CheckFileNameConflict(fileName);
     if (this.m_assemblyData.m_strDir == null)
     {
         fullPath = Path.Combine(Environment.CurrentDirectory, fileName);
         writer = new ResourceWriter(fullPath);
     }
     else
     {
         fullPath = Path.Combine(this.m_assemblyData.m_strDir, fileName);
         writer = new ResourceWriter(fullPath);
     }
     fullPath = Path.GetFullPath(fullPath);
     fileName = Path.GetFileName(fullPath);
     this.m_assemblyData.AddResWriter(new ResWriterData(writer, null, name, fileName, fullPath, attribute));
     return writer;
 }
Exemplo n.º 46
0
 public IResourceWriter DefineResource(String name, String description, ResourceAttributes attribute)
 { 
     // Define embedded managed resource to be stored in this module
     lock(SyncRoot) 
     { 
         return DefineResourceNoLock(name, description, attribute);
     } 
 }
Exemplo n.º 47
0
        /// <summary>Enbdeds resource into assembly</summary>
        /// <param name="builder"><see cref="ModuleBuilder"/> to embede resource in</param>
        /// <param name="name">Name of the resource</param>
        /// <param name="path">File to obtain resource from</param>
        /// <param name="attributes">Defines resource visibility</param>

        //DefineResource
        // Exceptions:
        //   System.ArgumentException:
        //     name has been previously defined or if there is another file in the assembly
        //     named fileName.-or- The length of name is zero.-or- The length of fileName
        //     is zero.-or- fileName includes a path.
        //
        //   System.ArgumentNullException:
        //     name or fileName is null.
        //
        //   System.Security.SecurityException:
        //     The caller does not have the required permission.

        //ResourceReader
        // Exceptions:
        //   System.ArgumentException:
        //     The stream is not readable.
        //
        //   System.ArgumentNullException:
        //     The stream parameter is null.
        //
        //   System.IO.IOException:
        //     An I/O error has occurred while accessing stream.

        //AddResource
        // Exceptions:
        //   System.ArgumentNullException:
        //     The name parameter is null.

        //ReadAllBytes
        // Exceptions:
        //   System.ArgumentException:
        //     path is a zero-length string, contains only white space, or contains one
        //     or more invalid characters as defined by System.IO.Path.InvalidPathChars.
        //
        //   System.ArgumentNullException:
        //     path is null.
        //
        //   System.IO.PathTooLongException:
        //     The specified path, file name, or both exceed the system-defined maximum
        //     length. For example, on Windows-based platforms, paths must be less than
        //     248 characters, and file names must be less than 260 characters.
        //
        //   System.IO.DirectoryNotFoundException:
        //     The specified path is invalid (for example, it is on an unmapped drive).
        //
        //   System.IO.IOException:
        //     An I/O error occurred while opening the file.
        //
        //   System.UnauthorizedAccessException:
        //     path specified a file that is read-only.-or- This operation is not supported
        //     on the current platform.-or- path specified a directory.-or- The caller does
        //     not have the required permission.
        //
        //   System.IO.FileNotFoundException:
        //     The file specified in path was not found.
        //
        //   System.NotSupportedException:
        //     path is in an invalid format.
        //
        //   System.Security.SecurityException:
        //     The caller does not have the required permission.
        private void AddResourceFile(ModuleBuilder builder,string name, FullPath path, ResourceAttributes attributes) {
            IResourceWriter rw = builder.DefineResource(path.FileName, name, attributes);
            string ext = path.Extension.ToLower();
            if(ext == ".resources") {
                ResourceReader rr = new ResourceReader(path);
                using(rr) {
                    System.Collections.IDictionaryEnumerator de = rr.GetEnumerator();
                    while(de.MoveNext()) {
                        string key = de.Key as string;
                        rw.AddResource(key, de.Value);
                    }
                }
            } else {
                rw.AddResource(name, File.ReadAllBytes(path));
            }              
        }
Exemplo n.º 48
0
		public IResourceWriter DefineResource (string name, string description,
						       string fileName, ResourceAttributes attribute)
		{
			IResourceWriter writer;

			// description seems to be ignored
			AddResourceFile (name, fileName, attribute, false);
			writer = new ResourceWriter (fileName);
			if (resource_writers == null)
				resource_writers = new ArrayList ();
			resource_writers.Add (writer);
			return writer;
		}
Exemplo n.º 49
0
		internal void EmbedResource (string name, byte[] blob, ResourceAttributes attribute)
		{
			if (resources != null) {
				MonoResource[] new_r = new MonoResource [resources.Length + 1];
				System.Array.Copy(resources, new_r, resources.Length);
				resources = new_r;
			} else {
				resources = new MonoResource [1];
			}
			int p = resources.Length - 1;
			resources [p].name = name;
			resources [p].attrs = attribute;
			resources [p].data = blob;
		}
Exemplo n.º 50
0
        /**********************************************
        *
        * Define embedded managed resource to be stored in this module
        *                                                               
        *
        **********************************************/
        /// <include file='doc\ModuleBuilder.uex' path='docs/doc[@for="ModuleBuilder.DefineResource1"]/*' />
        
        public IResourceWriter DefineResource(
            String      name,
            String      description,
            ResourceAttributes attribute)
        {
            CodeAccessPermission.DemandInternal(PermissionType.ReflectionEmit);
            try
            {
                Enter();

                BCLDebug.Log("DYNIL","## DYNIL LOGGING: ModuleBuilder.DefineResource( " + name + ")");

                if (IsTransient())
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadResourceContainer"));

                if (name == null)
                    throw new ArgumentNullException("name");
                if (name.Length == 0)
                    throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");

                Assembly assembly = this.Assembly;
                if (assembly is AssemblyBuilder)
                {
                    AssemblyBuilder asmBuilder = (AssemblyBuilder)assembly;
                    if (asmBuilder.IsPersistable())
                    {
                        asmBuilder.m_assemblyData.CheckResNameConflict(name);

                        MemoryStream stream = new MemoryStream();
                        ResourceWriter resWriter = new ResourceWriter(stream);
                        ResWriterData resWriterData = new ResWriterData( resWriter, stream, name, String.Empty, String.Empty, attribute);

                        // chain it to the embedded resource list
                        resWriterData.m_nextResWriter = m_moduleData.m_embeddedRes;
                        m_moduleData.m_embeddedRes = resWriterData;
                        return resWriter;
                    }
                    else
                    {
                        throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadResourceContainer"));
                    }
                }
                else
                {
                    throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadResourceContainer"));
                }
            }
            finally
            {
                Exit();
            }
        }
Exemplo n.º 51
0
 /// <summary>Adds an existing resource file to this assembly.</summary><param name="name">The logical name of the resource. </param><param name="fileName">The physical file name (.resources file) to which the logical name is mapped. This should not include a path; the file must be in the same directory as the assembly to which it is added. </param><param name="attribute">The resource attributes. </param><exception cref="T:System.ArgumentException"><paramref name="name" /> has been previously defined.-or- There is another file in the assembly named <paramref name="fileName" />.-or- The length of <paramref name="name" /> is zero or if the length of <paramref name="fileName" /> is zero.-or- <paramref name="fileName" /> includes a path. </exception><exception cref="T:System.ArgumentNullException"><paramref name="name" /> or <paramref name="fileName" /> is null. </exception><exception cref="T:System.IO.FileNotFoundException">If the file <paramref name="fileName" /> is not found. </exception><exception cref="T:System.Security.SecurityException">The caller does not have the required permission. </exception><PermissionSet><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /></PermissionSet>
 public void AddResourceFile(string name, string fileName, ResourceAttributes attribute)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 52
0
		public IResourceWriter DefineResource (string name, string description, ResourceAttributes attribute)
		{
			if (name == null)
				throw new ArgumentNullException ("name");
			if (name == String.Empty)
				throw new ArgumentException ("name cannot be empty");
			if (transient)
				throw new InvalidOperationException ("The module is transient");
			if (!assemblyb.IsSave)
				throw new InvalidOperationException ("The assembly is transient");
			ResourceWriter writer = new ResourceWriter (new MemoryStream ());
			if (resource_writers == null)
				resource_writers = new Hashtable ();
			resource_writers [name] = writer;

			// The data is filled out later
			if (resources != null) {
				MonoResource[] new_r = new MonoResource [resources.Length + 1];
				System.Array.Copy(resources, new_r, resources.Length);
				resources = new_r;
			} else {
				resources = new MonoResource [1];
			}
			int p = resources.Length - 1;
			resources [p].name = name;
			resources [p].attrs = attribute;

			return writer;
		}
Exemplo n.º 53
0
		public void AddResourceFile (string name, string fileName, ResourceAttributes attribute)
		{
			AddResourceFile (name, fileName, attribute, true);
		}
Exemplo n.º 54
0
		public void DefineManifestResource (string name, Stream stream, ResourceAttributes attribute) {
			if (name == null)
				throw new ArgumentNullException ("name");
			if (name == String.Empty)
				throw new ArgumentException ("name cannot be empty");
			if (stream == null)
				throw new ArgumentNullException ("stream");
			if (transient)
				throw new InvalidOperationException ("The module is transient");
			if (!assemblyb.IsSave)
				throw new InvalidOperationException ("The assembly is transient");

			if (resources != null) {
				MonoResource[] new_r = new MonoResource [resources.Length + 1];
				System.Array.Copy(resources, new_r, resources.Length);
				resources = new_r;
			} else {
				resources = new MonoResource [1];
			}
			int p = resources.Length - 1;
			resources [p].name = name;
			resources [p].attrs = attribute;
			resources [p].stream = stream;
		}
Exemplo n.º 55
0
		void EmbedResourceFile (string name, string fileName, ResourceAttributes attribute)
		{
			if (resources != null) {
				MonoResource[] new_r = new MonoResource [resources.Length + 1];
				System.Array.Copy(resources, new_r, resources.Length);
				resources = new_r;
			} else {
				resources = new MonoResource [1];
			}
			int p = resources.Length - 1;
			resources [p].name = name;
			resources [p].attrs = attribute;
			try {
				FileStream s = new FileStream (fileName, FileMode.Open, FileAccess.Read);
				long len = s.Length;
				resources [p].data = new byte [len];
				s.Read (resources [p].data, 0, (int)len);
				s.Close ();
			} catch {
			}
		}
Exemplo n.º 56
0
 /**********************************************
 *
 * Define stand alone managed resource for Assembly
 *
 **********************************************/
 public IResourceWriter DefineResource(
     String      name,
     String      description,
     String      fileName,
     ResourceAttributes attribute)
 {
     lock(SyncRoot)
     {
         return DefineResourceNoLock(name, description, fileName, attribute);
     }
 }
Exemplo n.º 57
0
        public IResourceWriter DefineResource(String name, String description, ResourceAttributes attribute)
        {
            // Define embedded managed resource to be stored in this module
            Contract.Ensures(Contract.Result<IResourceWriter>() != null);

            lock(SyncRoot)
            {
                return DefineResourceNoLock(name, description, attribute);
            }
        }
Exemplo n.º 58
0
		/// <summary>
		/// <para>
		/// This method allows a generalized implementation of transfering
		/// a value from a 
		/// <see cref="ResourceBuilder.ResourceAttributes"/>
		/// to a
		/// <see cref="MediaResource"/>
		/// object. 
		/// </para>
		/// 
		/// <para>
		/// Classes derived from the
		/// <see cref="ResourceBuilder.ResourceAttributes"/>
		/// class have fields, with names that match against fields in a 
		/// <see cref="MediaResource"/>
		/// object. 
		/// </para>
		/// </summary>
		/// <param name="attribName">name of the attribute to transfer</param>
		/// <param name="res">The
		/// <see cref="MediaResource"/>
		/// object to transfer to.
		/// </param>
		/// <param name="attribs">
		/// The
		/// <see cref="ResourceBuilder.ResourceAttributes"/>
		/// object to transfer from.
		/// </param>
		private static void TransferValue(string attribName, MediaResource res, ResourceAttributes attribs)
		{
			object val = null;
			
			System.Type type = attribs.GetType();
			FieldInfo info = type.GetField(attribName);
			if (info != null)
			{
				val = info.GetValue(attribs);

				if (val != null)
				{
					IValueType ivt = val as IValueType;

					bool ok = true;
					if (ivt != null)
					{
						ok = ivt.IsValid;
					}
					if (ok)
					{
						//res.m_Attributes[attribName] = val;
						res[attribName] = val;
					}
				}
			}
		}
Exemplo n.º 59
0
        private void DefineManifestResourceNoLock(String name, Stream stream, ResourceAttributes attribute)
        {
            // Define embedded managed resource to be stored in this module
           if (IsTransient())
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadResourceContainer"));
           Contract.EndContractBlock();

            if (name == null)
                throw new ArgumentNullException("name");
            if (name.Length == 0)
                throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "name");
        
            if (m_assemblyBuilder.IsPersistable())
            {
                m_assemblyBuilder.m_assemblyData.CheckResNameConflict(name);

                ResWriterData resWriterData = new ResWriterData( null, stream, name, String.Empty, String.Empty, attribute);
    
                // chain it to the embedded resource list
                resWriterData.m_nextResWriter = m_moduleData.m_embeddedRes;
                m_moduleData.m_embeddedRes = resWriterData;
            }
            else
            { 
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadResourceContainer"));
            }
        }
Exemplo n.º 60
0
 [System.Security.SecurityCritical] // auto-generated
 #endif
 public void AddResourceFile(
     String      name,
     String      fileName,
     ResourceAttributes attribute)
 {
     lock(SyncRoot)
     {
         AddResourceFileNoLock(name, fileName, attribute);
     }
 }