示例#1
0
        public void CanSetComponentFieldInFileTupleByNew()
        {
            var fileTuple = new FileTuple();

            fileTuple.Component_ = "Foo";
            Assert.Equal("Foo", fileTuple.Component_);
        }
示例#2
0
        public PrgState execute(PrgState state)
        {
            MyIStack <IStmt> stk = state.getExeStack();
            // stk.pop();

            MyIDictionary <String, int> symTbl  = state.getSymTable();
            IFileTable <int, FileTuple> fileTbl = state.getFileTable();

            int value_exp = this.exp_file_id.eval(symTbl);


            FileTuple ft = fileTbl.getValue(value_exp);

            if (!fileTbl.isDefined(value_exp))
            {
                throw new Exception("The key is not defined in the file table");
            }

            StreamReader streamReader = fileTbl.getValue(value_exp).getStreamReader();

            try
            {
                streamReader.Close();
            }
            catch (IOException ex) { throw new Exception(ex.Message); }

            fileTbl.remove(value_exp);
            return(state);
        }
示例#3
0
        public void CanCheckNameofField()
        {
            var fileTuple = new FileTuple();

            Assert.Equal("Component_", fileTuple.Definition.FieldDefinitions[1].Name);
            Assert.Null(fileTuple.Fields[0]);
            fileTuple.Component_ = "Foo";
            Assert.Equal("Component_", fileTuple.Fields[1].Name);
            Assert.Same(fileTuple.Definition.FieldDefinitions[1].Name, fileTuple.Fields[1].Name);
        }
示例#4
0
        public void CanGetContext()
        {
            using (new IntermediateFieldContext("bar"))
            {
                var fileTuple = new FileTuple();
                fileTuple.Component_ = "Foo";

                var field = fileTuple[FileTupleFields.Component_];
                Assert.Equal("Foo", field.AsString());
                Assert.Equal("bar", field.Context);
            }
        }
示例#5
0
        public void CanSetInNestedContext()
        {
            var fileTuple = new FileTuple();

            using (new IntermediateFieldContext("bar"))
            {
                fileTuple.Component_ = "Foo";

                var field = fileTuple[FileTupleFields.Component_];
                Assert.Equal("Foo", field.AsString());
                Assert.Equal("bar", field.Context);

                using (new IntermediateFieldContext("baz"))
                {
                    fileTuple.Component_ = "Foo2";

                    field = fileTuple[FileTupleFields.Component_];
                    Assert.Equal("Foo2", field.AsString());
                    Assert.Equal("baz", field.Context);

                    Assert.Equal("Foo", (string)field.PreviousValue);
                    Assert.Equal("bar", field.PreviousValue.Context);
                }

                fileTuple.Component_ = "Foo3";

                field = fileTuple[FileTupleFields.Component_];
                Assert.Equal("Foo3", field.AsString());
                Assert.Equal("bar", field.Context);

                Assert.Equal("Foo2", (string)field.PreviousValue);
                Assert.Equal("baz", field.PreviousValue.Context);

                Assert.Equal("Foo", (string)field.PreviousValue.PreviousValue);
                Assert.Equal("bar", field.PreviousValue.PreviousValue.Context);
            }

            fileTuple.Component_ = "Foo4";

            var fieldOutside = fileTuple[FileTupleFields.Component_];

            Assert.Equal("Foo4", fieldOutside.AsString());
            Assert.Null(fieldOutside.Context);
        }
示例#6
0
        public PrgState execute(PrgState state)
        {
            MyIStack <IStmt>            stk     = state.getExeStack();
            MyIDictionary <String, int> symTbl  = state.getSymTable();
            IFileTable <int, FileTuple> fileTbl = state.getFileTable();

            int value_exp = this.exp_file_id.eval(symTbl);

            FileTuple ft = fileTbl.getValue(value_exp);

            if (!symTbl.isDefined(ft.getFileName()))
            {
                //throw new MyStmtExecException("The key is not defined in the file table");
            }

            StreamReader streamReader = ft.getStreamReader();
            int          val          = -1;

            try
            {
                String line = streamReader.ReadLine();

                if (line == null)
                {
                    val = 0;
                }
                else
                {
                    try
                    {
                        val = int.Parse(line);
                    }
                    catch (Exception ex) { Console.WriteLine(ex.Message); }
                }


                symTbl.put(this.var_name, val);
            }
            catch (IOException ex) { throw new Exception(ex.Message); }
            return(state);
        }
