Example #1
0
        private byte[] GetResourceAsBinaryFromZipped(string resourcePath)
        {
            if (_zipFile != null)
            {
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "# Loading resource from zipped file: " + resourcePath);
                //Stopwatch stopwatch = new Stopwatch();
                //stopwatch.Start();

                ZipEntry entry = this.GetZipEntry(resourcePath);                  // getting the entry from the _zipFile.GetEntry() method is less efficient
                if (entry != null)
                {
                    //SystemLogger.Log(SystemLogger.Module.PLATFORM, "# entry found [" + entry.Name + "]: " + entry.Size);

                    //long et1 = stopwatch.ElapsedMilliseconds;
                    Stream entryStream = _zipFile.GetInputStream(entry);

                    //long et2 = stopwatch.ElapsedMilliseconds;

                    // entryStream is not seekable, it should be first readed
                    byte[] data = IPhoneUtils.ConvertNonSeekableStreamToByteArray(entryStream);                     //, entry.Size
                    //SystemLogger.Log(SystemLogger.Module.PLATFORM, "# entry found [" + entry.Name + "], data byte array size:" + data.Length);

                    //long et3 = stopwatch.ElapsedMilliseconds;
                    //SystemLogger.Log(SystemLogger.Module.PLATFORM, "CSV," + resourcePath + "," + entry.Size + "," + entry.CompressedSize + ","+ et1 +","+(et2-et1)+","+(et3-et2)+","+(et3));
                    //stopwatch.Stop();
                    return(data);
                }

                //stopwatch.Stop();
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// Stores the module zip file.
        /// </summary>
        /// <returns><c>true</c>, if module zip file was stored, <c>false</c> otherwise.</returns>
        /// <param name="module">Module.</param>
        /// <param name="tempFile">Temp file.</param>
        public override bool StoreModuleZipFile(Module module, string tempFile)
        {
            bool       result           = false;
            FileStream streamWriter     = null;
            String     fullTempFilePath = null;

            try {
                fullTempFilePath = Path.Combine(this.GetFileSystemService().GetDirectoryRoot().FullName, tempFile);

                string location         = this.GetModuleLocation(module, true);
                string moduleRootDir    = module.Id + "-" + module.Version.ToString() + Path.DirectorySeparatorChar;
                string versionDirectory = Path.Combine(this.GetFileSystemService().GetDirectoryRoot().FullName, location);
                string appDirectory     = Path.Combine(this.GetFileSystemService().GetDirectoryRoot().FullName, this.GetModuleLocation(module, false));
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "Storing module to: " + location);

                if (!Directory.Exists(appDirectory))
                {
                    Directory.CreateDirectory(versionDirectory);
                }
                else
                {
                    Directory.Delete(appDirectory, true);
                    Directory.CreateDirectory(versionDirectory);
                }

                ZipFile zipFile = new ZipFile(fullTempFilePath);
                foreach (ZipEntry theEntry in zipFile)
                {
                    // just for testing...
                    // SystemLogger.Log(SystemLogger.Module.PLATFORM, "Storing module entry name: " + theEntry.Name);
                    string fileName = Path.GetFileName(theEntry.Name);
                    if (fileName != String.Empty)
                    {
                        string fullPath = versionDirectory + "/" + theEntry.Name;

                        if (theEntry.Name.IndexOf(moduleRootDir) == 0)
                        {
                            fullPath = versionDirectory + "/" + theEntry.Name.Substring(moduleRootDir.Length);
                        }

                        fullPath = fullPath.Replace("\\", "/");
                        string fullDirPath = Path.GetDirectoryName(fullPath);
                        if (!Directory.Exists(fullDirPath))
                        {
                            Directory.CreateDirectory(fullDirPath);
                        }
                        streamWriter = File.Create(fullPath);

                        Stream entryStream = zipFile.GetInputStream(theEntry);
                        byte[] data        = IPhoneUtils.ConvertNonSeekableStreamToByteArray(entryStream);
                        streamWriter.Write(data, 0, data.Length);

                        streamWriter.Close();
                        streamWriter = null;
                    }
                }
                result = true;
            } catch (Exception ex) {
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "Exception when storing module: " + ex.Message, ex);
            } finally {
                if (streamWriter != null)
                {
                    streamWriter.Close();
                }

                if (fullTempFilePath != null && File.Exists(fullTempFilePath))
                {
                    // deleting tempFile
                    File.Delete(fullTempFilePath);
                    SystemLogger.Log(SystemLogger.Module.PLATFORM, "tmp file deleted");
                }
            }
            return(result);
        }