예제 #1
0
 /// <summary>
 /// Moves the asset to the given drop.
 /// </summary>
 /// <param name="asset">The asset.</param>
 /// <param name="targetDrop">The target drop.</param>
 /// <returns></returns>
 public bool MoveAsset(Asset asset, Drop targetDrop)
 {
     return this.ServiceAdapter.CopyAsset(asset, targetDrop, false);
 }
예제 #2
0
 /// <summary>Saves the asset.</summary>
 /// <returns>A <see cref="bool"/> indicating the sucess of the update</returns>
 public bool UpdateAsset(Asset asset)
 {
     return this.ServiceAdapter.UpdateAsset(asset);
 }
예제 #3
0
 /// <summary>
 /// Deletes the asset.
 /// </summary>
 /// <param name="asset">The asset.</param>
 /// <returns></returns>
 public bool DeleteAsset(Asset asset)
 {
     return this.ServiceAdapter.DeleteAsset(asset);
 }
예제 #4
0
 /// <summary>
 /// Gets an original file download url.
 /// </summary>
 /// <param name="asset">The asset.</param>
 /// <returns></returns>
 public string GenerateOriginalFileUrl(Asset asset)
 {
     return this.ServiceAdapter.GenerateOriginalFileUrl(asset);
 }
예제 #5
0
 /// <summary>
 /// Create a job for an Asset conversion
 /// </summary>
 /// <param name="asset">
 /// A <see cref="Asset"/>
 /// </param>
 /// <param name="outputs">
 /// A <see cref="List<Hashtable>"/>
 /// </param>
 /// <param name="plugin">
 /// A <see cref="System.String"/>
 /// </param>
 /// <param name="pingbackUrl">
 /// A <see cref="System.String"/>
 /// </param>
 /// <returns>
 /// A <see cref="System.Boolean"/>
 /// </returns>
 public bool ConvertAsset( Asset asset, List<Hashtable> outputs, string plugin, string pingbackUrl)
 {
     return this.ServiceAdapter.ConvertAsset( asset, outputs, plugin, pingbackUrl);
 }
예제 #6
0
 /// <summary>
 /// Copies the asset to the given drop and returns the new asset.
 /// </summary>
 /// <param name="asset">The asset.</param>
 /// <param name="targetDrop">The target drop.</param>
 /// <returns></returns>
 public bool CopyAsset(Asset asset, Drop targetDrop)
 {
     return this.ServiceAdapter.CopyAsset(asset, targetDrop, true);
 }
예제 #7
0
        /// <summary>
        /// Updates the asset.
        /// </summary>
        /// <param name="asset">The asset.</param>
        /// <param name="newTitle"></param>
        /// <param name="newDescription"></param>
        /// <returns></returns>
        public bool UpdateAsset(Asset asset)
        {
            if (asset == null)
                throw new ArgumentNullException("asset", "The given asset can't be null");

            bool updated = false;
            Drop drop = asset.Drop;

            Hashtable parameters = new Hashtable();

            parameters.Add( "title", asset.Title );
            parameters.Add( "description", asset.Description );

            //			if( !string.IsNullOrEmpty( newTitle ))
            //				parameters.Add("name", newTitle);
            //			if( !string.IsNullOrEmpty( newDescription ))
            //				parameters.Add("description", newDescription );
            //if( !string.IsNullOrEmpty( asset.))

            HttpWebRequest request = this.CreatePutRequest(this.CreateAssetUrl(drop.Name, asset.Id, string.Empty), parameters);
            CompleteRequest(request, delegate(HttpWebResponse response)
            {
                ReadResponse(response, delegate(XmlDocument doc)
                {
                    XmlNode node = doc.SelectSingleNode("/asset");
                    MapAsset( asset, drop, node );
                    updated = true;
                });
            });

            return updated;
        }
예제 #8
0
 /// <summary>
 /// Creates the and map asset.
 /// </summary>
 /// <param name="d">The d.</param>
 /// <param name="node">The node.</param>
 /// <returns></returns>
 protected Asset CreateAndMapAsset(Drop d, XmlNode node)
 {
     Asset a = new Asset();
     this.MapAsset(a, d, node);
     return a;
 }
예제 #9
0
        /// <summary>
        /// Gets an original file download url.
        /// </summary>
        /// <param name="asset">An <see cref="Asset"/> object</param>
        /// <returns></returns>
        public string GenerateOriginalFileUrl(Asset asset )
        {
            // create the API call
            StringBuilder sb = new StringBuilder ();
            sb.Append (this.ApiBaseUrl + DROPS + asset.Drop.Name + ASSETS + asset.Id + DOWNLOAD_ORIGINAL);

            // we just need the "common" parameters for this request, and sign if secret was provided
            Hashtable parameters = new Hashtable ();
            AddCommonParameters( ref parameters );
            SignIfNeeded( ref parameters );

            // add the parameters to the end of the url
            sb.Append("?");
            sb.Append( BuildParameterString( parameters ));

            // return as a string
            return sb.ToString();
        }