示例#7
0
        public PrgState execute(PrgState state)
        {
            MyIStack <IStmt>            stk       = state.getExeStack();
            IFileTable <int, FileTuple> filetable = state.getFileTable();
            MyIDictionary <String, int> symTbl    = state.getSymTable();

            try
            {
                FileStream   reader         = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
                StreamReader bufferedStream = new StreamReader(reader);
                int          id             = IdGenerator.generateId();
                FileTuple    tuple          = new FileTuple(this.filename, bufferedStream);
                filetable.put(id, tuple);

                symTbl.put(this.var_file_id, id);
            }
            catch (Exception ex) { throw new Exception(ex.Message); }


            return(state);
        }
示例#8
0
        private void AddFileTuple(FileTuple tuple, Output output)
        {
            var table = output.EnsureTable(this.TableDefinitions["File"]);
            var row   = (FileRow)table.CreateRow(tuple.SourceLineNumbers);

            row.File      = tuple.File;
            row.Component = tuple.Component_;
            row.FileName  = GetMsiFilenameValue(tuple.ShortFileName, tuple.LongFileName);
            row.FileSize  = tuple.FileSize;
            row.Version   = tuple.Version;
            row.Language  = tuple.Language;

            var attributes = tuple.Checksum ? MsiInterop.MsidbFileAttributesChecksum : 0;

            attributes    |= (tuple.Compressed.HasValue && tuple.Compressed.Value) ? MsiInterop.MsidbFileAttributesCompressed : 0;
            attributes    |= (tuple.Compressed.HasValue && !tuple.Compressed.Value) ? MsiInterop.MsidbFileAttributesNoncompressed : 0;
            attributes    |= tuple.Hidden ? MsiInterop.MsidbFileAttributesHidden : 0;
            attributes    |= tuple.ReadOnly ? MsiInterop.MsidbFileAttributesReadOnly : 0;
            attributes    |= tuple.System ? MsiInterop.MsidbFileAttributesSystem : 0;
            attributes    |= tuple.Vital ? MsiInterop.MsidbFileAttributesVital : 0;
            row.Attributes = attributes;
        }
示例#9
0
 public FileFacade(FileTuple file, WixFileTuple wixFile, WixDeltaPatchFileTuple deltaPatchFile)
 {
     this.File           = file;
     this.WixFile        = wixFile;
     this.DeltaPatchFile = deltaPatchFile;
 }
示例#10
0
 public FileFacade(bool fromModule, FileTuple file, WixFileTuple wixFile)
 {
     this.FromModule = fromModule;
     this.File       = file;
     this.WixFile    = wixFile;
 }
