text:
package com.twitter.hraven.etl;

import static com.twitter.hraven.etl.ProcessState.LOADED;
import static com.twitter.hraven.etl.ProcessState.PROCESSED;

import java.io.IOException;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.filecache.DistributedCache;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.mapreduce.MultiTableOutputFormat;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.util.GenericOptionsParser;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import com.twitter.hraven.AggregationConstants;
import com.twitter.hraven.Constants;
import com.twitter.hraven.datasource.JobHistoryRawService;
import com.twitter.hraven.datasource.RowKeyParseException;
import com.twitter.hraven.mapreduce.JobFileTableMapper;

/**
 * Used to process one ProcessingRecord at at time. For each record an HBase job
 * is created to scan the corresponding rows in the raw
 *
 */
public class JobFileProcessor extends Configured implements Tool {

  final static String NAME = JobFileProcessor.class.getSimpleName();
  private static Log LOG = LogFactory.getLog(JobFileProcessor.class);

  private final String startTimestamp =
      Constants.TIMESTAMP_FORMAT.format(new Date(System.currentTimeMillis()));

  private final AtomicInteger jobCounter = new AtomicInteger(0);

  /**
   * Maximum number of files to process in one batch.
   */
  private final static int DEFAULT_BATCH_SIZE = 100;

  /**
   * Default constructor.
   */
  public JobFileProcessor() {

  }

  /**
   * Used for injecting confs while unit testing
   *
   * @param conf
   */
  public JobFileProcessor(Configuration conf) {
    super(conf);

  }

  /**
   * Parse command-line arguments.
   *
   * @param args command line arguments passed to program.
   * @return parsed command line.
   * @throws ParseException
   */
  private static CommandLine parseArgs(String[] args) throws ParseException {
    Options options = new Options();

    // Input
    Option o = new Option("c", "cluster", true,
        "cluster for which jobs are processed");
    o.setArgName("cluster");
    o.setRequired(true);
    options.addOption(o);

    // Whether to skip existing files or not.
    o = new Option("r", "reprocess", false,
        "Reprocess only those records that have been marked to be reprocessed. Otherwise process all rows indicated in the processing records, but successfully processed job files are skipped.");
    o.setRequired(false);
    options.addOption(o);

    // Whether to aggregate or not.
    // if re-process is on, need to consider turning aggregation off
    o = new Option("a", "aggregate", true,
        "Whether to aggreagate job details or not.");
    o.setArgName("aggreagte");
    o.setRequired(false);
    options.addOption(o);

    // Whether to force re-aggregation or not.
    o = new Option("ra", "re-aggregate", true,
        "Whether to re-aggreagate job details or not.");
    o.setArgName("re-aggreagte");
    o.setRequired(false);
    options.addOption(o);

    // Batch
    o = new Option("b", "batchSize", true,
        "The number of files to process in one batch. Default "
            + DEFAULT_BATCH_SIZE);
    o.setArgName("batch-size");
    o.setRequired(false);
    options.addOption(o);

    o = new Option("t", "threads", true,
        "Number of parallel threads to use to run Hadoop jobs simultaniously. Default = 1");
    o.setArgName("thread-count");
    o.setRequired(false);
    options.addOption(o);

    o = new Option("p", "processFileSubstring", true,
        "use only those process records where the process file path contains the provided string. Useful when processing production jobs in parallel to historic loads.");
    o.setArgName("processFileSubstring");
    o.setRequired(false);
    options.addOption(o);

    // Debugging
    options.addOption("d", "debug", false, "switch on DEBUG log level");

    o = new Option("zf", "costFile", true,
        "The cost properties file location on HDFS");
    o.setArgName("costfile_loc");
    o.setRequired(true);
    options.addOption(o);

    // Machine type
    o = new Option("m", "machineType", true,
        "The type of machine this job ran on");
    o.setArgName("machinetype");
    o.setRequired(true);
    options.addOption(o);

    CommandLineParser parser = new PosixParser();
    CommandLine commandLine = null;
    try {
      commandLine = parser.parse(options, args);
    } catch (Exception e) {
      System.err.println("ERROR: " + e.getMessage() + "\n");
      HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp(NAME + " ", options, true);
      System.exit(-1);
    }

    // Set debug level right away
    if (commandLine.hasOption("d")) {
      Logger log = Logger.getLogger(JobFileProcessor.class);
      log.setLevel(Level.DEBUG);
    }

    return commandLine;

  }

  /*
   * (non-Javadoc)
   *
   * @see org.apache.hadoop.util.Tool#run(java.lang.String[])
   */
  public int run(String[] args) throws Exception {

    Configuration hbaseConf = HBaseConfiguration.create(getConf());

    // Grab input args and allow for -Dxyz style arguments
    String[] otherArgs =
        new GenericOptionsParser(hbaseConf, args).getRemainingArgs();

    // Grab the arguments we're looking for.
    CommandLine commandLine = parseArgs(otherArgs);

    // Grab the cluster argument
    String cluster = commandLine.getOptionValue("c");
    LOG.info("cluster=" + cluster);

    // Number of parallel threads to use
    int threadCount = 1;
    if (commandLine.hasOption("t")) {
      try {
        threadCount = Integer.parseInt(commandLine.getOptionValue("t"));
      } catch (NumberFormatException nfe) {
        throw new IllegalArgumentException(
            "Provided thread-count argument (-t) is not a number: "
                + commandLine.getOptionValue("t"),
            nfe);
      }
      if (threadCount < 1) {
        throw new IllegalArgumentException(
            "Cannot run fewer than 1 thread. Provided thread-count argument (-t): "
                + threadCount);
      }
    }
    LOG.info("threadCount=" + threadCount);

    boolean reprocess = commandLine.hasOption("r");
    LOG.info("reprocess=" + reprocess);

    // Grab the batch-size argument
    int batchSize;
    if (commandLine.hasOption("b")) {
      try {
        batchSize = Integer.parseInt(commandLine.getOptionValue("b"));
      } catch (NumberFormatException nfe) {
        throw new IllegalArgumentException(
            "batch size option -b is is not a valid number: "
                + commandLine.getOptionValue("b"),
            nfe);
      }
      // Additional check
      if (batchSize < 1) {
        throw new IllegalArgumentException(
            "Cannot process files in batches smaller than 1. Specified batch size option -b is: "
                + commandLine.getOptionValue("b"));
      }
    } else {
      batchSize = DEFAULT_BATCH_SIZE;
    }

    // Grab the costfile argument

    String costFilePath = commandLine.getOptionValue("zf");
    LOG.info("cost properties file on hdfs=" + costFilePath);
    if (costFilePath == null)
      costFilePath = Constants.COST_PROPERTIES_HDFS_DIR;
    Path hdfsPath = new Path(costFilePath + Constants.COST_PROPERTIES_FILENAME);
    // add to distributed cache
    DistributedCache.addCacheFile(hdfsPath.toUri(), hbaseConf);

    // Grab the machine type argument
    String machineType = commandLine.getOptionValue("m");
    // set it as part of conf so that the
    // hRaven job can access it in the mapper
    hbaseConf.set(Constants.HRAVEN_MACHINE_TYPE, machineType);

    // check if re-aggregate option is forced on
    // if yes, we need to aggregate for this job inspite of
    // job having aggregation done status in raw table
    boolean reAggregateFlagValue = false;
    if (commandLine.hasOption("ra")) {
      String reaggregateFlag = commandLine.getOptionValue("ra");
      // set it as part of conf so that the
      // hRaven jobProcessor can access it in the mapper
      if (StringUtils.isNotBlank(reaggregateFlag)) {
        LOG.info(" reaggregateFlag is: " + reaggregateFlag);
        if (StringUtils.equalsIgnoreCase(reaggregateFlag,
            Boolean.TRUE.toString())) {
          reAggregateFlagValue = true;
        }
      }
    }
    LOG.info(AggregationConstants.RE_AGGREGATION_FLAG_NAME + "="
        + reAggregateFlagValue);
    hbaseConf.setBoolean(AggregationConstants.RE_AGGREGATION_FLAG_NAME,
        reAggregateFlagValue);

    // set aggregation to off by default
    boolean aggFlagValue = false;
    if (commandLine.hasOption("a")) {
      String aggregateFlag = commandLine.getOptionValue("a");
      // set it as part of conf so that the
      // hRaven jobProcessor can access it in the mapper
      if (StringUtils.isNotBlank(aggregateFlag)) {
        LOG.info(" aggregateFlag is: " + aggregateFlag);
        if (StringUtils.equalsIgnoreCase(aggregateFlag,
            Boolean.TRUE.toString())) {
          aggFlagValue = true;
        }
      }
    }
    if (reprocess) {
      // turn off aggregation if reprocessing is true
      // we don't want to inadvertently aggregate again while re-processing
      // re-aggregation needs to be a conscious setting
      aggFlagValue = false;
    }
    LOG.info(AggregationConstants.AGGREGATION_FLAG_NAME + "=" + aggFlagValue);
    hbaseConf.setBoolean(AggregationConstants.AGGREGATION_FLAG_NAME,
        aggFlagValue);

    String processFileSubstring = null;
    if (commandLine.hasOption("p")) {
      processFileSubstring = commandLine.getOptionValue("p");
    }
    LOG.info("processFileSubstring=" + processFileSubstring);

    // hbase.client.keyvalue.maxsize somehow defaults to 10 MB and we have
    // history files exceeding that. Disable limit.
    hbaseConf.setInt("hbase.client.keyvalue.maxsize", 0);

    // Shove this into the jobConf so that we can get it out on the task side.
    hbaseConf.setStrings(Constants.CLUSTER_JOB_CONF_KEY, cluster);

    boolean success = false;
    Connection hbaseConnection = null;
    try {
      hbaseConnection = ConnectionFactory.createConnection(hbaseConf);
      if (reprocess) {
        success = reProcessRecords(hbaseConf, hbaseConnection, cluster,
            batchSize, threadCount);
      } else {
        success = processRecords(hbaseConf, hbaseConnection, cluster, batchSize,
            threadCount, processFileSubstring);
      }
    } finally {
      if (hbaseConnection == null) {
        success = false;
      } else {
        hbaseConnection.close();
      }
    }

    // Return the status
    return success ? 0 : 1;
  }

