// Path: dotTrace-common/src/main/java/jetbrains/buildServer/dotTrace/Constants.java
// public class Constants {
//     public static final String USE_VAR = "dot_trace";
//     public static final String PATH_VAR = "dot_trace_path";
//     public static final String THRESHOLDS_VAR = "dot_trace_thresholds";
//     public static final String MEASURE_TYPE_VAR = "dot_trace_measure_type";
//     public static final String PROFILE_CHILD_PROCESSES_VAR = "dot_trace_profile_child_processes";
//     public static final String PROCESS_FILTERS_VAR = "dot_trace_process_filters";
//     public static final String SNAPSHOTS_PATH_VAR = "dot_trace_snapshots_path";
// }


import com.intellij.openapi.util.text.StringUtil;
import java.util.Collections;
import jetbrains.buildServer.dotNet.buildRunner.agent.*;
import jetbrains.buildServer.dotTrace.Constants;
import org.jetbrains.annotations.NotNull;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/*
 * Copyright 2000-2021 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package jetbrains.buildServer.dotTrace.agent;


public class PatternsGenerator implements ResourceGenerator<Context> {
  private static final String PATTERNS_ELEMENT = "Patterns";
  private static final String PATTERN_ELEMENT = "Pattern";

  private final TextParser<Metrics> myThresholdsParser;
  private final RunnerParametersService myParametersService;
  private final XmlDocumentManager myDocumentManager;

  public PatternsGenerator(
    @NotNull final TextParser<Metrics> thresholdsParser,
    @NotNull final RunnerParametersService parametersService,
    @NotNull final XmlDocumentManager documentManager) {
    myThresholdsParser = thresholdsParser;
    myParametersService = parametersService;
    myDocumentManager = documentManager;
  }

  @NotNull
  @Override
  public String create(@NotNull final Context context) {
    final Document doc = myDocumentManager.createDocument();
    final Element patternsElement = doc.createElement(PATTERNS_ELEMENT);
// Path: dotTrace-common/src/main/java/jetbrains/buildServer/dotTrace/Constants.java
// public class Constants {
//     public static final String USE_VAR = "dot_trace";
//     public static final String PATH_VAR = "dot_trace_path";
//     public static final String THRESHOLDS_VAR = "dot_trace_thresholds";
//     public static final String MEASURE_TYPE_VAR = "dot_trace_measure_type";
//     public static final String PROFILE_CHILD_PROCESSES_VAR = "dot_trace_profile_child_processes";
//     public static final String PROCESS_FILTERS_VAR = "dot_trace_process_filters";
//     public static final String SNAPSHOTS_PATH_VAR = "dot_trace_snapshots_path";
// }


// Path: dotTrace-agent/src/main/java/jetbrains/buildServer/dotTrace/agent/PatternsGenerator.java
import com.intellij.openapi.util.text.StringUtil;
import java.util.Collections;
import jetbrains.buildServer.dotNet.buildRunner.agent.*;
import jetbrains.buildServer.dotTrace.Constants;
import org.jetbrains.annotations.NotNull;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/*
 * Copyright 2000-2021 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package jetbrains.buildServer.dotTrace.agent;


public class PatternsGenerator implements ResourceGenerator<Context> {
  private static final String PATTERNS_ELEMENT = "Patterns";
  private static final String PATTERN_ELEMENT = "Pattern";

  private final TextParser<Metrics> myThresholdsParser;
  private final RunnerParametersService myParametersService;
  private final XmlDocumentManager myDocumentManager;

  public PatternsGenerator(
    @NotNull final TextParser<Metrics> thresholdsParser,
    @NotNull final RunnerParametersService parametersService,
    @NotNull final XmlDocumentManager documentManager) {
    myThresholdsParser = thresholdsParser;
    myParametersService = parametersService;
    myDocumentManager = documentManager;
  }

  @NotNull
  @Override
  public String create(@NotNull final Context context) {
    final Document doc = myDocumentManager.createDocument();
    final Element patternsElement = doc.createElement(PATTERNS_ELEMENT);
    String thresholdsStr = myParametersService.tryGetRunnerParameter(Constants.THRESHOLDS_VAR);