/// <summary>
        /// Creates a workbook <see cref="ISession"/> where the cache of the associated <see cref="Assembler"/>
        /// is populated with data sourced from the workbook
        /// </summary>
        /// <param name="dal">
        /// The <see cref="IDal"/> instance used to communicate with the data-source.
        /// </param>
        /// <param name="credentials">
        /// The <see cref="Credentials"/> used to communicate with the data-source.
        /// </param>
        /// <returns>
        /// An instance of <see cref="ISession"/> that is specific to the <see cref="Workbook"/>
        /// </returns>
        private async Task <ISession> CreateWorkbookSession(IDal dal, Credentials credentials)
        {
            var workbookDataDal = new WorkbookDataDal(this.workbook);
            var workbookData    = workbookDataDal.Read();

            var workbookSession = dal.CreateSession(credentials);

            if (workbookData != null)
            {
                if (workbookData.SiteDirectoryThings != null && workbookData.SiteDirectoryThings.Any())
                {
                    await workbookSession.Assembler.Synchronize(workbookData.SiteDirectoryThings, false);
                }

                if (workbookData.IterationThings != null && workbookData.IterationThings.Any())
                {
                    var iterationThings = workbookData.IterationThings.ToList();

                    this.SetIterationContainer(ref iterationThings);

                    await workbookSession.Assembler.Synchronize(iterationThings, false);
                }
            }

            return(workbookSession);
        }
        public void VerifyThatTheSessionDataIsWrittenToAWorkbookandCanBeRetrieved()
        {
            var sw = new Stopwatch();

            NetOffice.ExcelApi.Application application = null;
            Workbook workbook = null;

            try
            {
                sw.Start();
                application = new Application();
                Console.WriteLine("Excel application started in " + sw.ElapsedMilliseconds);

                workbook = application.Workbooks.Open(this.testfilepath, false, false);

                var workbookDataDal = new WorkbookDataDal(workbook);
                workbookDataDal.Write(this.workbookData);
                workbook.Save();

                var retrievedWbData = workbookDataDal.Read();

                Assert.NotNull(retrievedWbData);

                Assert.IsNotEmpty(retrievedWbData.SitedirectoryData.Value);

                var things = retrievedWbData.IterationThings;

                var iterationDto = things.SingleOrDefault(x => x.Iid == this.iteration.Iid);
                Assert.IsNotNull(iterationDto);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw ex;
            }
            finally
            {
                if (workbook != null)
                {
                    Console.WriteLine("Closing workbook {0}", this.testfilepath);
                    workbook.Close();
                    workbook.Dispose();
                }

                if (application != null)
                {
                    Console.WriteLine("Closing Excel Application");
                    application.Quit();
                    application.Dispose();
                }
            }
        }
Пример #3
0
        public void VerifyThatIfCustomXmlPartDoesNotExistsTheWorkbookSessionIsNull()
        {
            var application = new Application();
            var workbook    = application.Workbooks.Open(this.excelFilePath, false, false);

            Assert.NotNull(workbook);

            try
            {
                var workbookDataDal  = new WorkbookDataDal(workbook);
                var retrievedSession = workbookDataDal.Read();

                Assert.IsNull(retrievedSession);
            }
            finally
            {
                workbook.Close();
                workbook.Dispose();

                application.Quit();
                application.Dispose();
            }
        }
        public void VerifyThatIfCustomXmlPartDoesNotExistsTheWorkbookSessionIsNull()
        {
            NetOffice.ExcelApi.Application application = null;
            Workbook workbook = null;

            try
            {
                application = new Application();
                workbook    = application.Workbooks.Open(this.testfilepath, false, false);

                var workbookDataDal    = new WorkbookDataDal(workbook);
                var retrievedWbSession = workbookDataDal.Read();
                Assert.IsNull(retrievedWbSession);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw ex;
            }
            finally
            {
                if (workbook != null)
                {
                    Console.WriteLine("Closing workbook {0}", this.testfilepath);
                    workbook.Close();
                    workbook.Dispose();
                }

                if (application != null)
                {
                    Console.WriteLine("Closing Excel Application");
                    application.Quit();
                    application.Dispose();
                }
            }
        }