public static void perform_ocr(this IObjVerEx obj)
        {
            OCROptions opts = new OCROptions();

            opts.PrimaryLanguage = MFOCRLanguage.MFOCRLanguageEnglishUS;

            obj.objVerEx.CheckOut();
            ObjectFiles files = obj.objVerEx.Vault.ObjectFileOperations.GetFiles(obj.objVerEx.ObjVer);

            foreach (ObjectFile file in files)
            {
                switch (file.Extension.ToLower())
                {
                case "tif":
                case "tiff":
                case "jpg":
                case "jpeg":
                case "pdf":
                    obj.objVerEx.Vault.ObjectFileOperations.PerformOCROperation(obj.objVerEx.ObjVer, file.FileVer,
                                                                                opts, MFOCRZoneRecognitionMode.MFOCRZoneRecognitionModeNoZoneRecognition, null, true);
                    break;

                default:
                    break;
                }
            }
            obj.objVerEx.CheckIn();
        }
        protected virtual Mock <ObjectVersionAndProperties> CreateObjectVersionAndPropertiesMock
        (
            Vault vault,
            int objectType = 0,
            PropertyValues propertyValues = null,
            ObjectFiles objectFiles       = null
        )
        {
            // Sanity.
            propertyValues = propertyValues ?? new PropertyValues();

            // Create a new object version.
            var objVer = new ObjVer();

            objVer.SetIDs(objectType, ++count, 1);

            // Create the object version mock.
            var objectVersionMock = new Mock <ObjectVersion>();

            objectVersionMock.Setup(m => m.ObjVer).Returns(objVer);
            objectVersionMock.Setup(m => m.Files).Returns(objectFiles ?? new Mock <ObjectFiles>().Object);
            objectVersionMock.Setup(m => m.FilesCount).Returns(objectFiles?.Count ?? 0);

            // Create the mock for the object version and properties.
            var objectVersionAndPropertiesMock = new Mock <ObjectVersionAndProperties>();

            objectVersionAndPropertiesMock.SetupAllProperties();
            objectVersionAndPropertiesMock.Setup(m => m.ObjVer).Returns(objVer);
            objectVersionAndPropertiesMock.Setup(m => m.Vault).Returns(vault);
            objectVersionAndPropertiesMock.Setup(m => m.VersionData).Returns(objectVersionMock.Object);
            objectVersionAndPropertiesMock.Setup(m => m.Properties).Returns(propertyValues);
            return(objectVersionAndPropertiesMock);
        }
        public static bool download_file(Vault Vault, int object_id, string download_path)
        {
            bool success = false;

            try {
                ObjID objId = new ObjID();
                objId.SetIDs((int)MFBuiltInObjectType.MFBuiltInObjectTypeDocument, object_id);
                objId.Type = 0;

                ObjectVersion objectVersion;
                ObjectVersionAndProperties objectVersionAndProperties;
                objectVersionAndProperties = Vault.ObjectOperations.GetLatestObjectVersionAndProperties(objId, true);
                objectVersion = objectVersionAndProperties.VersionData;

                ObjectFiles objectFiles = objectVersion.Files;

                foreach (ObjectFile objectFile in objectFiles)
                {
                    Vault.ObjectFileOperations.DownloadFile(objectFile.ID, objectFile.Version, download_path + objectFile.GetNameForFileSystem());
                }

                success = true;
            } catch (Exception ex) {
                throw ex;
            }
            return(success);
        }
Exemple #4
0
        public void CanCreateEntities()
        {
            using (var ctx = TestCommon.CreateClientContext())
            {
                var template = new ProvisioningTemplate();
                template = new ObjectFiles().CreateEntities(ctx.Web, template, null);

                Assert.IsInstanceOfType(template.Files, typeof(List <Core.Framework.Provisioning.Model.File>));
            }
        }
