예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandLineConversionProcessor"/> class.
        /// </summary>
        /// <param name="executablePath">The path to the executable to call</param>
        /// <param name="outputFolderName">The destination folder used to generate the output file name</param>
        /// <param name="outputFileExtension">The extension to use when renaming the output file</param>
        /// <param name="commandLineTemplate">The command line template to use.  This should contain 2 variables {0} and {1}.
        /// Where {0} represents the input file, and {1} will be replaced with the output file</param>
        public CommandLineConversionProcessor(
            string executablePath,
            string outputFolderName,
            string outputFileExtension,
            string commandLineTemplate)
        {
            Precondition.NotNullOrEmpty(executablePath, "executablePath");
            Precondition.NotNullOrEmpty(outputFolderName, "outputFolderName");
            Precondition.NotNullOrEmpty(outputFileExtension, "outputFileExtension");
            Precondition.NotNullOrEmpty(commandLineTemplate, "commandLineTemplate");

            Precondition.Assert(() => File.Exists(executablePath), "Invalid executablePath");

            Logger.InfoFormat("Executable Path:       '{0}'", executablePath);
            Logger.InfoFormat("Output Folder Name:    '{0}'", outputFolderName);
            Logger.InfoFormat("Output File Extension: '{0}'", outputFileExtension);
            Logger.InfoFormat("Command Line       :   '{0}'", commandLineTemplate);

            this.outputDirectoryInfo = new DirectoryInfo(outputFolderName);
            this.commandLineTemplate = commandLineTemplate;
            this.executablePath      = executablePath;
            this.outputFileExtension = outputFileExtension.StartsWith(".")
                                            ? outputFileExtension
                                            : "." + outputFileExtension;

            if (!this.outputDirectoryInfo.Exists)
            {
                this.outputDirectoryInfo.Create();
            }
        }
        /// <summary>
        /// Based on a supplied input stream, this method parses the data and constructs
        /// a new pipeline.
        /// </summary>
        /// <param name="sourceStream">The source stream to read from</param>
        /// <returns>The new pipeline of processors</returns>
        public IDocumentProcessorPipeline Parse(Stream sourceStream)
        {
            XDocument document = XDocument.Load(sourceStream);

            XElement root = document.Root;

            Precondition.Assert(() => root != null, "No root element found in XML data");

            // ReSharper disable once PossibleNullReferenceException
            XElement processorsRootElement = root.Element("processors");
            var      pipeline = new DocumentProcessorPipeline();

            if (processorsRootElement != null)
            {
                this.Variables = new VariableProvider(root.Element("variables"));
                var processorElements = processorsRootElement.Elements("processor");

                foreach (var processorElement in processorElements)
                {
                    IDocumentProcessor processor = LoadProcessorFromConfig(this.Variables, processorElement);
                    if (processor != null)
                    {
                        pipeline.AddProcessor(processor);
                    }
                }
            }

            return(pipeline);
        }
예제 #3
0
        public void raid_aliases_remove(Context ctx, [RegexParameter(@"\w+")] string key)
        {
            //Check that the alias exists
            Precondition.Assert(this.raidConfig.HasAlias(key.ToUpper()), "No existing alias with that name.");

            //Pass on to the implementation
            this.raid_aliases_remove_impl(ctx, key.ToUpper());
        }
예제 #4
0
        public void raid_aliases_add(Context ctx, [RegexParameter(@"\w+")] string key, [RegexParameter(@"\w+")] string value)
        {
            //Check that the role exists
            Precondition.Assert(this.raidConfig.HasRole(value.ToUpper()), "No role with that name.");

            //Pass on to the implementation
            this.raid_aliases_add_impl(ctx, key.ToUpper(), value.ToUpper());
        }
예제 #5
0
        public void raid_delete(Context ctx, uint id)
        {
            //Determine if a raid with this ID exists
            var exists = RaidManager.EnumerateRaids().Any(r => r.raid_id == id);

            Precondition.Assert(exists, $"No raid with that id ({id}).");

            //Pass on to the implementation
            this.raid_delete_impl(ctx, (int)id);
        }
예제 #6
0
        public void raid_add(Context ctx, uint id, [RegexParameter(@"[\S\s]+")] string name, [RegexParameter(@"[\S\s]+")] string roles)
        {
            //Determine if a raid with this ID exists
            var exists = RaidManager.EnumerateRaids().Any(r => r.raid_id == id);

            Precondition.Assert(exists, $"No raid with that id ({id}).");

            //Pass on to the implementation
            this.raid_add_impl(ctx, (int)id, name.Trim(), roles);
        }