예제 #10
0
        /// <summary>
        /// Deletes the asset.
        /// </summary>
        /// <param name="asset">The asset.</param>
        /// <returns></returns>
        public bool DeleteAsset(Asset asset)
        {
            if (asset == null)
                throw new ArgumentNullException("asset", "The given asset can't be null");

            bool destroyed = false;
            Drop drop = asset.Drop;

            Hashtable parameters = new Hashtable();

            HttpWebRequest request = this.CreateUrlEncodedRequest("DELETE",this.CreateAssetUrl(drop.Name, asset.Id, string.Empty), parameters);
            CompleteRequest(request, (HttpWebResponse response) => { destroyed = true; });

            if( destroyed == true)
            {
                // empty the Asset object
                asset.CreatedAt = new DateTime();
                asset.Description = string.Empty;
                asset.Drop = null;
                asset.DropName = string.Empty;
                asset.Filesize = 0;
                asset.Id = string.Empty;
                asset.Name = string.Empty;
                asset.Roles = new List<AssetRoleAndLocations>();
                asset.Title = string.Empty;
            }

            return destroyed;
        }
예제 #11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="asset">
        /// A <see cref="Asset"/>
        /// </param>
        /// <param name="dropName">
        /// A <see cref="System.String"/>
        /// </param>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// </returns>
        public bool CopyAsset(Asset asset, Drop drop, bool keepOriginal)
        {
            if (asset == null)
                throw new ArgumentNullException("asset", "The given asset can't be null");

            if (drop == null)
                throw new ArgumentNullException("drop", "The given drop can't be null");

            bool copied = false;

            Hashtable parameters = new Hashtable();

            parameters.Add("drop_name", drop.Name);

            HttpWebRequest request = this.CreatePostRequest(this.CreateAssetUrl(asset.Drop.Name, asset.Id, keepOriginal == true ? COPY : MOVE ), parameters);
            CompleteRequest(request, (HttpWebResponse response) => { copied = true; });

            if( copied == true )
            {
                // increase asset count by 1 if the asset was copied sucessfully
                Console.WriteLine( "yo...");
                drop.AssetCount++;
            }

            if( keepOriginal == false )
            {
                // we moved (not copied) so decrease assets count on drop that asset was moved from
                asset.Drop.AssetCount--;
            }

            return copied;
        }
예제 #12
0
        public bool ConvertAsset( Asset asset, List<Hashtable> outputs, string plugin, string pingbackUrl)
        {
            // can't do much if we don't have an asset to act on...
            if (asset == null)
                throw new ArgumentNullException("asset", "The given asset can't be null");

            // get the job type by using the asset's type
            string type = asset.Type.ToString().ToUpper();

            // create the input hash
            List<Hashtable> inputs = new List<Hashtable>();
            Hashtable input = new Hashtable();
            input.Add( "asset_id", asset.Id );
            input.Add( "role", "original_content");
            input.Add( "name", "source");
            inputs.Add( input );

            // add the "asset_id" param to the outputs hash is it isn't already there
            foreach( Hashtable hash in outputs)
            {
                if( !hash.Contains( "asset_id"))
                {
                    hash.Add( "asset_id", asset.Id );
                }
            }

            return this.Convert( type, inputs, outputs, plugin, pingbackUrl );
        }
예제 #13
0
        /// <summary>
        /// Maps the asset.
        /// </summary>
        /// <param name="asset">The asset.</param>
        /// <param name="drop">The drop.</param>
        /// <param name="node">The node.</param>
        protected Asset MapAsset(Asset asset, Drop drop, XmlNode node)
        {
            asset.CreatedAt = this.ExtractDateTime(this.ExtractInnerText(node, "created_at"));
            asset.Filesize = this.ExtractInt(node, "filesize");
            asset.Description = this.ExtractInnerText(node, "description");
            asset.Title = this.ExtractInnerText(node,"title");
            asset.Name = this.ExtractInnerText(node, "name");
            asset.Id = this.ExtractInnerText(node, "id");
            asset.DropName = this.ExtractInnerText(node, "drop_name");
            asset.Type = this.MapAssetType( this.ExtractInnerText(node, "type") );
            asset.Drop = drop;

            asset.Roles = new List<AssetRoleAndLocations>();

            XmlNodeList roles = node.SelectNodes( "roles/role");

            foreach( XmlNode roleNode in roles )
            {
                AssetRoleAndLocations rolesAndLocations = new AssetRoleAndLocations();
                rolesAndLocations.Role = new Hashtable();
                rolesAndLocations.Locations = new List<Hashtable>();

                foreach( XmlNode roleInfo in roleNode)
                {
                    if ( roleInfo.Name == "locations")
                    {
                        XmlNodeList locations = roleInfo.SelectNodes( "location" );
                        foreach( XmlNode locationNode in locations )
                        {
                            Hashtable temp = new Hashtable();
                            foreach( XmlNode locationInfo in locationNode )
                            {
                                // PUT STUFF INTO LOCATION HASH
                                temp.Add( locationInfo.Name, locationInfo.InnerText );
                            }
                            rolesAndLocations.Locations.Add( temp );
                        }
                    }
                    else
                    {
                        rolesAndLocations.Role.Add( roleInfo.Name.ToString(), roleInfo.InnerText.ToString() );
                    }
                }
                asset.Roles.Add( rolesAndLocations );
            }

            return asset;
        }