Dispose() public méthode

Releases unmanaged resources and performs other cleanup operations before the is reclaimed by garbage collection.
public Dispose ( ) : void
Résultat void
		public void LoadFileDeleteGraphic()
		{
			string fileName					= "hallo_rem_graphic.odt";
			string graphicFile				= "";
			TextDocument document			= new TextDocument();
			document.Load(AARunMeFirstAndOnce.inPutFolder+"hallo.odt");
			foreach(IContent iContent in document.Content)
			{
				if (iContent is Paragraph && ((Paragraph)iContent).Content.Count > 0
					&& ((Paragraph)iContent).Content[0] is Frame)
				{
					Frame frame				= ((Paragraph)iContent).Content[0] as Frame;
					Assert.IsTrue(frame.Content[0] is Graphic, "Must be a graphic!");
					Graphic graphic			= frame.Content[0] as Graphic;
					//now access the full qualified graphic path
					Assert.IsNotNull(graphic.GraphicRealPath, "The graphic real path must exist!");
					Assert.IsTrue(File.Exists(graphic.GraphicRealPath));
					graphicFile				= graphic.GraphicRealPath;
					//Delete the graphic
					frame.Content.Remove(graphic);
				}
			}
			document.SaveTo(AARunMeFirstAndOnce.outPutFolder+fileName);
			//Special case, only for this test neccessary
			document.Dispose();
			//Load file again
			TextDocument documentRel		= new TextDocument();
			documentRel.Load(AARunMeFirstAndOnce.outPutFolder+fileName);
			Assert.IsFalse(File.Exists(graphicFile), "This file must be removed from this file!");
		}
        protected void PrintSelected_Click(object sender, EventArgs e)
        {
            string fileName = string.Format("configurations-{0:yyyy-MM-dd_hh-mm-ss}.odt", DateTime.Now);

            Response.Clear();
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
            Response.ContentType = "application/octet-stream";

            TextDocument document = new TextDocument();
            AODL.Document.Content.Tables.Table table;
            document.New();

            using (EditConfigurationProvider provider = new EditConfigurationProvider())
            {
                List<GridColumn> columns = provider.GetGridColumns();
                DataTable data = provider.GetList(ProductID).Tables[0];

                List<Guid> selectedRows;
                if (SelectedProductsHidden.Value != "")
                    selectedRows = SelectedProductsHidden.Value.Split(',').Select(s => new Guid(s)).ToList();
                else
                    selectedRows = new List<Guid>();

                //Create a table for a text document using the TableBuilder
                table = TableBuilder.CreateTextDocumentTable(
                    document,
                    "table1",
                    "table1",
                    selectedRows.Count + 1,
                    columns.Count,
                    16.99,
                    false,
                    true);

                //Fill the cells
                int columnIndex = 0, rowIndex = 0;
                foreach (GridColumn column in columns)
                {
                    Cell cell = table.RowCollection[0].CellCollection[columnIndex];
                    Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
                    paragraph.TextContent.Add(new SimpleText(document, column.Name));
                    cell.Content.Add(paragraph);
                    columnIndex++;
                }
                rowIndex++;

                foreach (DataRow row in data.Rows)
                {
                    Guid rodId = row.Field<Guid>("ConfigurationID");
                    if (!selectedRows.Contains(rodId)) continue;

                    columnIndex = 0;
                    foreach (GridColumn column in columns)
                    {
                        if (!row.IsNull(column.DataItem))
                        {
                            try
                            {
                                Cell cell = table.RowCollection[rowIndex].CellCollection[columnIndex];
                                Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
                                string value = row.Field<string>(column.DataItem);
                                paragraph.TextContent.Add(new SimpleText(document, value));
                                cell.Content.Add(paragraph);
                            }
                            catch (System.Exception)
                            {
                                try
                                {
                                    Cell cell = table.RowCollection[rowIndex].CellCollection[columnIndex];
                                    Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
                                    int value = row.Field<int>(column.DataItem);
                                    paragraph.TextContent.Add(new SimpleText(document, value.ToString()));
                                    cell.Content.Add(paragraph);
                                }
                                catch (System.Exception)
                                {
                                    try
                                    {
                                        Cell cell = table.RowCollection[rowIndex].CellCollection[columnIndex];
                                        Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
                                        decimal value = row.Field<decimal>(column.DataItem);
                                        paragraph.TextContent.Add(new SimpleText(document, value.ToString()));
                                        cell.Content.Add(paragraph);
                                    }
                                    catch (System.Exception)
                                    {

                                    }
                                }
                            }
                        }
                        columnIndex++;
                    }
                    rowIndex++;
                }

            }

            //Merge some cells. Notice this is only available in text documents!
            // table.RowCollection[1].MergeCells(document, 1, 2, true);
            //Add table to the document
            document.Content.Add(table);
            //Save the document
            String fs_guid = Server.MapPath(String.Format("/tmp/{0}.odt", Guid.NewGuid().ToString()));
            document.SaveTo(fs_guid);
            document.Dispose();

            // Copy file to Response stream
            FileStream fs = new FileStream(fs_guid, FileMode.Open);

            int bufferSize = 4096;
            byte[] buffer = new byte[bufferSize];
            while (true)
            {
                int read = fs.Read(buffer, 0, buffer.Length);
                if (read <= 0)
                {
                    break;
                }
                Response.OutputStream.Write(buffer, 0, read);
            }

            fs.Close(); //закрываем writer
            File.Delete(fs_guid);
            Response.End(); //заканчиваем ответ сервера, иначе после этого вставится весь контент страницы
            return;
        }
