private static bool TryGetViewId(Entity entityList, out Guid viewId) { // First, try get the view from the newer view configuration JSON. viewId = Guid.Empty; var viewMetadataJson = entityList.GetAttributeValue <string>("adx_views"); if (!string.IsNullOrWhiteSpace(viewMetadataJson)) { try { var viewMetadata = ViewMetadata.Parse(viewMetadataJson); var view = viewMetadata.Views.FirstOrDefault(); if (view != null) { viewId = view.ViewId; return(true); } } catch (Exception e) { ADXTrace.Instance.TraceError(TraceCategory.Application, string.Format("Error parsing adx_views JSON: {0}", e.ToString())); } } // Fall back to the legacy comma-delimited list of IDs. var viewIds = (entityList.GetAttributeValue <string>("adx_view") ?? string.Empty) .Split(',') .Select(s => { Guid id; return(Guid.TryParse(s, out id) ? new Guid?(id) : null); }) .Where(id => id != null); viewId = viewIds.FirstOrDefault() ?? Guid.Empty; return(viewId != Guid.Empty); }
private static bool TryGetViewId(Entity entityList, out Guid viewId) { // First, try get the view from the newer view configuration JSON. viewId = Guid.Empty; var viewMetadataJson = entityList.GetAttributeValue <string>("adx_views"); if (!string.IsNullOrWhiteSpace(viewMetadataJson)) { try { var viewMetadata = ViewMetadata.Parse(viewMetadataJson); var view = viewMetadata.Views.FirstOrDefault(); if (view != null) { viewId = view.ViewId; return(true); } } catch (Exception e) { Tracing.FrameworkError(typeof(PackageRepositoryHelpers).FullName, "TryGetViewId", "Error parsing adx_views JSON: {0}", e); } } // Fall back to the legacy comma-delimited list of IDs. var viewIds = (entityList.GetAttributeValue <string>("adx_view") ?? string.Empty) .Split(',') .Select(s => { Guid id; return(Guid.TryParse(s, out id) ? new Guid?(id) : null); }) .Where(id => id != null); viewId = viewIds.FirstOrDefault() ?? Guid.Empty; return(viewId != Guid.Empty); }