コード例 #1
0
ファイル: Apply.cs プロジェクト: jean/phosphorusfive
        public static void lambda_apply_braid(ApplicationContext context, ActiveEventArgs e)
        {
            // Retrieving [template], and performing basic sanity check.
            var templates = e.Args.Children.Where(ix => ix.Name == "template");

            if (templates.Count() != 1)
            {
                throw new LambdaException("You must provide exactly one [template] to [apply]", e.Args, context);
            }
            var template = templates.First();

            // Retrieving source, ignoring [template], and making sure source is not null, before we start braiding source(s) and template into destination.
            var source = XUtil.Sources(context, e.Args, "template");

            if (source.Count != 0)
            {
                // Looping through each destination, and braiding source(s) and template, before appending into destination node,
                // assuming destination is node type of expression.
                foreach (var idxDest in XUtil.DestinationMatch(context, e.Args, true))
                {
                    // Iterating through each source, braiding with template, and appending to destination node.
                    foreach (var idxSource in source)
                    {
                        // Braiding template and source, appending into destination.
                        idxDest.Node.AddRange(BraidTemplateWithSource(context, template, idxSource));
                    }
                }
            }
        }
コード例 #2
0
        public static void zip(ApplicationContext context, ActiveEventArgs e)
        {
            using (new ArgsRemover(e.Args)) {
                // Getting root folder
                var rootFolder = Helpers.GetBaseFolder(context);

                // Getting destination file
                var destination = Helpers.GetSystemPath(context, e.Args.GetExValue <string> (context));

                // Getting destination path, and verify path can be legally written to
                var destinationFile = Helpers.GetLegalDestinationFilename(
                    context,
                    e.Args,
                    rootFolder,
                    destination);

                // Getting source file(s)
                var source = XUtil.Sources(context, e.Args, "compression-level", "password", "key-size");

                // Making sure we are able to delete zip file, if an exception occurs
                try {
                    // Creating zip file, supplying FileStream as stream to store results into
                    using (ZipCreator creator = new ZipCreator(
                               context,
                               File.Create(rootFolder + destinationFile),
                               e.Args.GetExChildValue("compression-level", context, 3),
                               e.Args.GetExChildValue <string> ("password", context, null),
                               e.Args.GetExChildValue("key-size", context, 256))) {
                        // Looping through each input file/folder given
                        foreach (var idxSourceFileFolder in source)
                        {
                            var idxSource = Helpers.GetSystemPath(context, Utilities.Convert <string> (context, idxSourceFileFolder));

                            // Verifies source folder can be read from
                            Helpers.VerfifySourceFileFolderCanBeReadFrom(
                                context,
                                e.Args,
                                rootFolder,
                                destinationFile,
                                idxSource);

                            // Adding currently iterated file/folder to zip file stream
                            creator.AddToArchive(rootFolder + idxSource, e.Args);
                        }
                    }

                    // Making sure we return actual destination to caller
                    e.Args.Value = destinationFile;
                } catch {
                    // Checking if destination file exist, and if so, delete it, before we rethrow exception
                    if (File.Exists(rootFolder + destinationFile))
                    {
                        File.Delete(rootFolder + destinationFile);
                    }
                    throw;
                }
            }
        }
コード例 #3
0
ファイル: Add.cs プロジェクト: yinpanqiang/phosphorusfive
        public static void lambda_add(ApplicationContext context, ActiveEventArgs e)
        {
            // Finding source nodes, and returning early if no source is given.
            var src = XUtil.Sources(context, e.Args);

            if (src.Count == 0)
            {
                return;
            }

            // Looping through each destination, adding all source nodes to it, cloning them before adding them.
            foreach (var idxDestination in XUtil.DestinationMatch(context, e.Args, true))
            {
                idxDestination.Node.AddRange(src.Select(ix => ix.Clone()));
            }
        }
コード例 #4
0
ファイル: Insert.cs プロジェクト: jean/phosphorusfive
        /*
         * Common insertion method for both of the above Active Events.
         */
        private static void InsertNodes(ApplicationContext context, Node args, bool after)
        {
            // Finding source nodes, and returning early if no source is given.
            var src = XUtil.Sources(context, args);

            if (src.Count == 0)
            {
                return;
            }

            // Looping through each destination, and inserting all source node at specified position, in order of appearance.
            foreach (var idxDestination in XUtil.DestinationMatch(context, args, true))
            {
                // Figuring out insertion point before we insert nodes.
                var index = idxDestination.Node.Parent.IndexOf(idxDestination.Node) + (after ? 1 : 0);
                idxDestination.Node.Parent.InsertRange(index, src.Select(ix => ix.Clone()));
            }
        }