Esempio n. 1
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);
        }