Exemple #3
0
        public void EventListenerTest()
        {
            try
            {
                TextDocument textdocument = new TextDocument();
                textdocument.New();

                // Create a frame (GraphicName == name property of frame)
                Frame frame						= new Frame(textdocument, "frame1", "img1", _imagefile);

                // Create some event listeners (using OpenOffice friendly syntax).
                EventListener script1 = new EventListener(textdocument,
                    "dom:mouseover", "javascript",
                    "vnd.sun.star.script:HelloWorld.helloworld.js?language=JavaScript&location=share");
                EventListener script2 = new EventListener(textdocument,
                    "dom:mouseout", "javascript",
                    "vnd.sun.star.script:HelloWorld.helloworld.js?language=JavaScript&location=share");
                EventListeners listeners = new EventListeners(textdocument, new EventListener[] { script1, script2 });

                // Create and add some area rectangles; reuse event listeners
                DrawAreaRectangle[] rects = new DrawAreaRectangle[2];
                rects[0] = new DrawAreaRectangle(textdocument, "4cm", "4cm", "2cm", "2cm", listeners);
                //Reuse a clone of the EventListener
                rects[1] = new DrawAreaRectangle(textdocument, "1cm", "1cm", "2cm", "2cm", (EventListeners)listeners.Clone());

                // Create and add an image map, referencing the area rectangles
                ImageMap map = new ImageMap(textdocument, rects);
                frame.Content.Add(map);

                // Add the frame to the text document
                textdocument.Content.Add(frame);

                // Save the document
                textdocument.SaveTo(_framefile);
                textdocument.Dispose();
            }
            catch (Exception ex)
            {
                //Console.Write(ex.Message);
            }
        }