  /**
   * Pick up the ranges of jobs to process from ProcessRecords. Skip raw rows
   * that have already been processed.
   *
   * @param conf used to contact HBase and to run jobs against
   * @param hbaseConnection
   * @param cluster for which to process records.
   * @param batchSize the total number of jobs to process in a batch (a MR job
   *          scanning these many records in the raw table).
   * @param threadCount how many parallel threads should be used to run Hadoop
   *          jobs in parallel.
   * @param processFileSubstring Use only process records where the process file
   *          path contains this string. If null or empty string,
   *          then no filtering is applied.
   * @return whether all job files for all processRecords were properly
   *         processed.
   * @throws IOException
   * @throws ClassNotFoundException when problems occur setting up the job.
   * @throws InterruptedException
   * @throws ExecutionException when at least one of the jobs could not be
   *           scheduled.
   * @throws RowKeyParseException
   */
  boolean processRecords(Configuration conf, Connection hbaseConnection,
      String cluster, int batchSize, int threadCount,
      String processFileSubstring) throws IOException, InterruptedException,
      ClassNotFoundException, ExecutionException, RowKeyParseException {

    List<ProcessRecord> processRecords =
        getProcessRecords(conf, hbaseConnection, cluster, processFileSubstring);

    // Bail out early if needed
    if ((processRecords == null) || (processRecords.size() == 0)) {
      return true;
    }

    // Grab the min and the max jobId from all processing records.
    MinMaxJobFileTracker minMaxJobFileTracker = new MinMaxJobFileTracker();

    for (ProcessRecord processRecord : processRecords) {
      minMaxJobFileTracker.track(processRecord.getMinJobId());
      minMaxJobFileTracker.track(processRecord.getMaxJobId());
    }

    List<JobRunner> jobRunners = getJobRunners(conf, hbaseConnection, cluster, false, batchSize,
        minMaxJobFileTracker.getMinJobId(), minMaxJobFileTracker.getMaxJobId());

    boolean success = runJobs(threadCount, jobRunners);
    if (success) {
      updateProcessRecords(conf, hbaseConnection, processRecords);
    }

    return success;
  }

  /**
   * @param conf used to contact HBase and to run jobs against
   * @param hbaseConnection
   * @param cluster for which to process records.
   * @param batchSize the total number of jobs to process in a batch (a MR job
   *          scanning these many records in the raw table).
   * @param threadCount how many parallel threads should be used to run Hadoop
   *          jobs in parallel.
   * @return whether all job files for all processRecords were properly
   *         processed.
   * @throws IOException
   * @throws ClassNotFoundException when problems occur setting up the job.
   * @throws InterruptedException
   * @throws ExecutionException when at least one of the jobs could not be
   *           scheduled.
   * @throws RowKeyParseException
   */
  boolean reProcessRecords(Configuration conf, Connection hbaseConnection,
      String cluster, int batchSize, int threadCount)
      throws IOException, InterruptedException, ClassNotFoundException,
      ExecutionException, RowKeyParseException {

    List<JobRunner> jobRunners =
        getJobRunners(conf, hbaseConnection, cluster, true, batchSize, null, null);

    boolean success = runJobs(threadCount, jobRunners);
    return success;
  }

  /**
   * Run the jobs and wait for all of them to complete.
   *
   * @param threadCount up to how many jobs to run in parallel
   * @param jobRunners the list of jobs to run.
   * @return whether all jobs completed successfully or not.
   * @throws InterruptedException when interrupted while running jobs.
   * @throws ExecutionException when at least one of the jobs could not be
   *           scheduled.
   */
  private boolean runJobs(int threadCount, List<JobRunner> jobRunners)
      throws InterruptedException, ExecutionException {
    ExecutorService execSvc = Executors.newFixedThreadPool(threadCount);

    if ((jobRunners == null) || (jobRunners.size() == 0)) {
      return true;
    }

    boolean success = true;
    try {
      List<Future<Boolean>> jobFutures = new LinkedList<Future<Boolean>>();
      for (JobRunner jobRunner : jobRunners) {
        Future<Boolean> jobFuture = execSvc.submit(jobRunner);
        jobFutures.add(jobFuture);
      }

      // Wait for all jobs to complete.
      for (Future<Boolean> jobFuture : jobFutures) {
        success = jobFuture.get();
        if (!success) {
          // Stop the presses as soon as we see an error. Note that several
          // other jobs may have already been scheduled. Others will never be
          // scheduled.
          break;
        }
      }
    } finally {
      // Shut down the executor so that the JVM can exit.
      List<Runnable> neverRan = execSvc.shutdownNow();
      if (neverRan != null && neverRan.size() > 0) {
        System.err.println(
            "Interrupted run. Currently running Hadoop jobs will continue unless cancelled. "
                + neverRan + " jobs never scheduled.");
      }
    }
    return success;
  }

  /**
   * @param conf to be used to connect to HBase
   * @param hbaseConnection
   * @param cluster for which we're finding processRecords.
   * @param processFileSubstring if specified, this string must be part of the
   *          processFile path to limit which records we want to process.
   * @return a list of processRecords in {@link ProcessState#LOADED} stqte that
   *         still need to be processed.
   * @throws IOException
   */
  private List<ProcessRecord> getProcessRecords(Configuration conf,
      Connection hbaseConnection, String cluster, String processFileSubstring)
      throws IOException {
    ProcessRecordService processRecordService =
        new ProcessRecordService(conf, hbaseConnection);
    List<ProcessRecord> processRecords = null;
    // Grab all records.
    processRecords = processRecordService.getProcessRecords(cluster, LOADED,
        Integer.MAX_VALUE, processFileSubstring);

    LOG.info("Processing " + processRecords.size() + " for: " + cluster);

    return processRecords;
  }

  /**
   * @param conf to be used to connect to HBase
   * @param processRecords Set the list of ProcessRecord to PROCESSED.
   * @throws IOException
   */
  private void updateProcessRecords(Configuration conf,
      Connection hbaseConnection, List<ProcessRecord> processRecords)
      throws IOException {
    ProcessRecordService processRecordService =
        new ProcessRecordService(conf, hbaseConnection);

    IOException caught = null;
    for (ProcessRecord processRecord : processRecords) {
      // Even if we get an exception, still try to set the other records
      try {
        processRecordService.setProcessState(processRecord, PROCESSED);
      } catch (IOException ioe) {
        caught = ioe;
      }
    }
    if (caught != null) {
      throw caught;
    }

  }

  /**
   * @param conf used to communicate arguments to the running jobs.
   * @param hbaseConnection used to create Table references connecting to HBase.
   * @param cluster for which we are processing
   * @param reprocess Reprocess those records that may have been processed
   *          already. Otherwise successfully processed job files are skipped.
   * @param batchSize the total number of jobs to process in a batch (a MR job
   *          scanning these many records in the raw table).
   * @param minJobId used to start the scan. If null then there is no min limit
   *          on JobId.
   * @param maxJobId used to end the scan (inclusive). If null then there is no
   *          max limit on jobId.
   * @throws IOException
   * @throws InterruptedException
   * @throws ClassNotFoundException
   * @throws ExecutionException
   * @throws RowKeyParseException
   */
  private List<JobRunner> getJobRunners(Configuration conf, Connection hbaseConnection, String cluster,
      boolean reprocess, int batchSize, String minJobId, String maxJobId)
      throws IOException, InterruptedException, ClassNotFoundException,
      RowKeyParseException {
    List<JobRunner> jobRunners = new LinkedList<JobRunner>();

    JobHistoryRawService jobHistoryRawService = new JobHistoryRawService(hbaseConnection);

    // Bind all MR jobs together with one runID.
    long now = System.currentTimeMillis();
    conf.setLong(Constants.MR_RUN_CONF_KEY, now);

    List<Scan> scanList = jobHistoryRawService.getHistoryRawTableScans(cluster,
        minJobId, maxJobId, reprocess, batchSize);

    for (Scan scan : scanList) {
      Job job = getProcessingJob(conf, scan, scanList.size());

      JobRunner jobRunner = new JobRunner(job, null);
      jobRunners.add(jobRunner);
    }

    return jobRunners;

  }

  /**
   * @param conf to use to create and run the job
   * @param scan to be used to scan the raw table.
   * @param totalJobCount the total number of jobs that need to be run in this
   *          batch. Used in job name.
   * @return The job to be submitted to the cluster.
   * @throws IOException
   * @throws InterruptedException
   * @throws ClassNotFoundException
   */
  private Job getProcessingJob(Configuration conf, Scan scan, int totalJobCount)
      throws IOException {

    Configuration confClone = new Configuration(conf);

    // Turn off speculative execution.
    // Note: must be BEFORE the job construction with the new mapreduce API.
    confClone.setBoolean("mapred.map.tasks.speculative.execution", false);

    // Set up job
    Job job = new Job(confClone, getJobName(totalJobCount));

    // This is a map-only class, skip reduce step
    job.setNumReduceTasks(0);
    job.setJarByClass(JobFileProcessor.class);
    job.setOutputFormatClass(MultiTableOutputFormat.class);

    TableMapReduceUtil.initTableMapperJob(Constants.HISTORY_RAW_TABLE, scan,
        JobFileTableMapper.class, JobFileTableMapper.getOutputKeyClass(),
        JobFileTableMapper.getOutputValueClass(), job);

    return job;
  }

  /**
   * @param totalJobCount how many jobs there will be in total. Used as
   *          indicator in the name how far along this job is.
   * @return the name to use for each consecutive Hadoop job to launch.
   */
  private synchronized String getJobName(int totalJobCount) {
    String jobName = NAME + " [" + startTimestamp + " "
        + jobCounter.incrementAndGet() + "/" + totalJobCount + "]";
    return jobName;
  }

