Example #1
0
        internal static void ExportClixml(IEnumerable items, string directory)
        {
            ExportDialog ui = new ExportDialog("Export-Clixml", null, true);

            for (; ;)
            {
                if (!ui._Dialog.Show())
                {
                    return;
                }
                if (ui._Depth.Text.Length != 0)
                {
                    if (!int.TryParse(ui._Depth.Text, out int r) || r <= 0)
                    {
                        A.Message("Invalid depth value");
                        ui._Dialog.Focused = ui._Depth;
                        continue;
                    }
                }
                break;
            }
            string ext = Path.GetExtension(ui._File.Text);

            if (ext.Length == 0)
            {
                ui._File.Text += ".clixml";
            }

            try
            {
                string filePath = ui._File.Text;
                if (!string.IsNullOrEmpty(directory) && filePath.IndexOfAny(new char[] { '\\', '/', ':' }) < 0)
                {
                    filePath = My.PathEx.Combine(directory, filePath);
                }

                if (File.Exists(filePath))
                {
                    if (Far.Api.Message("File " + filePath + " exists. Continue?", "Confirm", MessageOptions.YesNo) != 0)
                    {
                        return;
                    }
                }

                const string code = "$args[0] | Export-Clixml -Path $args[1] -Encoding $args[2] -Force -ErrorAction Stop";
                if (ui._Depth.Text.Length > 0)
                {
                    A.InvokeCode(code + " -Depth $args[3]",
                                 items, filePath, ui._Encoding.Text, int.Parse(ui._Depth.Text, null));
                }
                else
                {
                    A.InvokeCode(code,
                                 items, filePath, ui._Encoding.Text);
                }
            }
            catch (RuntimeException ex)
            {
                A.Msg(ex);
            }
        }
Example #2
0
        internal static void ExportClixml(IEnumerable items, string directory)
        {
            ExportDialog ui = new ExportDialog("Export-Clixml", null, true);
            for (; ; )
            {
                if (!ui._Dialog.Show())
                    return;
                if (ui._Depth.Text.Length != 0)
                {
                    int r;
                    if (!int.TryParse(ui._Depth.Text, out r) || r <= 0)
                    {
                        A.Message("Invalid depth value");
                        ui._Dialog.Focused = ui._Depth;
                        continue;
                    }
                }
                break;
            }
            string ext = Path.GetExtension(ui._File.Text);
            if (ext.Length == 0)
                ui._File.Text += ".clixml";

            try
            {
                string filePath = ui._File.Text;
                if (!string.IsNullOrEmpty(directory) && filePath.IndexOfAny(new char[] { '\\', '/', ':' }) < 0)
                    filePath = My.PathEx.Combine(directory, filePath);

                if (File.Exists(filePath))
                    if (Far.Api.Message("File " + filePath + " exists. Continue?", "Confirm", MessageOptions.YesNo) != 0)
                        return;

                const string code = "$args[0] | Export-Clixml -Path $args[1] -Encoding $args[2] -Force -ErrorAction Stop";
                if (ui._Depth.Text.Length > 0)
                    A.InvokeCode(code + " -Depth $args[3]",
                        items, filePath, ui._Encoding.Text, int.Parse(ui._Depth.Text, null));
                else
                    A.InvokeCode(code,
                        items, filePath, ui._Encoding.Text);
            }
            catch (RuntimeException ex)
            {
                A.Msg(ex);
            }
        }