public override void RunCommand(object sender)
        {
            var engine               = (IAutomationEngineInstance)sender;
            var vAssetName           = v_AssetName.ConvertUserVariableToString(engine);
            var vOutputDirectoryPath = v_OutputDirectoryPath.ConvertUserVariableToString(engine);

            var client = AuthMethods.GetAuthToken();
            var asset  = AssetMethods.GetAsset(client, vAssetName, v_AssetType);

            if (asset == null)
            {
                throw new DataException($"No Asset was found for '{vAssetName}' with type '{v_AssetType}'");
            }

            dynamic assetValue;

            switch (v_AssetType)
            {
            case "Text":
                assetValue = asset.TextValue;
                break;

            case "Number":
                assetValue = asset.NumberValue;
                break;

            case "Json":
                assetValue = asset.JsonValue;
                break;

            case "File":
                var  fileID = asset.FileID;
                File file   = FileMethods.GetFile(client, fileID);
                AssetMethods.DownloadFileAsset(client, asset.Id, vOutputDirectoryPath, file.Name);
                assetValue = string.Empty;
                break;

            default:
                assetValue = string.Empty;
                break;
            }

            if (v_AssetType != "File")
            {
                ((object)assetValue).StoreInUserVariable(engine, v_OutputUserVariableName, nameof(v_OutputUserVariableName), this);
            }
        }
예제 #2
0
        public async override Task RunCommand(object sender)
        {
            var engine     = (IAutomationEngineInstance)sender;
            var vAssetName = (string)await v_AssetName.EvaluateCode(engine);

            var vOutputDirectoryPath = (string)await v_OutputDirectoryPath.EvaluateCode(engine);

            var userInfo = ServerSessionVariableMethods.GetUserInfo(engine);
            var asset    = AssetMethods.GetAsset(userInfo, vAssetName, v_AssetType);

            if (asset == null)
            {
                throw new DataException($"No Asset was found for '{vAssetName}' with type '{v_AssetType}'");
            }

            dynamic assetValue;

            switch (v_AssetType)
            {
            case "Text":
                assetValue = asset.TextValue;
                break;

            case "Number":
                assetValue = asset.NumberValue;
                break;

            case "Json":
                assetValue = asset.JsonValue;
                break;

            case "File":
                AssetMethods.DownloadFileAsset(userInfo, asset, vOutputDirectoryPath);
                assetValue = string.Empty;
                break;

            default:
                assetValue = string.Empty;
                break;
            }

            if (v_AssetType != "File")
            {
                ((object)assetValue).SetVariableValue(engine, v_OutputUserVariableName);
            }
        }
        public override void RunCommand(object sender)
        {
            var engine               = (AutomationEngineInstance)sender;
            var vAssetName           = v_AssetName.ConvertUserVariableToString(engine);
            var vOutputDirectoryPath = v_OutputDirectoryPath.ConvertUserVariableToString(engine);

            var client = AuthMethods.GetAuthToken();
            var asset  = AssetMethods.GetAsset(client, $"name eq '{vAssetName}' and type eq '{v_AssetType}'");

            if (asset == null)
            {
                throw new Exception($"No Asset was found for '{vAssetName}' with type '{v_AssetType}'");
            }

            string assetValue = string.Empty;

            switch (v_AssetType)
            {
            case "Text":
                assetValue = asset.TextValue;
                break;

            case "Number":
                assetValue = asset.NumberValue.ToString();
                break;

            case "JSON":
                assetValue = asset.JsonValue;
                break;

            case "File":
                var          binaryObjectID = asset.BinaryObjectID;
                BinaryObject binaryObject   = BinaryObjectMethods.GetBinaryObject(client, binaryObjectID);
                AssetMethods.DownloadFileAsset(client, asset.Id, vOutputDirectoryPath, binaryObject.Name);
                break;

            default:
                assetValue = string.Empty;
                break;
            }

            if (v_AssetType != "File")
            {
                assetValue.StoreInUserVariable(engine, v_OutputUserVariableName);
            }
        }