Exemple #4
0
        protected void PrintSelected_Click(object sender, EventArgs e)
        {
            string fileName = string.Format("products-{0:yyyy-MM-dd_hh-mm-ss}.odt", DateTime.Now);

            TextDocument document = new TextDocument();
            AODL.Document.Content.Tables.Table table;
            document.New();

            using (ContentDomain provider = Common.GetContentDomain(ClassifiacationTypeView))
            {
                //TreeNode node = ClassificationView.SelectedNode;
                List<GridColumn> columns = provider.GetGridColumns(this.User.ID, this.RequestClassificationTreeID, FieldPlaceHolder.Grid);
                DataSet data = provider.GetList(this.RequestClassificationTreeID, this.User.ID, this.OrderExpression,
                    this.SearchConditions, new PagingInfo(false));

                // составляем список выделенных продуктов
                List<Guid> selectedRows;
                if (hiddenSelectedProducts.Value.ToString() != "")
                    selectedRows = hiddenSelectedProducts.Value.ToString().Split(',').Select(s => new Guid(s)).ToList();
                else
                    selectedRows = new List<Guid>();

                //Create a table for a text document using the TableBuilder
                table = TableBuilder.CreateTextDocumentTable(
                    document,
                    "table1",
                    "table1",
                    selectedRows.Count + 1,
                    columns.Count,
                    16.99,
                    false,
                    true);

                //Fill the cells
                int columnIndex = 0, rowIndex = 0;
                foreach (GridColumn column in columns)
                {
                    Cell cell = table.RowCollection[0].CellCollection[columnIndex];
                    Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
                    paragraph.TextContent.Add(new SimpleText(document, column.Name));
                    cell.Content.Add(paragraph);
                    columnIndex++;
                }
                rowIndex++;

                foreach (DataRow row in data.Tables[0].Rows)
                {
                    Guid rodId = row.Field<Guid>("ID");
                    if (!selectedRows.Contains(rodId)) continue;

                    columnIndex = 0;
                    foreach (GridColumn column in columns)
                    {
                        if (!row.IsNull(column.DataItem))
                        {
                            try
                            {
                                Cell cell = table.RowCollection[rowIndex].CellCollection[columnIndex];
                                Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
                                string value = row.Field<string>(column.DataItem);
                                paragraph.TextContent.Add(new SimpleText(document, value));
                                cell.Content.Add(paragraph);
                            }
                            catch (System.Exception)
                            {
                                try
                                {
                                    Cell cell = table.RowCollection[rowIndex].CellCollection[columnIndex];
                                    Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
                                    int value = row.Field<int>(column.DataItem);
                                    paragraph.TextContent.Add(new SimpleText(document, value.ToString()));
                                    cell.Content.Add(paragraph);
                                }
                                catch (System.Exception)
                                {
                                    try
                                    {
                                        Cell cell = table.RowCollection[rowIndex].CellCollection[columnIndex];
                                        Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
                                        decimal value = row.Field<decimal>(column.DataItem);
                                        paragraph.TextContent.Add(new SimpleText(document, value.ToString()));
                                        cell.Content.Add(paragraph);
                                    }
                                    catch (System.Exception)
                                    {

                                    }
                                }
                            }
                        }
                        columnIndex++;
                    }
                    rowIndex++;
                }

            }

            //Add table to the document
            document.Content.Add(table);
            //Save the document
            string tmpCurrentDitectory = Environment.CurrentDirectory;
            Environment.CurrentDirectory = Server.MapPath("~/tmp").ToString();
            String fs_guid = Server.MapPath(String.Format("~/tmp/{0}.odt", Guid.NewGuid().ToString()));
            document.SaveTo(fs_guid);
            document.Dispose();
            Environment.CurrentDirectory = tmpCurrentDitectory;

            Response.Clear();
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
            Response.ContentType = "application/octet-stream";

            // Copy file to Response stream
            FileStream fs = new FileStream(fs_guid, FileMode.Open);
            Response.AddHeader("Content-Length", fs.Length.ToString());

            int bufferSize = 4096;
            byte[] buffer = new byte[bufferSize];
            while (true)
            {
                int read = fs.Read(buffer, 0, buffer.Length);
                if (read <= 0)
                {
                    break;
                }
                Response.OutputStream.Write(buffer, 0, read);
            }

            fs.Close(); //закрываем writer
            File.Delete(fs_guid);
            Response.End(); //заканчиваем ответ сервера, иначе после этого вставится весь контент страницы
            return;
        }
Exemple #5
0
        public void FrameWriteTest()
        {
            try
            {
                TextDocument textdocument = new TextDocument();
                textdocument.New();

                // Create a frame incl. graphic file
                Frame frame					= FrameBuilder.BuildStandardGraphicFrame(
                    textdocument, "frame1", "graphic1", _imagefile);

                // Create some event listeners (using OpenOffice friendly syntax).
                EventListener script1 = new EventListener(textdocument,
                    "dom:mouseover", "javascript",
                    "vnd.sun.star.script:HelloWorld.helloworld.js?language=JavaScript&location=share");
                EventListener script2 = new EventListener(textdocument,
                    "dom:mouseout", "javascript",
                    "vnd.sun.star.script:HelloWorld.helloworld.js?language=JavaScript&location=share");
                EventListeners listeners = new EventListeners(textdocument, new EventListener[] { script1, script2 });

                // Create and add some area rectangles
                DrawAreaRectangle[] rects = new DrawAreaRectangle[2];
                rects[0] = new DrawAreaRectangle(textdocument, "4cm", "4cm", "2cm", "2cm");
                rects[0].Href = @"http://www.eduworks.com";
                rects[1] = new DrawAreaRectangle(textdocument, "1cm", "1cm", "2cm", "2cm", listeners);

                // Create and add an image map, referencing the area rectangles
                ImageMap map = new ImageMap(textdocument, rects);
                frame.Content.Add(map);

                // Add the frame to the text document
                textdocument.Content.Add(frame);

                // Save the document
                textdocument.SaveTo(_framefile3);
                textdocument.Dispose();
            }
            catch (Exception ex)
            {
                //Console.Write(ex.Message);
            }
        }