Пример #1
0
        /* Opens a workbook handle based on a request */
        public SpreadsheetGear.IWorkbook GetWorkBook(EIA.Repository.CModelRequest Request)
        {
            /* Shared */
            Guid mGuid = Guid.Parse(Request.Model.Guid);
            Byte[] WbData, WbDataCopy;

            /* Sanitize the cache before we decrypt */
            if (lDecryptedCache.ContainsKey(mGuid)) {
                WbData = lDecryptedCache[mGuid];
            }
            else
            {
                /* Create a new instance of encryptor */
                AesEncryption Decryptor = new AesEncryption(Key, Vector);

                /* Calculate Path */
                String ModelPath = Environment.GetFolderPath(
                    Environment.SpecialFolder.CommonDocuments) + "\\EIA\\Models\\"
                    + Request.Model.Name + " - " + Request.Model.Country + " - " + Request.Model.Type + ".xlsm";

                /* Read in model */
                Byte[] EncryptedWbData = File.ReadAllBytes(ModelPath);
                WbData = Decryptor.StrToByteArray(Decryptor.Decrypt(EncryptedWbData));

                /* Store */
                lDecryptedCache.Add(mGuid, WbData);
            }

            /* Create a copy of the data */
            WbDataCopy = new Byte[WbData.Length];
            WbData.CopyTo(WbDataCopy, 0);

            /* Create the memory stream */
            MemoryStream mStream = new MemoryStream(WbDataCopy);

            /* Open Workbook */
            return SpreadsheetGear.Factory.GetWorkbookSet().Workbooks.OpenFromStream(mStream);
        }