/// <summary>
        /// Performs model upload in one go, without first checking for the price
        /// </summary>
        /// <param name="callback">Callback that will be invoke upon completion of the upload. Null is sent on request failure</param>
        public void Upload(ModelUploadCallback callback)
        {
            PrepareUpload((result =>
            {
                if (result == null && callback != null)
                {
                    callback(null);
                    return;
                }

                if (result is OSDMap)
                {
                    var res = (OSDMap)result;
                    Uri uploader = new Uri(res["uploader"]);
                    PerformUpload(uploader, (contents =>
                    {
                        if (contents != null)
                        {
                            var reply = (OSDMap)contents;
                            if (reply.ContainsKey("new_inventory_item") && reply.ContainsKey("new_asset"))
                            {
                                // Request full update on the item in order to update the local store
                                Client.Inventory.RequestFetchInventory(reply["new_inventory_item"].AsUUID(), Client.Self.AgentID);
                            }
                        }
                        if (callback != null)
                        {
                            callback(contents);
                        }
                    }));
                }
            }));
        }
        /// <summary>
        /// Performas actual mesh and image upload
        /// </summary>
        /// <param name="uploader">Uri recieved in the upload prepare stage</param>
        /// <param name="callback">Callback that will be invoke upon completion of the upload. Null is sent on request failure</param>
        public void PerformUpload(Uri uploader, ModelUploadCallback callback)
        {
            CapsClient request = new CapsClient(uploader);

            request.OnComplete += (client, result, error) =>
            {
                if (error != null || result == null || result.Type != OSDType.Map)
                {
                    Logger.Log("Mesh upload request failure", Helpers.LogLevel.Error);
                    if (callback != null)
                    {
                        callback(null);
                    }
                    return;
                }
                OSDMap res = (OSDMap)result;
                Logger.Log("Response from mesh upload perform:\n" + OSDParser.SerializeLLSDNotationFormatted(result), Helpers.LogLevel.Debug);
                if (callback != null)
                {
                    callback(res);
                }
            };

            request.BeginGetResponse(AssetResources(true), OSDFormat.Xml, 60 * 1000);
        }
Beispiel #3
0
        /// <summary>
        /// Ask server for details of cost and impact of the mesh upload
        /// </summary>
        /// <param name="callback">Callback that will be invoke upon completion of the upload. Null is sent on request failure</param>
        public void PrepareUpload(ModelUploadCallback callback)
        {
            CapsClient request = null;

            if (Client.Network.CurrentSim == null ||
                Client.Network.CurrentSim.Caps == null ||
                (request = Client.Network.CurrentSim.Caps.CreateCapsClient("NewFileAgentInventory")) == null)
            {
                Logger.Log("Cannot upload mesh, no connection or NewFileAgentInventory not available", Helpers.LogLevel.Warning);
                callback?.Invoke(null);
                return;
            }

            Images   = new List <byte[]>();
            ImgIndex = new Dictionary <string, int>();

            OSDMap req = new OSDMap
            {
                ["name"]              = InvName,
                ["description"]       = InvDescription,
                ["asset_resources"]   = AssetResources(false),
                ["asset_type"]        = "mesh",
                ["inventory_type"]    = "object",
                ["folder_id"]         = Client.Inventory.FindFolderForType(AssetType.Object),
                ["texture_folder_id"] = Client.Inventory.FindFolderForType(AssetType.Texture),
                ["everyone_mask"]     = (int)PermissionMask.All,
                ["group_mask"]        = (int)PermissionMask.All,
                ["next_owner_mask"]   = (int)PermissionMask.All
            };

            request.OnComplete += (client, result, error) =>
            {
                if (error != null || result == null || result.Type != OSDType.Map)
                {
                    Logger.Log("Mesh upload request failure", Helpers.LogLevel.Error);
                    callback?.Invoke(null);
                    return;
                }
                OSDMap res = (OSDMap)result;

                if (res["state"] != "upload")
                {
                    Logger.Log("Mesh upload failure: " + res["message"], Helpers.LogLevel.Error);
                    callback?.Invoke(null);
                    return;
                }

                Logger.Log("Response from mesh upload prepare:" + Environment.NewLine + OSDParser.SerializeLLSDNotationFormatted(result), Helpers.LogLevel.Debug);
                callback?.Invoke(result);
            };

            request.PostRequestAsync(req, OSDFormat.Xml, 3 * 60 * 1000);
        }
