Beispiel #1
0
        protected IO.Item BuildItem()
        {
            // Create IO Item
            IO.Item dbitem = new IO.Item(this.Item.ItemType.Name, this.Name);
            dbitem.ID = this.Item.ID;

            // Add Classification

            if (this.Item.Class == null)
            {
                dbitem.SetProperty("classification", null);
            }
            else
            {
                dbitem.SetProperty("classification", this.Item.Class.Fullname);
            }

            // Add Properties
            foreach (Property prop in this.Item.Properties)
            {
                if ((!this.Transaction.Session.OptimiseAML || prop.Modified) && !prop.Type.ReadOnly && !prop.Type.Name.Equals("source_id"))
                {
                    if (prop is Properties.Item)
                    {
                        // Check that related Item is processed
                        Properties.Item itemprop = (Properties.Item)prop;

                        if (itemprop.Value != null)
                        {
                            Action itempropaction = this.Transaction.Get(((Model.Item)itemprop.Value).ID);

                            if (itempropaction != null)
                            {
                                itempropaction.Commit();
                            }
                        }
                    }

                    dbitem.SetProperty(prop.Type.Name, prop.DBValue);
                }
            }

            // Add Relations
            foreach (Actions.Relationship relationshipaction in this.RelationshipsCache.Values)
            {
                IO.Item dbrelationship = relationshipaction.Commit();
                dbitem.AddRelationship(dbrelationship);
            }

            return(dbitem);
        }
Beispiel #2
0
        public void Refresh()
        {
            // Run Query
            IO.Item dbquery = this.Query.DBQuery();

            if (dbquery != null)
            {
                if (this.Source != null)
                {
                    dbquery.SetProperty("source_id", this.Source.ID);
                }

                IO.Request  request  = this.ItemType.Session.IO.Request(IO.Request.Operations.ApplyItem, dbquery);
                IO.Response response = request.Execute();

                if (!response.IsError)
                {
                    this.Load(response.Items);

                    if (this.Paging)
                    {
                        if (response.Items.Count() > 0)
                        {
                            this.NoPages = response.Items.First().PageMax;
                        }
                        else
                        {
                            this.NoPages = 0;
                        }
                    }
                    else
                    {
                        this.NoPages = 0;
                    }
                }
                else
                {
                    if (!response.ErrorMessage.Equals("No items of type " + this.ItemType.Name + " found."))
                    {
                        throw new Exceptions.ServerException(response);
                    }
                    else
                    {
                        this.Load(null);
                    }
                }
            }
        }
Beispiel #3
0
        public void Promote(Relationships.LifeCycleState NewState)
        {
            IO.Request request = this.ItemType.Session.IO.Request(IO.Request.Operations.PromoteItem);
            IO.Item    item    = request.NewItem(this.ItemType.Name, "get");
            item.ID = this.ID;
            item.SetProperty("state", NewState.Name);
            IO.Response response = request.Execute();

            if (!response.IsError)
            {
                // Update Current State
                this.Property(this.ItemType.PropertyType("current_state")).SetValue(NewState);
                this.Property(this.ItemType.PropertyType("state")).SetValue(NewState.Name);
            }
            else
            {
                throw new Exceptions.ServerException(response);
            }
        }
Beispiel #4
0
        public Response VaultWrite(Stream Stream, String Filename)
        {
            IO.Response response = null;

            // Read Cached File
            byte[] filebytes = null;

            if (Stream is MemoryStream)
            {
                filebytes = ((MemoryStream)Stream).ToArray();
            }
            else
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    Stream.CopyTo(ms);
                    filebytes = ms.ToArray();
                }
            }

            // Build Request
            String contentboundary           = "-------------S36Ut9A3ZtWwum";
            MultipartFormDataContent content = new MultipartFormDataContent(contentboundary);

            StringContent soapaction = new StringContent("ApplyItem");

            content.Add(soapaction, "SOAPACTION");

            StringContent authuser = new StringContent(this.Username);

            content.Add(authuser, "AUTHUSER");

            StringContent password = new StringContent(this.Password);

            content.Add(password, "AUTHPASSWORD");

            StringContent database = new StringContent(this.Database.ID);

            content.Add(database, "DATABASE");

            StringContent locale = new StringContent("");

            content.Add(locale, "LOCALE");

            StringContent timezone = new StringContent("GMT Standard Time");

            content.Add(timezone, "TIMEZONE_NAME");

            StringContent vault = new StringContent(this.VaultID);

            content.Add(vault, "VAULTID");

            IO.Item dbfile = new IO.Item("File", "add");
            dbfile.ID = Server.NewID();
            dbfile.SetProperty("filename", Filename);
            dbfile.SetProperty("file_size", filebytes.Length.ToString());
            IO.Item dbloacted = new IO.Item("Located", "add");
            dbloacted.SetProperty("related_id", this.VaultID);
            dbfile.AddRelationship(dbloacted);

            String        xmldata = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body><ApplyItem>" + dbfile.GetString() + "</ApplyItem></SOAP-ENV:Body></SOAP-ENV:Envelope>";
            StringContent xml     = new StringContent(xmldata);

            content.Add(xml, "XMLdata");

            ByteArrayContent filedata = new ByteArrayContent(filebytes);

            content.Add(filedata, dbfile.ID, Filename);

            // Post Request to Vault Server
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.VaultBaseURL);

            request.CookieContainer        = this.Cookies;
            request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            request.ContentType            = "multipart/form-data; boundary=" + contentboundary;
            request.Method      = "POST";
            request.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
            request.Headers.Add("Cache-Control", "no-cache");
            request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";

            using (Stream poststream = request.GetRequestStream())
            {
                content.CopyToAsync(poststream);
            }

            using (HttpWebResponse webresponse = (HttpWebResponse)request.GetResponse())
            {
                using (Stream result = webresponse.GetResponseStream())
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(result);
                    response = new IO.Response(webresponse.Cookies, doc);
                }
            }

            return(response);
        }