Exemple #5
0
        /// <summary>
        /// Lists object code files
        /// </summary>
        /// <returns>FileInfo[] with object code files</returns>
        static FileInfo[] ListLoadablePrograms()
        {
            int i = 0;

            Console.WriteLine($"Listing object code files in");
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine($"{ObjectFiles.FullName}\n");
            Console.ResetColor();
            FileInfo[] files = ObjectFiles.GetFiles("*.txt");
            foreach (var file in files)
            {
                Console.WriteLine($"{i++} {Path.GetFileNameWithoutExtension(file.FullName)}");
            }
            return(files);
        }
        public void CanCreateEntities()
        {
            using (var ctx = TestCommon.CreateClientContext())
            {
                // Load the base template which will be used for the comparison work
                var creationInfo = new ProvisioningTemplateCreationInformation(ctx.Web)
                {
                    BaseTemplate = ctx.Web.GetBaseTemplate()
                };

                var template = new ProvisioningTemplate();
                template = new ObjectFiles().ExtractObjects(ctx.Web, template, creationInfo);

                Assert.IsInstanceOfType(template.Files, typeof(Core.Framework.Provisioning.Model.FileCollection));
            }
        }
Exemple #7
0
        public override bool Execute()
        {
            Logger.Instance = new XBuildLogProvider(Log);             // TODO: maybe initialise statically; this put in constructor causes NRE

            if (!ObjectFiles.Any())
            {
                return(true);
            }

            var lfiles = new List <string>();
            var ofiles = ObjectFiles.Select(x => x.ItemSpec);
            var flags  = (Flags != null && Flags.Any()) ? Flags.Select(x => x.ItemSpec).ToList() : new List <string>();

            if (Libraries != null)
            {
                foreach (var library in Libraries.Select(x => x.ItemSpec))
                {
                    if (File.Exists(library))
                    {
                        var directory = Path.GetDirectoryName(library);
                        var fileName  = Path.GetFileName(library);

                        lfiles.Add(library);
                        flags.Add(string.Format(" -L{0} -l:{1}", directory, fileName));
                    }
                    else
                    {
                        flags.Add(string.Format("-l{0}", library));
                    }
                }
            }

            var joinedFlags = string.Join(" ", flags);

            using (var cache = new FileCacheManager(Path.GetDirectoryName(Output)))
            {
                if (!cache.SourceHasChanged(ofiles.Union(lfiles), joinedFlags) && File.Exists(Output))
                {
                    return(true);
                }
            }

            // linking
            var linker = new GLD(string.IsNullOrEmpty(LinkerPath) ? DefaultLinker : LinkerPath);

            return(linker.Link(ofiles, Output, joinedFlags));
        }
        public override bool Execute()
        {
            Logger.Instance = new XBuildLogProvider(Log);             // TODO: maybe initialise statically; this put in constructor causes NRE

            if (!ObjectFiles.Any())
            {
                return(true);
            }

            var lfiles = new List <string>();
            var ofiles = ObjectFiles.Select(x => x.ItemSpec);
            var flags  = (Flags != null && Flags.Any()) ? Flags.Select(x => x.ItemSpec).ToList() : new List <string>();

            if (Libraries != null)
            {
                foreach (var library in Libraries.Select(x => x.ItemSpec))
                {
                    if (File.Exists(library))
                    {
                        var directory = Path.GetDirectoryName(library);
                        var fileName  = Path.GetFileName(library);

                        lfiles.Add(library);
                        flags.Add(string.Format(" -L{0} -l:{1}", directory, fileName));
                    }
                    else
                    {
                        flags.Add(string.Format("-l{0}", library));
                    }
                }
            }

            var joinedFlags = string.Join(" ", flags);

            using (var cache = new FileCacheManager(Path.GetDirectoryName(Output)))
            {
                if (!cache.SourceHasChanged(ofiles.Union(lfiles), joinedFlags) && File.Exists(Output))
                {
                    return(true);
                }
            }

            // linking
            var linkerPath = string.IsNullOrEmpty(LinkerPath) ? DefaultLinker : LinkerPath;
            var linker     = new GLD(linkerPath);

            try
            {
                return(linker.Link(ofiles, Output, joinedFlags));
            }
            catch (Exception e)
            {
                if (e is Win32Exception error)
                {
                    if (error.NativeErrorCode == Utilities.ErrorFileNotFound)
                    {
                        Logger.Instance.LogError($"Could not find \"{LinkerPath}\" linker.");
                    }
                    else
                    {
                        Logger.Instance.LogError($"An error was encountered while trying to run \"{LinkerPath}\" linker: {e.Message}.");
                    }
                }
                else
                {
                    Logger.Instance.LogError($"An unknown exception has been thrown in CLinkerTask. Message: { e.Message }.");
                }
                return(false);
            }
        }
