Exemplo n.º 1
0
        protected override byte[] LoadDocument(Document Document)
        {
            try
            {
                logger.InfoFormat("LoadDocument " + Document.IdDocument);
                string[] pathAndPort = Document.Storage.MainPath.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                string   path        = pathAndPort.FirstOrDefault();
                string   port        = pathAndPort.LastOrDefault();

                logger.Debug(path + " (port" + port + ")");

                FTPFactory fact = new FTPFactory();
                fact.setRemoteUser(Document.Storage.AuthenticationKey);
                fact.setRemotePass(Document.Storage.AuthenticationPassword);
                fact.setRemoteHost(path);
                fact.setRemotePath(Document.StorageArea.Path);
                fact.setRemotePort(int.Parse(port));

                fact.login();
                string LocalFilePath = Path.GetTempFileName();
                fact.download(GetFileName(Document), LocalFilePath);

                return(File.ReadAllBytes(LocalFilePath));
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                throw;
            }
        }
Exemplo n.º 2
0
        protected override BindingList <DocumentAttributeValue> LoadAttributes(Document Document)
        {
            byte[] metadata = null;

            try
            {
                logger.InfoFormat("LoadAttributes " + Document.IdDocument);
                string[] pathAndPort = Document.Storage.MainPath.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                string   path        = pathAndPort.FirstOrDefault();
                string   port        = pathAndPort.LastOrDefault();

                logger.Debug(path + " (port" + port + ")");

                FTPFactory fact = new FTPFactory();
                fact.setRemoteUser(Document.Storage.AuthenticationKey);
                fact.setRemotePass(Document.Storage.AuthenticationPassword);
                fact.setRemoteHost(path);
                fact.setRemotePath(Document.StorageArea.Path);
                fact.setRemotePort(int.Parse(port));

                fact.login();
                string LocalFilePath = Path.GetTempFileName();
                fact.download(string.Format("{0}{2}.{1}", Document.IdDocument, "xml", Path.GetExtension(Document.Name)), LocalFilePath);

                metadata = File.ReadAllBytes(LocalFilePath);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                throw;
            }
            try
            {
                XmlTextReader reader = new XmlTextReader(new MemoryStream(metadata));

                BindingList <DocumentAttributeValue> saveAttributes = new BindingList <DocumentAttributeValue>();
                //Gianni: Use linq to Xml because with the object type of value th deserialize fail
                var attr = from c in XElement.Load(reader).Elements("DocumentAttributeValue")
                           select c;
                DocumentAttributeValue attributeItem;
                foreach (var item in attr)
                {
                    attributeItem           = new DocumentAttributeValue();
                    attributeItem.Value     = item.Element("Value").Value.TryConvert(Type.GetType(item.Element("Attribute").Element("AttributeType").Value));
                    attributeItem.Attribute = new DocumentAttribute
                    {
                        IdAttribute = new Guid(item.Element("Attribute").Element("IdAttribute").Value),
                        Name        = item.Element("Attribute").Element("Name").Value
                    };
                    saveAttributes.Add(attributeItem);
                }
                return(saveAttributes);
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }
            return(Document.AttributeValues);
        }