private MatchResult(MatchResultType resultType, IEnumerable<IRestriction> matchedRestrictions, IEnumerable<IRestriction> unmatchedRestrictions, string cacheKey) { _resultType = resultType; _matchedRestrictions = matchedRestrictions.IfNotNull(arg => new HashSet<IRestriction>(arg)); _unmatchedRestrictions = unmatchedRestrictions.IfNotNull(arg => new HashSet<IRestriction>(arg)); _cacheKey = cacheKey; }
public TemplateNode GetTemplates() { TemplatesManager mgr = new TemplatesManager(excludeFolders.IfNotNull(p => p)); var root = mgr.LoadTemplates(templatePath); return(root); }
public static List <List <T> > SplitToList <T>(this IEnumerable <T> collection, uint chunkSize) { if (chunkSize < 1) { throw new ArgumentException("Chunk size must have value greater than 0", nameof(chunkSize)); } return(collection.IfNotNull(col => { var result = new List <List <T> >(); var currentList = new List <T>(); col.ForEach(element => { currentList.Add(element); if (currentList.Count == chunkSize) { result.Add(currentList); currentList = new List <T>(); } }); if (currentList.Count > 0) { result.Add(currentList); } return result; })); }
/// <summary> /// Take a WorkflowItem and the computed list of ActivityAssemblyItems it depends on and translate them into DC form for an upload /// </summary> /// <param name="assembly"></param> /// <param name="assemblyItemsUsed">Assemblies list (computed by WorkflowUploader.ComputeDependencies())</param> /// <returns></returns> public static StoreLibraryAndActivitiesRequestDC ToStoreLibraryAndActivitiesRequestDC(this ActivityAssemblyItem assembly, IEnumerable<ActivityAssemblyItem> assemblyItemsUsed = null) { return new StoreLibraryAndActivitiesRequestDC { Incaller = Utility.GetCallerName(), IncallerVersion = Utility.GetCallerVersion(), InInsertedByUserAlias = !String.IsNullOrEmpty(assembly.CreatedBy) ? assembly.CreatedBy : Utility.GetCurrentUserName(), InUpdatedByUserAlias = Utility.GetCurrentUserName(), // TODO, bug #21381, Remove hardcoded values from WorkflowUploader ActivityLibrary = new ActivityLibraryDC() { Name = assembly.Name, VersionNumber = assembly.Version.ToString(), Executable = File.ReadAllBytes(assembly.Location), Description = assembly.Description, AuthGroupName = assembly.AuthorityGroup ?? AuthorizationService.GetWorkflowAuthGroupName(), CategoryName = assembly.Category, ImportedBy = Utility.GetCurrentUserName(), InsertedByUserAlias = !String.IsNullOrEmpty(assembly.CreatedBy) ? assembly.CreatedBy : Utility.GetCurrentUserName(), UpdatedByUserAlias = Utility.GetCurrentUserName(), Guid = Guid.NewGuid() }, // library for this workflow StoreActivitiesList = new List<StoreActivitiesDC>(assembly.ActivityItems.Select(asm => DataContractTranslator.ActivityItemToStoreActivitiyDC(asm))), StoreActivityLibraryDependenciesGroupsRequestDC = assemblyItemsUsed.IfNotNull(used => new StoreActivityLibraryDependenciesGroupsRequestDC() { Name = assembly.Name, Version = assembly.Version.ToString(), List = new List<StoreActivityLibraryDependenciesGroupsRequestDC>( used.Select(asm => new StoreActivityLibraryDependenciesGroupsRequestDC { Name = asm.Name, Version = asm.Version.ToString(), }.SetIncaller()) ) }.SetIncaller()) }; }
/// <summary> /// Discovers tests in the application and maps routes to allow them to be called over HTTP. /// </summary> /// <param name="configuration">The configuration.</param> /// <param name="configureTargets">A delegate to configure the test targets.</param> /// <param name="baseUri">The base URI segment that the tests will be routed under.</param> /// <param name="testTypes">The Types to map routes for. If omitted, all discovered implementations of <see cref="IMonitoringTest" /> will be routed.</param> /// <param name="handler">A message handler to handle test requests, if you would like to provide authentication, logging, or other functionality during calls to monitoring tests.</param> /// <param name="testUiScriptUrl">The location of the test UI script.</param> /// <param name="testUiLibraryUrls">The locations of any libraries the UI script depends on</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">configuration</exception> public static HttpConfiguration MapTestRoutes( this HttpConfiguration configuration, Action<TestTargetRegistry> configureTargets = null, string baseUri = "tests", IEnumerable<Type> testTypes = null, HttpMessageHandler handler = null, string testUiScriptUrl = null, IEnumerable<string> testUiLibraryUrls = null) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (!Trace.Listeners.OfType<TracingFilter.TraceListener>().Any()) { var traceListener = new TracingFilter.TraceListener(); Trace.Listeners.Add(traceListener); Instrumentation.Log.EntryPosted += (_, args) => traceListener.WriteLine(args.LogEntry.ToLogString()); } // set up specialized handling on the specified routes configuration.Filters.Add(new TestErrorFilter(baseUri)); if (!string.IsNullOrEmpty(testUiScriptUrl) && Uri.IsWellFormedUriString(testUiScriptUrl, UriKind.RelativeOrAbsolute)) { configuration.TestUiUriIs(testUiScriptUrl); } var testUiLibraryUrlsArray = testUiLibraryUrls .IfNotNull() .Then(a => a.Where(u => !string.IsNullOrEmpty(u) && Uri.IsWellFormedUriString(u, UriKind.RelativeOrAbsolute)) .ToArray()) .Else(() => new string[] {}); configuration.TestLibraryUrisAre(testUiLibraryUrlsArray); var testRootRouteTemplate = baseUri.AppendSegment("{environment}/{application}"); configuration.RootTestUriIs(baseUri); // set up test discovery routes configuration.Routes.MapHttpRoute( TestRootRouteName, testRootRouteTemplate, defaults: new { controller = "MonitoringTest", action = "tests", application = RouteParameter.Optional, environment = RouteParameter.Optional }, constraints: null, handler: handler); // set up test execution routes var targetRegistry = new TestTargetRegistry(configuration); configuration.TestTargetsAre(targetRegistry); configureTargets?.Invoke(targetRegistry); testTypes = testTypes ?? Discover.ConcreteTypes() .DerivedFrom(typeof (IMonitoringTest)); var testDefinitions = testTypes.GetTestDefinitions(); configuration.TestDefinitionsAre(testDefinitions); testDefinitions.Select(p => p.Value) .ForEach(test => { var targetConstraint = new TargetConstraint(test); targetRegistry.ForEach(target => { Task.Run(() => targetConstraint.Match(target)); }); configuration.Routes.MapHttpRoute( test.RouteName, testRootRouteTemplate.AppendSegment(test.TestName), defaults: new { controller = "MonitoringTest", action = "run", testName = test.TestName }, constraints: new { tag = new TagConstraint(test), application = new ApplicationConstraint(test), environment = new EnvironmentConstraint(test), target = targetConstraint }, handler: handler ); }); return configuration; }
public ActionResult UploadWrhse(BulkSaleImpIModel model, IEnumerable<HttpPostedFileBase> uploadedFiles) { CountUnLocked(model.IfNotNull(m => m.RunName)); HttpPostedFileBase file = uploadedFiles.IfNotNull(f => f.First()); if (file == null) { ModelState.AddModelError("", "No file was uploaded"); } if (ModelState.IsValid) { Stream stream = file.InputStream; StreamReader sr = new StreamReader(stream); int rowCount = 0; if (model.SkipFirstRow) { sr.ReadLine(); } string line; string[] row; while ((line = sr.ReadLine()) != null) { if (!String.IsNullOrWhiteSpace(line)) { row = line.Trim().Split(','); BulkSaleImport newImport = new BulkSaleImport(); newImport.RunName = model.RunName; newImport.SerialNum = row[0]; if (row.Length > 1) { newImport.CustPO = row[1]; } BulkSaleImport existImport = null; if (!model.Insert) { existImport = (from i in UtilDBContext.BulkSaleImports where i.RunName == newImport.RunName && i.SerialNum == newImport.SerialNum select i).FirstOrDefault(); } if (existImport == null) { UtilDBContext.BulkSaleImports.AddObject(newImport); } else { existImport.CustPO = newImport.CustPO; } rowCount++; } } if (rowCount > 0) { UtilDBContext.SaveChanges(); return RedirectToAction("EditWrhse", new {id = model.RunName}); } else ModelState.AddModelError("", "No rows were imported"); } return View(model); }
public ActionResult UploadNsPartNos(UpldNsPartsImpIModel model, IEnumerable<HttpPostedFileBase> uploadedFiles) { HttpPostedFileBase file = uploadedFiles.IfNotNull(f => f.First()); if (file == null) { ModelState.AddModelError("", "No file was uploaded"); } if (ModelState.IsValid) { model.FileName = file.FileName; model.QtyLoaded = 0; Stream stream = file.InputStream; StreamReader sr = new StreamReader(stream); int partCount = 0; if (model.SkipFirstRow) { sr.ReadLine(); } //PS_TO_NS_PARTNO newPart = new PS_TO_NS_PARTNO(); //newPart.INTERNALID = "1"; //newPart.NS_NAME = "One"; //UtilDBContext.PS_TO_NS_PARTNOS.AddObject(newPart); //UtilDBContext.SaveChanges(); string sql = "DELETE FROM PS_TO_NS_PARTNO"; UtilDBContext.ExecuteStoreCommand(sql); //UtilDBContext.SaveChanges(); int insertCount = 0; insertCount = ReadFileLoadParts(sr); while (insertCount != 0) { partCount = partCount + insertCount; insertCount = ReadFileLoadParts(sr); } //UtilDBContext.SaveChanges(); model.QtyLoaded = partCount; } return View(model); }