示例#11
0
        private bool CreateFacadesForMergeModuleFiles(WixMergeTuple wixMergeRow, List <FileFacade> mergeModulesFileFacades, Dictionary <string, FileFacade> indexedFileFacades)
        {
            bool containsFiles = false;

            try
            {
                // read the module's File table to get its FileMediaInformation entries and gather any other information needed from the module.
                using (Database db = new Database(wixMergeRow.SourceFile, OpenDatabase.ReadOnly))
                {
                    if (db.TableExists("File") && db.TableExists("Component"))
                    {
                        Dictionary <string, FileFacade> uniqueModuleFileIdentifiers = new Dictionary <string, FileFacade>(StringComparer.OrdinalIgnoreCase);

                        using (View view = db.OpenExecuteView("SELECT `File`, `Directory_` FROM `File`, `Component` WHERE `Component_`=`Component`"))
                        {
                            // add each file row from the merge module into the file row collection (check for errors along the way)
                            while (true)
                            {
                                using (Record record = view.Fetch())
                                {
                                    if (null == record)
                                    {
                                        break;
                                    }

                                    // NOTE: this is very tricky - the merge module file rows are not added to the
                                    // file table because they should not be created via idt import.  Instead, these
                                    // rows are created by merging in the actual modules.
                                    var fileRow = new FileTuple(wixMergeRow.SourceLineNumbers, new Identifier(record[1], AccessModifier.Private));
                                    fileRow.File       = record[1];
                                    fileRow.Compressed = wixMergeRow.FileCompression;
                                    //FileRow fileRow = (FileRow)this.FileTable.CreateRow(wixMergeRow.SourceLineNumbers, false);
                                    //fileRow.File = record[1];
                                    //fileRow.Compressed = wixMergeRow.FileCompression;

                                    var wixFileRow = new WixFileTuple(wixMergeRow.SourceLineNumbers);
                                    wixFileRow.Directory_ = record[2];
                                    wixFileRow.DiskId     = wixMergeRow.DiskId;
                                    wixFileRow.PatchGroup = -1;
                                    wixFileRow.Source     = new IntermediateFieldPathValue {
                                        Path = Path.Combine(this.IntermediateFolder, wixMergeRow.Id.Id, record[1])
                                    };
                                    //WixFileRow wixFileRow = (WixFileRow)this.WixFileTable.CreateRow(wixMergeRow.SourceLineNumbers, false);
                                    //wixFileRow.Directory = record[2];
                                    //wixFileRow.DiskId = wixMergeRow.DiskId;
                                    //wixFileRow.PatchGroup = -1;
                                    //wixFileRow.Source = Path.Combine(this.IntermediateFolder, "MergeId.", wixMergeRow.Number.ToString(CultureInfo.InvariantCulture), record[1]);

                                    var mergeModuleFileFacade = new FileFacade(true, fileRow, wixFileRow);

                                    // If case-sensitive collision with another merge module or a user-authored file identifier.
                                    if (indexedFileFacades.TryGetValue(mergeModuleFileFacade.File.File, out var collidingFacade))
                                    {
                                        this.Messaging.Write(ErrorMessages.DuplicateModuleFileIdentifier(wixMergeRow.SourceLineNumbers, wixMergeRow.Id.Id, collidingFacade.File.File));
                                    }
                                    else if (uniqueModuleFileIdentifiers.TryGetValue(mergeModuleFileFacade.File.File, out collidingFacade)) // case-insensitive collision with another file identifier in the same merge module
                                    {
                                        this.Messaging.Write(ErrorMessages.DuplicateModuleCaseInsensitiveFileIdentifier(wixMergeRow.SourceLineNumbers, wixMergeRow.Id.Id, mergeModuleFileFacade.File.File, collidingFacade.File.File));
                                    }
                                    else // no collision
                                    {
                                        mergeModulesFileFacades.Add(mergeModuleFileFacade);

                                        // Keep updating the indexes as new rows are added.
                                        indexedFileFacades.Add(mergeModuleFileFacade.File.File, mergeModuleFileFacade);
                                        uniqueModuleFileIdentifiers.Add(mergeModuleFileFacade.File.File, mergeModuleFileFacade);
                                    }

                                    containsFiles = true;
                                }
                            }
                        }
                    }

                    // Get the summary information to detect the Schema
                    using (SummaryInformation summaryInformation = new SummaryInformation(db))
                    {
                        string moduleInstallerVersionString = summaryInformation.GetProperty(14);

                        try
                        {
                            int moduleInstallerVersion = Convert.ToInt32(moduleInstallerVersionString, CultureInfo.InvariantCulture);
                            if (moduleInstallerVersion > this.OutputInstallerVersion)
                            {
                                this.Messaging.Write(WarningMessages.InvalidHigherInstallerVersionInModule(wixMergeRow.SourceLineNumbers, wixMergeRow.Id.Id, moduleInstallerVersion, this.OutputInstallerVersion));
                            }
                        }
                        catch (FormatException)
                        {
                            throw new WixException(ErrorMessages.MissingOrInvalidModuleInstallerVersion(wixMergeRow.SourceLineNumbers, wixMergeRow.Id.Id, wixMergeRow.SourceFile, moduleInstallerVersionString));
                        }
                    }
                }
            }
            catch (FileNotFoundException)
            {
                throw new WixException(ErrorMessages.FileNotFound(wixMergeRow.SourceLineNumbers, wixMergeRow.SourceFile));
            }
            catch (Win32Exception)
            {
                throw new WixException(ErrorMessages.CannotOpenMergeModule(wixMergeRow.SourceLineNumbers, wixMergeRow.Id.Id, wixMergeRow.SourceFile));
            }

            return(containsFiles);
        }