/// <summary> /// Updates a player. /// </summary> /// <param name="operation"> /// The operation. /// </param> /// <returns> /// The <see cref="object"/>. /// </returns> protected override object Update(ExportOperation operation) { var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item); if (synchronizer == null) { return(null); } var authenticator = new OoyalaAthenticator(operation.AccountItem); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); var player = (Player)synchronizer.CreateEntity(operation.Item); string playerId = player.Id; player.Id = null; return(context.Update <Player, Player>( "update_player", player, new List <Parameter> { new Parameter { Type = ParameterType.UrlSegment, Name = "id", Value = playerId } }).Data); }
/// <summary> /// Creates a channel. /// </summary> /// <param name="operation"> /// The operation. /// </param> /// <returns> /// The <see cref="object"/>. /// </returns> protected override object Create(ExportOperation operation) { var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item); if (synchronizer == null) { return(null); } var authenticator = new OoyalaAthenticator(operation.AccountItem); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); var channel = (Channel)synchronizer.CreateEntity(operation.Item); channel.EmbedCode = null; channel.CreatedAt = null; channel.UpdatedAt = null; channel.Duration = null; channel.PostProcessingStatus = null; channel.Metadata = null; channel.PreviewImageUrl = null; channel.Status = null; var createdChannel = context.Create <Channel, Channel>("create_channel", channel).Data; this.UpdateLineup(operation, createdChannel.EmbedCode); this.UpdateLabels(operation, createdChannel.EmbedCode); this.UpdatePlayer(operation, createdChannel.EmbedCode); this.UpdateMetadata(operation, createdChannel.EmbedCode); return(createdChannel); }
protected override object Update(ExportOperation operation) { var itemSynchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item); if (itemSynchronizer == null) { return(null); } var playList = (PlayList)itemSynchronizer.CreateEntity(operation.Item); playList.ReferenceId = null; //Video ids used only for EXPLICIT playlist. //In other case will be used playlistsearch if (playList.PlaylistType == PlaylistType.EXPLICIT.ToString()) { playList.PlayListSearch = null; } else { playList.VideoIds = null; } var authenticator = new BrightcoveAuthenticator(operation.AccountItem); var data = new PlaylistProxy(authenticator).Patch(playList); if (data == null) { return(null); } return(data); }
public async void ExportBacpac() { var result = GetLiveAutoCompleteTestObjects(); SqlTestDb testdb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, null, "DacFxExportTest"); string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DacFxTest"); Directory.CreateDirectory(folderPath); try { var exportParams = new ExportParams { DatabaseName = testdb.DatabaseName, PackageFilePath = Path.Combine(folderPath, string.Format("{0}.bacpac", testdb.DatabaseName)) }; DacFxService service = new DacFxService(); ExportOperation operation = new ExportOperation(exportParams, result.ConnectionInfo); service.PerformOperation(operation, TaskExecutionMode.Execute); VerifyAndCleanup(exportParams.PackageFilePath); } finally { testdb.Cleanup(); } }
/// <summary> /// Update a label. /// </summary> /// <param name="operation"> /// The operation. /// </param> /// <returns> /// The <see cref="object"/>. /// </returns> protected override object Update(ExportOperation operation) { var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item); if (synchronizer == null) { return(null); } var authenticator = new OoyalaAthenticator(operation.AccountItem); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); var lab = (Label)synchronizer.CreateEntity(operation.Item); return(context.Update <Label, Label>( "update_label", new Label { Name = lab.Name, ParentId = !string.IsNullOrEmpty(lab.ParentId) ? lab.ParentId : "root" }, new List <Parameter> { new Parameter { Type = ParameterType.UrlSegment, Name = "id", Value = lab.Id } }).Data); }
protected override void Delete(ExportOperation operation) { var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item); if (synchronizer == null) { return; } var playlist = (PlayList)synchronizer.CreateEntity(operation.Item); var parameters = new Dictionary <string, object> { { "playlist_id", playlist.Id }, { "cascade", "true" }, }; var authenticator = new BrightcoveAthenticator(operation.AccountItem); var updateData = new PostData("delete_playlist", authenticator, parameters); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); context.Delete <PostData, ResultData <PlayList> >("update_data", updateData); }
/// <summary> /// Update /// </summary> /// <param name="operation"></param> /// <returns></returns> protected override object Update(ExportOperation operation) { IItemSynchronizer itemSynchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item); if (itemSynchronizer == null) { return(null); } var video = (Video)itemSynchronizer.CreateEntity(operation.Item); if (video.CustomFields != null && video.CustomFields.Count == 0) { video.CustomFields = null; } var authenticator = new BrightcoveAuthenticator(operation.AccountItem); var result = new VideoProxy(authenticator).Patch(video); if (result == null || result.Id == null) { return(null); } if (result.CustomFields == null) { result.CustomFields = video.CustomFields; } return(result); }
protected override void Delete(ExportOperation operation) { var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item); if (synchronizer == null) { return; } var video = (Video)synchronizer.CreateEntity(operation.Item); var inactivatedVideo = new Video { Id = video.Id, ItemState = ItemState.INACTIVE }; var authenticator = new BrightcoveAthenticator(operation.AccountItem); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); var updateData = new PostData("update_video", authenticator, "video", inactivatedVideo); var data = context.Update <PostData, ResultData <Video> >("update_data", updateData).Data; }
/// <summary> /// Updates player for an asset. /// </summary> /// <param name="operation"> /// The operation. /// </param> /// <param name="assetEmbedCode"> /// The asset embed code. /// </param> protected virtual void UpdatePlayer(ExportOperation operation, string assetEmbedCode) { var authenticator = new OoyalaAthenticator(operation.AccountItem); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); string playerId = this.GetPlayerId(operation.Item); context.Update <RestEmptyType, RestEmptyType>( "update_player_of_asset", null, new List <Parameter> { new Parameter { Type = ParameterType.UrlSegment, Name = "embedcode", Value = assetEmbedCode }, new Parameter { Type = ParameterType.UrlSegment, Name = "id", Value = playerId } }); }
private async Task <Mock <RequestContext <DacFxResult> > > SendAndValidateExportRequest() { var result = GetLiveAutoCompleteTestObjects(); var requestContext = new Mock <RequestContext <DacFxResult> >(); requestContext.Setup(x => x.SendResult(It.IsAny <DacFxResult>())).Returns(Task.FromResult(new object())); SqlTestDb testdb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, null, "DacFxExportTest"); string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DacFxTest"); Directory.CreateDirectory(folderPath); var exportParams = new ExportParams { DatabaseName = testdb.DatabaseName, PackageFilePath = Path.Combine(folderPath, string.Format("{0}.bacpac", testdb.DatabaseName)) }; DacFxService service = new DacFxService(); ExportOperation operation = new ExportOperation(exportParams, result.ConnectionInfo); service.PerformOperation(operation); // cleanup VerifyAndCleanup(exportParams.PackageFilePath); testdb.Cleanup(); return(requestContext); }
private void OnExportFinished(IAsyncResult ar) { lock (LockObj) { ExportOperation eo = (ExportOperation)ar.AsyncState; if (eo.Result == ExportOperation.OperationResult.Finished) { Services.UI.Info.DisplayMessage(string.Format(Catalog.GetString("Exported data to '{0}'"), (eo.Exporter.Builder.OutputStream as FileStream).Name)); this.Hide(); } else if (eo.Result == ExportOperation.OperationResult.CaughtException) { ErrorAlert ea; if (eo.ThreadException.GetType() == typeof(FormatException)) { ea = new ErrorAlert(Catalog.GetString("Export Pattern Error"), eo.ThreadException.Message, mainWindow); } else { ea = new ErrorAlert(Catalog.GetString("Exporting Error"), eo.ThreadException.Message, mainWindow); } ea.Run(); ea.Destroy(); } if (eo.Exporter.Builder.OutputStream != null) { eo.Exporter.Builder.OutputStream.Close(); } CloseButton.Sensitive = true; ExportButton.Sensitive = true; } }
/// <summary> /// Deletes a video. /// </summary> /// <param name="operation"> /// The operation. /// </param> protected override void Delete(ExportOperation operation) { var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item); if (synchronizer == null) { return; } var authenticator = new OoyalaAthenticator(operation.AccountItem); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); var video = (Video)synchronizer.CreateEntity(operation.Item); context.Delete <Video, RestEmptyType>( "delete_video", parameters: new List <Parameter> { new Parameter { Name = "embedcode", Type = ParameterType.UrlSegment, Value = video.EmbedCode } }); }
/// <summary> /// Deletes a label. /// </summary> /// <param name="operation"> /// The operation. /// </param> protected override void Delete(ExportOperation operation) { var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item); if (synchronizer == null) { return; } var authenticator = new OoyalaAthenticator(operation.AccountItem); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); var label = (Label)synchronizer.CreateEntity(operation.Item); context.Delete <Label, RestEmptyType>( "delete_label", parameters: new List <Parameter> { new Parameter { Type = ParameterType.UrlSegment, Name = "id", Value = label.Id } }); }
public IActionResult Export(ExportOperation operation) { var result = operation.Execute(); string filePath = Request.Scheme + "://" + Request.Host.Value + "/" + "Documents/" + result.file; return(Ok(new { FilePath = filePath })); }
protected override object Create(ExportOperation operation) { var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item); if (synchronizer == null) { return(null); } var playlist = (PlayList)synchronizer.CreateEntity(operation.Item); playlist.Id = null; playlist.ReferenceId = null; playlist.ThumbnailUrl = null; //Video ids used only for EXPLICIT playlist. //In other case will be used filter tags & tag inclusion if (playlist.PlaylistType == PlaylistType.EXPLICIT.ToString()) { playlist.FilterTags = null; playlist.TagInclusion = null; } else { playlist.VideoIds = null; } var authenticator = new BrightcoveAthenticator(operation.AccountItem); var updateData = new PostData("create_playlist", authenticator, "playlist", playlist); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); var data = context.Create <PostData, ResultData <string> >("update_data", updateData).Data; if (data != null && !string.IsNullOrEmpty(data.Result)) { //we could not to use existing playlist object because it does not contain all data var playlistData = context.Read <PlayList>("read_playlist_by_id", new List <Parameter> { new Parameter { Type = ParameterType.UrlSegment, Name = "playlist_id", Value = data.Result } }).Data; if (playlistData == null) { playlist.Id = data.Result; return(playlist); } return(playlistData); } return(null); }
protected override void Delete(ExportOperation operation) { var itemSynchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item); if (itemSynchronizer == null) { return; } var authenticator = new BrightcoveAuthenticator(operation.AccountItem); new PlaylistProxy(authenticator).Delete(((Asset)itemSynchronizer.CreateEntity(operation.Item)).Id); }
private void Export(Export1cMode mode) { var dateStart = dateperiodpicker1.StartDate; var dateEnd = dateperiodpicker1.EndDate; using (var exportOperation = new ExportOperation(new OrderParametersProvider(new ParametersProvider()), mode, dateStart, dateEnd)) { this.exportInProgress = true; UpdateExportButtonSensitivity(); LongOperationDlg.StartOperation(exportOperation.Run, "", 1, false); this.exportInProgress = false; UpdateExportButtonSensitivity(); exportData = exportOperation.Result; } this.labelTotalCounterparty.Text = exportData.Objects .OfType <CatalogObjectNode>() .Count(node => node.Type == Common1cTypes.ReferenceCounterparty) .ToString(); this.labelTotalNomenclature.Text = exportData.Objects .OfType <CatalogObjectNode>() .Count(node => node.Type == Common1cTypes.ReferenceNomenclature) .ToString(); this.labelTotalSales.Text = exportData.Objects .OfType <SalesDocumentNode>() .Count() .ToString(); this.labelTotalSum.Text = exportData.OrdersTotalSum.ToString("C"); this.labelExportedSum.Markup = String.Format("<span foreground=\"{1}\">{0:C}</span>", exportData.ExportedTotalSum, exportData.ExportedTotalSum == exportData.OrdersTotalSum ? "green" : "red"); this.labelTotalInvoices.Text = exportData.Objects .OfType <InvoiceDocumentNode>() .Count() .ToString(); GtkScrolledWindowErrors.Visible = exportData.Errors.Count > 0; if (exportData.Errors.Count > 0) { TextTagTable textTags = new TextTagTable(); var tag = new TextTag("Red"); tag.Foreground = "red"; textTags.Add(tag); TextBuffer tempBuffer = new TextBuffer(textTags); TextIter iter = tempBuffer.EndIter; tempBuffer.InsertWithTags(ref iter, String.Join("\n", exportData.Errors), tag); textviewErrors.Buffer = tempBuffer; } buttonSave.Sensitive = exportData != null && exportData.Errors.Count == 0; }
private async Task <Mock <RequestContext <DacFxResult> > > SendAndValidateImportRequest() { // first export a bacpac var result = GetLiveAutoCompleteTestObjects(); var exportRequestContext = new Mock <RequestContext <DacFxResult> >(); exportRequestContext.Setup(x => x.SendResult(It.IsAny <DacFxResult>())).Returns(Task.FromResult(new object())); SqlTestDb sourceDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, null, "DacFxImportTest"); string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DacFxTest"); Directory.CreateDirectory(folderPath); var exportParams = new ExportParams { DatabaseName = sourceDb.DatabaseName, PackageFilePath = Path.Combine(folderPath, string.Format("{0}.bacpac", sourceDb.DatabaseName)) }; SqlConnection sqlConn = ConnectionService.OpenSqlConnection(result.ConnectionInfo, "Import"); DacFxService service = new DacFxService(); ExportOperation exportOperation = new ExportOperation(exportParams, sqlConn); service.PerformOperation(exportOperation); // import the created bacpac var importRequestContext = new Mock <RequestContext <DacFxResult> >(); importRequestContext.Setup(x => x.SendResult(It.IsAny <DacFxResult>())).Returns(Task.FromResult(new object())); var importParams = new ImportParams { PackageFilePath = exportParams.PackageFilePath, DatabaseName = string.Concat(sourceDb.DatabaseName, "-imported") }; ImportOperation importOperation = new ImportOperation(importParams, sqlConn); service.PerformOperation(importOperation); SqlTestDb targetDb = SqlTestDb.CreateFromExisting(importParams.DatabaseName); // cleanup VerifyAndCleanup(exportParams.PackageFilePath); sourceDb.Cleanup(); targetDb.Cleanup(); return(importRequestContext); }
private IAsyncResult BeginExport(IExporter exporter, IBuffer buf, long start, long end) { exportFinishedEvent.Reset(); ExportOperation eo = new ExportOperation(exporter, buf, start, end, ExportProgressCallback, OnExportFinished); CloseButton.Sensitive = false; ExportButton.Sensitive = false; // start export thread Thread exportThread = new Thread(eo.OperationThread); exportThread.IsBackground = true; exportThread.Start(); return new ThreadedAsyncResult(eo, exportFinishedEvent, false); }
/// <summary> /// Updates list of the assigned labels. /// </summary> /// <param name="operation"> /// The operation. /// </param> /// <param name="assetEmbedCode"> /// The asset embed code. /// </param> protected virtual void UpdateLabels(ExportOperation operation, string assetEmbedCode) { var authenticator = new OoyalaAthenticator(operation.AccountItem); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); List <string> labels = this.GetLabels(operation.Item); context.Update <List <string>, PagedCollection <Label> >( "update_labels_of_asset", labels, new List <Parameter> { new Parameter { Type = ParameterType.UrlSegment, Name = "embedcode", Value = assetEmbedCode } }); }
public async void ImportBacpac() { // first export a bacpac var result = GetLiveAutoCompleteTestObjects(); SqlTestDb sourceDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, null, "DacFxImportTest"); SqlTestDb targetDb = null; string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DacFxTest"); Directory.CreateDirectory(folderPath); try { var exportParams = new ExportParams { DatabaseName = sourceDb.DatabaseName, PackageFilePath = Path.Combine(folderPath, string.Format("{0}.bacpac", sourceDb.DatabaseName)) }; DacFxService service = new DacFxService(); ExportOperation exportOperation = new ExportOperation(exportParams, result.ConnectionInfo); service.PerformOperation(exportOperation, TaskExecutionMode.Execute); // import the created bacpac var importParams = new ImportParams { PackageFilePath = exportParams.PackageFilePath, DatabaseName = string.Concat(sourceDb.DatabaseName, "-imported") }; ImportOperation importOperation = new ImportOperation(importParams, result.ConnectionInfo); service.PerformOperation(importOperation, TaskExecutionMode.Execute); targetDb = SqlTestDb.CreateFromExisting(importParams.DatabaseName); VerifyAndCleanup(exportParams.PackageFilePath); } finally { sourceDb.Cleanup(); if (targetDb != null) { targetDb.Cleanup(); } } }
/// <summary> /// Update /// </summary> /// <param name="operation"></param> /// <returns></returns> protected override object Update(ExportOperation operation) { var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item); if (synchronizer == null) { return(null); } var video = (Video)synchronizer.CreateEntity(operation.Item); video.ThumbnailUrl = null; video.CreationDate = null; video.VideoStillURL = null; video.PublishedDate = null; video.PlaysTrailingWeek = null; video.PlaysTotal = null; video.LastModifiedDate = null; video.Length = null; if (video.CustomFields != null && video.CustomFields.Count == 0) { video.CustomFields = null; } var authenticator = new BrightcoveAthenticator(operation.AccountItem); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); var updateData = new PostData("update_video", authenticator, "video", video); var data = context.Update <PostData, ResultData <Video> >("update_data", updateData).Data; if (data != null && data.Result != null) { if (data.Result.CustomFields == null) { data.Result.CustomFields = video.CustomFields; } return(data.Result); } return(null); }
protected override void Delete(ExportOperation operation) { IItemSynchronizer itemSynchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item); if (itemSynchronizer == null) { return; } var video1 = (Video)itemSynchronizer.CreateEntity(operation.Item); var video2 = new Video(); video2.Id = video1.Id; video2.ItemState = ItemState.INACTIVE; Video video3 = video2; var authenticator = new BrightcoveAuthenticator(operation.AccountItem); new VideoProxy(authenticator).Patch(video3); }
/// <summary> /// Updates a video. /// </summary> /// <param name="operation"> /// The operation. /// </param> /// <returns> /// The <see cref="object"/>. /// </returns> protected override object Update(ExportOperation operation) { var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item); if (synchronizer == null) { return(null); } var authenticator = new OoyalaAthenticator(operation.AccountItem); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); var video = (Video)synchronizer.CreateEntity(operation.Item); string embedCode = video.EmbedCode; video.EmbedCode = null; video.CreatedAt = null; video.UpdatedAt = null; video.Duration = null; video.PostProcessingStatus = null; video.PreviewImageUrl = null; video.Status = null; video.AssetType = null; video.Metadata = null; video.OriginalFileName = null; this.UpdateLabels(operation, embedCode); this.UpdatePlayer(operation, embedCode); this.UpdateMetadata(operation, embedCode); return(context.Update <Video, Video>( "update_video", video, new List <Parameter> { new Parameter { Type = ParameterType.UrlSegment, Name = "embedcode", Value = embedCode } }).Data); }
private async Task <Mock <RequestContext <DacFxResult> > > ValidateExportCancellation() { var result = GetLiveAutoCompleteTestObjects(); var requestContext = new Mock <RequestContext <DacFxResult> >(); requestContext.Setup(x => x.SendResult(It.IsAny <DacFxResult>())).Returns(Task.FromResult(new object())); SqlTestDb testdb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, null, "DacFxExportTest"); string folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DacFxTest"); Directory.CreateDirectory(folderPath); var exportParams = new ExportParams { DatabaseName = testdb.DatabaseName, PackageFilePath = Path.Combine(folderPath, string.Format("{0}.bacpac", testdb.DatabaseName)) }; SqlConnection sqlConn = ConnectionService.OpenSqlConnection(result.ConnectionInfo, "Export"); DacFxService service = new DacFxService(); ExportOperation operation = new ExportOperation(exportParams, sqlConn); // set cancellation token to cancel operation.Cancel(); OperationCanceledException expectedException = null; try { service.PerformOperation(operation); } catch (OperationCanceledException canceledException) { expectedException = canceledException; } Assert.NotNull(expectedException); // cleanup testdb.Cleanup(); return(requestContext); }
/// <summary> /// Updates metadata for an asset. /// </summary> /// <param name="operation"> /// The operation. /// </param> /// <param name="assetEmbedCode"> /// The asset embed code. /// </param> /// <returns> /// The <see cref="Dictionary"/>. /// </returns> protected virtual Dictionary <string, string> UpdateMetadata(ExportOperation operation, string assetEmbedCode) { var authenticator = new OoyalaAthenticator(operation.AccountItem); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); Dictionary <string, string> metadata = this.GetMetadata(operation.Item); return(context.Update <Dictionary <string, string>, Dictionary <string, string> >( "update_metadata_of_asset", metadata, new List <Parameter> { new Parameter { Type = ParameterType.UrlSegment, Name = "embedcode", Value = assetEmbedCode } }).Data); }
/// <summary> /// Creates a player. /// </summary> /// <param name="operation"> /// The operation. /// </param> /// <returns> /// The <see cref="object"/>. /// </returns> protected override object Create(ExportOperation operation) { var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item); if (synchronizer == null) { return(null); } var authenticator = new OoyalaAthenticator(operation.AccountItem); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); var player = (Player)synchronizer.CreateEntity(operation.Item); player.Id = null; player.IsDefault = false; return(context.Create <Player, Player>("create_player", player).Data); }
/// <summary> /// Updates a lineup. /// </summary> /// <param name="operation"> /// The operation. /// </param> /// <param name="channelEmbedCode"> /// The channel Embed Code. /// </param> /// <returns> /// The <see cref="List"/>. /// </returns> protected virtual List <string> UpdateLineup(ExportOperation operation, string channelEmbedCode) { var authenticator = new OoyalaAthenticator(operation.AccountItem); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); List <string> lineup = this.GetLineup(operation.Item); return(context.Update <List <string>, List <string> >( "update_channel_lineup", lineup, new List <Parameter> { new Parameter { Type = ParameterType.UrlSegment, Name = "embedcode", Value = channelEmbedCode } }).Data); }
/// <summary> /// 导出图层中选定要素到单独的shp文件 /// </summary> /// <param name="featureLayer">要素图层</param> /// <param name="selectionSet">要素选择集</param> /// <param name="outName">输出shp文件路径</param> public void exportSelectedFeatureToShp(IFeatureLayer featureLayer, ISelectionSet selectionSet, string outName) { if (featureLayer == null) { return; } if (!Directory.Exists(System.IO.Path.GetDirectoryName(outName))) { return; } // 裁剪要素 IDataset dataset = featureLayer as IDataset; IFeatureClassName infeatClassName = dataset.FullName as IFeatureClassName; IDatasetName datasetName = infeatClassName as IDatasetName; // 输出要素类 IFeatureClassName outFeatClassName = new FeatureClassName() as IFeatureClassName; outFeatClassName.FeatureType = esriFeatureType.esriFTSimple; outFeatClassName.ShapeType = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryAny; outFeatClassName.ShapeFieldName = "Shape"; // 输出文件 IDatasetName outDatasetName = outFeatClassName as IDatasetName; outDatasetName.Name = System.IO.Path.GetFileNameWithoutExtension(outName); IWorkspaceName workspaceName = new WorkspaceName() as IWorkspaceName; workspaceName.PathName = System.IO.Path.GetDirectoryName(outName); workspaceName.WorkspaceFactoryProgID = "esriDataSourcesGDB.ShapefileWorkspaceFactory"; outDatasetName.WorkspaceName = workspaceName; // 导出 IExportOperation exportOper = new ExportOperation(); exportOper.ExportFeatureClass(datasetName, null, selectionSet, null, outFeatClassName, 0); }
/// <summary> /// Creates a label. /// </summary> /// <param name="operation"> /// The operation. /// </param> /// <returns> /// The <see cref="object"/>. /// </returns> protected override object Create(ExportOperation operation) { var synchronizer = MediaFrameworkContext.GetItemSynchronizer(operation.Item); if (synchronizer == null) { return(null); } var authenticator = new OoyalaAthenticator(operation.AccountItem); var context = new RestContext(Constants.SitecoreRestSharpService, authenticator); var label = (Label)synchronizer.CreateEntity(operation.Item); return(context.Create <Label, Label>( "create_label", new Label { Name = label.Name, ParentId = !string.IsNullOrEmpty(label.ParentId) ? label.ParentId : "root" }).Data); }
private void Export(string tempMdbPathName, string attributeDatasetName, bool selectedOnly) { IRelationshipClass relClass = null; IFeatureClass outFeatureClass = null; IFeatureClass joinFeatureClass = null; IFeatureLayer joinLayer = null; IDataset attributeDataset; ITable exportAttributes; IWorkspaceFactory joinWorkspaceFactory = new OLEDBWorkspaceFactoryClass(); object outWS = null; try { SetCursor(true); OpenOleDbWorkspace(tempMdbPathName, attributeDatasetName, ref joinWorkspaceFactory, out attributeDataset, out exportAttributes); IDisplayTable hluDisplayTable = (IDisplayTable)_hluLayer; IFeatureClass hluDisplayTableFeatureClass = (IFeatureClass)hluDisplayTable.DisplayTable; // Set the selected and total feature counts. int selectedFeatureCount = _hluFeatureSelection.SelectionSet.Count; int totalFeatureCount = _hluLayer.FeatureClass.FeatureCount(null); int exportFeatureCount = 0; // Prompt the user for where to save the export layer. IExportOperation exportOp = new ExportOperation(); bool saveProjection; esriExportTableOptions exportOptions; IDatasetName exportDatasetName = exportOp.GetOptions(hluDisplayTableFeatureClass, _hluLayer.Name, _hluFeatureSelection != null && _hluFeatureSelection.SelectionSet.Count > 0, true, _application.hWnd, out saveProjection, out exportOptions); // If no export dataset name was chosen by the user then cancel the export. if (exportDatasetName == null) { _pipeData.Add("cancelled"); return; } // Open the export dataset workspace. outWS = ((IName)exportDatasetName.WorkspaceName).Open(); // Determine if the export layer is a shapefile. bool isShp = IsShp(outWS as IWorkspace); //--------------------------------------------------------------------- // FIX: 050 Warn ArcGIS users if field names may be truncated or // renamed exporting to shapefiles. // // If the export layer is a shapefile check if any of // the attribute field names will be truncated. if (isShp) { bool fieldNamesTruncated = false; for (int i = 0; i < exportAttributes.Fields.FieldCount; i++) { IField attributeField = exportAttributes.Fields.get_Field(i); if (attributeField.Name.Length > 10) { fieldNamesTruncated = true; break; } } // Warn the user that some field names may get truncated. if (fieldNamesTruncated) { MessageBoxResult userResponse = MessageBoxResult.No; userResponse = MessageBox.Show("Some field names may get truncated or renamed exporting to a shapefile.\n\nDo you wish to proceed?", "HLU: Export", MessageBoxButton.YesNo, MessageBoxImage.Question); if (userResponse != MessageBoxResult.Yes) { _pipeData.Add("cancelled"); return; } } } //--------------------------------------------------------------------- // Get the geometry definition for the feature layer. IGeometryDef geomDef = _hluFeatureClass.Fields.get_Field(_hluFeatureClass.FindField( _hluFeatureClass.ShapeFieldName)).GeometryDef; ITable joinLayerTable; IDisplayTable joinDisplayTable; //--------------------------------------------------------------------- // CHANGED: CR13 (Export features performance) // // If only a sub-set of features are being exported then // export the sub-set to a temporary feature class before // joining the temporary layer to the attribute dataset. if (selectedOnly) { // Set the export options for which records to export. exportOptions = esriExportTableOptions.esriExportSelectedRecords; // Set the input DataSet name IDataset inDataset; inDataset = (IDataset)hluDisplayTable.DisplayTable; IDatasetName inDatasetName; inDatasetName = (IDatasetName)inDataset.FullName; // set the output temporary DataSet name IFeatureClassName outFCName = new FeatureClassNameClass(); IDatasetName outDatasetName = (IDatasetName)outFCName; outDatasetName.Name = String.Format("{0}_temp", exportDatasetName.Name); outDatasetName.WorkspaceName = exportDatasetName.WorkspaceName; // Get the selected features for export ISelectionSet selectionSet = _hluFeatureSelection.SelectionSet; // If there is no selection cancel the export. if (_hluFeatureSelection.SelectionSet.Count == 0) { _pipeData.Add("noselection"); return; } // Export the selected features to the temporary dataset. exportOp.ExportFeatureClass(inDatasetName, null, selectionSet, geomDef, (IFeatureClassName)outDatasetName, _application.hWnd); // Cast the workspace to IFeatureWorkspace and open the feature class. IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)outWS; joinFeatureClass = featureWorkspace.OpenFeatureClass(outDatasetName.Name); // Add an attribute index to the incid field. AddFieldIndex(joinFeatureClass, String.Format("IX_{0}", _hluLayerStructure.incidColumn.ColumnName), _hluLayerStructure.incidColumn.ColumnName); // Set the join layer to the temporary feature class. joinLayer = new FeatureLayerClass(); joinLayer.FeatureClass = joinFeatureClass; joinLayer.Name = joinFeatureClass.AliasName; // Set the join layer table to the temporary feature class. joinDisplayTable = (IDisplayTable)joinLayer; //IFeatureClass joinDisplayTableFC = (IFeatureClass)joinDisplayTable.DisplayTable; IFeatureClass joinDisplayTableFC = joinFeatureClass; joinLayerTable = (ITable)joinDisplayTableFC; // Set the count for the number of features to be exported. exportFeatureCount = selectedFeatureCount; } // Otherwise, join the whole feature layer to the // attribute dataset. else { // Clear any current selection. _hluFeatureSelection.SelectionSet = null; // Set the export options for which records to export. exportOptions = esriExportTableOptions.esriExportAllRecords; // Set the join feature class to the current HLU feature class. joinFeatureClass = _hluFeatureClass; // Set the join layer to the current HLU feature layer. joinLayer = _hluLayer; joinLayerTable = (ITable)hluDisplayTableFeatureClass; joinDisplayTable = hluDisplayTable; // Set the count for the number of features to be exported. exportFeatureCount = totalFeatureCount; } //--------------------------------------------------------------------- // Get the field names to be used when joining the attribute data and the feature layer string originPKJoinField = _hluLayerStructure.incidColumn.ColumnName; string originFKJoinField = _hluFeatureClass.Fields.get_Field(_hluFieldMap[_hluLayerStructure.incidColumn.Ordinal]).Name; // Get a list of all the fields to be used in the export layer (plus separate lists of all // those fields that will come from the attribute table and those that will come from the // feature layer). List<IField> attributeFields; List<IField> featClassFields; List<IField> exportFields = ExportFieldLists(isShp, originPKJoinField, originFKJoinField, joinFeatureClass, exportAttributes, out attributeFields, out featClassFields); // Add x/y, length, or area and length fields to the list of fields in the export layer // if the export layer is a shapefile. ExportAddGeometryPropertyFields(isShp, exportFields); // Create a virtual relationship between the feature class // and the attribute dataset. IMemoryRelationshipClassFactory memoryRelFactory = new MemoryRelationshipClassFactoryClass(); relClass = memoryRelFactory.Open("ExportRelClass", (IObjectClass)exportAttributes, originPKJoinField, (IObjectClass)joinLayerTable, originFKJoinField, "forward", "backward", esriRelCardinality.esriRelCardinalityOneToMany); // Use the relationship to perform a join. IDisplayRelationshipClass displayRelClass = (IDisplayRelationshipClass)joinLayer; displayRelClass.DisplayRelationshipClass(relClass, esriJoinType.esriLeftInnerJoin); // Create query filter for the export cursor so that // only the required fields are retrieved. bool featClassFieldsQualified; bool attributeFieldsQualified; IQueryFilter exportQueryFilter = ExportQueryFilter(originPKJoinField, joinLayer, joinFeatureClass, joinDisplayTable, attributeDataset, featClassFields, attributeFields, out featClassFieldsQualified, out attributeFieldsQualified); // Create a collection of fields for the output feature class. // Adds OID and SHAPE at beginning. IFields outFields = CreateFieldsCollection(true, geomDef.HasZ, geomDef.HasM, outWS, joinFeatureClass.ShapeType, exportFields.Select(f => f.Length).ToArray(), exportFields.Select(f => f.Name).ToArray(), exportFields.Select(f => f.Name).ToArray(), exportFields.Select(f => f.Type).ToArray(), exportFields.Select(f => f.Type != esriFieldType.esriFieldTypeOID).ToArray(), geomDef.SpatialReference); // Create the output feature class. outFeatureClass = CreateFeatureClass(exportDatasetName.Name, null, outWS, outFields, esriFeatureType.esriFTSimple, joinFeatureClass.ShapeType, null, null); // Map the fields between the display and table and the output feature // class as the display table always includes all fields. // The first two fields are always OID and SHAPE. int[] exportFieldMap = new int[] { 0, 1 }.Concat(featClassFields .Select(f => joinDisplayTable.DisplayTable.Fields.FindField(featClassFieldsQualified ? joinLayer.Name + "." + f.Name : f.Name))).Concat(attributeFields .Select(f => joinDisplayTable.DisplayTable.Fields.FindField(attributeFieldsQualified ? attributeDataset.Name + "." + f.Name : f.Name))).ToArray(); //--------------------------------------------------------------------- // FIX: 038 Display the export progress bar correctly when exporting // from ArcGIS. // Pass the number of features to be exported, not the number of incids, // so that the export progress is displayed corectly // // Insert the features and attributes into the new feature class. ExportInsertFeatures(joinDisplayTable, exportQueryFilter, exportFeatureCount, exportFieldMap, isShp, outWS, outFeatureClass); //--------------------------------------------------------------------- //--------------------------------------------------------------------- // CHANGED: CR16 (Adding exported features) // Ask the user if they want to add the new export layer // to the active map. MessageBoxResult addResponse = MessageBoxResult.No; addResponse = MessageBox.Show("The export operation succeeded.\n\nAdd the exported layer to the current map?", "HLU: Export", MessageBoxButton.YesNo, MessageBoxImage.Question); if (addResponse == MessageBoxResult.Yes) { // Add the exported feature layer to the active map. IFeatureLayer hluExportLayer; hluExportLayer = new FeatureLayer(); hluExportLayer.FeatureClass = outFeatureClass; hluExportLayer.Name = outFeatureClass.AliasName; _focusMap.AddLayer(hluExportLayer); } //--------------------------------------------------------------------- } catch (Exception ex) { _pipeData.Add(ex.Message); } finally { // Remove the virtual relationship. if (relClass != null) { //IRelationshipClassCollectionEdit relClassEdit = (IRelationshipClassCollectionEdit)joinLayer; //relClassEdit.RemoveAllRelationshipClasses(); ((IDisplayRelationshipClass)joinLayer).DisplayRelationshipClass( null, esriJoinType.esriLeftInnerJoin); } // Destroy workspace factory so the attribute dataset can // be deleted later. attributeDataset = null; exportAttributes = null; joinWorkspaceFactory = null; // Delete the temporary feature class. try { if (joinFeatureClass != _hluFeatureClass) { IDataset tempDataset = (IDataset)joinFeatureClass; if (tempDataset != null) tempDataset.Delete(); } } catch { } SetCursor(false); } }
private void Export(string tempMdbPathName, string attributeDatasetName, int exportRowCount) { IRelationshipClass relClass = null; IFeatureClass outFeatureClass = null; try { SetCursor(true); IDataset attributeDataset; ITable exportAttributes; OpenOleDbWorkspace(tempMdbPathName, attributeDatasetName, out attributeDataset, out exportAttributes); IDisplayTable hluDisplayTable = (IDisplayTable)_hluLayer; IFeatureClass hluDisplayTableFeatureClass = (IFeatureClass)hluDisplayTable.DisplayTable; ITable hluLayerTable = (ITable)hluDisplayTableFeatureClass; IExportOperation exportOp = new ExportOperation(); bool saveProjection; esriExportTableOptions exportOptions; IDatasetName exportDatasetName = exportOp.GetOptions(hluDisplayTableFeatureClass, _hluLayer.Name, _hluFeatureSelection != null && _hluFeatureSelection.SelectionSet.Count > 0, true, _application.hWnd, out saveProjection, out exportOptions); if (exportDatasetName == null) { _pipeData.Add("cancelled"); return; } object outWS = ((IName)exportDatasetName.WorkspaceName).Open(); string originPKJoinField = _hluLayerStructure.incidColumn.ColumnName; string originFKJoinField = _hluFeatureClass.Fields.get_Field(_hluFieldMap[_hluLayerStructure.incidColumn.Ordinal]).Name; List<IField> attributeFields; List<IField> featClassFields; List<IField> exportFields = ExportFieldLists(originPKJoinField, originFKJoinField, exportAttributes, out attributeFields, out featClassFields); bool isShp = IsShp(outWS as IWorkspace); ExportAddGeometryPropertyFields(isShp, exportFields); // create virtual relate IMemoryRelationshipClassFactory memoryRelFactory = new MemoryRelationshipClassFactoryClass(); relClass = memoryRelFactory.Open("ExportRelClass", (IObjectClass)exportAttributes, originPKJoinField, (IObjectClass)hluLayerTable, originFKJoinField, "forward", "backward", esriRelCardinality.esriRelCardinalityOneToMany); // use Relate to perform a join IDisplayRelationshipClass displayRelClass = (IDisplayRelationshipClass)_hluLayer; displayRelClass.DisplayRelationshipClass(relClass, esriJoinType.esriLeftOuterJoin); // create query filter for export cursor bool featClassFieldsQualified; bool attributeFieldsQualified; IQueryFilter exportQueryFilter = ExportQueryFilter(originPKJoinField, hluDisplayTable, attributeDataset, featClassFields, attributeFields, out featClassFieldsQualified, out attributeFieldsQualified); IGeometryDef geomDef = _hluFeatureClass.Fields.get_Field(_hluFeatureClass.FindField( _hluFeatureClass.ShapeFieldName)).GeometryDef; // adds OID and SHAPE at beginning, possibly Shape_Length and Shape_Area at end // when populating new rows we loop over exportFieldOrdinals // if we export shp we calculate geometry props into the last two fields, which are // not in exportFields IFields outFields = CreateFieldsCollection(true, geomDef.HasZ, geomDef.HasM, outWS, _hluFeatureClass.ShapeType, exportFields.Select(f => f.Length).ToArray(), exportFields.Select(f => f.Name).ToArray(), exportFields.Select(f => f.Name).ToArray(), exportFields.Select(f => f.Type).ToArray(), exportFields.Select(f => f.Type != esriFieldType.esriFieldTypeOID).ToArray(), geomDef.SpatialReference); // create output feature class outFeatureClass = CreateFeatureClass(exportDatasetName.Name, null, outWS, outFields, esriFeatureType.esriFTSimple, _hluFeatureClass.ShapeType, null, null); // field map between display and output feature class, as display // table always includes all fields, regardless of SubFields // the first two fields are always OID and SHAPE // the last two Shape_Length and Shape_Area, either added automatically or here int[] exportFieldMap = new int[] { 0, 1 }.Concat(featClassFields .Select(f => hluDisplayTable.DisplayTable.Fields.FindField(featClassFieldsQualified ? _hluLayer.Name + "." + f.Name : f.Name))).Concat(attributeFields .Select(f => hluDisplayTable.DisplayTable.Fields.FindField(attributeFieldsQualified ? attributeDataset.Name + "." + f.Name : f.Name))).ToArray(); // insert features into new feature class ExportInsertFeatures(hluDisplayTable, exportQueryFilter, exportRowCount, exportFieldMap, isShp, outWS, outFeatureClass); } catch (Exception ex) { _pipeData.Add(ex.Message); } finally { if (relClass != null) ((IDisplayRelationshipClass)_hluLayer).DisplayRelationshipClass( null, esriJoinType.esriLeftInnerJoin); outFeatureClass = null; try { if (File.Exists(tempMdbPathName)) File.Delete(tempMdbPathName); } catch { } SetCursor(false); } }