Пример #1
0
        private string createTemplateXML(IExportDocument docRef, IExportTools exportTools, string tempfolder, string tempName)
        {
            string templateFolder = tempfolder;
            string templateName = tempName.ToString() + ".xml";
            string temp = templateFolder + "\\" + templateName;

            NTAccount ntAccount = new NTAccount("Everyone");
            SecurityIdentifier sid = (SecurityIdentifier)ntAccount.Translate(typeof(SecurityIdentifier));
            byte[] sidArray = new byte[sid.BinaryLength];
            sid.GetBinaryForm(sidArray, 0);

            if (!File.Exists(temp))
            {
                fileCabinetForm = new DocuwareFileCabinet(docRef, exportTools, temp);
                fileCabinetForm.ShowDialog();
            }
            if (File.Exists(temp))
            {
                // create the XmlReader object
                XmlReaderSettings settings = new XmlReaderSettings();
                XmlReader reader = XmlReader.Create(temp.ToString(), settings);

                int depth = -1; // tree depth is -1, no indentation

                while (reader.Read()) // display each node's content
                {
                    switch (reader.NodeType)
                    {
                        case XmlNodeType.Element: // XML Element, display its name
                            depth++; // increase tab depth
                            TabOutput(depth); // insert tabs

                            if (reader.Name == "FileCabinetName")
                            {
                                depth++;
                                reader.Read();
                                xmlfilecabinetpath = reader.Value;
                                depth--;
                                reader.Read();
                            }
                            if (reader.Name == "FieldName")
                            {
                                depth++;
                                reader.Read();
                                xmlfieldname = reader.Value;
                                fieldnamelist.Add(reader.Value);
                                getFields(docRef.Children, docRef, xmlfieldname);
                                depth--;
                                reader.Read();
                            }
                            if (reader.Name == "FieldIndex")
                            {
                                depth++;
                                reader.Read();
                                xmlfieldindex = reader.Value;
                                fieldindexlist.Add(Convert.ToUInt32(reader.Value));
                                depth--;
                                reader.Read();
                                openWith.Add(Convert.ToInt32(xmlfieldindex), fieldValue);
                            }

                            // if empty element, decrease depth
                            if (reader.IsEmptyElement)
                                depth--;
                            break;
                        case XmlNodeType.Comment: // XML Comment, display it
                            TabOutput(depth); // insert tabs
                            break;
                        case XmlNodeType.Text: // XML Text, display it
                            TabOutput(depth); // insert tabs
                            break;

                        // XML XMLDeclaration, display it
                        case XmlNodeType.XmlDeclaration:
                            TabOutput(depth); // insert tabs
                            break;
                        case XmlNodeType.EndElement: // XML EndElement, display it
                            TabOutput(depth); // insert tabs
                            depth--; // decrement depth
                            break;
                    } // end switch
                } // end while

                //------------------- DocuWare -------------------
                string fullimportimagepath = exportImages(docRef, exportTools, templateFolder);
                UpdateLogFile("Full path of current working image: "+fullimportimagepath);

                //select filecabinet
                filecabinet = new FileCabinet(session, xmlfilecabinetpath);
                UpdateLogFile(filecabinet.FileCabinetPath);
                filecabinet.Open();
                abasket = new ActiveBasket(session);

                // open basket
                basket = session.GetActiveBasket();
                basket = new Basket(session, abasket.BasketPath);
                UpdateLogFile("Active Basket Path: " + abasket.BasketPath);
                basket = new ActiveBasket(session);
                basket.Open();
                basket.SetAsActive();
                UpdateLogFile("Basket: "+basket.BasketPath);

                //sending bantran.tif to current basket.
                docum = basket.ImportFile(fullimportimagepath);

                UpdateLogFile("FileName: "+docum.FileName);
                if (File.Exists(fullimportimagepath))
                {
                    File.Delete(fullimportimagepath);
                }

                int numberofdocuments = basket.GetNumberOfDocuments();

                docum = new Document(basket, docum.FileName);
                UpdateLogFile("Name: " + docum.Name);
                UpdateLogFile("FileName: " + docum.FileName);

                if (!File.Exists(docum.FileName))
                {
                    UpdateLogFile(docum.FileName + " path does not exist after import into basket.");
                }

                try
                {
                    filecabinet.Store(docum, false, true, openWith);
                }
                catch (Exception e)
                {
                    UpdateLogFile(filecabinet.LastException.Message+ " | " + e.Message);
                }
            }
            return templateName;
        }