public PSSavedSearchProperties(SavedSearchProperties properties)
 {
     if (properties != null)
     {
         this.Category = properties.Category;
         this.DisplayName = properties.DisplayName;
         this.Query = properties.Query;
         this.Version = properties.Version;
     }
 }
        protected override void ProcessRecord()
        {
            SavedSearchProperties properties = new SavedSearchProperties()
            {
                Category = this.Category,
                DisplayName = this.DisplayName,
                Query = this.Query,
                Version = this.Version,
                Tags = new List<Tag>() { new Tag() { Name = "Group", Value = "Computer" } }
            };

            WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, Force, ConfirmAction), true);
        }
        protected override void ProcessRecord()
        {
            SavedSearchProperties properties = new SavedSearchProperties()
            {
                Category = this.Category,
                DisplayName = this.DisplayName,
                Query = this.Query,
                Version = this.Version
            };

            properties.Tags = SearchCommandHelper.PopulateAndValidateTagsForProperties(this.Tags, properties.Query);

            WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, true, ConfirmAction), true);
        }
        protected override void ProcessRecord()
        {
            SavedSearchProperties properties = new SavedSearchProperties()
            {
                Category = this.Category,
                DisplayName = this.DisplayName,
                Query = this.Query,
                Version = this.Version,
                Tags = new List<Tag>() { new Tag() { Name = "Group", Value = "Computer" } }
            };

            if (!SearchCommandHelper.IsListOfComputers(this.Query))
            {
                throw new PSArgumentException("Query is not a list of computers. Please use aggregations such as: distinct Computer or measure count() by Computer.");
            }

            WriteObject(OperationalInsightsClient.CreateOrUpdateSavedSearch(ResourceGroupName, WorkspaceName, SavedSearchId, properties, Force, ConfirmAction), true);
        }
        public PSSavedSearchProperties(SavedSearchProperties properties)
        {
            if (properties != null)
            {
                this.Category = properties.Category;
                this.DisplayName = properties.DisplayName;
                this.Query = properties.Query;
                this.Version = properties.Version;
                this.Tags = new Hashtable();

                if (properties.Tags != null)
                {
                    foreach (Tag tag in properties.Tags)
                    {
                        this.Tags[tag.Name] = tag.Value;
                    }
                }
            }
        }
        public virtual HttpStatusCode CreateOrUpdateSavedSearch(string resourceGroupName, string workspaceName, string savedSearchId, SavedSearchProperties properties, bool force, Action<bool, string, string, string, Action> ConfirmAction, string ETag = null)
        {
            HttpStatusCode status = HttpStatusCode.Ambiguous;
            Action createSavedSearch = () =>
                {
                    SearchCreateOrUpdateSavedSearchParameters searchParameters = new SearchCreateOrUpdateSavedSearchParameters();
                    if (ETag != null && ETag != "")
                    {
                        searchParameters.ETag = ETag;
                    }
                    searchParameters.Properties = properties;
                    AzureOperationResponse response = OperationalInsightsManagementClient.Search.CreateOrUpdateSavedSearch(resourceGroupName, workspaceName, savedSearchId, searchParameters);
                    status = response.StatusCode;
                };
            if (force)
            {
                createSavedSearch();
            }
            else
            {
                bool savedSearchExists = CheckSavedSearchExists(resourceGroupName, workspaceName, savedSearchId);

                ConfirmAction(
                    !savedSearchExists,    // prompt only if the saved search exists
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.SavedSearchExists,
                        savedSearchId,
                        workspaceName),
                    string.Format(
                        CultureInfo.InvariantCulture,
                        Resources.SavedSearchCreating,
                        savedSearchId,
                        workspaceName),
                    savedSearchId,
                    createSavedSearch);
            }
            return status;
        }