  /**
   * DoIt.
   * @param args the arguments to do it with
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
    ToolRunner.run(new JobFileProcessor(), args);
  }

}


text:
"GoogleContactExport" lets you export your Google contacts into Outlook using the Google People API v1. You just need to authorize yourself using your Google account and then copy all your Google Contacts with one single click!

![](http://i.imgur.com/G6u1t59.jpg)

__You can find the Add-In on the backstage view tab "Open and Export"!__

## Getting Started
These instructions will get you a copy of the project up and running on your own computer.

### Prerequisites
To use my Add-In you only need:
* A computer with at least Windows Vista
* [Microsoft .NET Framework 4.5](https://www.microsoft.com/en-us/download/details.aspx?id=30653)
* [Outlook 2016](https://products.office.com/outlook/email-and-calendar-software-microsoft-outlook) (duh)

Please note that while other Versions of Outlook might work aswell they haven't been tested. Please report back if the Add-In works with your version of Outlook!

### Installing
Installing is very easy, just run the installer. It will automatically extract the needed files to a temporary folder and start the VSTO installer which then adds the Add-In and all needed resources to Outlook! You can then start the Add-In through the button it adds on the "Open and Export" tab in the backstage view.

## Built With

* [Microsoft Visual Studio 2017 Community](https://www.visualstudio.com/vs/) - The IDE and Compiler used
* [Inno Setup 5.5.9](http://www.jrsoftware.org/isinfo.php) - The installer software used
* [Semantic Versioning 2.0.0](http://semver.org/#semantic-versioning-200) - The way I version my software
* [Google People API v1](https://developers.google.com/people/) - The API used to read Googles contact data

## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details!

redpajama_set_name: RedPajamaGithub


text:
package media

// Copyright (c) Microsoft and contributors.  All rights reserved.
//
// 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.
//
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

import (
	"context"
	"github.com/Azure/go-autorest/autorest"
	"github.com/Azure/go-autorest/autorest/azure"
	"github.com/Azure/go-autorest/autorest/validation"
	"github.com/Azure/go-autorest/tracing"
	"net/http"
)

// StreamingEndpointsClient is the client for the StreamingEndpoints methods of the Media service.
type StreamingEndpointsClient struct {
	BaseClient
}

// NewStreamingEndpointsClient creates an instance of the StreamingEndpointsClient client.
func NewStreamingEndpointsClient(subscriptionID string) StreamingEndpointsClient {
	return NewStreamingEndpointsClientWithBaseURI(DefaultBaseURI, subscriptionID)
}

// NewStreamingEndpointsClientWithBaseURI creates an instance of the StreamingEndpointsClient client.
func NewStreamingEndpointsClientWithBaseURI(baseURI string, subscriptionID string) StreamingEndpointsClient {
	return StreamingEndpointsClient{NewWithBaseURI(baseURI, subscriptionID)}
}

// Create creates a StreamingEndpoint.
// Parameters:
// resourceGroupName - the name of the resource group within the Azure subscription.
// accountName - the Media Services account name.
// streamingEndpointName - the name of the StreamingEndpoint.
// parameters - streamingEndpoint properties needed for creation.
// autoStart - the flag indicates if the resource should be automatically started on creation.
func (client StreamingEndpointsClient) Create(ctx context.Context, resourceGroupName string, accountName string, streamingEndpointName string, parameters StreamingEndpoint, autoStart *bool) (result StreamingEndpointsCreateFuture, err error) {
	if tracing.IsEnabled() {
		ctx = tracing.StartSpan(ctx, fqdn+"/StreamingEndpointsClient.Create")
		defer func() {
			sc := -1
			if result.Response() != nil {
				sc = result.Response().StatusCode
			}
			tracing.EndSpan(ctx, sc, err)
		}()
	}
	if err := validation.Validate([]validation.Validation{
		{TargetValue: streamingEndpointName,
			Constraints: []validation.Constraint{{Target: "streamingEndpointName", Name: validation.MaxLength, Rule: 24, Chain: nil},
				{Target: "streamingEndpointName", Name: validation.MinLength, Rule: 1, Chain: nil},
				{Target: "streamingEndpointName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]+(-*[a-zA-Z0-9])*$`, Chain: nil}}},
		{TargetValue: parameters,
			Constraints: []validation.Constraint{{Target: "parameters.StreamingEndpointProperties", Name: validation.Null, Rule: false,
				Chain: []validation.Constraint{{Target: "parameters.StreamingEndpointProperties.ScaleUnits", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
		return result, validation.NewError("media.StreamingEndpointsClient", "Create", err.Error())
	}

	req, err := client.CreatePreparer(ctx, resourceGroupName, accountName, streamingEndpointName, parameters, autoStart)
	if err != nil {
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "Create", nil, "Failure preparing request")
		return
	}

	result, err = client.CreateSender(req)
	if err != nil {
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "Create", result.Response(), "Failure sending request")
		return
	}

	return
}

// CreatePreparer prepares the Create request.
func (client StreamingEndpointsClient) CreatePreparer(ctx context.Context, resourceGroupName string, accountName string, streamingEndpointName string, parameters StreamingEndpoint, autoStart *bool) (*http.Request, error) {
	pathParameters := map[string]interface{}{
		"accountName":           autorest.Encode("path", accountName),
		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
		"streamingEndpointName": autorest.Encode("path", streamingEndpointName),
		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
	}

	const APIVersion = "2018-07-01"
	queryParameters := map[string]interface{}{
		"api-version": APIVersion,
	}
	if autoStart != nil {
		queryParameters["autoStart"] = autorest.Encode("query", *autoStart)
	}

	preparer := autorest.CreatePreparer(
		autorest.AsContentType("application/json; charset=utf-8"),
		autorest.AsPut(),
		autorest.WithBaseURL(client.BaseURI),
		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices/{accountName}/streamingEndpoints/{streamingEndpointName}", pathParameters),
		autorest.WithJSON(parameters),
		autorest.WithQueryParameters(queryParameters))
	return preparer.Prepare((&http.Request{}).WithContext(ctx))
}

// CreateSender sends the Create request. The method will close the
// http.Response Body if it receives an error.
func (client StreamingEndpointsClient) CreateSender(req *http.Request) (future StreamingEndpointsCreateFuture, err error) {
	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
	var resp *http.Response
	resp, err = autorest.SendWithSender(client, req, sd...)
	if err != nil {
		return
	}
	future.Future, err = azure.NewFutureFromResponse(resp)
	return
}

// CreateResponder handles the response to the Create request. The method always
// closes the http.Response Body.
func (client StreamingEndpointsClient) CreateResponder(resp *http.Response) (result StreamingEndpoint, err error) {
	err = autorest.Respond(
		resp,
		client.ByInspecting(),
		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
		autorest.ByUnmarshallingJSON(&result),
		autorest.ByClosing())
	result.Response = autorest.Response{Response: resp}
	return
}

// Delete deletes a StreamingEndpoint.
// Parameters:
// resourceGroupName - the name of the resource group within the Azure subscription.
// accountName - the Media Services account name.
// streamingEndpointName - the name of the StreamingEndpoint.
func (client StreamingEndpointsClient) Delete(ctx context.Context, resourceGroupName string, accountName string, streamingEndpointName string) (result StreamingEndpointsDeleteFuture, err error) {
	if tracing.IsEnabled() {
		ctx = tracing.StartSpan(ctx, fqdn+"/StreamingEndpointsClient.Delete")
		defer func() {
			sc := -1
			if result.Response() != nil {
				sc = result.Response().StatusCode
			}
			tracing.EndSpan(ctx, sc, err)
		}()
	}
	if err := validation.Validate([]validation.Validation{
		{TargetValue: streamingEndpointName,
			Constraints: []validation.Constraint{{Target: "streamingEndpointName", Name: validation.MaxLength, Rule: 24, Chain: nil},
				{Target: "streamingEndpointName", Name: validation.MinLength, Rule: 1, Chain: nil},
				{Target: "streamingEndpointName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]+(-*[a-zA-Z0-9])*$`, Chain: nil}}}}); err != nil {
		return result, validation.NewError("media.StreamingEndpointsClient", "Delete", err.Error())
	}

	req, err := client.DeletePreparer(ctx, resourceGroupName, accountName, streamingEndpointName)
	if err != nil {
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "Delete", nil, "Failure preparing request")
		return
	}

	result, err = client.DeleteSender(req)
	if err != nil {
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "Delete", result.Response(), "Failure sending request")
		return
	}

	return
}

// DeletePreparer prepares the Delete request.
func (client StreamingEndpointsClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string, streamingEndpointName string) (*http.Request, error) {
	pathParameters := map[string]interface{}{
		"accountName":           autorest.Encode("path", accountName),
		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
		"streamingEndpointName": autorest.Encode("path", streamingEndpointName),
		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
	}

	const APIVersion = "2018-07-01"
	queryParameters := map[string]interface{}{
		"api-version": APIVersion,
	}

	preparer := autorest.CreatePreparer(
		autorest.AsDelete(),
		autorest.WithBaseURL(client.BaseURI),
		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices/{accountName}/streamingEndpoints/{streamingEndpointName}", pathParameters),
		autorest.WithQueryParameters(queryParameters))
	return preparer.Prepare((&http.Request{}).WithContext(ctx))
}

// DeleteSender sends the Delete request. The method will close the
// http.Response Body if it receives an error.
func (client StreamingEndpointsClient) DeleteSender(req *http.Request) (future StreamingEndpointsDeleteFuture, err error) {
	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
	var resp *http.Response
	resp, err = autorest.SendWithSender(client, req, sd...)
	if err != nil {
		return
	}
	future.Future, err = azure.NewFutureFromResponse(resp)
	return
}

// DeleteResponder handles the response to the Delete request. The method always
// closes the http.Response Body.
func (client StreamingEndpointsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
	err = autorest.Respond(
		resp,
		client.ByInspecting(),
		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
		autorest.ByClosing())
	result.Response = resp
	return
}

// Get gets a StreamingEndpoint.
// Parameters:
// resourceGroupName - the name of the resource group within the Azure subscription.
// accountName - the Media Services account name.
// streamingEndpointName - the name of the StreamingEndpoint.
func (client StreamingEndpointsClient) Get(ctx context.Context, resourceGroupName string, accountName string, streamingEndpointName string) (result StreamingEndpoint, err error) {
	if tracing.IsEnabled() {
		ctx = tracing.StartSpan(ctx, fqdn+"/StreamingEndpointsClient.Get")
		defer func() {
			sc := -1
			if result.Response.Response != nil {
				sc = result.Response.Response.StatusCode
			}
			tracing.EndSpan(ctx, sc, err)
		}()
	}
	if err := validation.Validate([]validation.Validation{
		{TargetValue: streamingEndpointName,
			Constraints: []validation.Constraint{{Target: "streamingEndpointName", Name: validation.MaxLength, Rule: 24, Chain: nil},
				{Target: "streamingEndpointName", Name: validation.MinLength, Rule: 1, Chain: nil},
				{Target: "streamingEndpointName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]+(-*[a-zA-Z0-9])*$`, Chain: nil}}}}); err != nil {
		return result, validation.NewError("media.StreamingEndpointsClient", "Get", err.Error())
	}

	req, err := client.GetPreparer(ctx, resourceGroupName, accountName, streamingEndpointName)
	if err != nil {
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "Get", nil, "Failure preparing request")
		return
	}

	resp, err := client.GetSender(req)
	if err != nil {
		result.Response = autorest.Response{Response: resp}
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "Get", resp, "Failure sending request")
		return
	}

	result, err = client.GetResponder(resp)
	if err != nil {
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "Get", resp, "Failure responding to request")
	}

	return
}

// GetPreparer prepares the Get request.
func (client StreamingEndpointsClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string, streamingEndpointName string) (*http.Request, error) {
	pathParameters := map[string]interface{}{
		"accountName":           autorest.Encode("path", accountName),
		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
		"streamingEndpointName": autorest.Encode("path", streamingEndpointName),
		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
	}

	const APIVersion = "2018-07-01"
	queryParameters := map[string]interface{}{
		"api-version": APIVersion,
	}

	preparer := autorest.CreatePreparer(
		autorest.AsGet(),
		autorest.WithBaseURL(client.BaseURI),
		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices/{accountName}/streamingEndpoints/{streamingEndpointName}", pathParameters),
		autorest.WithQueryParameters(queryParameters))
	return preparer.Prepare((&http.Request{}).WithContext(ctx))
}

// GetSender sends the Get request. The method will close the
// http.Response Body if it receives an error.
func (client StreamingEndpointsClient) GetSender(req *http.Request) (*http.Response, error) {
	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
	return autorest.SendWithSender(client, req, sd...)
}

// GetResponder handles the response to the Get request. The method always
// closes the http.Response Body.
func (client StreamingEndpointsClient) GetResponder(resp *http.Response) (result StreamingEndpoint, err error) {
	err = autorest.Respond(
		resp,
		client.ByInspecting(),
		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNotFound),
		autorest.ByUnmarshallingJSON(&result),
		autorest.ByClosing())
	result.Response = autorest.Response{Response: resp}
	return
}

// List lists the StreamingEndpoints in the account.
// Parameters:
// resourceGroupName - the name of the resource group within the Azure subscription.
// accountName - the Media Services account name.
func (client StreamingEndpointsClient) List(ctx context.Context, resourceGroupName string, accountName string) (result StreamingEndpointListResultPage, err error) {
	if tracing.IsEnabled() {
		ctx = tracing.StartSpan(ctx, fqdn+"/StreamingEndpointsClient.List")
		defer func() {
			sc := -1
			if result.selr.Response.Response != nil {
				sc = result.selr.Response.Response.StatusCode
			}
			tracing.EndSpan(ctx, sc, err)
		}()
	}
	result.fn = client.listNextResults
	req, err := client.ListPreparer(ctx, resourceGroupName, accountName)
	if err != nil {
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "List", nil, "Failure preparing request")
		return
	}

	resp, err := client.ListSender(req)
	if err != nil {
		result.selr.Response = autorest.Response{Response: resp}
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "List", resp, "Failure sending request")
		return
	}

	result.selr, err = client.ListResponder(resp)
	if err != nil {
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "List", resp, "Failure responding to request")
	}

	return
}

// ListPreparer prepares the List request.
func (client StreamingEndpointsClient) ListPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
	pathParameters := map[string]interface{}{
		"accountName":       autorest.Encode("path", accountName),
		"resourceGroupName": autorest.Encode("path", resourceGroupName),
		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
	}

	const APIVersion = "2018-07-01"
	queryParameters := map[string]interface{}{
		"api-version": APIVersion,
	}

	preparer := autorest.CreatePreparer(
		autorest.AsGet(),
		autorest.WithBaseURL(client.BaseURI),
		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices/{accountName}/streamingEndpoints", pathParameters),
		autorest.WithQueryParameters(queryParameters))
	return preparer.Prepare((&http.Request{}).WithContext(ctx))
}

// ListSender sends the List request. The method will close the
// http.Response Body if it receives an error.
func (client StreamingEndpointsClient) ListSender(req *http.Request) (*http.Response, error) {
	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
	return autorest.SendWithSender(client, req, sd...)
}

// ListResponder handles the response to the List request. The method always
// closes the http.Response Body.
func (client StreamingEndpointsClient) ListResponder(resp *http.Response) (result StreamingEndpointListResult, err error) {
	err = autorest.Respond(
		resp,
		client.ByInspecting(),
		azure.WithErrorUnlessStatusCode(http.StatusOK),
		autorest.ByUnmarshallingJSON(&result),
		autorest.ByClosing())
	result.Response = autorest.Response{Response: resp}
	return
}

// listNextResults retrieves the next set of results, if any.
func (client StreamingEndpointsClient) listNextResults(ctx context.Context, lastResults StreamingEndpointListResult) (result StreamingEndpointListResult, err error) {
	req, err := lastResults.streamingEndpointListResultPreparer(ctx)
	if err != nil {
		return result, autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "listNextResults", nil, "Failure preparing next results request")
	}
	if req == nil {
		return
	}
	resp, err := client.ListSender(req)
	if err != nil {
		result.Response = autorest.Response{Response: resp}
		return result, autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "listNextResults", resp, "Failure sending next results request")
	}
	result, err = client.ListResponder(resp)
	if err != nil {
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "listNextResults", resp, "Failure responding to next results request")
	}
	return
}

// ListComplete enumerates all values, automatically crossing page boundaries as required.
func (client StreamingEndpointsClient) ListComplete(ctx context.Context, resourceGroupName string, accountName string) (result StreamingEndpointListResultIterator, err error) {
	if tracing.IsEnabled() {
		ctx = tracing.StartSpan(ctx, fqdn+"/StreamingEndpointsClient.List")
		defer func() {
			sc := -1
			if result.Response().Response.Response != nil {
				sc = result.page.Response().Response.Response.StatusCode
			}
			tracing.EndSpan(ctx, sc, err)
		}()
	}
	result.page, err = client.List(ctx, resourceGroupName, accountName)
	return
}

// Scale scales an existing StreamingEndpoint.
// Parameters:
// resourceGroupName - the name of the resource group within the Azure subscription.
// accountName - the Media Services account name.
// streamingEndpointName - the name of the StreamingEndpoint.
// parameters - streamingEndpoint scale parameters
func (client StreamingEndpointsClient) Scale(ctx context.Context, resourceGroupName string, accountName string, streamingEndpointName string, parameters StreamingEntityScaleUnit) (result StreamingEndpointsScaleFuture, err error) {
	if tracing.IsEnabled() {
		ctx = tracing.StartSpan(ctx, fqdn+"/StreamingEndpointsClient.Scale")
		defer func() {
			sc := -1
			if result.Response() != nil {
				sc = result.Response().StatusCode
			}
			tracing.EndSpan(ctx, sc, err)
		}()
	}
	if err := validation.Validate([]validation.Validation{
		{TargetValue: streamingEndpointName,
			Constraints: []validation.Constraint{{Target: "streamingEndpointName", Name: validation.MaxLength, Rule: 24, Chain: nil},
				{Target: "streamingEndpointName", Name: validation.MinLength, Rule: 1, Chain: nil},
				{Target: "streamingEndpointName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]+(-*[a-zA-Z0-9])*$`, Chain: nil}}}}); err != nil {
		return result, validation.NewError("media.StreamingEndpointsClient", "Scale", err.Error())
	}

	req, err := client.ScalePreparer(ctx, resourceGroupName, accountName, streamingEndpointName, parameters)
	if err != nil {
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "Scale", nil, "Failure preparing request")
		return
	}

	result, err = client.ScaleSender(req)
	if err != nil {
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "Scale", result.Response(), "Failure sending request")
		return
	}

	return
}

// ScalePreparer prepares the Scale request.
func (client StreamingEndpointsClient) ScalePreparer(ctx context.Context, resourceGroupName string, accountName string, streamingEndpointName string, parameters StreamingEntityScaleUnit) (*http.Request, error) {
	pathParameters := map[string]interface{}{
		"accountName":           autorest.Encode("path", accountName),
		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
		"streamingEndpointName": autorest.Encode("path", streamingEndpointName),
		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
	}

	const APIVersion = "2018-07-01"
	queryParameters := map[string]interface{}{
		"api-version": APIVersion,
	}

	preparer := autorest.CreatePreparer(
		autorest.AsContentType("application/json; charset=utf-8"),
		autorest.AsPost(),
		autorest.WithBaseURL(client.BaseURI),
		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices/{accountName}/streamingEndpoints/{streamingEndpointName}/scale", pathParameters),
		autorest.WithJSON(parameters),
		autorest.WithQueryParameters(queryParameters))
	return preparer.Prepare((&http.Request{}).WithContext(ctx))
}

// ScaleSender sends the Scale request. The method will close the
// http.Response Body if it receives an error.
func (client StreamingEndpointsClient) ScaleSender(req *http.Request) (future StreamingEndpointsScaleFuture, err error) {
	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
	var resp *http.Response
	resp, err = autorest.SendWithSender(client, req, sd...)
	if err != nil {
		return
	}
	future.Future, err = azure.NewFutureFromResponse(resp)
	return
}

// ScaleResponder handles the response to the Scale request. The method always
// closes the http.Response Body.
func (client StreamingEndpointsClient) ScaleResponder(resp *http.Response) (result autorest.Response, err error) {
	err = autorest.Respond(
		resp,
		client.ByInspecting(),
		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
		autorest.ByClosing())
	result.Response = resp
	return
}

// Start starts an existing StreamingEndpoint.
// Parameters:
// resourceGroupName - the name of the resource group within the Azure subscription.
// accountName - the Media Services account name.
// streamingEndpointName - the name of the StreamingEndpoint.
func (client StreamingEndpointsClient) Start(ctx context.Context, resourceGroupName string, accountName string, streamingEndpointName string) (result StreamingEndpointsStartFuture, err error) {
	if tracing.IsEnabled() {
		ctx = tracing.StartSpan(ctx, fqdn+"/StreamingEndpointsClient.Start")
		defer func() {
			sc := -1
			if result.Response() != nil {
				sc = result.Response().StatusCode
			}
			tracing.EndSpan(ctx, sc, err)
		}()
	}
	if err := validation.Validate([]validation.Validation{
		{TargetValue: streamingEndpointName,
			Constraints: []validation.Constraint{{Target: "streamingEndpointName", Name: validation.MaxLength, Rule: 24, Chain: nil},
				{Target: "streamingEndpointName", Name: validation.MinLength, Rule: 1, Chain: nil},
				{Target: "streamingEndpointName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]+(-*[a-zA-Z0-9])*$`, Chain: nil}}}}); err != nil {
		return result, validation.NewError("media.StreamingEndpointsClient", "Start", err.Error())
	}

	req, err := client.StartPreparer(ctx, resourceGroupName, accountName, streamingEndpointName)
	if err != nil {
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "Start", nil, "Failure preparing request")
		return
	}

	result, err = client.StartSender(req)
	if err != nil {
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "Start", result.Response(), "Failure sending request")
		return
	}

	return
}

// StartPreparer prepares the Start request.
func (client StreamingEndpointsClient) StartPreparer(ctx context.Context, resourceGroupName string, accountName string, streamingEndpointName string) (*http.Request, error) {
	pathParameters := map[string]interface{}{
		"accountName":           autorest.Encode("path", accountName),
		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
		"streamingEndpointName": autorest.Encode("path", streamingEndpointName),
		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
	}

	const APIVersion = "2018-07-01"
	queryParameters := map[string]interface{}{
		"api-version": APIVersion,
	}

	preparer := autorest.CreatePreparer(
		autorest.AsPost(),
		autorest.WithBaseURL(client.BaseURI),
		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices/{accountName}/streamingEndpoints/{streamingEndpointName}/start", pathParameters),
		autorest.WithQueryParameters(queryParameters))
	return preparer.Prepare((&http.Request{}).WithContext(ctx))
}

// StartSender sends the Start request. The method will close the
// http.Response Body if it receives an error.
func (client StreamingEndpointsClient) StartSender(req *http.Request) (future StreamingEndpointsStartFuture, err error) {
	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
	var resp *http.Response
	resp, err = autorest.SendWithSender(client, req, sd...)
	if err != nil {
		return
	}
	future.Future, err = azure.NewFutureFromResponse(resp)
	return
}

// StartResponder handles the response to the Start request. The method always
// closes the http.Response Body.
func (client StreamingEndpointsClient) StartResponder(resp *http.Response) (result autorest.Response, err error) {
	err = autorest.Respond(
		resp,
		client.ByInspecting(),
		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
		autorest.ByClosing())
	result.Response = resp
	return
}

// Stop stops an existing StreamingEndpoint.
// Parameters:
// resourceGroupName - the name of the resource group within the Azure subscription.
// accountName - the Media Services account name.
// streamingEndpointName - the name of the StreamingEndpoint.
func (client StreamingEndpointsClient) Stop(ctx context.Context, resourceGroupName string, accountName string, streamingEndpointName string) (result StreamingEndpointsStopFuture, err error) {
	if tracing.IsEnabled() {
		ctx = tracing.StartSpan(ctx, fqdn+"/StreamingEndpointsClient.Stop")
		defer func() {
			sc := -1
			if result.Response() != nil {
				sc = result.Response().StatusCode
			}
			tracing.EndSpan(ctx, sc, err)
		}()
	}
	if err := validation.Validate([]validation.Validation{
		{TargetValue: streamingEndpointName,
			Constraints: []validation.Constraint{{Target: "streamingEndpointName", Name: validation.MaxLength, Rule: 24, Chain: nil},
				{Target: "streamingEndpointName", Name: validation.MinLength, Rule: 1, Chain: nil},
				{Target: "streamingEndpointName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]+(-*[a-zA-Z0-9])*$`, Chain: nil}}}}); err != nil {
		return result, validation.NewError("media.StreamingEndpointsClient", "Stop", err.Error())
	}

	req, err := client.StopPreparer(ctx, resourceGroupName, accountName, streamingEndpointName)
	if err != nil {
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "Stop", nil, "Failure preparing request")
		return
	}

	result, err = client.StopSender(req)
	if err != nil {
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "Stop", result.Response(), "Failure sending request")
		return
	}

	return
}

// StopPreparer prepares the Stop request.
func (client StreamingEndpointsClient) StopPreparer(ctx context.Context, resourceGroupName string, accountName string, streamingEndpointName string) (*http.Request, error) {
	pathParameters := map[string]interface{}{
		"accountName":           autorest.Encode("path", accountName),
		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
		"streamingEndpointName": autorest.Encode("path", streamingEndpointName),
		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
	}

	const APIVersion = "2018-07-01"
	queryParameters := map[string]interface{}{
		"api-version": APIVersion,
	}

	preparer := autorest.CreatePreparer(
		autorest.AsPost(),
		autorest.WithBaseURL(client.BaseURI),
		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices/{accountName}/streamingEndpoints/{streamingEndpointName}/stop", pathParameters),
		autorest.WithQueryParameters(queryParameters))
	return preparer.Prepare((&http.Request{}).WithContext(ctx))
}

// StopSender sends the Stop request. The method will close the
// http.Response Body if it receives an error.
func (client StreamingEndpointsClient) StopSender(req *http.Request) (future StreamingEndpointsStopFuture, err error) {
	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
	var resp *http.Response
	resp, err = autorest.SendWithSender(client, req, sd...)
	if err != nil {
		return
	}
	future.Future, err = azure.NewFutureFromResponse(resp)
	return
}

// StopResponder handles the response to the Stop request. The method always
// closes the http.Response Body.
func (client StreamingEndpointsClient) StopResponder(resp *http.Response) (result autorest.Response, err error) {
	err = autorest.Respond(
		resp,
		client.ByInspecting(),
		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
		autorest.ByClosing())
	result.Response = resp
	return
}

// Update updates a existing StreamingEndpoint.
// Parameters:
// resourceGroupName - the name of the resource group within the Azure subscription.
// accountName - the Media Services account name.
// streamingEndpointName - the name of the StreamingEndpoint.
// parameters - streamingEndpoint properties needed for creation.
func (client StreamingEndpointsClient) Update(ctx context.Context, resourceGroupName string, accountName string, streamingEndpointName string, parameters StreamingEndpoint) (result StreamingEndpointsUpdateFuture, err error) {
	if tracing.IsEnabled() {
		ctx = tracing.StartSpan(ctx, fqdn+"/StreamingEndpointsClient.Update")
		defer func() {
			sc := -1
			if result.Response() != nil {
				sc = result.Response().StatusCode
			}
			tracing.EndSpan(ctx, sc, err)
		}()
	}
	if err := validation.Validate([]validation.Validation{
		{TargetValue: streamingEndpointName,
			Constraints: []validation.Constraint{{Target: "streamingEndpointName", Name: validation.MaxLength, Rule: 24, Chain: nil},
				{Target: "streamingEndpointName", Name: validation.MinLength, Rule: 1, Chain: nil},
				{Target: "streamingEndpointName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]+(-*[a-zA-Z0-9])*$`, Chain: nil}}}}); err != nil {
		return result, validation.NewError("media.StreamingEndpointsClient", "Update", err.Error())
	}

	req, err := client.UpdatePreparer(ctx, resourceGroupName, accountName, streamingEndpointName, parameters)
	if err != nil {
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "Update", nil, "Failure preparing request")
		return
	}

	result, err = client.UpdateSender(req)
	if err != nil {
		err = autorest.NewErrorWithError(err, "media.StreamingEndpointsClient", "Update", result.Response(), "Failure sending request")
		return
	}

	return
}

// UpdatePreparer prepares the Update request.
func (client StreamingEndpointsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, accountName string, streamingEndpointName string, parameters StreamingEndpoint) (*http.Request, error) {
	pathParameters := map[string]interface{}{
		"accountName":           autorest.Encode("path", accountName),
		"resourceGroupName":     autorest.Encode("path", resourceGroupName),
		"streamingEndpointName": autorest.Encode("path", streamingEndpointName),
		"subscriptionId":        autorest.Encode("path", client.SubscriptionID),
	}

	const APIVersion = "2018-07-01"
	queryParameters := map[string]interface{}{
		"api-version": APIVersion,
	}

	preparer := autorest.CreatePreparer(
		autorest.AsContentType("application/json; charset=utf-8"),
		autorest.AsPatch(),
		autorest.WithBaseURL(client.BaseURI),
		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaservices/{accountName}/streamingEndpoints/{streamingEndpointName}", pathParameters),
		autorest.WithJSON(parameters),
		autorest.WithQueryParameters(queryParameters))
	return preparer.Prepare((&http.Request{}).WithContext(ctx))
}

// UpdateSender sends the Update request. The method will close the
// http.Response Body if it receives an error.
func (client StreamingEndpointsClient) UpdateSender(req *http.Request) (future StreamingEndpointsUpdateFuture, err error) {
	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
	var resp *http.Response
	resp, err = autorest.SendWithSender(client, req, sd...)
	if err != nil {
		return
	}
	future.Future, err = azure.NewFutureFromResponse(resp)
	return
}

// UpdateResponder handles the response to the Update request. The method always
// closes the http.Response Body.
func (client StreamingEndpointsClient) UpdateResponder(resp *http.Response) (result StreamingEndpoint, err error) {
	err = autorest.Respond(
		resp,
		client.ByInspecting(),
		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
		autorest.ByUnmarshallingJSON(&result),
		autorest.ByClosing())
	result.Response = autorest.Response{Response: resp}
	return
}


text:
package prometheus

import (
	"time"

	"github.com/prometheus/client_golang/prometheus"

	"github.com/peterbourgon/gokit/metrics"
)

// Prometheus has strong opinions about the dimensionality of fields. Users
// must predeclare every field key they intend to use. On every observation,
// fields with keys that haven't been predeclared will be silently dropped,
// and predeclared field keys without values will receive the value
// PrometheusLabelValueUnknown.
var PrometheusLabelValueUnknown = "unknown"

type prometheusCounter struct {
	*prometheus.CounterVec
	Pairs map[string]string
}

// NewCounter returns a new Counter backed by a Prometheus metric. The counter
// is automatically registered via prometheus.Register.
func NewCounter(namespace, subsystem, name, help string, fieldKeys []string) metrics.Counter {
	return NewCounterWithLabels(namespace, subsystem, name, help, fieldKeys, prometheus.Labels{})
}

// NewCounterWithLabels is the same as NewCounter, but attaches a set of const
// label pairs to the metric.
func NewCounterWithLabels(namespace, subsystem, name, help string, fieldKeys []string, constLabels prometheus.Labels) metrics.Counter {
	m := prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Namespace:   namespace,
			Subsystem:   subsystem,
			Name:        name,
			Help:        help,
			ConstLabels: constLabels,
		},
		fieldKeys,
	)
	prometheus.MustRegister(m)

	p := map[string]string{}
	for _, fieldName := range fieldKeys {
		p[fieldName] = PrometheusLabelValueUnknown
	}

	return prometheusCounter{
		CounterVec: m,
		Pairs:      p,
	}
}

func (c prometheusCounter) With(f metrics.Field) metrics.Counter {
	return prometheusCounter{
		CounterVec: c.CounterVec,
		Pairs:      merge(c.Pairs, f),
	}
}

func (c prometheusCounter) Add(delta uint64) {
	c.CounterVec.With(prometheus.Labels(c.Pairs)).Add(float64(delta))
}

type prometheusGauge struct {
	*prometheus.GaugeVec
	Pairs map[string]string
}

// NewGauge returns a new Gauge backed by a Prometheus metric. The gauge is
// automatically registered via prometheus.Register.
func NewGauge(namespace, subsystem, name, help string, fieldKeys []string) metrics.Gauge {
	return NewGaugeWithLabels(namespace, subsystem, name, help, fieldKeys, prometheus.Labels{})
}

// NewGaugeWithLabels is the same as NewGauge, but attaches a set of const
// label pairs to the metric.
func NewGaugeWithLabels(namespace, subsystem, name, help string, fieldKeys []string, constLabels prometheus.Labels) metrics.Gauge {
	m := prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Namespace:   namespace,
			Subsystem:   subsystem,
			Name:        name,
			Help:        help,
			ConstLabels: constLabels,
		},
		fieldKeys,
	)
	prometheus.MustRegister(m)

	return prometheusGauge{
		GaugeVec: m,
		Pairs:    pairsFrom(fieldKeys),
	}
}

func (g prometheusGauge) With(f metrics.Field) metrics.Gauge {
	return prometheusGauge{
		GaugeVec: g.GaugeVec,
		Pairs:    merge(g.Pairs, f),
	}
}

func (g prometheusGauge) Set(value int64) {
	g.GaugeVec.With(prometheus.Labels(g.Pairs)).Set(float64(value))
}

func (g prometheusGauge) Add(delta int64) {
	g.GaugeVec.With(prometheus.Labels(g.Pairs)).Add(float64(delta))
}

type prometheusHistogram struct {
	*prometheus.SummaryVec
	Pairs map[string]string
}

// NewHistogram returns a new Histogram backed by a Prometheus summary. It
// uses a 10-second max age for bucketing. The histogram is automatically
// registered via prometheus.Register.
func NewHistogram(namespace, subsystem, name, help string, fieldKeys []string) metrics.Histogram {
	return NewHistogramWithLabels(namespace, subsystem, name, help, fieldKeys, prometheus.Labels{})
}

// NewHistogramWithLabels is the same as NewHistogram, but attaches a set of
// const label pairs to the metric.
func NewHistogramWithLabels(namespace, subsystem, name, help string, fieldKeys []string, constLabels prometheus.Labels) metrics.Histogram {
	m := prometheus.NewSummaryVec(
		prometheus.SummaryOpts{
			Namespace:   namespace,
			Subsystem:   subsystem,
			Name:        name,
			Help:        help,
			ConstLabels: constLabels,
			MaxAge:      10 * time.Second,
		},
		fieldKeys,
	)
	prometheus.MustRegister(m)

	return prometheusHistogram{
		SummaryVec: m,
		Pairs:      pairsFrom(fieldKeys),
	}
}

func (h prometheusHistogram) With(f metrics.Field) metrics.Histogram {
	return prometheusHistogram{
		SummaryVec: h.SummaryVec,
		Pairs:      merge(h.Pairs, f),
	}
}

func (h prometheusHistogram) Observe(value int64) {
	h.SummaryVec.With(prometheus.Labels(h.Pairs)).Observe(float64(value))
}

func pairsFrom(fieldKeys []string) map[string]string {
	p := map[string]string{}
	for _, fieldName := range fieldKeys {
		p[fieldName] = PrometheusLabelValueUnknown
	}
	return p
}

func merge(orig map[string]string, f metrics.Field) map[string]string {
	if _, ok := orig[f.Key]; !ok {
		return orig
	}

	newPairs := make(map[string]string, len(orig))
	for k, v := range orig {
		newPairs[k] = v
	}

	newPairs[f.Key] = f.Value
	return newPairs
}


text:
using System;

namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.Common.Models
{
    public class IoTHub
    {
        public string MessageId { get; set; }
        public string CorrelationId { get; set; }
        public string ConnectionDeviceId { get; set; }
        public string ConnectionDeviceGenerationId { get; set; }
        public DateTime EnqueuedTime { get; set; }
        public string StreamId { get; set; }
        public override string ToString()
        {
            return Newtonsoft.Json.JsonConvert.SerializeObject(this);
        }
    }
}


text:
package edu.ur.ir.web.action.repository;

import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.Validateable;

import edu.ur.file.db.FileDatabase;
import edu.ur.file.db.FileServerService;
import edu.ur.ir.NoIndexFoundException;
import edu.ur.ir.file.IrFile;
import edu.ur.ir.handle.HandleService;
import edu.ur.ir.handle.HandleNameAuthority;
import edu.ur.ir.repository.LicenseService;
import edu.ur.ir.repository.LicenseVersion;
import edu.ur.ir.repository.Repository;
import edu.ur.ir.repository.RepositoryService;
import edu.ur.ir.user.IrUser;
import edu.ur.ir.user.UserIndexService;
import edu.ur.ir.user.UserService;
import edu.ur.ir.web.action.UserIdAware;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

/**
 * View/Edit repository actions.
 *
 * @author Nathan Sarr
 *
 */
public class EditRepository extends ActionSupport implements Preparable,
Validateable, UserIdAware{

	/**  Logger for editing a file database. */
	private static final Logger log = LogManager.getLogger(EditRepository.class);

	/**  Name of the repository */
	private String repositoryName;

	/**  Name of the institution */
	private String institutionName;

	/**  Generated version id */
	private static final long serialVersionUID = -6421997690248407461L;

	/**  The new repository */
	private Repository repository;

	/** Service for dealing with repository */
	private RepositoryService repositoryService;

	/** Delete the picture from the repository */
	private Long irFilePictureId;

	/** id of the name authority to set on the repository */
	private Long handleNameAuthorityId;

	/** default id for file databases */
	private Long defaultFileDatabaseId;

	/** location of the name index folder  */
	private String nameIndexFolder;

	/** location of the institutional item index folder */
	private String institutionalItemIndexFolder;

	/** location of the researcher index folder. */
	private String researcherIndexFolder;

	/** user index folder */
	private String userIndexFolder;

	/** location for user workspace folders  */
	private String userWorkspaceIndexFolder;

	/** Service for dealing with handle information  */
	private HandleService handleService;

	/** Service for file server/database information */
	private FileServerService fileServerService;

	/** Set of handle name authorities in the system  */
	private List<HandleNameAuthority> handleNameAuthorities;

	/** List of available file databases  */
	private List<FileDatabase> fileDatabases;

	/** Service for dealing with user information  */
	private UserService userService;

	/** Service for dealing with user information  */
	private UserIndexService userIndexService;

	/** batch size for re-indexing repository information - number of records to process*/
	private int batchSize = 10;

	/** id of the default versioned license for the repository */
	private Long defaultLicenseVersionId;

	/** indicates that subscriptions should be suspended  */
	private boolean suspendSubscriptions = false;

	/** Service for dealing with license information  */
	private LicenseService licenseService;

	/** Set of licenses */
	private List<LicenseVersion> licenses;

	private Long userId;

	/**
	 * Prepare the repository.
	 *
	 * @see com.opensymphony.xwork.Preparable#prepare()
	 */
	public void prepare() throws Exception{
		log.debug("prepare called");
		repository = repositoryService.getRepository(Repository.DEFAULT_REPOSITORY_ID, false);

		log.debug("repository " + repository + " found ");
		handleNameAuthorities = handleService.getAllNameAuthorities();
		fileDatabases = fileServerService.getFileDatabases();
		if( repository != null )
		{
		    licenses = repositoryService.getAvailableRepositoryLicenses(repository.getId());
		}
		else
		{
			licenses = licenseService.getAllLicenseVersions();
		}
	}

	/**
	 * Create a new repository.
	 *
	 * @return
	 * @throws NoIndexFoundException
	 */
	public String create() throws NoIndexFoundException
	{
		log.debug("Create called");
		FileDatabase fileDatabase = null;
		IrUser user = userService.getUser(userId, false);
		if( defaultFileDatabaseId != -1l  )
		{
			fileDatabase = fileServerService.getDatabaseById(defaultFileDatabaseId, false);
		}

		if( handleNameAuthorityId != -1l )
		{
		    HandleNameAuthority authority = handleService.getNameAuthority(handleNameAuthorityId, false);
		    repository.setDefaultHandleNameAuthority(authority);
		}

		if( defaultLicenseVersionId  != -1l )
		{
			LicenseVersion defaultLicense = licenseService.getLicenseVersion(defaultLicenseVersionId, false);
			repository.updateDefaultLicense(user, defaultLicense);

		}

		repository = repositoryService.createRepository(repositoryName, fileDatabase);
		repository.setInstitutionName(institutionName);
		Timestamp lastEmailDate = new Timestamp(new Date().getTime());
		repository.setLastSubscriptionProcessEmailDate(lastEmailDate);
		repository.setSuspendSuscriptionEmails(suspendSubscriptions);

		try {
			updateNameIndexFolder(repository, nameIndexFolder);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		try {
			updateUserWorkspaceIndexFolder(repository, userWorkspaceIndexFolder);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		try {
			updateInstitutionalItemIndexFolder(repository, institutionalItemIndexFolder);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		try {
			updateResearcherIndexFolder(repository, researcherIndexFolder);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		try {
			updateUserIndexFolder(repository, userIndexFolder);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		if(!repository.getInitalized())
		{
			repository.setInitalized(true);
		}

		repositoryService.saveRepository(repository);

		return SUCCESS;

	}

	/**
	 * Update the repository
	 *
	 * @return
	 */
	public String update() {
		log.debug("update called");
		if (repository == null) {
			throw new IllegalStateException("repository is null");
		}
		repository.setName(repositoryName);
		repository.setInstitutionName(institutionName);
		IrUser user = userService.getUser(userId, false);
		if(repositoryService == null )
		{
			throw new IllegalStateException ("repository service is null");
		}

		repository.setSuspendSuscriptionEmails(suspendSubscriptions);

		if( handleNameAuthorityId == -1l  )
		{
			repository.setDefaultHandleNameAuthority(null);
		}
		else
		{
			HandleNameAuthority repositoryHandleAuthority = repository.getDefaultHandleNameAuthority();

			// the handle name authority is being changed
			if( repositoryHandleAuthority == null ||
				!repositoryHandleAuthority.getId().equals(handleNameAuthorityId) )
			{
			    HandleNameAuthority authority = handleService.getNameAuthority(handleNameAuthorityId, false);
			    repository.setDefaultHandleNameAuthority(authority);
			}
		}

		log.debug("Default file database id = " + defaultFileDatabaseId);
		if( defaultFileDatabaseId == -1l  )
		{
			repository.setFileDatabase(null);
		}
		else
		{
			FileDatabase repositoryFileDatabase = repository.getFileDatabase();

			// the handle name authority is being changed
			if( repositoryFileDatabase == null ||
				!repositoryFileDatabase.getId().equals(defaultFileDatabaseId) )
			{
				FileDatabase fileDatabase = fileServerService.getDatabaseById(defaultFileDatabaseId, false);
			    repository.setFileDatabase(fileDatabase);
			}
		}

		log.debug("Default license version id = " + defaultLicenseVersionId);
		if( defaultLicenseVersionId == -1l  )
		{
			repository.updateDefaultLicense(user, null);
		}
		else
		{
			LicenseVersion defaultLicense = repository.getDefaultLicense();

			// the handle name authority is being changed
			if( defaultLicense == null ||
				!defaultLicense.getId().equals(defaultLicenseVersionId) )
			{
				LicenseVersion newDefaultLicense = licenseService.getLicenseVersion(defaultLicenseVersionId, false);
			    repository.updateDefaultLicense(user, newDefaultLicense);
			}
		}

		try {
			updateNameIndexFolder(repository, nameIndexFolder);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		try {
			updateUserWorkspaceIndexFolder(repository, userWorkspaceIndexFolder);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		try {
			updateInstitutionalItemIndexFolder(repository, institutionalItemIndexFolder);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		try {
			updateResearcherIndexFolder(repository, researcherIndexFolder);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		try {
			updateUserIndexFolder(repository, userIndexFolder);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (NoIndexFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		if( log.isDebugEnabled())
		{
		    log.debug("Saving repository " + repository);
		}

		repositoryService.saveRepository(repository);
		return SUCCESS;
	}

	/**
	 * Delete the picture from the repository.
	 *
	 * @return
	 */
	public String deletePicture()
	{
		IrFile file = repository.getPicture(irFilePictureId);
		repositoryService.deleteRepositoryPicture(repository, file);
		return SUCCESS;
	}

	/**
	 * Cancel called
	 *
	 * @return cancel
	 */
	public String cancel() {
		return SUCCESS;
	}

	/**
	 * The repository being edited.
	 *
	 * @return
	 */
	public Repository getRepository() {
		return repository;
	}

	/**
	 * Set the file server to create
	 *
	 * @param fileServer
	 */
	public void setRepository(Repository repository) {
		this.repository = repository;
	}

	/**
	 * Validate the repository information.
	 *
	 * @see com.opensymphony.xwork.ActionSupport#validate()
	 */
	public void validate()
	{
		if( repository == null )
		{
			throw new IllegalStateException("repository cannot be null");
		}
	}

	public RepositoryService getRepositoryService() {
		return repositoryService;
	}

	public void setRepositoryService(RepositoryService repositoryService) {
		this.repositoryService = repositoryService;
	}

	public Long getIrFilePictureId() {
		return irFilePictureId;
	}

	public void setIrFilePictureId(Long irFilePictureId) {
		this.irFilePictureId = irFilePictureId;
	}

	public int getBatchSize() {
		return batchSize;
	}

	public void setBatchSize(int batchSize) {
		this.batchSize = batchSize;
	}

	public HandleService getHandleService() {
		return handleService;
	}

	public void setHandleService(HandleService handleService) {
		this.handleService = handleService;
	}

	public List<HandleNameAuthority> getHandleNameAuthorities() {
		return handleNameAuthorities;
	}

	public void setHandleNameAuthorities(
			List<HandleNameAuthority> handleNameAuthorities) {
		this.handleNameAuthorities = handleNameAuthorities;
	}

	public Long getHandleNameAuthorityId() {
		return handleNameAuthorityId;
	}

	public void setHandleNameAuthorityId(Long handleNameAuthorityId) {
		this.handleNameAuthorityId = handleNameAuthorityId;
	}

	public List<FileDatabase> getFileDatabases() {
		return fileDatabases;
	}

	public void setFileDatabases(List<FileDatabase> fileDatabases) {
		this.fileDatabases = fileDatabases;
	}

	public FileServerService getFileServerService() {
		return fileServerService;
	}

	public void setFileServerService(FileServerService fileServerService) {
		this.fileServerService = fileServerService;
	}

	public Long getDefaultFileDatabaseId() {
		return defaultFileDatabaseId;
	}

	public void setDefaultFileDatabaseId(Long defaultFileDatabaseId) {
		this.defaultFileDatabaseId = defaultFileDatabaseId;
	}

	public String getNameIndexFolder() {
		return nameIndexFolder;
	}

	public void setNameIndexFolder(String nameIndexFolder) {
		this.nameIndexFolder = nameIndexFolder;
	}

	public String getInstitutionalItemIndexFolder() {
		return institutionalItemIndexFolder;
	}

	public void setInstitutionalItemIndexFolder(String institutionalItemIndexFolder) {
		this.institutionalItemIndexFolder = institutionalItemIndexFolder;
	}

	public String getResearcherIndexFolder() {
		return researcherIndexFolder;
	}

	public void setResearcherIndexFolder(String researcherIndexFolder) {
		this.researcherIndexFolder = researcherIndexFolder;
	}

	public String getUserIndexFolder() {
		return userIndexFolder;
	}

	public void setUserIndexFolder(String userIndexFolder) {
		this.userIndexFolder = userIndexFolder;
	}

	private void updateUserIndex() throws NoIndexFoundException
	{
		// handle any pre-loaded users
		List<IrUser> users = userService.getAllUsers();
		log.debug("User size = " + users.size());
		File userIndexFolder = new File(repository.getUserIndexFolder());
		for( IrUser user : users)
		{
			userIndexService.addToIndex(user, userIndexFolder);
		}
	}

	private void updateNameIndexFolder(Repository r, String folder) throws IOException
	{

		String oldFolder = r.getNameIndexFolder();
		boolean change = true;
		if( folder != null)
		{
			// add the end seperator
		    if (folder.charAt(folder.length() - 1) != IOUtils.DIR_SEPARATOR)
		    {
		    	folder = folder + IOUtils.DIR_SEPARATOR;
		    }
			File f = new File(folder);
			if(oldFolder != null)
			{
				File oldFolderFile = new File(oldFolder);

				if( f.getAbsolutePath().equals(oldFolderFile.getAbsolutePath()))
			    {
				    change = false;
			    }
			}

			if(change)
			{
				FileUtils.forceMkdir(f);
			    r.setNameIndexFolder(folder);
			    if( oldFolder != null)
				{
				    FileUtils.deleteQuietly(new File(oldFolder));
				}
			}
		}
		else
		{
			if(oldFolder != null)
			{
				FileUtils.deleteQuietly(new File(oldFolder));
			}
		}
	}

	private void updateInstitutionalItemIndexFolder(Repository r, String folder) throws IOException
	{

		String oldFolder = r.getInstitutionalItemIndexFolder();
		boolean change = true;
		if( folder != null)
		{
			// add the end seperator
		    if (folder.charAt(folder.length() - 1) != IOUtils.DIR_SEPARATOR)
		    {
		    	folder = folder + IOUtils.DIR_SEPARATOR;
		    }
			File f = new File(folder);
			if(oldFolder != null)
			{
				File oldFolderFile = new File(oldFolder);

				if( f.getAbsolutePath().equals(oldFolderFile.getAbsolutePath()))
			    {
				    change = false;
			    }
			}

			if(change)
			{
				FileUtils.forceMkdir(f);
			    r.setInstitutionalItemIndexFolder(folder);
			    if( oldFolder != null)
				{
				    FileUtils.deleteQuietly(new File(oldFolder));
				}
			}
		}
		else
		{
			if(oldFolder != null)
			{
				FileUtils.deleteQuietly(new File(oldFolder));
			}
		}
	}

	private void updateResearcherIndexFolder(Repository r, String folder) throws IOException
	{

		String oldFolder = r.getResearcherIndexFolder();
		boolean change = true;
		if( folder != null)
		{
			// add the end seperator
		    if (folder.charAt(folder.length() - 1) != IOUtils.DIR_SEPARATOR)
		    {
		    	folder = folder + IOUtils.DIR_SEPARATOR;
		    }
			File f = new File(folder);
			if(oldFolder != null)
			{
				File oldFolderFile = new File(oldFolder);

				if( f.getAbsolutePath().equals(oldFolderFile.getAbsolutePath()))
			    {
				    change = false;
			    }
			}

			if(change)
			{
				FileUtils.forceMkdir(f);
			    r.setResearcherIndexFolder(folder);
			    if( oldFolder != null)
				{
				    FileUtils.deleteQuietly(new File(oldFolder));
				}
			}
		}
		else
		{
			if(oldFolder != null)
			{
				FileUtils.deleteQuietly(new File(oldFolder));
			}
		}
	}

	private void updateUserIndexFolder(Repository r, String folder) throws IOException, NoIndexFoundException
	{

		String oldFolder = r.getUserIndexFolder();
		boolean change = true;
		if( folder != null)
		{
			// add the end seperator
		    if (folder.charAt(folder.length() - 1) != IOUtils.DIR_SEPARATOR)
		    {
		    	folder = folder + IOUtils.DIR_SEPARATOR;
		    }
			File f = new File(folder);
			if(oldFolder != null)
			{
				File oldFolderFile = new File(oldFolder);

				if( f.getAbsolutePath().equals(oldFolderFile.getAbsolutePath()))
			    {
				    change = false;
			    }
			}

			if(change)
			{
				FileUtils.forceMkdir(f);
			    r.setUserIndexFolder(folder);
			    if( oldFolder != null)
				{
				    FileUtils.deleteQuietly(new File(oldFolder));
				}
			    updateUserIndex();
			}
		}
		else
		{
			if(oldFolder != null)
			{
				FileUtils.deleteQuietly(new File(oldFolder));
			}
		}
	}

	private void updateUserWorkspaceIndexFolder(Repository r, String folder) throws IOException
	{

		log.debug("update user workspace index folder " + folder);
		String oldFolder = r.getUserWorkspaceIndexFolder();
		boolean change = true;
		if( folder != null)
		{
			// add the end seperator
		    if (folder.charAt(folder.length() - 1) != IOUtils.DIR_SEPARATOR)
		    {
		    	folder = folder + IOUtils.DIR_SEPARATOR;
		    }
			File f = new File(folder);
			if(oldFolder != null)
			{
				File oldFolderFile = new File(oldFolder);

				if( f.getAbsolutePath().equals(oldFolderFile.getAbsolutePath()))
			    {
				    change = false;
			    }
			}

			if(change)
			{
				FileUtils.forceMkdir(f);
				log.debug("setting user workspace index folder to " + folder);
			    r.setUserWorkspaceIndexFolder(folder);
			    if( oldFolder != null)
				{
				    FileUtils.deleteQuietly(new File(oldFolder));
				}
			}
		}
		else
		{
			if(oldFolder != null)
			{
				FileUtils.deleteQuietly(new File(oldFolder));
			}
		}
	}

	public String getRepositoryName() {
		return repositoryName;
	}

	public void setRepositoryName(String repositoryName) {
		this.repositoryName = repositoryName;
	}

	public String getInstitutionName() {
		return institutionName;
	}

	public void setInstitutionName(String institutionName) {
		this.institutionName = institutionName;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public UserIndexService getUserIndexService() {
		return userIndexService;
	}

	public void setUserIndexService(UserIndexService userIndexService) {
		this.userIndexService = userIndexService;
	}

	public String getUserWorkspaceIndexFolder() {
		return userWorkspaceIndexFolder;
	}

	public void setUserWorkspaceIndexFolder(String userWorkspaceIndexFolder) {
		this.userWorkspaceIndexFolder = userWorkspaceIndexFolder;
	}

	public boolean getSuspendSubscriptions() {
		return suspendSubscriptions;
	}

	public void setSuspendSubscriptions(boolean suspendSubscriptions) {
		this.suspendSubscriptions = suspendSubscriptions;
	}

	public Long getDefaultLicenseVersionId() {
		return defaultLicenseVersionId;
	}

	public void setDefaultLicenseVersionId(Long defaultLicenseVersionId) {
		this.defaultLicenseVersionId = defaultLicenseVersionId;
	}

	public LicenseService getLicenseService() {
		return licenseService;
	}

	public void setLicenseService(LicenseService licenseService) {
		this.licenseService = licenseService;
	}

	public List<LicenseVersion> getLicenses() {
		return licenses;
	}

	public void setLicenses(List<LicenseVersion> licenses) {
		this.licenses = licenses;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

}


text:
using WeihanLi.Common.Models;
using WeihanLi.Extensions;
using Xunit;

namespace WeihanLi.Common.Test.ExtensionsTest;

/// <summary>
/// CoreExtensionTest
/// </summary>
public class CoreExtensionTest
{
    #region ObjectExtension

    [Fact]
    public void ToGenericTest()
    {
        var num1 = 1.2;
        var toNum1 = num1.To<decimal>();
        Assert.Equal(typeof(decimal), toNum1.GetType());
        Assert.Equal(typeof(double), toNum1.To<double>().GetType());

        // nullable test
        var nullableNum = num1.To<decimal?>();
        Assert.NotNull(nullableNum);
        Assert.Equal(1.2m, nullableNum!.Value);
        Assert.Equal(1.2m, nullableNum.To<decimal>());
        // nullable to nullable
        var nullableNum2 = nullableNum.To<double?>();
        Assert.NotNull(nullableNum2);
        Assert.Equal(1.2d, nullableNum2!.Value);

        // int to bool test
        Assert.False(0.To<bool>());
        Assert.True(1.To<bool>());
    }

    [Fact]
    public void ToTest()
    {
        var num1 = 1.2;
        var toNum1 = num1.To(typeof(decimal))!;
        Assert.Equal(typeof(decimal), toNum1.GetType());
        Assert.Equal(typeof(double), toNum1.To(typeof(double))!.GetType());

        // nullable test
        var nullableNum = num1.To(typeof(decimal?));
        Assert.NotNull(nullableNum);
        Assert.Equal(1.2m, ((decimal?)nullableNum).GetValueOrDefault());
        Assert.Equal(1.2m, nullableNum.To(typeof(decimal)));
        // nullable to nullable
        var nullableNum2 = nullableNum.To(typeof(double?));
        Assert.NotNull(nullableNum2);
        Assert.Equal(1.2d, (double)nullableNum2.To(typeof(double))!);

        // int to bool test
        Assert.False((bool)0.To(typeof(bool))!);
        Assert.True((bool)1.To(typeof(bool))!);
    }

    [Fact]
    public void ToSafeString()
    {
        var category = new Category();
        Assert.Equal(category.ToString(), category.ToSafeString());
        category = null;
        Assert.Equal(string.Empty, category.ToSafeString());
    }

    #endregion ObjectExtension

    #region BoolExtensions

    [Fact]
    public void IfTest()
    {
        var num = 1;
        true.IfTrue(() => num++);
        Assert.Equal(2, num);
        false.IfTrue(() => num++);
        Assert.Equal(2, num);
        true.IfFalse(() => num++);
        Assert.Equal(2, num);
        false.IfFalse(() => num++);
        Assert.Equal(3, num);
    }

    #endregion BoolExtensions

    #region StringExtensionTest

    [Fact]
    public void SafeSubstring()
    {
        var str = "abcdefg";
        Assert.Equal(str.Substring(1, 2), str.SafeSubstring(1, 2));
        Assert.Equal("bcdefg", str.SafeSubstring(1, 20));
        Assert.Equal("", str.SafeSubstring(10, 20));

        Assert.Equal(str.Substring(str.Length), str.SafeSubstring(str.Length));
        Assert.Equal("", str.SafeSubstring(10));
    }

    [Fact]
    public void Sub()
    {
        var str = "abcdef";
        Assert.Equal("ef", str.Sub(-2));
        Assert.Equal("def", str.Sub(3));
    }

    #endregion StringExtensionTest
}


text:
{#
    Renders a schema name given a custom schema name. If the custom
    schema name is none, then the resulting schema is just the "schema"
    value in the specified target. If a schema override is specified, then
    the resulting schema is the default schema concatenated with the
    custom schema.

    This macro can be overriden in projects to define different semantics
    for rendering a schema name.

    Arguments:
    custom_schema_name: The custom schema name specified for a model, or none
    node: The node the schema is being generated for

#}
{% macro generate_schema_name(custom_schema_name=none, node=none) -%}
    {{ return(adapter.dispatch('generate_schema_name', 'dbt')(custom_schema_name, node)) }}
{% endmacro %}

{% macro default__generate_schema_name(custom_schema_name, node) -%}

    {%- set default_schema = target.schema -%}
    {%- if custom_schema_name is none -%}

        {{ default_schema }}

    {%- else -%}

        {{ default_schema }}_{{ custom_schema_name | trim }}

    {%- endif -%}

{%- endmacro %}

{#
    Renders a schema name given a custom schema name. In production, this macro
    will render out the overriden schema name for a model. Otherwise, the default
    schema specified in the active target is used.

    Arguments:
    custom_schema_name: The custom schema name specified for a model, or none
    node: The node the schema is being generated for

#}
{% macro generate_schema_name_for_env(custom_schema_name, node) -%}

    {%- set default_schema = target.schema -%}
    {%- if target.name == 'prod' and custom_schema_name is not none -%}

        {{ custom_schema_name | trim }}

    {%- else -%}

        {{ default_schema }}

    {%- endif -%}

{%- endmacro %}