Exemple #9
0
        public static string GetSecureNoticeNew(EventHandlerEnvironment env) //程序划图片表格
        {
            var rpd = new ReportPrintData();

            Writelog(env.Vault.Name + env.Input + "GetSecureNotice : 查询条件");
            try
            {
                var input = JsonConvert.DeserializeObject <ReportInput>(env.Input);

                #region search issuenotice

                var conditions = new SearchConditions();
                {
                    var condition = new SearchCondition
                    {
                        ConditionType = MFConditionType.MFConditionTypeEqual,
                        Expression    =
                        {
                            DataStatusValueType = MFStatusType.MFStatusTypeObjectTypeID
                        }
                    };
                    condition.TypedValue.SetValueToLookup(new Lookup {
                        Item = OtSecureAdjustNotice.ID
                    });
                    //    Writelog("OtSecureAdjustNotice=" + OtSecureAdjustNotice.ID);
                    conditions.Add(-1, condition);
                }
                {
                    var sc = new SearchCondition
                    {
                        ConditionType = MFConditionType.MFConditionTypeNotEqual,
                        Expression    = { DataStatusValueType = MFStatusType.MFStatusTypeDeleted }
                    };
                    sc.TypedValue.SetValue(MFDataType.MFDatatypeBoolean, true);
                    conditions.Add(-1, sc);
                }
                {
                    var condition = new SearchCondition
                    {
                        ConditionType = MFConditionType.MFConditionTypeGreaterThanOrEqual,
                        Expression    = { DataPropertyValuePropertyDef = PropCheckDate.ID }
                    };
                    //   Writelog("PropCheckDate=" + PropCheckDate.ID);
                    condition.TypedValue.SetValue(MFDataType.MFDatatypeDate, input.StartDate);
                    conditions.Add(-1, condition);
                }
                {
                    var condition = new SearchCondition
                    {
                        ConditionType = MFConditionType.MFConditionTypeLessThanOrEqual,
                        Expression    = { DataPropertyValuePropertyDef = PropCheckDate.ID }
                    };
                    condition.TypedValue.SetValue(MFDataType.MFDatatypeDate, input.EndDate);
                    conditions.Add(-1, condition);
                }
                if (input.Principal != 0)
                {
                    var condition = new SearchCondition();
                    //  Writelog("PropPrincipal=" + PropPrincipal.ID);
                    condition.ConditionType = MFConditionType.MFConditionTypeEqual;
                    condition.Expression.DataPropertyValuePropertyDef = PropPrincipal.ID;
                    condition.TypedValue.SetValueToLookup(new Lookup {
                        Item = input.Principal
                    });
                    conditions.Add(-1, condition);
                }
                if (input.Receiver != 0)
                {
                    var condition = new SearchCondition();
                    //    Writelog("PropSecureReceiver=" + PropSecureReceiver.ID);
                    condition.ConditionType = MFConditionType.MFConditionTypeEqual;
                    condition.Expression.DataPropertyValuePropertyDef = PropSecureReceiver.ID;
                    condition.TypedValue.SetValueToLookup(new Lookup {
                        Item = input.Receiver
                    });
                    conditions.Add(-1, condition);
                }
                ObjectVersions allwork = env.Vault.ObjectSearchOperations.SearchForObjectsByConditionsEx(conditions,
                                                                                                         MFSearchFlags.MFSearchFlagNone, false, 0, 0).GetAsObjectVersions();

                #endregion search issuenotice

                //  Writelog("allwork=" + allwork.Count);

                string templatefile = GetTemplateFile(env);

                try
                {
                    object oMissing = Missing.Value;
                    object objWhat  = WdGoToItem.wdGoToPage;
                    object objWhich = WdGoToDirection.wdGoToLast;
                    var    app      = new Application();
                    object unknow   = Type.Missing;
                    //  var msocoding = MsoEncoding.msoEncodingSimplifiedChineseGB18030;
                    Document doc = app.Documents.Open(templatefile,
                                                      ref unknow, false, ref unknow, ref unknow, ref unknow,
                                                      //        ref unknow, ref unknow, ref unknow, ref unknow, msocoding,
                                                      ref unknow, ref unknow, ref unknow, ref unknow, ref unknow,
                                                      ref unknow, ref unknow, ref unknow, ref unknow, ref unknow);

                    int    issueindex = 0;//问题唯一序号,跨页接续
                    int    tableindex = 1;
                    string temppath   = Path.GetTempPath();
                    doc.Content.Copy();

                    Writelog(String.Format("vault:{0},conditions{1},results:{2}", env.Vault.Name, env.Input,
                                           allwork.Count));
                    int  rowpos  = 1;//问题填写位置,每页刷新
                    bool newpage = false;
                    foreach (ObjectVersion objectVersion in allwork)
                    {
                        // Writelog("debug info aaaa");
                        if (newpage)
                        {
                            newpage = false;
                            //   Writelog("debug info bbbb");
                            object    nothing = Missing.Value;
                            Paragraph para    = doc.Content.Paragraphs.Add(ref nothing);
                            object    pBreak  = (int)WdBreakType.wdSectionBreakNextPage;
                            para.Range.InsertBreak(ref pBreak);
                            //   Writelog("debug info bbbb1111");

                            app.Selection.GoTo(ref objWhat, ref objWhich, ref unknow, ref unknow);
                            //    Writelog("debug info dddd");

                            app.Selection.Paste();
                            //   Writelog("debug info ffff");
                            tableindex++;
                            rowpos = 1;
                        }

                        PropertyValues onepvs = env.Vault.ObjectPropertyOperations.GetProperties(objectVersion.ObjVer);
                        issueindex++;

                        string issuename = env.Vault.Name;
                        //  Writelog("debug info 6666");
                        doc.Tables[tableindex].Cell(4, 2).Range.Text = issuename;


                        //   Writelog("debug info 7777");
                        int rowindex = 6 + rowpos;

                        string secureissuename = onepvs.SearchForProperty(PropIssueCategory).GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 1).Range.Text =
                            issueindex.ToString(CultureInfo.InvariantCulture);

                        doc.Tables[tableindex].Cell(rowindex, 2).Range.Text = secureissuename;
                        doc.Tables[tableindex].Cell(rowindex, 3).Range.Text =
                            onepvs.SearchForProperty(PropSecureIssues.ID).GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 4).Range.Text =
                            onepvs.SearchForProperty(PropAdjustMeasure.ID).GetValueAsLocalizedText();

                        doc.Tables[tableindex].Cell(rowindex, 5).Range.Text =
                            onepvs.SearchForProperty(PropPrincipal.ID)
                            .GetValueAsLocalizedText();


                        doc.Tables[tableindex].Cell(rowindex, 6).Range.Text =
                            onepvs.SearchForProperty(PropSecureReceiver.ID)
                            .GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 7).Range.Text =
                            onepvs.SearchForProperty(PropAdjustMan.ID)
                            .GetValueAsLocalizedText();


                        doc.Tables[tableindex].Cell(rowindex, 8).Range.Text =
                            onepvs.SearchForProperty(PropFuChaRen.ID)
                            .GetValueAsLocalizedText();
                        doc.Tables[tableindex].Cell(rowindex, 9).Range.Text =
                            onepvs.SearchForProperty(PropCountercheckDescription.ID)
                            .GetValueAsLocalizedText();
                        //       Writelog(string.Format("表 {0}, 行 {1},序号 {2}, 行号 {3}",tableindex,rowindex,issueindex,rowpos));
                        if (rowpos++ >= 10)
                        {
                            newpage = true;
                        }
                    }

                    int index = 0;
                    foreach (ObjectVersion objectVersion in allwork)
                    {
                        PropertyValues onepvs = env.Vault.ObjectPropertyOperations.GetProperties(objectVersion.ObjVer);

                        object    nothing = Missing.Value;
                        Paragraph para    = doc.Content.Paragraphs.Add(ref nothing);
                        object    pBreak  = (int)WdBreakType.wdSectionBreakNextPage;
                        para.Range.InsertBreak(ref pBreak);

                        app.Selection.GoTo(ref objWhat, ref objWhich, ref unknow, ref unknow);

                        app.Selection.PageSetup.Orientation = WdOrientation.wdOrientPortrait;
                        Range range = app.Selection.Range;
                        Table table = app.Selection.Tables.Add(range, 7, 1, ref oMissing, ref oMissing);

                        table.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleDouble;
                        table.Borders.InsideLineStyle  = WdLineStyle.wdLineStyleSingle;
                        table.Cell(1, 1).Split(1, 2);
                        for (int i = 2; i <= 3; i++)
                        {
                            table.Cell(i, 1).Split(1, 4);
                        }

                        //Writelog("debug info 888111");
                        //app.Selection.TypeText("序号:" + page);
                        //Writelog("debug info 999000 v1");
                        table.Cell(1, 1).Range.Text = "序号:";
                        table.Cell(1, 2).Range.Text = (++index).ToString(CultureInfo.InvariantCulture);
                        //table.Cell(1, 3).Range.Text = "存在问题:";
                        //table.Cell(1, 4).Range.Text =
                        //    onepvs.SearchForProperty(PropSecureIssues.ID).GetValueAsLocalizedText();
                        //Writelog("debug info 1111 v1-" + tableindex);
                        //table.Cell(rowindex, 1).Range.Text = "检查负责人:";
                        table.Cell(2, 1).Range.Text = "检查日期:";
                        //table.Cell(2, 2).Range.Text =
                        //    onepvs.SearchForProperty(PropPrincipal.ID)
                        //        .GetValueAsLocalizedText();
                        table.Cell(2, 2).Range.Text =
                            onepvs.SearchForProperty(PropCheckDate.ID)
                            .GetValueAsLocalizedText();
                        //Writelog("debug info 222 v1-" + tableindex);
                        //table.Cell(rowindex, 1).Range.Text = "接收人  :";
                        //table.Cell(rowindex++, 3).Range.Text = "整改人:";
                        //table.Cell(3, 2).Range.Text =
                        //    onepvs.SearchForProperty(PropSecureReceiver.ID)
                        //        .GetValueAsLocalizedText();
                        //table.Cell(3, 4).Range.Text =
                        //    onepvs.SearchForProperty(PropAdjustMan.ID)
                        //        .GetValueAsLocalizedText();
                        //   Writelog("debug info 333 v1-" + tableindex);
                        table.Cell(2, 3).Range.Text = "整改期限  :";
                        table.Cell(3, 3).Range.Text = "整改次数:";
                        table.Cell(2, 4).Range.Text =
                            onepvs.SearchForProperty(PropZhengGaiQiXin.ID)
                            .GetValueAsLocalizedText();
                        table.Cell(3, 4).Range.Text =
                            onepvs.SearchForProperty(PropRectificationCount.ID)
                            .GetValueAsLocalizedText();
                        //Writelog("debug info 444 v1-" + tableindex);
                        //table.Cell(rowindex, 1).Range.Text = "复查人  :";
                        table.Cell(3, 1).Range.Text = "复查日期:";
                        //table.Cell(5, 2).Range.Text =
                        //    onepvs.SearchForProperty(PropFuChaRen.ID)
                        //        .GetValueAsLocalizedText();
                        table.Cell(3, 2).Range.Text =
                            onepvs.SearchForProperty(PropReviewDate.ID)
                            .GetValueAsLocalizedText();
                        //    Writelog("debug info 555 v1-" + tableindex);
                        // int rowindex = 2;
                        table.Cell(4, 1).Range.Text = "整改前照片:";
                        table.Cell(6, 1).Range.Text = "复查照片:";
                        ObjectFiles files  = env.Vault.ObjectFileOperations.GetFiles(objectVersion.ObjVer);
                        int         picrow = 5;
                        //  Writelog("before 000000000000");
                        foreach (ObjectFile objectFile in files)
                        {
                            string apicture = temppath + objectFile.GetNameForFileSystem();
                            env.Vault.ObjectFileOperations.DownloadFile(objectFile.ID,
                                                                        objectFile.Version, apicture);
                            object      linkToFile       = false;
                            object      saveWithDocument = true;
                            object      anchor           = table.Cell(picrow, 1).Range;
                            InlineShape insh             = doc.InlineShapes.AddPicture(apicture, ref linkToFile,
                                                                                       ref saveWithDocument,
                                                                                       ref anchor);
                            insh.Height = 259;
                            insh.Width  = 416;
                            picrow     += 2;
                            if (picrow > 7)
                            {
                                break;
                            }
                        }
                    }
                    doc.Close();
                    app.Quit();
                }
                catch (Exception ex)
                {
                    Writelog(ex.Message);
                }

                var pvs = new PropertyValues();
                var pv  = new PropertyValue {
                    PropertyDef = 0
                };
                pv.Value.SetValue(MFDataType.MFDatatypeText, "securenoticereport");
                pvs.Add(-1, pv);
                pv.PropertyDef = 100;
                pv.Value.SetValueToLookup(new Lookup {
                    Item = ClassSecureReport
                });
                pvs.Add(-1, pv);
                var file = new SourceObjectFile {
                    Title = "report", SourceFilePath = templatefile, Extension = "docx"
                };

                try
                {
                    ObjectVersionAndProperties t = env.Vault.ObjectOperations.CreateNewSFDObject(0, pvs, file, true);
                    ObjectFiles f = env.Vault.ObjectFileOperations.GetFiles(t.ObjVer);

                    rpd.Objid       = t.ObjVer.ID;
                    rpd.Objtype     = t.ObjVer.Type;
                    rpd.Objversion  = t.ObjVer.Version;
                    rpd.Fileid      = f[1].FileVer.ID;
                    rpd.Fileversion = f[1].FileVer.Version;
                }
                catch (Exception ex)
                {
                    Writelog("getsecurenotice - create object :" + ex.Message);
                }
            }
            catch (Exception ex)
            {
                Writelog(env.Input + "GetSecureNotice error:" + ex.Message);
            }
            var ret = JsonConvert.SerializeObject(rpd, Formatting.None);
            Writelog("GetSecureNotice ok return:" + ret);
            return(ret);
        }