예제 #7
0
        public void raid_make_comp(Context ctx, [RegexParameter(@"[\S\s]+")] string name)
        {
            //Get the next raid
            var handle = RaidManager.GetNextRaid();

            //Check if we have one
            Precondition.Assert(handle.HasValue, "No raids up.");

            //Pass on
            this.raid_make_comp(ctx, name, (uint)handle.Value.raid_id);
        }
예제 #8
0
        public void raid_delete(Context ctx)
        {
            //Get the next raid
            var handle = RaidManager.GetNextRaid();

            //Check if we have one
            Precondition.Assert(handle.HasValue, "No raids up.");

            //Pass on
            this.raid_delete(ctx, (uint)handle.Value.raid_id);
        }
        private void raid_upload_logs_impl(Context ctx)
        {
            //Get the attachment
            var attachment = ctx.message.Attachments.First();

            //Send status report
            var dlStatus = ctx.message.Channel.SendMessageAsync("Downloading...");

            //Download it
            Stream file = null;

            using (var httpClient = new HttpClient())
            {
                file = httpClient.GetStreamAsync(attachment.Url).GetAwaiter().GetResult();
            }

            //Update status report
            var msg       = dlStatus.GetAwaiter().GetResult();
            var zipStatus = msg.ModifyAsync(prop =>
            {
                prop.Content = "Unzipping...";
            });

            //Open the zip archive and accept only the first 30 distinct streams
            var streams = ZipHelper.GetUnzippedStreams(file)
                          .GroupBy(t => t.filename).Select(g => g.First())
                          .Take(30).ToList();

            //Close the zip archive
            file.Close();

            //Update status report
            zipStatus.GetAwaiter().GetResult();
            var verifyStatus = msg.ModifyAsync(prop =>
            {
                prop.Content = "Verifying...";
            });

            //Check that we have some streams
            Precondition.Assert(streams.Count > 0, "No .evtc files found in zip!");

            //Get the encounter ids
            var encounters = streams.Select(log => Debug.Try(() =>
            {
                //Open the log
                using (var evtcReader = new EVTCReader(log.stream.GetStream()))
                {
                    //Read the header
                    var header = evtcReader.ReadHeader();

                    //Group filename and encounter id
                    return(log.filename, id: header.encounter_id);
                }
            }, default, severity: LOG_LEVEL.WARNING))
예제 #10
0
        public void raid_create(Context ctx, uint day, uint month, uint hours, uint minutes, int offset, [RegexParameter(@"[\S\s]+")] string description)
        {
            //Derive the year
            var year = DateTool.GetDefaultYear((int)day, (int)month);

            //Validate our inputs
            Precondition.Assert(DateTool.IsValidDate((int)day, (int)month, year), "Invalid date!");
            Precondition.Assert(hours < 24, "Invalid hours!");
            Precondition.Assert(minutes < 60, "Invalid minutes!");
            Precondition.Assert(Math.Abs(offset) <= 12, "Invalid offset!");

            //Pass on to the implementation
            this.raid_create_impl(ctx, (int)day, (int)month, year, (int)hours, (int)minutes, offset, description);
        }
예제 #11
0
        public void raid_upload_logs(Context ctx)
        {
            //Check that we got an attachment
            Precondition.Assert(ctx.message.Attachments.Count > 0, "Missing attachment!");

            //Get the attachment
            var attachment = ctx.message.Attachments.First();

            //Check that it's a zip file
            Precondition.Assert(attachment.Filename.EndsWith(".zip"), "Only .zip files are accepted!");

            //Pass on to the implementation
            this.raid_upload_logs_impl(ctx);
        }
        public SystemConfiguration(ISettingsReader settingsReader, [ImportMany] IEnumerable <IDocumentProcessorFactory> factories)
        {
            string fileName = settingsReader.GetSetting("printerConfigFile", string.Empty);

            Precondition.Assert(
                () => !string.IsNullOrEmpty(fileName) && File.Exists(fileName),
                "Invalid configuration provided - missing configuration file");

            using (Stream inputStream = File.OpenRead(fileName))
            {
                parser            = new PrinterConfigurationParser(factories);
                processorPipeline = parser.Parse(inputStream);
            }

            string printerDir     = parser.Variables.Get("printer-dir");
            string printerFileExt = parser.Variables.Get("printer-file-extension");
            string printerName    = parser.Variables.Get("printer-name");
            string driverName     = parser.Variables.Get("printer-driver");

            string port = Path.Combine(new DirectoryInfo(printerDir).FullName, Guid.NewGuid().ToString()) + printerFileExt;

            var driverConfiguration = new DriverConfiguration
            {
                ConfigFileName     = parser.Variables.Get("driver-config-file"),
                DataFileName       = parser.Variables.Get("driver-data-file"),
                DependentFileNames = parser.Variables.Get("driver-dependent-file").Split(","[0]),
                DriverFileName     = parser.Variables.Get("driver-path"),
                Environment        = parser.Variables.Get("driver-environment"),
                HelpFileName       = parser.Variables.Get("driver-help-file"),
                Name = parser.Variables.Get("driver-name")
            };

            printerConfiguration = new VirtualPrinterConfiguration
            {
                DefaultPort         = port,
                PrinterName         = printerName,
                DriverConfiguration = driverConfiguration
            };

            Logger.Info("Using the following configuration:");
            Logger.Info(string.Empty);
            Logger.InfoFormat("  Print Name:      {0}", printerName);
            Logger.InfoFormat("  Print Driver:    {0}", driverName);
            Logger.InfoFormat("  Print Directory: {0}", printerDir);
            Logger.InfoFormat("  File Extension:  {0}", printerFileExt);
            Logger.Info(string.Empty);
        }
예제 #13
0
        /// <summary>
        /// Called to create a new document processor from the given initialization parameters
        /// </summary>
        /// <param name="parameters">The parameters used to configure the processor</param>
        /// <returns>The created processor </returns>
        public override IDocumentProcessor Create(IDictionary <string, string> parameters)
        {
            Precondition.NotNull(parameters, "parameters");

            string timeoutInSeconds;
            string retryDelayInMilliSeconds;

            parameters.TryGetValue("timeoutInSeconds", out timeoutInSeconds);
            parameters.TryGetValue("retryDelayInMilliSeconds", out retryDelayInMilliSeconds);

            int timeoutInSecondsInt = DefaultTimeoutInSecondsInt;

            if (!string.IsNullOrEmpty(timeoutInSeconds))
            {
                if (!int.TryParse(timeoutInSeconds, out timeoutInSecondsInt))
                {
                    timeoutInSecondsInt = DefaultTimeoutInSecondsInt;
                }
                else
                {
                    throw new ArgumentException(
                              string.Format("timeoutInSeconds parameter value '{0}' is not a valid number", timeoutInSeconds));
                }
            }

            int retryDelayInMilliSecondsInt = DefaultRetryDelayInMilliSecondsInt;

            if (!string.IsNullOrEmpty(retryDelayInMilliSeconds))
            {
                if (!int.TryParse(retryDelayInMilliSeconds, out retryDelayInMilliSecondsInt))
                {
                    retryDelayInMilliSecondsInt = DefaultRetryDelayInMilliSecondsInt;
                }
                else
                {
                    throw new ArgumentException(
                              string.Format("retryDelayInMilliSeconds parameter value '{0}' is not a valid number", timeoutInSeconds));
                }
            }

            // Verify values are reasonable
            Precondition.Assert(() => timeoutInSecondsInt > 0, "timeout must be > 0");
            Precondition.Assert(() => retryDelayInMilliSecondsInt > 0, "retryDelayInMilliSeconds must be > 0");

            return(new WaitForFileProcessor(timeoutInSecondsInt, retryDelayInMilliSecondsInt));
        }
예제 #14
0
        public void raid_kick(Context ctx, uint id, ulong userID)
        {
            //Get a handle to the raid
            var handle = RaidManager.GetRaidFromID((int)id);

            //Make sure it exists
            Precondition.Assert(handle.HasValue, $"No raid with that id ({id}).");

            //Find the raider that matches the ID
            var player = RaidManager.FindRaider(handle.Value, userID);

            //Check that the raider exists in the roster
            Precondition.Assert(player.HasValue, "That raider is not in the roster.");

            //Pass on to the implementation
            this.raid_kick_impl(ctx, handle.Value, player.Value);
        }
예제 #15
0
        public void raid_leave(Context ctx, uint id)
        {
            //Get a handle to the raid
            var handle = RaidManager.GetRaidFromID((int)id);

            //Make sure it exists
            Precondition.Assert(handle.HasValue, $"No raid with that id ({id}).");

            //Find the raider in the roster
            var player = RaidManager.FindRaider(handle.Value, ctx.message.Author.Id);

            //Check that the raider exists in the roster
            Precondition.Assert(player.HasValue, "You are not in the roster.");

            //Pass on to the implementation
            this.raid_leave_impl(ctx, handle.Value, player.Value);
        }
        private void raid_create_comp_impl(Context ctx, string name, string roles)
        {
            //Get all the roles (including duplicates)
            var layout = Regex.Matches(roles, @"\w+")
                         .Select(r => r.Value.ToUpper())
                         .ToArray();

            //Check that we got a comp
            Precondition.Assert(layout.Length > 0, "No roles provided!");

            //Add the composition
            this.raidConfig.AddComposition(name.ToUpper(), layout);

            //Send success message
            Bot.GetBotInstance().SendSuccessMessage(ctx.message.Channel,
                                                    "Success", "Comp was created."
                                                    );
        }
예제 #17
0
        public void raid_kick(Context ctx, uint id, [RegexParameter(@"[\S\s]+")] string name)
        {
            //Get a handle to the raid
            var handle = RaidManager.GetRaidFromID((int)id);

            //Make sure it exists
            Precondition.Assert(handle.HasValue, $"No raid with that id ({id}).");

            //Find any raiders that match the name
            var players = RaidManager.FindRaiders(handle.Value, name);

            //Check that we got only one
            Precondition.Assert(players.Count > 0, "No one with that name.");
            Precondition.Assert(players.Count == 1, $"More than one matches that name.");

            //Pass on to the implementation
            this.raid_kick_impl(ctx, handle.Value, players.First());
        }
예제 #18
0
        public void raid_make_comp(Context ctx, [RegexParameter(@"[\S\s]+")] string name, uint id)
        {
            //Get a handle to the raid
            var handle = RaidManager.GetRaidFromID((int)id);

            //Make sure it exists
            Precondition.Assert(handle.HasValue, $"No raid with that id ({id}");

            //Check that the composition exists
            string[] layout;
            Precondition.Assert
            (
                this.raidConfig.Compositions.TryGetValue(name.ToUpper(), out layout),
                "No comp with that name. These are the recognised comps: \n" +
                string.Join(", ", this.raidConfig.Compositions.Keys)
            );

            //Pass on to the implementation
            this.raid_make_comp_impl(ctx, handle.Value, layout);
        }
        private void raid_add_impl(Context ctx, int id, string name, string roles)
        {
            //Get a handle to the raid
            var handle = RaidManager.GetRaidFromID(id).Value;

            //Extract the roles
            var  extractedRoles = this.raidConfig.MatchRoles(roles);
            bool bu             = roles.ToUpper().Contains("BACKUP");

            //Check that we got any roles
            Precondition.Assert(extractedRoles.Length > 0, "No recognized roles provided!");

            //Add to the raid
            RaidManager.AppendRaider(handle, name, bu, extractedRoles);

            //Return success
            Bot.GetBotInstance()
            .SendSuccessMessage(ctx.message.Channel,
                                "Success",
                                $"They were added to the raid{(bu ? " as backup" : "")} with these roles: \"{string.Join(", ", extractedRoles)}\"."
                                );
        }
        private void raid_delete_impl(Context ctx, int id)
        {
            //Get a handle to the raid
            var handle = RaidManager.GetRaidFromID(id).Value;

            //Grab the data from the raid
            var data = RaidManager.GetRaidData(handle);

            //Check that it's valid
            Precondition.Assert(data.HasValue, "There was an error processing the raid.");

            //Get the owner
            var owner_id = data.Value.owner_id;

            //Check that the user is the owner
            Precondition.Assert(ctx.message.Author.Id == owner_id, "You are not the owner of the raid!");

            //Delete the raid
            RaidManager.DeleteRaid(handle);

            //Return success
            Bot.GetBotInstance()
            .SendSuccessMessage(ctx.message.Channel, "Success", $"Raid has been deleted.");
        }
        private void raid_kick_impl(Context ctx, RaidHandle handle, Entry e)
        {
            //Grab the data from the raid
            var data = RaidManager.GetRaidData(handle);

            //Check that it's valid
            Precondition.Assert(data.HasValue, "There was an error processing the raid.");

            //Get the owner
            var owner_id = data.Value.owner_id;

            //Check that the user is the owner
            Precondition.Assert(ctx.message.Author.Id == owner_id, "You are not the owner of the raid!");

            //Remove from the raid
            RaidManager.RemoveRaider(handle, e);

            //Return success
            Bot.GetBotInstance()
            .SendSuccessMessage(ctx.message.Channel,
                                "Success",
                                $"They were removed from the roster."
                                );
        }
예제 #22
0
        public void raid_delete_comp(Context ctx, [RegexParameter(@"[^ ]+")] string name)
        {
            //Check that they're not trying to delete the default comp
            Precondition.Assert
            (
                !string.Equals(name.ToUpper(), "DEFAULT"),
                "Cannot delete the default comp.\nOverwrite it instead."
            );

            //Get the index of the comp
            //var idx = this.raidConfig.GetCompIndex(name.ToUpper());
            bool exists = this.raidConfig.Compositions.ContainsKey(name.ToUpper());

            //Check that it exists
            Precondition.Assert
            (
                exists,
                "No comp with that name. These are the recognised comps: \n" +
                string.Join(", ", this.raidConfig.Compositions.Keys)
            );

            //Pass on to implementation
            this.raid_delete_comp_impl(ctx, name);
        }