예제 #1
0
            public void Apply(IServiceProvider serviceProvider)
            {
                var settings = serviceProvider.GetService <IOptions <Settings> >().Value;

                if (Host.HasValue())
                {
                    settings.Admin.Host = Host.Value();
                }

                if (OutputFolder.HasValue())
                {
                    settings.OutputFolder = OutputFolder.Value();
                }

                if (Port.HasValue())
                {
                    settings.Admin.Port = int.Parse(Port.Value());
                }

                settings.DryRun = DryRun.HasValue();

                if (InputFolder.HasValue())
                {
                    settings.InputFolder = InputFolder.Value();
                }
            }
예제 #2
0
            public ExitCode?Validate()
            {
                if (!Host.HasValue())
                {
                    return(ExitCode.MissingHost);
                }

                if (!Port.HasValue())
                {
                    return(ExitCode.MissingPort);
                }

                if (!int.TryParse(Port.Value(), out var port) || port > MaxPort || port < MinPort)
                {
                    return(ExitCode.InvalidPort);
                }

                if (InputFolder.HasValue() && OutputFolder.HasValue())
                {
                    return(ExitCode.IncompatibleArguments);
                }

                if (!InputFolder.HasValue() && !OutputFolder.HasValue())
                {
                    return(ExitCode.IncompatibleArguments);
                }

                return(null);
            }
예제 #3
0
        private void ChooseBtn_Click(object sender, EventArgs e)
        {
            DialogResult result = InputFolder.ShowDialog();

            if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(InputFolder.SelectedPath))
            {
                InputFolderDir = new DirectoryInfo(InputFolder.SelectedPath);
                InputFolderSet = true;
            }
        }
예제 #4
0
        protected override void Execute(NativeActivityContext context)
        {
            this._context = ContextName.Get(context);
            string aFolder = "";

            if (Retries == null || Retries.Get(context) <= 0)
            {
                throw new Exception("Retries cannot be zero or negative.");
            }

            if (InputFolder != null)
            {
                aFolder = InputFolder.Get(context);
            }

            Dictionary <string, string> aArguments = new Dictionary <string, string>();

            aArguments["Folder"]  = aFolder;
            aArguments["Retries"] = Retries.Get(context).ToString();

            try
            {
                aContext = new ContextClient(ContextType, this._context, aArguments, this.Debug);

                aContext.CreateClient();
                if (ContextType == contextType.File && this.ClearContext)
                {
                    aContext.ClearAll();
                }

                if (Body != null)
                {
                    //scheduling the execution of the child activities
                    // and passing the value of the delegate argument
                    context.ScheduleAction(Body, aContext, OnCompleted, OnFaulted);
                }
            }
            catch (Exception exception)
            {
                if (this.Debug)
                {
                    Console.WriteLine("[SharedContext Scope] There is an error!!");
                    Console.WriteLine(exception.Message);
                }
                CleanupContext();
                throw;
            }
        }
        private void btnSelectFolder_Click(object sender, EventArgs e)
        {
            DialogResult result = InputFolder.ShowDialog();

            if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(InputFolder.SelectedPath))
            {
                var ext = new List <string> {
                    ".jpg", ".gif", ".png", ".jpeg", ".tiff", ".bmp"
                };
                DirectoryInfo InputFolderDir = new DirectoryInfo(InputFolder.SelectedPath);
                foreach (var file in InputFolderDir.GetFiles("*.*", SearchOption.AllDirectories).Where(s => ext.Contains(Path.GetExtension(s.FullName).ToLowerInvariant())))
                {
                    ProcessImage(file.FullName);
                }
            }
        }
예제 #6
0
        protected override ConversionJob CreateDataObject()
        {
            bool test = false;
            ShouldProcessReason reason;

            if (!base.ShouldProcess(null, null, null, out reason))
            {
                if (reason == ShouldProcessReason.WhatIf)
                {
                    test = true;
                }
            }
            if (test)
            {
                Logger.Verbose = true;
            }

            SPWeb  contextWeb = null;
            object input      = null;
            object output     = null;

            if (ParameterSetName == "Library")
            {
                input  = InputList.Read();
                output = OutputList.Read();
                if (input != null)
                {
                    contextWeb = ((SPList)input).ParentWeb;
                }
            }
            else if (ParameterSetName == "Folder")
            {
                input  = InputFolder.Read();
                output = OutputFolder.Read();
                if (input != null)
                {
                    contextWeb = ((SPFolder)input).ParentWeb;
                }
            }
            else if (ParameterSetName == "File")
            {
                input = InputFile.Read();
                if (!((SPFile)input).Exists)
                {
                    throw new Exception("The specified input file does not exist.");
                }

                output = OutputFile;
                if (input != null)
                {
                    contextWeb = ((SPFile)input).ParentFolder.ParentWeb;
                }
                if (contextWeb != null)
                {
                    input = contextWeb.Site.MakeFullUrl(((SPFile)input).ServerRelativeUrl);
                }
            }
            if (input == null)
            {
                throw new Exception("The input can not be a null or empty value.");
            }
            if (output == null)
            {
                throw new Exception("The output can not be a null or empty value.");
            }

            WordServiceApplicationProxy proxy = GetWordServiceApplicationProxy(contextWeb.Site.WebApplication);

            ConversionJobSettings settings = new ConversionJobSettings();

            settings.OutputFormat        = OutputFormat;
            settings.OutputSaveBehavior  = OutputSaveBehavior;
            settings.UpdateFields        = UpdateFields;
            settings.AddThumbnail        = AddThumbnail;
            settings.CompatibilityMode   = CompatibilityMode;
            settings.EmbedFonts          = EmbedFonts;
            settings.SubsetEmbeddedFonts = SubsetEmbeddedFonts;
            settings.MarkupView          = MarkupView;
            settings.RevisionState       = RevisionState;
            ConversionJob job = new ConversionJob(proxy, settings);

            job.UserToken = contextWeb.CurrentUser.UserToken;
            if (ParameterSetName == "Library")
            {
                job.AddLibrary((SPList)input, (SPList)output);
            }
            else if (ParameterSetName == "Folder")
            {
                job.AddFolder((SPFolder)input, (SPFolder)output, Recurse);
            }
            else if (ParameterSetName == "File")
            {
                job.AddFile((string)input, (string)output);
            }

            job.Start();

            if (Wait)
            {
                ConversionJobStatus jobStatus = null;
                do
                {
                    Thread.Sleep(1000);
                    jobStatus = new ConversionJobStatus(proxy, job.JobId, null);
                } while (jobStatus.Failed == 0 && jobStatus.Succeeded == 0);
            }
            return(job);
        }