Exemple #10
0
        public bool Validate(Core.Framework.Provisioning.Model.FileCollection sourceFiles, Microsoft.SharePoint.Client.ClientContext ctx)
        {
            int scount = 0;
            int tcount = 0;

            try
            {
                // Check if this is not a noscript site as we're not allowed to write to the web property bag is that one
                bool isNoScriptSite = ctx.Web.IsNoScriptSite();

                foreach (var sf in sourceFiles)
                {
                    scount++;
                    string fileName   = sf.Src;
                    string folderName = sf.Folder;
                    string fileUrl    = UrlUtility.Combine(ctx.Web.ServerRelativeUrl, folderName + "/" + fileName);

                    // Skip the files we skipped to provision (if any)
                    if (ObjectFiles.SkipFile(isNoScriptSite, fileName, folderName))
                    {
                        continue;
                    }

                    var file = ctx.Web.GetFileByServerRelativeUrl(UrlUtility.Combine(ctx.Web.ServerRelativeUrl, folderName + "/" + fileName));
                    ctx.Load(file, f => f.Exists, f => f.Length);
                    ctx.ExecuteQueryRetry();

                    if (file.Exists)
                    {
                        tcount++;

                        #region File - Security
                        if (sf.Security != null)
                        {
                            ctx.Load(file, f => f.ListItemAllFields);
                            ctx.ExecuteQueryRetry();
                            bool isSecurityMatch = ValidateSecurityCSOM(ctx, sf.Security, file.ListItemAllFields);
                            if (!isSecurityMatch)
                            {
                                return(false);
                            }
                        }
                        #endregion

                        #region Overwrite validation
                        if (sf.Overwrite == false)
                        {
                            // lookup the original added file size...should be different from the one we retrieved from SharePoint since we opted to NOT overwrite
                            var files = System.IO.Directory.GetFiles(@".\framework\functional\templates");
                            foreach (var f in files)
                            {
                                if (f.Contains(sf.Src))
                                {
                                    if (new System.IO.FileInfo(f).Length == file.Length)
                                    {
                                        return(false);
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                // Return false if we get an exception
                Console.WriteLine(ex.ToDetailedString(ctx));
                return(false);
            }

            return(true);
        }
Exemple #11
0
        public override bool Execute()
        {
            if (String.IsNullOrEmpty(GCCBuild_ShellApp))
            {
                GCCBuild_ConvertPath = false;
            }
            if (!GCCBuild_ConvertPath)
            {
                GCCBuild_ShellApp = null;
            }
            if (!ObjectFiles.Any())
            {
                return(true);
            }



            Logger.Instance = new XBuildLogProvider(Log); // TODO: maybe initialise statically; this put in constructor causes NRE

            if (!ObjectFiles.Any())
            {
                return(true);
            }

            var lfiles = new List <string>();
            var ofiles = ObjectFiles.Select(x => x.ItemSpec);

            if (String.IsNullOrEmpty(GCCToolArchiverPath))
            {
                GCCToolArchiverPath = "";
            }

            string GCCToolArchiverCombined = GCCToolArchiverPath;

            ShellAppConversion shellApp = new ShellAppConversion(GCCBuild_SubSystem, GCCBuild_ShellApp, GCCBuild_PreRunApp,
                                                                 GCCBuild_ConvertPath, GCCBuild_ConvertPath_mntFolder, IntPath);

            if (OS.Equals("Windows_NT") && String.IsNullOrWhiteSpace(shellApp.shellapp))
            {
                GCCToolArchiverCombined = Utilities.FixAppPath(GCCToolArchiverCombined, GCCToolArchiverExe);
            }
            else
            {
                GCCToolArchiverCombined = Path.Combine(GCCToolArchiverPath, GCCToolArchiverExe);
            }

            string OutputFile_Converted = OutputFile;

            if (shellApp.convertpath)
            {
                OutputFile_Converted = shellApp.ConvertWinPathToWSL(OutputFile);
            }
            else if (!Directory.Exists(Path.GetDirectoryName(OutputFile)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(OutputFile));
            }


            // archiving - librerian
            Dictionary <string, string> Flag_overrides = new Dictionary <string, string>();

            Flag_overrides.Add("OutputFile", OutputFile_Converted);

            bool needRearchive = true;

            if (File.Exists(OutputFile))
            {
                needRearchive = false;
                FileInfo libInfo = fileinfoDict.GetOrAdd(OutputFile, (x) => new FileInfo(x));
                foreach (var obj in ObjectFiles.Select(x => x.ItemSpec).Concat(new string[] { ProjectFile }))
                {
                    string depfile = obj;

                    if (shellApp.convertpath)
                    {
                        depfile = shellApp.ConvertWSLPathToWin(obj);//here convert back to Windows path
                    }
                    FileInfo fi = fileinfoDict.GetOrAdd(depfile, (x) => new FileInfo(x));
                    if (fi.Exists == false || fi.Attributes == FileAttributes.Directory || fi.Attributes == FileAttributes.Device)
                    {
                        continue;
                    }
                    if (fi.LastWriteTime > libInfo.LastWriteTime)
                    {
                        needRearchive = true;
                        break;
                    }
                }
            }

            var flags = Utilities.GetConvertedFlags(GCCToolArchiver_Flags, GCCToolArchiver_AllFlags, ObjectFiles[0], Flag_overrides, shellApp);

            using (var runWrapper = new RunWrapper(GCCToolArchiverCombined, flags, shellApp, GCCToolSupportsResponsefile))
            {
                bool result = true;
                if (needRearchive)
                {
                    TryDeleteFile(OutputFile);
                    Logger.Instance.LogCommandLine($"{GCCToolArchiverCombined} {flags}");
                    result = runWrapper.RunArchiver(String.IsNullOrEmpty(ObjectFiles[0].GetMetadata("SuppressStartupBanner")) || ObjectFiles[0].GetMetadata("SuppressStartupBanner").Equals("true") ? false : true);
                }


                if (result)
                {
                    string allofiles = String.Join(",", ofiles);
                    if (allofiles.Length > 100)
                    {
                        allofiles = allofiles.Substring(0, 100) + "...";
                    }
                    if (needRearchive)
                    {
                        Logger.Instance.LogMessage($"  ({allofiles}) => {OutputFile_Converted}");
                    }
                    else
                    {
                        Logger.Instance.LogMessage($"  ({allofiles}) => {OutputFile_Converted} (not archive - already up to date)");
                    }
                }

                return(result);
            }
        }
Exemple #12
0
        public override bool Execute()
        {
            Logger.Instance = new XBuildLogProvider(Log); // TODO: maybe initialise statically; this put in constructor causes NRE

            if (!ObjectFiles.Any())
            {
                return(true);
            }

            var lfiles = new List <string>();
            var ofiles = ObjectFiles.Select(x => x.ItemSpec);

            if (String.IsNullOrEmpty(GCCToolLinkerPath))
            {
                GCCToolLinkerPath = "";
            }
            GCCToolLinkerPathCombined = GCCToolLinkerPath;

            shellApp = new ShellAppConversion(GCCBuild_SubSystem, GCCBuild_ShellApp, GCCBuild_PreRunApp,
                                              GCCBuild_ConvertPath, GCCBuild_ConvertPath_mntFolder, IntPath);

            if (OS.Equals("Windows_NT") && String.IsNullOrWhiteSpace(shellApp.shellapp))
            {
                GCCToolLinkerPathCombined = Utilities.FixAppPath(GCCToolLinkerPathCombined, GCCToolLinkerExe);
            }
            else
            {
                GCCToolLinkerPathCombined = Path.Combine(GCCToolLinkerPath, GCCToolLinkerExe);
            }

            string OutputFile_Converted = OutputFile;

            if (shellApp.convertpath)
            {
                OutputFile_Converted = shellApp.ConvertWinPathToWSL(OutputFile);
            }

            else if (!Directory.Exists(Path.GetDirectoryName(OutputFile)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(OutputFile));
            }


            // linking
            Dictionary <string, string> Flag_overrides = new Dictionary <string, string>();

            Flag_overrides.Add("OutputFile", OutputFile_Converted);

            var flags = Utilities.GetConvertedFlags(GCCToolLinker_Flags, GCCToolLinker_AllFlags, ObjectFiles[0], Flag_overrides, shellApp);

            Logger.Instance.LogCommandLine($"{GCCToolLinkerPathCombined} {flags}");

            using (var runWrapper = new RunWrapper(GCCToolLinkerPathCombined, flags, shellApp, GCCToolSupportsResponsefile))
            {
                bool result = runWrapper.RunLinker(String.IsNullOrEmpty(ObjectFiles[0].GetMetadata("SuppressStartupBanner")) || ObjectFiles[0].GetMetadata("SuppressStartupBanner").Equals("true") ? false : true);
                if (result)
                {
                    string allofiles = String.Join(",", ofiles);
                    if (allofiles.Length > 100)
                    {
                        allofiles = allofiles.Substring(0, 100) + "...";
                    }
                    Logger.Instance.LogMessage($"  ({allofiles}) => {OutputFile_Converted}");
                }

                return(result);
            }
        }