static string GetHash(PairwiseSettings settings, string input) { if (!settings.CanCache) { return(Guid.NewGuid().ToString()); } string both = settings.GetPictArgs() + input; return(Convert.ToBase64String(HashAlg.ComputeHash(EncodingForHashAlgorithm.GetBytes(both)))); }
public string[][] MaybeExecutePict(PairwiseSettings settings, string inputContent) { string key = GetHash(settings, inputContent); if (cache != null && settings.CanCache && cache.Contains(key)) { PictConstants.Trace("Found key, using cached value!"); this.last = cache[key]; return(last.ParsedOutput); } string randomFileName = Guid.NewGuid().ToString() + PictConstants.TempFileSuffix; using (StreamWriter sw = new StreamWriter(randomFileName)) { sw.WriteLine("# " + randomFileName + " " + settings.GetPictArgs()); sw.WriteLine(inputContent); } try { string[][] ret = AlwaysExecutePictOnFileName(randomFileName, settings); if (cache != null && settings.CanCache) { // always execute pict set last correctly cache[key] = this.LastExecutionInformation; } return(ret); } finally { File.Delete(randomFileName); } }
public string[][] AlwaysExecutePictOnFileName(string modelFileName, PairwiseSettings settings) { return(AlwaysExecutePictOnFileNameCore(modelFileName, settings.GetPictArgs(), settings)); }
public static PairwiseSettings Parse(string argsForPict) { if (argsForPict == null) { throw new ArgumentNullException("argsForPict"); } PairwiseSettings settings = new PairwiseSettings(2, false); foreach (string raw in argsForPict.Split()) { string s = raw.Trim(); if (s.Length == 0) { continue; } if (s[0] != '/') { throw new ArgumentOutOfRangeException("Unrecognized prefix: " + s); } char cmd = Char.ToLower(s[1], PictConstants.Culture); if (s.Length > 3 && s[2] != ':') { throw new ArgumentOutOfRangeException("Unrecognized delimiter: " + s); } PictConstants.Trace(s + " " + s.Length); string extra = s.Length > 2 ? s.Substring(3) : ""; switch (cmd) { case 'o': settings.Order = Int32.Parse(extra, PictConstants.Culture); break; case 'd': settings.delimParameter = GetChar(extra); settings.setValueSeparator = settings.delimParameter + " "; break; case 'a': settings.aliasDelimiter = GetChar(extra); break; case 'n': settings.negativePrefix = GetChar(extra); settings.negativePrefixString = settings.negativePrefix.ToString(PictConstants.Culture); break; case 'c': settings.IsCaseSensitive = true; break; case 'r': settings.RandomizeGeneration = true; if (extra.Length != 0) { settings.RandomSeedSpecified = true; settings.RandomSeed = Int32.Parse(extra); } break; case 'e': settings.seedFile = extra; break; default: throw new ArgumentOutOfRangeException("Unrecognized: " + raw); } } PictConstants.Trace("Parse: {0} -> {1}", argsForPict, settings.GetPictArgs()); return(settings); }