private void SaveMediaAssetSettings() { try { string filename = Path.GetFileName(fuAsset.FileName); Hashtable hs = new Hashtable(); if (!string.IsNullOrEmpty(txtTitle.Text)) { hs.Add("name", txtTitle.Text); } else { hs.Add("name", filename); } hs.Add("file_name", filename); string astType = Path.GetExtension(filename).ToUpper(); bool isValidType = WPHelper.fileType(astType); //switch (astType) //{ // case ".AVI": // case ".MPG": // case ".MOV": // case ".RM": // case ".MP4": // case ".WMV": // case ".WM": // hs.Add("asset_type", "video"); // break; // case ".WAV": // case ".AIF": // case ".MP3": // case ".MID": // case ".RA": // case ".AAC": // hs.Add("asset_type", "audio"); // break; // default: // isValidType = true; // break; //} if (!isValidType) { lblResults.Text = "<font color=red>File Type is not supported!</font>"; ResetFields(); return; } else { hs.Add("asset_type", "video"); } hs.Add("file_size", fuAsset.PostedFile.ContentLength.ToString()); if (!string.IsNullOrEmpty(txtDesc.Text)) { hs.Add("description", txtDesc.Text); } if (!string.IsNullOrEmpty(ddlPostUploadStatus.SelectedValue)) { hs.Add("post_processing_status", ddlPostUploadStatus.SelectedValue); } string id = OoyalaMediaUtils.NewMediaAsset(SecretKey, APIKey, hs); if (string.IsNullOrEmpty(id)) { lblResults.Text = "<font color=red> " + WPHelper.permissionErrorMsg + " </font>"; WPHelper.permissionErrorMsg = string.Empty; ResetFields(); return; } //if (string.IsNullOrEmpty(id)) //{ // lblResults.Text = "<font color=red>Not able to create New Media Asset</font>"; // ResetFields(); // return; //} OoyalaMediaUtils.NewMediaUploadStream(SecretKey, APIKey, id, fuAsset.PostedFile.InputStream); if (ShowLabels) { ArrayList arl = new ArrayList(); bool isAvailable = false; foreach (TreeNode tn in trvAsset.CheckedNodes) { if (!string.IsNullOrEmpty(tn.Value)) { arl.Add(tn.Value); isAvailable = true; } } if (isAvailable) { OoyalaMediaUtils.ApplyLabelsToAssets(SecretKey, APIKey, id, arl); } } if (ShowCustomMetadata) { Hashtable hsMD = new Hashtable(); bool isAvailable = false; foreach (GridViewRow rw in dtgMetadata.Rows) { TextBox txtCustomMetadataKey = (TextBox)rw.FindControl("txtCustomMetadataKey"); TextBox txtCustomMetadataValue = (TextBox)rw.FindControl("txtCustomMetadataValue"); if (!(string.IsNullOrEmpty(txtCustomMetadataKey.Text) && string.IsNullOrEmpty(txtCustomMetadataValue.Text))) { isAvailable = true; if (!hsMD.ContainsKey(txtCustomMetadataKey.Text)) { hsMD.Add(txtCustomMetadataKey.Text, txtCustomMetadataValue.Text); } } } if (isAvailable) { OoyalaMediaUtils.ApplyCustomMetadataToAssets(SecretKey, APIKey, id, hsMD); } } OoyalaMediaUtils.SetMediaFileStatus(SecretKey, APIKey, id, "uploaded"); lblResults.Text = "<font color=green>File Successfully Uploaded!</font>"; ResetFields(); } catch (Exception e) { lblResults.Text = e.Message; } }
private void SaveMediaAssetSettings() { try { UPLOAD_LIMIT = UPLOAD_LIMIT * WPHelper.fileSize(); string url = SPContext.Current.Web.Url.ToString() + "/" + trvSharePoint.CheckedNodes[0].Value; Stream stream = OoyalaMediaUtils.GetFileStream(url); if (stream == null) { lblResults.Text = "<font color=red>Please select valid file!</font>"; ResetFields(); return; } if (stream.Length > UPLOAD_LIMIT) { lblResults.Text = "<font color=red>The file could not be uploaded. File size should not be greater than " + Convert.ToString(WPHelper.fileSize()) + " MB</font>"; ResetFields(); return; } Hashtable hs = new Hashtable(); if (!string.IsNullOrEmpty(txtTitle.Text)) { hs.Add("name", txtTitle.Text); } else { hs.Add("name", trvSharePoint.CheckedNodes[0].Text); } string filename = trvSharePoint.CheckedNodes[0].Text; hs.Add("file_name", filename); string astType = Path.GetExtension(filename).ToUpper(); bool isValidType = WPHelper.fileType(astType); //switch (astType) //{ // case ".AVI": // case ".MPG": // case ".MOV": // case ".RM" : // case ".MP4": // case ".WMV": // case ".WM" : // hs.Add("asset_type", "video"); // break; // case ".WAV": // case ".AIF": // case ".MP3": // case ".MID": // case ".RA" : // hs.Add("asset_type", "audio"); // break; // default: // isValidType = true; // break; //} if (!isValidType) { lblResults.Text = "<font color=red>File Type is not supported!</font>"; ResetFields(); return; } else { hs.Add("asset_type", "video"); } hs.Add("file_size", stream.Length.ToString()); if (!string.IsNullOrEmpty(txtDesc.Text)) { hs.Add("description", txtDesc.Text); } if (!string.IsNullOrEmpty(ddlPostUploadStatus.SelectedValue)) { hs.Add("post_processing_status", ddlPostUploadStatus.SelectedValue); } string id = OoyalaMediaUtils.NewMediaAsset(SecretKey, APIKey, hs); if (string.IsNullOrEmpty(id)) { lblResults.Text = "<font color=red> " + WPHelper.permissionErrorMsg + " </font>"; WPHelper.permissionErrorMsg = string.Empty; return; } OoyalaMediaUtils.NewMediaUploadStream(SecretKey, APIKey, id, stream); if (ShowLabels) { ArrayList arl = new ArrayList(); foreach (TreeNode tn in trvAsset.CheckedNodes) { if (!string.IsNullOrEmpty(tn.Value)) { arl.Add(tn.Value); } } OoyalaMediaUtils.ApplyLabelsToAssets(SecretKey, APIKey, id, arl); } if (ShowCustomMetadata) { Hashtable hsMD = new Hashtable(); foreach (GridViewRow rw in dtgMetadata.Rows) { TextBox txtCustomMetadataKey = (TextBox)rw.FindControl("txtCustomMetadataKey"); TextBox txtCustomMetadataValue = (TextBox)rw.FindControl("txtCustomMetadataValue"); if (!(string.IsNullOrEmpty(txtCustomMetadataKey.Text) && string.IsNullOrEmpty(txtCustomMetadataValue.Text))) { if (!hsMD.ContainsKey(txtCustomMetadataKey.Text)) { hsMD.Add(txtCustomMetadataKey.Text, txtCustomMetadataValue.Text); } } } OoyalaMediaUtils.ApplyCustomMetadataToAssets(SecretKey, APIKey, id, hsMD); } OoyalaMediaUtils.SetMediaFileStatus(SecretKey, APIKey, id, "uploaded"); lblResults.Text = "<font color=green>File Successfully Uploaded!</font>"; ResetFields(); } catch (Exception e) { lblResults.Text = e.Message; } }
private void SaveMediaAssetSettings(int EditRowIndex) { string id = (string)dtgAssets.DataKeys[EditRowIndex].Value.ToString(); string APIKey, SecretKey; try { APIKey = txtAPIKey.Text; SecretKey = txtSecretKey.Text; if (AllowEdit) { Hashtable hs = new Hashtable(); TextBox txtAssetName = (TextBox)dtgAssets.Rows[EditRowIndex].FindControl("txtAssetName"); if (!string.IsNullOrEmpty(txtAssetName.Text)) { hs.Add("name", txtAssetName.Text); } TextBox txtAssetDesc = (TextBox)dtgAssets.Rows[EditRowIndex].FindControl("txtAssetDesc"); if (!string.IsNullOrEmpty(txtAssetDesc.Text)) { hs.Add("description", txtAssetDesc.Text); } else { hs.Add("description", txtAssetDesc.Text); } var res = OoyalaMediaUtils.ApplyMetadataToAssets(SecretKey, APIKey, id, hs); if (string.IsNullOrEmpty(res)) { lblResults.Text = "<font color=red> " + WPHelper.permissionErrorMsg + " </font>"; WPHelper.permissionErrorMsg = string.Empty; return; } if (ShowLabels) { TreeView trvAsset = (TreeView)dtgAssets.Rows[EditRowIndex].FindControl("trvAsset"); ArrayList arl = new ArrayList(); foreach (TreeNode tn in trvAsset.CheckedNodes) { if (!string.IsNullOrEmpty(tn.Value)) { arl.Add(tn.Value); } } OoyalaMediaUtils.DeleteLabelsFromAssets(SecretKey, APIKey, id); OoyalaMediaUtils.ApplyLabelsToAssets(SecretKey, APIKey, id, arl); } if (ShowCustomMetadata) { GridView dtgMetadata = (GridView)dtgAssets.Rows[EditRowIndex].FindControl("dtgMetadata"); Hashtable hsMD = new Hashtable(); foreach (GridViewRow rw in dtgMetadata.Rows) { TextBox txtCustomMetadataKey = (TextBox)rw.FindControl("txtCustomMetadataKey"); TextBox txtCustomMetadataValue = (TextBox)rw.FindControl("txtCustomMetadataValue"); if (!(string.IsNullOrEmpty(txtCustomMetadataKey.Text) && string.IsNullOrEmpty(txtCustomMetadataValue.Text))) { if (!hsMD.ContainsKey(txtCustomMetadataKey.Text)) { hsMD.Add(txtCustomMetadataKey.Text, txtCustomMetadataValue.Text); } } } OoyalaMediaUtils.ApplyCustomMetadataToAssets(SecretKey, APIKey, id, hsMD); } } } catch (Exception e) { lblResults.Text = e.Message; } }