Beispiel #4
0
        /// <summary>
        /// Performas actual mesh and image upload
        /// </summary>
        /// <param name="uploader">Uri recieved in the upload prepare stage</param>
        /// <param name="callback">Callback that will be invoke upon completion of the upload. Null is sent on request failure</param>
        public void PerformUpload(Uri uploader, ModelUploadCallback callback)
        {
            CapsClient request = new CapsClient(uploader, "MeshUploader");

            request.OnComplete += (client, result, error) =>
            {
                if (error != null || result == null || result.Type != OSDType.Map)
                {
                    Logger.Log("Mesh upload request failure", Helpers.LogLevel.Error);
                    callback?.Invoke(null);
                    return;
                }
                OSDMap res = (OSDMap)result;
                Logger.Log("Response from mesh upload perform:" + Environment.NewLine
                           + OSDParser.SerializeLLSDNotationFormatted(result), Helpers.LogLevel.Debug);
                callback?.Invoke(res);
            };

            request.PostRequestAsync(AssetResources(true), OSDFormat.Xml, 60 * 1000);
        }
        /// <summary>
        /// Performas actual mesh and image upload
        /// </summary>
        /// <param name="uploader">Uri recieved in the upload prepare stage</param>
        /// <param name="callback">Callback that will be invoke upon completion of the upload. Null is sent on request failure</param>
        public void PerformUpload(Uri uploader, ModelUploadCallback callback)
        {
            CapsClient request = new CapsClient(uploader);
            request.OnComplete += (client, result, error) =>
            {
                if (error != null || result == null || result.Type != OSDType.Map)
                {
                    Logger.Log("Mesh upload request failure", Helpers.LogLevel.Error);
                    if (callback != null) callback(null);
                    return;
                }
                OSDMap res = (OSDMap)result;
                Logger.Log("Response from mesh upload perform:\n" + OSDParser.SerializeLLSDNotationFormatted(result), Helpers.LogLevel.Debug);
                if (callback != null) callback(res);
            };

            request.BeginGetResponse(AssetResources(true), OSDFormat.Xml, 60 * 1000);
        }
        /// <summary>
        /// Ask server for details of cost and impact of the mesh upload
        /// </summary>
        /// <param name="callback">Callback that will be invoke upon completion of the upload. Null is sent on request failure</param>
        public void PrepareUpload(ModelUploadCallback callback)
        {
            Uri url = null;
            if (Client.Network.CurrentSim == null ||
                Client.Network.CurrentSim.Caps == null ||
                null == (url = Client.Network.CurrentSim.Caps.CapabilityURI("NewFileAgentInventory")))
            {
                Logger.Log("Cannot upload mesh, no connection or NewFileAgentInventory not available", Helpers.LogLevel.Warning);
                if (callback != null) callback(null);
                return;
            }

            Images = new List<byte[]>();
            ImgIndex = new Dictionary<string, int>();

            OSDMap req = new OSDMap();
            req["name"] = InvName;
            req["description"] = InvDescription;

            req["asset_resources"] = AssetResources(false);
            req["asset_type"] = "mesh";
            req["inventory_type"] = "object";

            req["folder_id"] = Client.Inventory.FindFolderForType(AssetType.Object);
            req["texture_folder_id"] = Client.Inventory.FindFolderForType(AssetType.Texture);

            req["everyone_mask"] = (int)PermissionMask.All;
            req["group_mask"] = (int)PermissionMask.All; ;
            req["next_owner_mask"] = (int)PermissionMask.All;

            CapsClient request = new CapsClient(url);
            request.OnComplete += (client, result, error) =>
            {
                if (error != null || result == null || result.Type != OSDType.Map)
                {
                    Logger.Log("Mesh upload request failure", Helpers.LogLevel.Error);
                    if (callback != null) callback(null);
                    return;
                }
                OSDMap res = (OSDMap)result;

                if (res["state"] != "upload")
                {
                    Logger.Log("Mesh upload failure: " + res["message"], Helpers.LogLevel.Error);
                    if (callback != null) callback(null);
                    return;
                }

                Logger.Log("Response from mesh upload prepare:\n" + OSDParser.SerializeLLSDNotationFormatted(result), Helpers.LogLevel.Debug);
                if (callback != null) callback(result);
            };

            request.BeginGetResponse(req, OSDFormat.Xml, 3 * 60 * 1000);

        }
        /// <summary>
        /// Performs model upload in one go, without first checking for the price
        /// </summary>
        /// <param name="callback">Callback that will be invoke upon completion of the upload. Null is sent on request failure</param>
        public void Upload(ModelUploadCallback callback)
        {
            PrepareUpload((result =>
            {
                if (result == null && callback != null)
                {
                    callback(null);
                    return;
                }

                if (result is OSDMap)
                {
                    var res = (OSDMap)result;
                    Uri uploader = new Uri(res["uploader"]);
                    PerformUpload(uploader, (contents =>
                    {
                        if (contents != null)
                        {
                            var reply = (OSDMap)contents;
                            if (reply.ContainsKey("new_inventory_item") && reply.ContainsKey("new_asset"))
                            {
                                // Request full update on the item in order to update the local store
                                Client.Inventory.RequestFetchInventory(reply["new_inventory_item"].AsUUID(), Client.Self.AgentID);
                            }
                        }
                        if (callback != null) callback(contents);
                    }));
                }
            }));

        }