protected override bool Process(IInteraction parameters) { var dataSink = Closest <IOutgoingBodiedInteraction> .From(parameters); FileInfo file = GetFileInfo(parameters); if (!file.FullName.StartsWith(this.ValidRootPath)) { return(FailForException(parameters, new Exception("File not in root path"))); } IInteraction fileParameters = new SimpleInteraction( parameters, "contentlength", file.Length); if (!this.Header.TryProcess(fileParameters)) { return(FailForException(fileParameters, new Exception("Header failed"))); } try { using (FileStream fileStream = file.OpenRead()) { Task copyTask = fileStream.CopyToAsync(dataSink.OutgoingBody); Meanwhile.TryProcess(fileParameters); copyTask.Wait(); } return((Successful == null) || Successful.TryProcess(fileParameters)); } catch (Exception ex) { return(FailForException(fileParameters, ex)); } }
protected override bool Process(IInteraction parameters) { TextReader reader; bool success; if (success = TryGetDatareader(parameters, null, out reader)) { string fullData = reader.ReadToEnd(); Match results = matcher.Match(fullData); SimpleInteraction inputs = new SimpleInteraction(parameters); foreach (string groupName in matcher.GetGroupNames()) { NameValueInteraction foundGroup = new NameValueInteraction(parameters) { Name = groupName, Value = Parser.GetBestPossible(results.Groups [groupName].Value) }; success &= TryReportPair(inputs, foundGroup); } if (this.DoMapping) { success &= this.Mapped.TryProcess(inputs); } } return(success); }
/// <summary> /// Shows form for faulty input /// </summary> /// <returns><c>true</c>, if successfully shown form, <c>false</c> otherwise.</returns> /// <param name="parsedData">Parsed data.</param> /// <param name="parameters">Parameters.</param> private bool DoFaultyForm(VerificationInteraction parsedData, IInteraction parameters) { bool success = true; Encoding encoding; IInteraction outgoingCandidate; if (parameters.TryGetClosest(typeof(IOutgoingBodiedInteraction), out outgoingCandidate)) { IOutgoingBodiedInteraction outgoing = (IOutgoingBodiedInteraction)outgoingCandidate; encoding = outgoing.Encoding; } else { encoding = Encoding.UTF8; } foreach (string fieldName in parsedData.FaultyFields) { string failName = string.Format("{0}_failure", fieldName); Service handler; FailureWrapperInteraction fwInteraction = null; IInteraction interaction = parameters; handler = FailureHandler ?? Branches [failName]; if (handler != null) { if (MapErrorStrings) { interaction = fwInteraction = new FailureWrapperInteraction(parameters, encoding); } if (FailureHandler != null) { SimpleInteraction failureInteraction; interaction = failureInteraction = new SimpleInteraction(interaction); failureInteraction ["failurename"] = failName; } success &= handler.TryProcess(interaction); if (fwInteraction != null) { parsedData [failName] = fwInteraction.GetTextAndClose(); } } } return(success & Form.TryProcess(parsedData)); }
public override IInteraction[] GenerateInteractionsFromTarget(InteractionEvent interactionEvent) { var interaction = new SimpleInteraction { Name = on ? "Turn off" : "Turn on", icon = turnOnIcon, CanInteractCallback = InteractionExtensions.RangeCheck, Interact = Toggle, }; return(new IInteraction[] { interaction }); }
protected override bool Process(IInteraction parameters) { try { string serviceName = GetServiceName(parameters); SimpleInteraction successInteraction = new SimpleInteraction(parameters); successInteraction [this.ServiceIdKey] = GetServiceByName(serviceName).ModelID; return(this.Successful.TryProcess(successInteraction)); } catch (ControlException ex) { return(this.Failure.TryProcess(new FailureInteraction(parameters, ex))); } }
protected override bool Process(IInteraction parameters) { bool success = true; SimpleInteraction foundType; foreach (string name in PossibleSiblingTypes.Dictionary.Keys) { foundType = new SimpleInteraction(parameters); foundType ["servicename"] = name; success &= SiblingIterator.TryProcess(foundType); } return(success); }
public void Configure(IExportRegistrationBlock block) { block.Export <GuiRequirementSatisfier>().As <IRequirementSatisfier>().Lifestyle.Singleton(); block.Export <WpfDialogService>().As <IDialogService>().Lifestyle.Singleton(); block.Export <SettingsService>().As <ISettingsService>().Lifestyle.Singleton(); block.Export <OpenFilePicker>().As <IOpenFilePicker>().Lifestyle.Singleton(); block.Export <DesktopFilePicker>().As <IFilePicker>().Lifestyle.Singleton(); block.ExportFactory <Uri, IFileSystemOperations, ZafiroFile>((uri, f) => new DesktopZafiroFile(uri, f, null)); block.Export <MarkdownService>().As <IMarkdownService>().Lifestyle.Singleton(); var simpleInteraction = new SimpleInteraction(); simpleInteraction.Register("Requirements", typeof(Requirements)); block.ExportInstance(simpleInteraction).As <ISimpleInteraction>(); block.Export <WoaDeployer>().Lifestyle.Singleton(); }
protected override bool Process(IInteraction parameters) { TextReader urlDataReader = null; bool success = true; SimpleInteraction valuesByName = new SimpleInteraction(parameters); Map <IInteraction> inputInteractionsByName = new Map <IInteraction> (); success = success && TryGetDatareader(parameters, null, out urlDataReader); success = success && this.ParserRunner.TryRun(urlDataReader, delegate(string name, string value) { WwwInputInteraction inputInteractions = new WwwInputInteraction(name, value, parameters); if (StringFieldWhiteList.Contains(inputInteractions.Name)) { if (Immediate) { success &= TryReportPair(valuesByName, inputInteractions); } else { if (this.DoMapping) { valuesByName [inputInteractions.Name] = inputInteractions.Value; } inputInteractionsByName [inputInteractions.Name] = inputInteractions; } } }); foreach (string fieldName in this.StringFieldWhiteList) { IInteraction currentField; if (!inputInteractionsByName.Has(fieldName)) { inputInteractionsByName [fieldName] = new WwwInputInteraction(fieldName, null, parameters); } currentField = inputInteractionsByName [fieldName]; success = success && (!Branches.Has(fieldName) || Branches [fieldName].TryProcess(currentField)); success = success && (!DoIterate || this.Iterator.TryProcess(currentField)); } success = success && (!this.DoMapping || this.Mapped.TryProcess(valuesByName)); return(success); }
public override bool TryWriteTo(StreamWriter writer, IInteraction context) { Service called = null; IInteraction callContext; if (Branches.Has(TEMPLATE_VARIABLE)) { called = Branches [TEMPLATE_VARIABLE]; callContext = new SimpleInteraction(context, TEMPLATE_VARIABLE, this.Name); if (called.TryProcess(callContext)) { return(true); } } return(this.Replacement.TryWriteTo(writer, context)); }
protected override bool Process(IInteraction parameters) { /* return "Basic " + Convert.ToBase64String ( * Encoding.ASCII.GetBytes ( * string.Format ( * "{0}:{1}", * Username, * Password * ) * ) * ); */ bool successful = true; IHttpInteraction httpParameters = (IHttpInteraction)parameters.GetClosest(typeof(IHttpInteraction)); string authHeader = httpParameters.RequestHeaders["Authorization"]; if ((authHeader != null) && authHeader.StartsWith("Basic ")) { string encAuthString = authHeader.Substring("Basic ".Length).Trim(); string authString = Encoding.ASCII.GetString(Convert.FromBase64String(encAuthString)); string[] userPass = authString.Split(':'); if (userPass.Length == 2) { var credentials = new SimpleInteraction(); credentials ["username"] = userPass [0]; credentials ["password"] = userPass [1]; successful &= Successful.TryProcess(credentials); } else { successful &= Failure.TryProcess(parameters); } } else { httpParameters.SetStatusCode(401); httpParameters.ResponseHeaders ["WWW-Authenticate"] = ResponseHeader; successful &= Failure.TryProcess(parameters); } return(successful); }
public void Configure(IExportRegistrationBlock block) { block.Export <GuiRequirementSatisfier>().As <IRequirementSatisfier>().Lifestyle.Singleton(); block.Export <WpfDialogService>().As <IDialogService>().Lifestyle.Singleton(); block.Export <SettingsService>().As <ISettingsService>().Lifestyle.Singleton(); block.Export <OpenFilePicker>().As <IOpenFilePicker>().Lifestyle.Singleton(); block.Export <DesktopFilePicker>().As <IFilePicker>().Lifestyle.Singleton(); block.ExportFactory <Uri, IFileSystemOperations, ZafiroFile>((uri, f) => new DesktopZafiroFile(uri, f, null)); block.Export <MarkdownService>().As <IMarkdownService>().Lifestyle.Singleton(); var simpleInteraction = new SimpleInteraction(); simpleInteraction.Register("Requirements", typeof(Requirements)); block.ExportInstance(simpleInteraction).As <ISimpleInteraction>(); block.Export <ScriptDeployer>().As <Core.Deployer>().Lifestyle.Singleton(); block.Export <DeviceDeployer>().As <Core.Deployer>().Lifestyle.Singleton(); block.ExportAssemblies(Assemblies.AppDomainAssemblies) .Where(y => typeof(ISection).IsAssignableFrom(y)) .ByInterface <ISection>() .ByInterface <IBusy>() .ByType() .ExportAttributedTypes() .Lifestyle.Singleton(); }
protected override bool Process(IInteraction parameters) { bool successful = true; IInteraction httpInteractionCandidate; if (successful = parameters.TryGetClosest(typeof(IHttpInteraction), out httpInteractionCandidate)) { IHttpInteraction httpInteraction = (IHttpInteraction)httpInteractionCandidate; if (httpInteraction.ContentType.StartsWith(MimeTypePrefix)) { string headerBoundary = httpInteraction.ContentType.Substring(MimeTypePrefix.Length); SimpleInteraction mappedValues = new SimpleInteraction(parameters); StreamingMultipartFormDataParser parser = new StreamingMultipartFormDataParser( httpInteraction.IncomingBody, headerBoundary, httpInteraction.Encoding, this.BufferSize ); parser.ParameterHandler += delegate(ParameterPart part) { if (this.StringFieldWhiteList.Contains(part.Name)) { mappedValues[part.Name] = part.Data; successful &= this.Branches.Get(part.Name, Stub).TryProcess( new WwwInputInteraction(part.Name, part.Data, parameters) ); } }; parser.FileHandler += delegate( string name, string fileName, string contentType, string contentDisposition, byte[] buffer, int bytes ) { if (this.StringFieldWhiteList.Contains(name)) { MemoryStream stream = new MemoryStream(buffer, 0, bytes); SimpleIncomingInteraction incoming = new SimpleIncomingInteraction( stream, mappedValues, contentDisposition, contentType ); incoming ["mimetype"] = contentType; incoming ["filename"] = fileName; successful &= this.Branches.Get(name, Stub).TryProcess(incoming); stream.Dispose(); } }; parser.Run(); successful &= this.Mapped.TryProcess(mappedValues); } else { Secretary.Report(5, "Require boundary content type for multipart forms"); successful &= Failure.TryProcess(parameters); } } else { Secretary.Report(5, "Require HttpInteraction for multipart forms"); successful &= Failure.TryProcess(parameters); } return(successful); }
/// <summary> /// The entry point of the program, where the program control starts and ends. /// </summary> /// <param name='args'> /// The command-line arguments. /// </param> static void Main(string[] args) { Queue <string> CommandLineArguments = new Queue <string> (args); string config = "apollogeese.conf", logfolder = ".", runbranch = ""; bool pluginsFromConfig = true; bool pluginsFromBin = true; SimpleInteraction miscArgs = new SimpleInteraction(); try { int logParamIndex = Array.IndexOf(args, "-l"); if (logParamIndex > -1) { logfolder = args [logParamIndex + 1]; } StartLog(logfolder); while (CommandLineArguments.Count > 0) { string paramAhead = CommandLineArguments.Dequeue(); if (paramAhead.ToLower().Contains("-h")) { throw new CommandLineArgumentException("Help requested"); } else if (paramAhead.ToLower() == "-b") { runbranch = CommandLineArguments.Dequeue(); Secretary.Report(5, "Branch name: ", runbranch); } else if (paramAhead.ToLower() == "-l") { CommandLineArguments.Dequeue(); Secretary.Report(5, "Logfolder: ", logfolder); } else if (paramAhead.ToLower() == "-c") { config = CommandLineArguments.Dequeue(); Secretary.Report(5, "Config file: ", config); } else if (paramAhead.ToLower() == "-pfc") { pluginsFromConfig = bool.Parse(CommandLineArguments.Dequeue()); Secretary.Report(5, "Plugins from Config: ", pluginsFromConfig.ToString()); } else if (paramAhead.ToLower() == "-pfb") { pluginsFromBin = bool.Parse(CommandLineArguments.Dequeue()); Secretary.Report(5, "Plugins from Bin: ", pluginsFromBin.ToString()); } else if (runbranch.Length > 0) { string[] pair = paramAhead.ToLower().Split('='); if (pair.Length == 2) { miscArgs [pair [0]] = pair [1]; Secretary.Report(5, pair [0], "=", pair [1]); } else { throw new CommandLineArgumentException( "Interaction variables need to be supplied as key=value-pair"); } } else { throw new CommandLineArgumentException("Not sure what to do with " + paramAhead.ToLower()); } } Map <Service> services = ServiceCollectionCache.Get( config, pluginsFromConfig, pluginsFromBin); if (runbranch.Length > 0) { services [runbranch].TryProcess(miscArgs); } } catch (CommandLineArgumentException ex) { Console.WriteLine("ApolloGeese\n" + "2013-2016 Rob Tierolff"); Console.WriteLine("Message: {0}", ex.Message); Console.WriteLine( "-h: This information\n" + "-c [file]: Specify bootstrapper config\n" + "-b [identifier]: Specify startup branch\n" + "-l [directory]: Logging directory\n" + "-pfc [*true|false]: Load plugin assemblies from plugins-array in bootstrapper config.\n" + "-pfb [*true|false]: Load plugin assemblies fron installation directory.\n" + "key=value: Extra context to feed into the startup branch"); Secretary.LatestLog.Dispose(); Secretary.Report(5, "Exiting now"); Environment.Exit(0); } }