Esempio n. 1
0
        /// <summary>
        /// Tries to load the core PROJ.4 library from a resource package.
        /// </summary>
        /// <param name="name">File name of the library.</param>
        /// <returns>True, if library was loaded, false otherwise.</returns>
        private static bool TryLoadResource(string name)
        {
            try
            {
                byte[] raw;

                using (Package resources = Package.Open(Assembly.GetExecutingAssembly().GetManifestResourceStream(typeof(CoordinateReferenceSystem).Namespace + ".resources.zip")))
                {
                    Uri partUri = new Uri("/" + name, UriKind.Relative);

                    if (!resources.PartExists(partUri))
                    {
                        return(false);
                    }

                    using (Stream dllStm = resources.GetPart(partUri).GetStream())
                        raw = Read(dllStm);
                }

                File.WriteAllBytes(name = TempSpace.TryMakeSpace() + Path.DirectorySeparatorChar + name, raw);
            }
            catch
            {
                return(false);
            }

            try { instance = ApiFactory.CreateNativeApi <ICoordinateTransformation>(name); }
            catch { instance = null; }

            return(instance != null);
        }
Esempio n. 2
0
        /// <summary>
        /// Tries to load the core PROJ.4 library from a file.
        /// </summary>
        /// <param name="name">File name of the library.</param>
        /// <returns>True, if library was loaded, false otherwise.</returns>
        private static bool TryLoad(string name)
        {
            string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) +
                          Path.DirectorySeparatorChar + name;

            if (!File.Exists(path))
            {
                return(instance != null);
            }
            try { instance = ApiFactory.CreateNativeApi <ICoordinateTransformation>(path); }
            catch { instance = null; }

            return(instance != null);
        }