Пример #1
0
        public static async Task InsertSectionAsync()
        {
            await SectionTable.InsertSection(CommandInsertModel.InsertSection());

            SectionContextList.Add(CommandModel.GetSectionContext());
            return;
        }
        /// <summary>
        /// Gets the definition of an item.
        /// </summary>
        /// <param name="itemId">The item ID.</param>
        /// <param name="context">The context.</param>
        /// <returns>Sitecore.Data.ItemDefinition.</returns>
        public override ItemDefinition GetItemDefinition(ID itemId, CallContext context)
        {
            if (!_setupComplete)
            {
                return(base.GetItemDefinition(itemId, context));
            }

            var sectiontable = SectionTable.ToList();//prevent "Collection was modified"
            var section      = sectiontable.FirstOrDefault(x => x.SectionId == itemId);

            if (section != null)
            {
                return(new GlassItemDefinition(itemId, section.Name, SectionTemplateId, ID.Null));
            }

            var fieldtable = FieldTable.ToList();//prevent "Collection was modified"
            var field      = fieldtable.FirstOrDefault(x => x.FieldId == itemId);

            if (field != null)
            {
                return(new GlassItemDefinition(itemId, field.Name, FieldTemplateId, ID.Null));
            }

            return(base.GetItemDefinition(itemId, context));
        }
Пример #3
0
        protected override void CreateSections(EmitContext context)
        {
            CreateTextSection();

            if (Assembly.RootResourceDirectory != null)
            {
                CreateResourceSection();
            }

            if (Assembly.RelocationDirectory != null)
            {
                CreateRelocationSection();
            }

            Assembly.SectionHeaders.Clear();
            Assembly.SectionHeaders.Add(_textSectionHeader);

            if (_relocSectionHeader != null)
            {
                Assembly.SectionHeaders.Add(_relocSectionHeader);
            }
            if (_rsrcSectionHeader != null)
            {
                Assembly.SectionHeaders.Add(_rsrcSectionHeader);
            }

            foreach (var section in Assembly.GetSections())
            {
                SectionTable.AddSection(section);
            }
        }
Пример #4
0
        public SectionViewerForm(SectionTable sectionTable)
            : this()
        {
            listView.BeginUpdate();

            try
            {
                foreach(SectionTableEntry entry in sectionTable)
                {
                    ListViewItem item = listView.Items.Add(entry.Name);

                    item.UseItemStyleForSubItems = true;
                    item.Font = lblFont.Font;

                    item.SubItems.Add(entry.VirtualAddress.ToString("X8"));
                    item.SubItems.Add(entry.VirtualSizeOrPhysicalAddress.ToString("X8"));
                    item.SubItems.Add(entry.PointerToRawData.ToString("X8"));
                    item.SubItems.Add(entry.SizeOfRawData.ToString("X8"));
                    item.SubItems.Add(entry.Characteristics.ToString("X8"));
                }
            }
            finally
            {
                listView.EndUpdate();
            }
        }
Пример #5
0
        private void UpdateFileHeader()
        {
            var header = Assembly.NtHeaders.FileHeader;

            header.NumberOfSections     = (ushort)SectionTable.GetSections().Count();
            header.SizeOfOptionalHeader = 0xE0;
        }
        /// <summary>
        /// Gets the fields of a specific item version.
        /// </summary>
        /// <param name="itemDefinition">The item.</param>
        /// <param name="versionUri">The version URI.</param>
        /// <param name="context">The context.</param>
        /// <returns>Sitecore.Data.FieldList.</returns>
        public override FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, CallContext context)
        {
            if (!_setupComplete)
            {
                return(base.GetItemFields(itemDefinition, versionUri, context));
            }

            var fields = new FieldList();

            var sectionTable = SectionTable.ToList();//prevent "Collection was modified"
            var sectionInfo  = sectionTable.FirstOrDefault(x => x.SectionId == itemDefinition.ID);

            if (sectionInfo != null)
            {
                GetStandardFields(fields, sectionInfo.SectionSortOrder >= 0 ? sectionInfo.SectionSortOrder : 100);

                return(fields);
            }

            var fieldtable = FieldTable.ToList();//prevent "Collection was modified"
            var fieldInfo  = fieldtable.FirstOrDefault(x => x.FieldId == itemDefinition.ID);

            if (fieldInfo != null)
            {
                GetStandardFields(fields, fieldInfo.FieldSortOrder >= 0 ? fieldInfo.FieldSortOrder : 100);
                GetFieldFields(fieldInfo, fields);
                return(fields);
            }

            return(base.GetItemFields(itemDefinition, versionUri, context));
        }
Пример #7
0
        /// <summary>
        /// Gets the fields of a specific item version.
        /// </summary>
        /// <param name="itemDefinition">The item.</param>
        /// <param name="versionUri">The version URI.</param>
        /// <param name="context">The context.</param>
        /// <returns>Sitecore.Data.FieldList.</returns>
        public override FieldList GetItemFields(ItemDefinition itemDefinition, VersionUri versionUri, CallContext context)
        {
            if (!_setupComplete)
            {
                return(base.GetItemFields(itemDefinition, versionUri, context));
            }

            var fields = new FieldList();

            var sectionInfo = SectionTable.FirstOrDefault(x => x.SectionId == itemDefinition.ID);

            if (sectionInfo != null)
            {
                GetStandardFields(fields,
                                  sectionInfo.SectionSortOrder >= 0
                        ? sectionInfo.SectionSortOrder
                        : (SectionTable.IndexOf(sectionInfo) + 100));

                return(fields);
            }

            var fieldInfo = FieldTable.FirstOrDefault(x => x.FieldId == itemDefinition.ID);

            if (fieldInfo != null)
            {
                GetStandardFields(fields,
                                  fieldInfo.FieldSortOrder >= 0 ? fieldInfo.FieldSortOrder : (FieldTable.IndexOf(fieldInfo) + 100));
                GetFieldFields(fieldInfo, fields);
                return(fields);
            }

            return(base.GetItemFields(itemDefinition, versionUri, context));
        }
        /// <summary>
        /// Gets the parent ID of an item.
        /// </summary>
        /// <param name="itemDefinition">The item definition.</param>
        /// <param name="context">The context.</param>
        /// <returns>Sitecore.Data.ID.</returns>
        public override ID GetParentID(ItemDefinition itemDefinition, CallContext context)
        {
            if (!_setupComplete)
            {
                return(base.GetParentID(itemDefinition, context));
            }

            var sectionTable = SectionTable.ToList();//prevent "Collection was modified"
            var section      = sectionTable.FirstOrDefault(x => x.SectionId == itemDefinition.ID);

            if (section != null)
            {
                return(section.TemplateId);
            }

            var fieldtable = FieldTable.ToList();//prevent "Collection was modified"
            var field      = fieldtable.FirstOrDefault(x => x.FieldId == itemDefinition.ID);

            if (field != null)
            {
                return(field.SectionId);
            }

            return(base.GetParentID(itemDefinition, context));
        }
Пример #9
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var source = new MvxSimpleTableViewSource(SectionTable, "MenuTableViewCell", MenuTableViewCell.Key);

            SectionTable.RowHeight = 50;

            var set = this.CreateBindingSet <MenuView, MenuViewModel>();

            set.Bind(source).To(vm => vm.Sections);

            var addItem = new UIBarButtonItem(UIBarButtonSystemItem.Add)
            {
                Title = "New"
            };

            set.Bind(addItem).To(vm => vm.AddCommand);

            NavigationItem.RightBarButtonItem = addItem;

            set.Apply();

            SectionTable.Source = source;

            SectionTable.ReloadData();
        }
Пример #10
0
        private IDList GetChildIDsTemplate(SitecoreClassConfig template, ItemDefinition itemDefinition)
        {
            IDList fields = new IDList();

            List <string> processed = new List <string>();
            var           sections  = template.Properties
                                      .Where(x => x.Property.DeclaringType == template.Type)
                                      .Select(x => x.Attribute).OfType <SitecoreFieldAttribute>()
                                      .Select(x => x.SectionName);

            foreach (var section in sections)
            {
                if (processed.Contains(section) || section.IsNullOrEmpty())
                {
                    continue;
                }

                var record = SectionTable.FirstOrDefault(x => x.TemplateId == itemDefinition.ID && x.Name == section);

                if (record == null)
                {
                    record = new SectionInfo(section, new ID(Guid.NewGuid()), itemDefinition.ID);
                    SectionTable.Add(record);
                }
                processed.Add(section);
                fields.Add(record.SectionId);
            }
            return(fields);
        }
        public void WhenIReadTheSectionTables()
        {
            var fileName = ScenarioContext.Current.Get <string>("FileName");
            var filePath = string.Format(@".\TestArtifacts\{0}", fileName);

            if (!File.Exists(filePath))
            {
                filePath = string.Format(@".\{0}", fileName);
                Console.WriteLine(string.Format(@"File not Found: .\TestArtifacts\{0}", fileName));
            }
            using (FileStream inputFile = File.OpenRead(filePath))
            {
                var msdos20Section = ScenarioContext.Current.Get <MSDOS20Section>("MSDOS20Section");
                var coffHeader     = ScenarioContext.Current.Get <COFFHeader>("COFFHeader");
                var coffOptionalHeaderStandardFields = ScenarioContext.Current.Get <COFFOptionalHeaderStandardFields>("COFFOptionalHeaderStandardFields");
                List <SectionTable> sectionTables    = new List <SectionTable>();
                inputFile.Position = SectionTable.StartingPosition(msdos20Section, coffOptionalHeaderStandardFields);
                for (int i = 0; i < coffHeader.NumberOfSections; i++)
                {
                    SectionTable?sectionTable =
                        inputFile.ReadStructure <SectionTable>();
                    sectionTables.Add(sectionTable.Value);
                }
                ScenarioContext.Current.Add("SectionTables", sectionTables);
            }
        }
        public override global::Sitecore.Data.FieldList GetItemFields(global::Sitecore.Data.ItemDefinition itemDefinition, global::Sitecore.Data.VersionUri versionUri, CallContext context)
        {
            Setup(context);

            FieldList fields = new FieldList();

            var sectionInfo = SectionTable.FirstOrDefault(x => x.SectionId == itemDefinition.ID);

            if (sectionInfo != null)
            {
                GetStandardFields(fields, sectionInfo.SectionSortOrder >= 0 ? sectionInfo.SectionSortOrder : (SectionTable.IndexOf(sectionInfo) + 100));

                return(fields);
            }

            var fieldInfo = FieldTable.FirstOrDefault(x => x.FieldId == itemDefinition.ID);

            if (fieldInfo != null)
            {
                GetStandardFields(fields, fieldInfo.FieldSortOrder >= 0 ? fieldInfo.FieldSortOrder : (FieldTable.IndexOf(fieldInfo) + 100));
                GetFieldFields(fieldInfo, fields);
                return(fields);
            }

            return(base.GetItemFields(itemDefinition, versionUri, context));
        }
Пример #13
0
        public static async Task <IList <string> > GetSectionsAsync()
        {
            IList <string> Sections = new List <string>();

            Sections = await SectionTable.ReadSectionTable(CommandReadModel.ReadSectionTable());

            return(Sections);
        }
Пример #14
0
        public void TestReadWrite()
        {
            FileInformationBlock fib = _hWPFDocFixture._fib;

            byte[] mainStream  = _hWPFDocFixture._mainStream;
            byte[] tableStream = _hWPFDocFixture._tableStream;
            int    fcMin       = fib.GetFcMin();

            CPSplitCalculator cps = new CPSplitCalculator(fib);

            ComplexFileTable cft = new ComplexFileTable(mainStream, tableStream, fib.GetFcClx(), fcMin);
            TextPieceTable   tpt = cft.GetTextPieceTable();

            SectionTable sectionTable = new SectionTable(mainStream, tableStream,
                                                         fib.GetFcPlcfsed(),
                                                         fib.GetLcbPlcfsed(),
                                                         fcMin, tpt, cps);
            HWPFFileSystem fileSys = new HWPFFileSystem();

            sectionTable.WriteTo(fileSys, 0);
            MemoryStream tableOut = fileSys.GetStream("1Table");
            MemoryStream mainOut  = fileSys.GetStream("WordDocument");

            byte[] newTableStream = tableOut.ToArray();
            byte[] newMainStream  = mainOut.ToArray();

            SectionTable newSectionTable = new SectionTable(
                newMainStream, newTableStream, 0,
                newTableStream.Length, 0, tpt, cps);

            List <SEPX> oldSections = sectionTable.GetSections();
            List <SEPX> newSections = newSectionTable.GetSections();

            Assert.AreEqual(oldSections.Count, newSections.Count);

            //test for proper char offset conversions
            PlexOfCps oldSedPlex = new PlexOfCps(tableStream, fib.GetFcPlcfsed(),
                                                 fib.GetLcbPlcfsed(), 12);
            PlexOfCps newSedPlex = new PlexOfCps(newTableStream, 0,
                                                 newTableStream.Length, 12);

            Assert.AreEqual(oldSedPlex.Length, newSedPlex.Length);

            for (int x = 0; x < oldSedPlex.Length; x++)
            {
                Assert.AreEqual(oldSedPlex.GetProperty(x).Start, newSedPlex.GetProperty(x).Start);
                Assert.AreEqual(oldSedPlex.GetProperty(x).End, newSedPlex.GetProperty(x).End);
            }

            int size = oldSections.Count;

            for (int x = 0; x < size; x++)
            {
                PropertyNode oldNode = (PropertyNode)oldSections[x];
                PropertyNode newNode = (PropertyNode)newSections[x];
                Assert.AreEqual(oldNode, newNode);
            }
        }
Пример #15
0
        /// <summary>
        /// Gets the child I ds template.
        /// </summary>
        /// <param name="template">The template.</param>
        /// <param name="itemDefinition">The item definition.</param>
        /// <param name="context">The context.</param>
        /// <param name="sqlProvider">The SQL provider.</param>
        /// <returns>
        /// IDList.
        /// </returns>
        private IDList GetChildIDsTemplate(SitecoreTypeConfiguration template, ItemDefinition itemDefinition, CallContext context, DataProvider sqlProvider)
        {
            var fields    = new IDList();
            var processed = new List <string>();
            var sections  = template.Properties
                            .Where(x => x.PropertyInfo.DeclaringType == template.Type)
                            .OfType <SitecoreFieldConfiguration>()
                            .Select(x => new { x.SectionName, x.SectionSortOrder });

            //If sitecore contains a section with the same name in the database, use that one instead of creating a new one
            var existing = sqlProvider.GetChildIDs(itemDefinition, context).OfType <ID>().Select(id => sqlProvider.GetItemDefinition(id, context))
                           .Where(item => item.TemplateID == SectionTemplateId).ToList();

            foreach (var section in sections)
            {
                if (processed.Contains(section.SectionName) || section.SectionName.IsNullOrEmpty())
                {
                    continue;
                }

                var record = SectionTable.FirstOrDefault(x => x.TemplateId == itemDefinition.ID && x.Name == section.SectionName);

                if (record == null)
                {
                    var       exists       = existing.FirstOrDefault(def => def.Name.Equals(section.SectionName, StringComparison.InvariantCultureIgnoreCase));
                    var       newId        = GetUniqueGuid(itemDefinition.ID + section.SectionName);
                    const int newSortOrder = 100;

                    record = exists != null ?
                             new SectionInfo(section.SectionName, exists.ID, itemDefinition.ID, section.SectionSortOrder)
                    {
                        Existing = true
                    } :
                    new SectionInfo(section.SectionName, new ID(newId), itemDefinition.ID, newSortOrder);

                    SectionTable.Add(record);
                }

                processed.Add(section.SectionName);

                if (!record.Existing)
                {
                    fields.Add(record.SectionId);
                }
            }

            //we need to add sections already in the db, 'cause we have to
            foreach (var sqlOne in existing.Where(ex => SectionTable.All(s => s.SectionId != ex.ID)))
            {
                SectionTable.Add(new SectionInfo(sqlOne.Name, sqlOne.ID, itemDefinition.ID, 0)
                {
                    Existing = true
                });
            }

            return(fields);
        }
Пример #16
0
        protected void LoadCBLSection(object o, EventArgs e)
        {
            var res = new SectionTable(db).GetAllSection();

            cbSection.DataSource = res;
            cbSection.DataBind();

            cbSection2.DataSource = res;
            cbSection2.DataBind();
        }
        private IDList GetChildIDsTemplate(SitecoreClassConfig template, ItemDefinition itemDefinition, CallContext context)
        {
            IDList fields = new IDList();

            List <string> processed = new List <string>();
            var           sections  = template.Properties
                                      .Where(x => x.Property.DeclaringType == template.Type)
                                      .Select(x => x.Attribute).OfType <SitecoreFieldAttribute>()
                                      .Select(x => new { x.SectionName, x.SectionSortOrder });

            var providers     = Database.GetDataProviders();
            var otherProvider = providers.FirstOrDefault(x => !(x is GlassDataProvider));
            //If sitecore contains a section with the same name in the database, use that one instead of creating a new one
            var existing = otherProvider.GetChildIDs(itemDefinition, context).OfType <ID>().Select(id => otherProvider.GetItemDefinition(id, context)).ToList();

            foreach (var section in sections)
            {
                if (processed.Contains(section.SectionName) || section.SectionName.IsNullOrEmpty())
                {
                    continue;
                }

                var record = SectionTable.FirstOrDefault(x => x.TemplateId == itemDefinition.ID && x.Name == section.SectionName);

                if (record == null)
                {
                    var exists = existing.FirstOrDefault(def => def.Name.Equals(section));
                    if (exists != null)
                    {
                        record = new SectionInfo(section.SectionName, exists.ID, itemDefinition.ID, section.SectionSortOrder)
                        {
                            Existing = true
                        };
                    }
                    else
                    {
                        record = new SectionInfo(section.SectionName, new ID(Guid.NewGuid()), itemDefinition.ID, section.SectionSortOrder);
                    }
                    SectionTable.Add(record);
                }
                processed.Add(section.SectionName);
                if (!record.Existing)
                {
                    fields.Add(record.SectionId);
                }
            }
            return(fields);
        }
Пример #18
0
        public override global::Sitecore.Collections.IDList GetChildIDs(global::Sitecore.Data.ItemDefinition itemDefinition, CallContext context)
        {
            if (Classes.Any(x => x.Value.TemplateId == itemDefinition.ID.Guid))
            {
                var cls = Classes.First(x => x.Value.TemplateId == itemDefinition.ID.Guid).Value;
                return(GetChildIDsTemplate(cls, itemDefinition));
            }

            var section = SectionTable.FirstOrDefault(x => x.SectionId == itemDefinition.ID);

            if (section != null)
            {
                return(GetChildIDsSection(itemDefinition, section));
            }

            return(base.GetChildIDs(itemDefinition, context));
        }
Пример #19
0
        /// <summary>
        /// Gets the definition of an item.
        /// </summary>
        /// <param name="itemId">The item ID.</param>
        /// <param name="context">The context.</param>
        /// <returns>Sitecore.Data.ItemDefinition.</returns>
        public override global::Sitecore.Data.ItemDefinition GetItemDefinition(global::Sitecore.Data.ID itemId, CallContext context)
        {
           // Setup(context);

            var section = SectionTable.FirstOrDefault(x => x.SectionId == itemId);
            if (section != null)
            {
                return  new ItemDefinition(itemId, section.Name, SectionTemplateId, ID.Null);
            }
            var field = FieldTable.FirstOrDefault(x => x.FieldId == itemId);
            if (field != null)
            {
                return new ItemDefinition(itemId, field.Name, FieldTemplateId, ID.Null);
            }


            return null;
        }
Пример #20
0
        public override global::Sitecore.Data.ID GetParentID(global::Sitecore.Data.ItemDefinition itemDefinition, CallContext context)
        {
            var section = SectionTable.FirstOrDefault(x => x.SectionId == itemDefinition.ID);

            if (section != null)
            {
                return(section.TemplateId);
            }

            var field = FieldTable.FirstOrDefault(x => x.FieldId == itemDefinition.ID);

            if (field != null)
            {
                return(field.SectionId);
            }

            return(base.GetParentID(itemDefinition, context));
        }
Пример #21
0
        private ExecutableImage(Stream sourceStream, bool ownStream)
        {
            _disposed = false;
            _stream = sourceStream;
            _own_stream = ownStream;
            _calc = null;

            _dos_header = null;
            _dos_stub = null;
            _nt_headers = null;
            _section_table = null;
            _sections = null;

            _is_32bit = false;
            _is_64bit = false;
            _is_clr = false;
            _is_signed = false;

            Load();
        }
Пример #22
0
        /// <summary>
        /// Gets the child ids of an item.
        /// </summary>
        /// <param name="itemDefinition">The item definition.</param>
        /// <param name="context">The context.</param>
        /// <returns>Sitecore.Collections.IDList.</returns>
        public override global::Sitecore.Collections.IDList GetChildIDs(global::Sitecore.Data.ItemDefinition itemDefinition, CallContext context)
        {
          //  Setup(context);

            if (_typeConfigurations == null)
                return base.GetChildIDs(itemDefinition, context);

            if (_typeConfigurations.Any(x => x.Value.TemplateId == itemDefinition.ID))
            {
                var cls = _typeConfigurations.First(x => x.Value.TemplateId == itemDefinition.ID).Value;
                return GetChildIDsTemplate(cls, itemDefinition, context);
            }

            var section = SectionTable.FirstOrDefault(x => x.SectionId == itemDefinition.ID);

            if (section != null)
            {
                return GetChildIDsSection(section, context);
            }

            return base.GetChildIDs(itemDefinition, context);
        }
Пример #23
0
        private ExeReader(Stream sourceStream, bool ownStream)
        {
            if (!sourceStream.CanRead)
                throw new IOException("Cannot read from stream.");

            if (!sourceStream.CanSeek)
                throw new IOException("Cannot seek in stream.");

            _disposed = false;
            _stream = sourceStream;
            _own_stream = ownStream;

            _dos_header = null;
            _dos_stub = null;
            _nt_headers = null;
            _section_table = null;
            _sections = null;

            is_32bit = false;
            is_64bit = false;
            is_clr = false;
        }
Пример #24
0
        /// <summary>
        /// Gets the child ids of an item.
        /// </summary>
        /// <param name="itemDefinition">The item definition.</param>
        /// <param name="context">The context.</param>
        /// <returns>Sitecore.Collections.IDList.</returns>
        public override IDList GetChildIDs(ItemDefinition itemDefinition, CallContext context)
        {
            if (!_setupComplete)
            {
                return(base.GetChildIDs(itemDefinition, context));
            }

            if (TypeConfigurations.Any(x => x.Value.TemplateId == itemDefinition.ID))
            {
                var cls = TypeConfigurations.First(x => x.Value.TemplateId == itemDefinition.ID).Value;
                return(GetChildIDsTemplate(cls, itemDefinition, context, GetSqlProvider(context.DataManager.Database)));
            }

            var section = SectionTable.FirstOrDefault(x => x.SectionId == itemDefinition.ID);

            if (section != null)
            {
                return(GetChildIDsSection(section, context, GetSqlProvider(context.DataManager.Database)));
            }

            return(base.GetChildIDs(itemDefinition, context));
        }
Пример #25
0
        /// <summary>
        /// Gets the parent ID of an item.
        /// </summary>
        /// <param name="itemDefinition">The item definition.</param>
        /// <param name="context">The context.</param>
        /// <returns>Sitecore.Data.ID.</returns>
        public override ID GetParentID(ItemDefinition itemDefinition, CallContext context)
        {
            if (!_setupComplete)
            {
                return(base.GetParentID(itemDefinition, context));
            }

            var section = SectionTable.FirstOrDefault(x => x.SectionId == itemDefinition.ID);

            if (section != null)
            {
                return(section.TemplateId);
            }

            var field = FieldTable.FirstOrDefault(x => x.FieldId == itemDefinition.ID);

            if (field != null)
            {
                return(field.SectionId);
            }

            return(base.GetParentID(itemDefinition, context));
        }
Пример #26
0
        /// <summary>
        /// Gets the definition of an item.
        /// </summary>
        /// <param name="itemId">The item ID.</param>
        /// <param name="context">The context.</param>
        /// <returns>Sitecore.Data.ItemDefinition.</returns>
        public override ItemDefinition GetItemDefinition(ID itemId, CallContext context)
        {
            if (!_setupComplete)
            {
                return(base.GetItemDefinition(itemId, context));
            }

            var section = SectionTable.FirstOrDefault(x => x.SectionId == itemId);

            if (section != null)
            {
                return(new ItemDefinition(itemId, section.Name, SectionTemplateId, ID.Null));
            }

            var field = FieldTable.FirstOrDefault(x => x.FieldId == itemId);

            if (field != null)
            {
                return(new ItemDefinition(itemId, field.Name, FieldTemplateId, ID.Null));
            }

            return(base.GetItemDefinition(itemId, context));
        }
Пример #27
0
        private void UpdateOptionalHeader()
        {
            var header = Assembly.NtHeaders.OptionalHeader;

            header.SizeOfCode            = _textSectionHeader.Section.GetPhysicalLength();
            header.SizeOfInitializedData = (_relocSectionHeader != null ? _relocSectionHeader.Section.GetPhysicalLength() : 0) +
                                           (_rsrcSectionHeader != null ? _rsrcSectionHeader.Section.GetPhysicalLength() : 0);
            header.BaseOfCode = _textSectionHeader.VirtualAddress;
            if (_relocSectionHeader != null)
            {
                header.BaseOfData = _relocSectionHeader.VirtualAddress;
            }

            var lastSection = SectionTable.GetSections().Last().Header;

            header.SizeOfImage = lastSection.VirtualAddress +
                                 Align(lastSection.VirtualSize, Assembly.NtHeaders.OptionalHeader.SectionAlignment);
            header.SizeOfHeaders = 0x200;

            header.AddressOfEntrypoint = (uint)Assembly.FileOffsetToRva(_textContents.Bootstrapper.StartOffset);

            UpdateDataDirectories();
        }
Пример #28
0
 public void MakeDocument(ReportDocument reportDocument)
 {
     if (this.mObj != null)
     {
         TextStyle.ResetStyles();
         DateTime serverDtm = GlobalWebServiceDAL.GetServerDtm();
         float    num       = 1f;
         float    num2      = 10f;
         float    num3      = 10f;
         float    num4      = 420f;
         float    num5      = 480f;
         float    num6      = 150f;
         float    num7      = 100f;
         try
         {
             num = Convert.ToSingle(ConfigurationSettings.AppSettings["eiroutprint.pen.width"]);
         }
         catch (Exception)
         {
         }
         try
         {
             num2 = Convert.ToSingle(ConfigurationSettings.AppSettings["eiroutprint.box.margin"]);
         }
         catch (Exception)
         {
         }
         try
         {
             num3 = Convert.ToSingle(ConfigurationSettings.AppSettings["eiroutprint.box.padding"]);
         }
         catch (Exception)
         {
         }
         try
         {
             num4 = Convert.ToSingle(ConfigurationSettings.AppSettings["eiroutprint.box.width"]);
         }
         catch (Exception)
         {
         }
         try
         {
             num5 = Convert.ToSingle(ConfigurationSettings.AppSettings["eiroutprint.box.height"]);
         }
         catch (Exception)
         {
         }
         try
         {
             num6 = Convert.ToSingle(ConfigurationSettings.AppSettings["eiroutprint.col1.width"]);
         }
         catch (Exception)
         {
         }
         try
         {
             num7 = Convert.ToSingle(ConfigurationSettings.AppSettings["eiroutprint.col2.width"]);
         }
         catch (Exception)
         {
         }
         Pen           borders = new Pen(Color.White, num / 100f);
         Pen           pen     = new Pen(Color.Black, num / 100f);
         ReportBuilder builder = new ReportBuilder(reportDocument);
         builder.StartBox(num2 / 100f, borders, num3 / 100f, Brushes.White, num4 / 100f, num5 / 100f);
         builder.StartLinearLayout(Direction.Vertical);
         builder.DefaultTablePen = borders;
         string name       = "Times New Roman";
         int    num8       = 12;
         string text       = "PT. MULTICON INDRAJAYA TERMINAL";
         string str3       = "EQUIPMENT INTERCHANGE RECEIPT (OUT)";
         string str4       = "Lucida Console";
         int    num9       = 10;
         string headerText = "D/O No.";
         string str6       = "Shipper";
         string str7       = "VESSEL/VOY No.";
         string str8       = "Destination";
         string str9       = "Quantity";
         string str10      = "Principal";
         string str11      = "Delivered";
         string str12      = "Vehicle No.";
         string str13      = "Lucida Console";
         int    num10      = 10;
         string str14      = "CONTAINER PREFIX + NUMBER";
         string str15      = "SIZE";
         string str16      = "TYPE";
         string str17      = "CONDITION";
         string str18      = "SEAL NUMBER";
         string format     = "REMARKS : {0} {1} {2}";
         string str20      = "Arial";
         int    num11      = 10;
         string str21      = "Printed and Authorized, {0} {1}";
         string str22      = "PT. MULTICON INDRAJAYA TERMINAL";
         try
         {
             num8 = Convert.ToInt32(ConfigurationSettings.AppSettings["eiroutprint.header.font.size"]);
         }
         catch (Exception)
         {
         }
         try
         {
             num9 = Convert.ToInt32(ConfigurationSettings.AppSettings["eiroutprint.main.font.size"]);
         }
         catch (Exception)
         {
         }
         try
         {
             num10 = Convert.ToInt32(ConfigurationSettings.AppSettings["eiroutprint.line.font.size"]);
         }
         catch (Exception)
         {
         }
         try
         {
             num11 = Convert.ToInt32(ConfigurationSettings.AppSettings["eiroutprint.footer.font.size"]);
         }
         catch (Exception)
         {
         }
         try
         {
             name = ConfigurationSettings.AppSettings["eiroutprint.header.font.name"];
         }
         catch (Exception)
         {
         }
         try
         {
             text = ConfigurationSettings.AppSettings["eiroutprint.header.1"];
         }
         catch (Exception)
         {
         }
         try
         {
             str3 = ConfigurationSettings.AppSettings["eiroutprint.header.2"];
         }
         catch (Exception)
         {
         }
         try
         {
             str4 = ConfigurationSettings.AppSettings["eiroutprint.main.font.name"];
         }
         catch (Exception)
         {
         }
         try
         {
             headerText = ConfigurationSettings.AppSettings["eiroutprint.main.1"];
         }
         catch (Exception)
         {
         }
         try
         {
             str6 = ConfigurationSettings.AppSettings["eiroutprint.main.2"];
         }
         catch (Exception)
         {
         }
         try
         {
             str7 = ConfigurationSettings.AppSettings["eiroutprint.main.3"];
         }
         catch (Exception)
         {
         }
         try
         {
             str8 = ConfigurationSettings.AppSettings["eiroutprint.main.4"];
         }
         catch (Exception)
         {
         }
         try
         {
             str9 = ConfigurationSettings.AppSettings["eiroutprint.main.5"];
         }
         catch (Exception)
         {
         }
         try
         {
             str10 = ConfigurationSettings.AppSettings["eiroutprint.main.6"];
         }
         catch (Exception)
         {
         }
         try
         {
             str11 = ConfigurationSettings.AppSettings["eiroutprint.main.7"];
         }
         catch (Exception)
         {
         }
         try
         {
             str12 = ConfigurationSettings.AppSettings["eiroutprint.main.8"];
         }
         catch (Exception)
         {
         }
         try
         {
             str13 = ConfigurationSettings.AppSettings["eiroutprint.line.font.name"];
         }
         catch (Exception)
         {
         }
         try
         {
             str14 = ConfigurationSettings.AppSettings["eiroutprint.line.1"];
         }
         catch (Exception)
         {
         }
         try
         {
             str15 = ConfigurationSettings.AppSettings["eiroutprint.line.2"];
         }
         catch (Exception)
         {
         }
         try
         {
             str16 = ConfigurationSettings.AppSettings["eiroutprint.line.3"];
         }
         catch (Exception)
         {
         }
         try
         {
             str17 = ConfigurationSettings.AppSettings["eiroutprint.line.4"];
         }
         catch (Exception)
         {
         }
         try
         {
             str18 = ConfigurationSettings.AppSettings["eiroutprint.line.5"];
         }
         catch (Exception)
         {
         }
         try
         {
             format = ConfigurationSettings.AppSettings["eiroutprint.line.6"];
         }
         catch (Exception)
         {
         }
         try
         {
             str20 = ConfigurationSettings.AppSettings["eiroutprint.footer.font.name"];
         }
         catch (Exception)
         {
         }
         try
         {
             str21 = ConfigurationSettings.AppSettings["eiroutprint.footer.1"];
         }
         catch (Exception)
         {
         }
         try
         {
             str22 = ConfigurationSettings.AppSettings["eiroutprint.footer.2"];
         }
         catch (Exception)
         {
         }
         TextStyle textStyle = new TextStyle(TextStyle.BoldStyle);
         textStyle.FontFamily      = new FontFamily(name);
         textStyle.Size            = num8;
         textStyle.StringAlignment = StringAlignment.Center;
         TextStyle style2 = new TextStyle(TextStyle.Normal);
         style2.FontFamily = new FontFamily(str4);
         style2.Size       = num9;
         TextStyle style3 = new TextStyle(TextStyle.Normal);
         style3.FontFamily = new FontFamily(str13);
         style3.Size       = num10;
         TextStyle style4 = new TextStyle(TextStyle.Normal);
         style4.FontFamily = new FontFamily(str20);
         style4.Size       = num11;
         builder.AddText(text, textStyle);
         builder.AddText(str3, textStyle);
         builder.AddHorizontalLine(pen);
         DataTable table = new DataTable("main");
         table.Columns.Add("column1", typeof(string));
         table.Columns.Add("column2", typeof(string));
         table.Rows.Add(new object[] { str6, this.mObj.Shipper });
         table.Rows.Add(new object[] { str7, this.mObj.VesselVoyageName });
         table.Rows.Add(new object[] { str8, this.mObj.DestinationName });
         table.Rows.Add(new object[] { str9, "?" });
         table.Rows.Add(new object[] { str10, this.mCust.Name });
         table.Rows.Add(new object[] { str11, this.mObj.AngkutanOut });
         table.Rows.Add(new object[] { str12, this.mObj.NoMobilOut });
         SectionTable table2 = builder.AddTable(table.DefaultView, true);
         table2.InnerPenHeaderBottom.Color = Color.White;
         table2.InnerPenRow.Color          = Color.White;
         table2.HeaderTextStyle.SetFromFont(style2.GetFont());
         table2.HorizontalAlignment = HorizontalAlignment.Center;
         ReportDataColumn column = builder.AddColumn("column1", headerText, num6 / 100f, false, false);
         column.HeaderTextStyle         = style2;
         column.DetailRowTextStyle      = style2;
         column.AlternatingRowTextStyle = style2;
         ReportDataColumn column2 = builder.AddColumn("column2", this.mObj.DoNumber, num7 / 100f, false, false);
         column2.HeaderTextStyle         = style2;
         column2.DetailRowTextStyle      = style2;
         column2.AlternatingRowTextStyle = style2;
         builder.AddHorizontalLine(pen);
         DataTable table3 = new DataTable("line");
         table3.Columns.Add("column1", typeof(string));
         table3.Columns.Add("column2", typeof(string));
         table3.Rows.Add(new object[] { str15, this.mObj.Size });
         table3.Rows.Add(new object[] { str16, this.mObj.Type });
         table3.Rows.Add(new object[] { str17, this.mObj.Condition });
         table3.Rows.Add(new object[] { str18, this.mObj.Seal });
         SectionTable table4 = builder.AddTable(table3.DefaultView, true);
         table4.InnerPenHeaderBottom = borders;
         table4.InnerPenRow          = borders;
         table4.OuterPens            = borders;
         table4.HeaderTextStyle.SetFromFont(style3.GetFont());
         table4.HorizontalAlignment = HorizontalAlignment.Center;
         ReportDataColumn column3 = builder.AddColumn("column1", str14.Replace('+', '&'), num6 / 100f, false, false);
         column3.HeaderTextStyle         = style3;
         column3.DetailRowTextStyle      = style3;
         column3.AlternatingRowTextStyle = style3;
         ReportDataColumn column4 = builder.AddColumn("column2", this.mObj.Cont, num7 / 100f, false, false);
         column4.HeaderTextStyle         = style3;
         column4.DetailRowTextStyle      = style3;
         column4.AlternatingRowTextStyle = style3;
         builder.AddText(" ", style3);
         builder.AddText(string.Format(format, this.mObj.Remarks), style3);
         builder.AddHorizontalLine(pen);
         builder.AddText(" ", style4);
         string introduced93 = serverDtm.ToLongDateString();
         builder.AddText(string.Format(str21, introduced93, serverDtm.ToLongTimeString()), style4);
         builder.AddText(str22, style4);
         builder.AddText(" \r\n ", style4);
         builder.FinishLinearLayout();
         builder.FinishBox();
     }
 }
Пример #29
0
        private void Load()
        {
            string error_message = String.Empty;
            PreloadedInformation preload_info = TryPreload(_stream,out error_message);

            if (preload_info == null)
                throw new ExecutableImageException(error_message);

            ulong image_base = 0;

            if (preload_info.OptHeader32 != null)
                image_base = preload_info.OptHeader32.Value.ImageBase;

            if (preload_info.OptHeader64 != null)
                image_base = preload_info.OptHeader64.Value.ImageBase;

            _dos_header = new DOSHeader(this,preload_info.DOSHeader,image_base);
            _dos_stub = new DOSStub(this,preload_info.StubOffset,preload_info.StubSize,image_base);

            FileHeader file_header = new FileHeader(this,preload_info.FileHeader,_dos_stub.Location.FileOffset + _dos_stub.Location.FileSize + 4,image_base);
            OptionalHeader opt_header;

            if (preload_info.Is32Bit)
            {
                opt_header = new OptionalHeader32(this,preload_info.OptHeader32.Value,file_header.Location.FileOffset + file_header.Location.FileSize,image_base);
            }
            else
            {
                opt_header = new OptionalHeader64(this,preload_info.OptHeader64.Value,file_header.Location.FileOffset + file_header.Location.FileSize,image_base);
            }

            DataDirectoryCollection data_dirs = new DataDirectoryCollection(this,opt_header,preload_info.DataDirectories);

            _nt_headers = new NTHeaders(this,file_header.Location.FileOffset - 4,image_base,file_header,opt_header,data_dirs);
            _section_table = new SectionTable(this,preload_info.SectionHeaders,_nt_headers.Location.FileOffset + _nt_headers.Location.FileSize,image_base);
            _sections = new Sections(_section_table);

            _is_32bit = preload_info.Is32Bit;
            _is_64bit = preload_info.Is64Bit;
            _is_clr = preload_info.IsCLR;
            _is_signed = preload_info.IsSigned;
        }
Пример #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HWPFDocument"/> class.
        /// </summary>
        /// <param name="directory">The directory.</param>
        public HWPFDocument(DirectoryNode directory)
            : base(directory)
        {
            _endnotes  = new NotesImpl(_endnotesTables);
            _footnotes = new NotesImpl(_footnotesTables);

            // Load the main stream and FIB
            // Also handles HPSF bits

            // Do the CP Split
            _cpSplit = new CPSplitCalculator(_fib);

            // Is this document too old for us?
            if (_fib.GetNFib() < 106)
            {
                throw new OldWordFileFormatException("The document is too old - Word 95 or older. Try HWPFOldDocument instead?");
            }

            // use the fib to determine the name of the table stream.
            String name = "0Table";

            if (_fib.IsFWhichTblStm())
            {
                name = "1Table";
            }

            // Grab the table stream.
            DocumentEntry tableProps;

            try
            {
                tableProps =
                    (DocumentEntry)directory.GetEntry(name);
            }
            catch (FileNotFoundException)
            {
                throw new InvalidOperationException("Table Stream '" + name + "' wasn't found - Either the document is corrupt, or is Word95 (or earlier)");
            }

            // read in the table stream.
            _tableStream = new byte[tableProps.Size];
            directory.CreatePOIFSDocumentReader(name).Read(_tableStream);

            _fib.FillVariableFields(_mainStream, _tableStream);

            // read in the data stream.
            try
            {
                DocumentEntry dataProps =
                    (DocumentEntry)directory.GetEntry("Data");
                _dataStream = new byte[dataProps.Size];
                directory.CreatePOIFSDocumentReader("Data").Read(_dataStream);
            }
            catch (FileNotFoundException)
            {
                _dataStream = new byte[0];
            }

            // Get the cp of the start of text in the main stream
            // The latest spec doc says this is always zero!
            int fcMin = 0;

            //fcMin = _fib.GetFcMin()

            // Start to load up our standard structures.
            _dop = new DocumentProperties(_tableStream, _fib.GetFcDop());
            _cft = new ComplexFileTable(_mainStream, _tableStream, _fib.GetFcClx(), fcMin);
            TextPieceTable _tpt = _cft.GetTextPieceTable();


            // Now load the rest of the properties, which need to be adjusted
            //  for where text really begin
            _cbt = new CHPBinTable(_mainStream, _tableStream, _fib.GetFcPlcfbteChpx(), _fib.GetLcbPlcfbteChpx(), _tpt);
            _pbt = new PAPBinTable(_mainStream, _tableStream, _dataStream, _fib.GetFcPlcfbtePapx(), _fib.GetLcbPlcfbtePapx(), _tpt);

            _text = _tpt.Text;

            /*
             * in this mode we preserving PAPX/CHPX structure from file, so text may
             * miss from output, and text order may be corrupted
             */
            bool preserveBinTables = false;

            try
            {
                preserveBinTables = Boolean.Parse(
                    ConfigurationManager.AppSettings[PROPERTY_PRESERVE_BIN_TABLES]);
            }
            catch (Exception)
            {
                // ignore;
            }

            if (!preserveBinTables)
            {
                _cbt.Rebuild(_cft);
                _pbt.Rebuild(_text, _cft);
            }

            /*
             * Property to disable text rebuilding. In this mode changing the text
             * will lead to unpredictable behavior
             */
            bool preserveTextTable = false;

            try
            {
                preserveTextTable = Boolean.Parse(
                    ConfigurationManager.AppSettings[PROPERTY_PRESERVE_TEXT_TABLE]);
            }
            catch (Exception)
            {
                // ignore;
            }
            if (!preserveTextTable)
            {
                _cft = new ComplexFileTable();
                _tpt = _cft.GetTextPieceTable();
                TextPiece textPiece = new SinglentonTextPiece(_text);
                _tpt.Add(textPiece);
                _text = textPiece.GetStringBuilder();
            }

            // Read FSPA and Escher information
            // _fspa = new FSPATable(_tableStream, _fib.getFcPlcspaMom(),
            // _fib.getLcbPlcspaMom(), getTextTable().getTextPieces());
            _fspaHeaders = new FSPATable(_tableStream, _fib,
                                         FSPADocumentPart.HEADER);
            _fspaMain = new FSPATable(_tableStream, _fib, FSPADocumentPart.MAIN);

            if (_fib.GetFcDggInfo() != 0)
            {
                _dgg = new EscherRecordHolder(_tableStream, _fib.GetFcDggInfo(), _fib.GetLcbDggInfo());
            }
            else
            {
                _dgg = new EscherRecordHolder();
            }

            // read in the pictures stream
            _pictures = new PicturesTable(this, _dataStream, _mainStream, _fspa, _dgg);
            // And the art shapes stream
            _officeArts = new ShapesTable(_tableStream, _fib);

            // And escher pictures
            _officeDrawingsHeaders = new OfficeDrawingsImpl(_fspaHeaders, _dgg, _mainStream);
            _officeDrawingsMain    = new OfficeDrawingsImpl(_fspaMain, _dgg, _mainStream);

            _st = new SectionTable(_mainStream, _tableStream, _fib.GetFcPlcfsed(), _fib.GetLcbPlcfsed(), fcMin, _tpt, _cpSplit);
            _ss = new StyleSheet(_tableStream, _fib.GetFcStshf());
            _ft = new FontTable(_tableStream, _fib.GetFcSttbfffn(), _fib.GetLcbSttbfffn());

            int listOffset = _fib.GetFcPlcfLst();
            int lfoOffset  = _fib.GetFcPlfLfo();

            if (listOffset != 0 && _fib.GetLcbPlcfLst() != 0)
            {
                _lt = new ListTables(_tableStream, _fib.GetFcPlcfLst(), _fib.GetFcPlfLfo());
            }

            int sbtOffset = _fib.GetFcSttbSavedBy();
            int sbtLength = _fib.GetLcbSttbSavedBy();

            if (sbtOffset != 0 && sbtLength != 0)
            {
                _sbt = new SavedByTable(_tableStream, sbtOffset, sbtLength);
            }

            int rmarkOffset = _fib.GetFcSttbfRMark();
            int rmarkLength = _fib.GetLcbSttbfRMark();

            if (rmarkOffset != 0 && rmarkLength != 0)
            {
                _rmat = new RevisionMarkAuthorTable(_tableStream, rmarkOffset, rmarkLength);
            }


            _bookmarksTables = new BookmarksTables(_tableStream, _fib);
            _bookmarks       = new BookmarksImpl(_bookmarksTables);

            _endnotesTables  = new NotesTables(NoteType.ENDNOTE, _tableStream, _fib);
            _endnotes        = new NotesImpl(_endnotesTables);
            _footnotesTables = new NotesTables(NoteType.FOOTNOTE, _tableStream, _fib);
            _footnotes       = new NotesImpl(_footnotesTables);

            _fieldsTables = new FieldsTables(_tableStream, _fib);
            _fields       = new FieldsImpl(_fieldsTables);
        }
        public void Setup(CallContext context)
        {
            if (_setupComplete || _setupProcessing)
            {
                return;
            }

            lock (_setupLock)
            {
                if (_setupComplete || _setupProcessing)
                {
                    return;
                }

                _setupProcessing = true;

                global::Sitecore.Diagnostics.Log.Info("Started CodeFirst setup", this);

                var providers = Factory.GetDatabase("master").GetDataProviders();
                var provider  = providers.FirstOrDefault(x => !(x is GlassDataProvider));

                var templateFolder = provider.GetItemDefinition(TemplateFolderId, context);

                var glassFolder = provider.GetItemDefinition(GlassFolderId, context);

                if (glassFolder == ItemDefinition.Empty || glassFolder == null)
                {
                    provider.CreateItem(GlassFolderId, "GlassTemplates", FolderTemplateId, templateFolder, context);
                    glassFolder = provider.GetItemDefinition(GlassFolderId, context);
                }


                foreach (var cls in Context.StaticContext.Classes.Where(x => x.Value.ClassAttribute.CodeFirst))
                {
                    var clsTemplate = provider.GetItemDefinition(new ID(cls.Value.TemplateId), context);

                    if (clsTemplate == ItemDefinition.Empty || clsTemplate == null)
                    {
                        //setup folders
                        IEnumerable <string> namespaces = cls.Key.Namespace.Split('.');
                        namespaces = namespaces.SkipWhile(x => x != "Templates").Skip(1);

                        ItemDefinition containing = glassFolder;
                        var            children   = provider.GetChildIDs(containing, context);
                        foreach (var ns in namespaces)
                        {
                            ItemDefinition found = null;
                            foreach (ID child in children)
                            {
                                if (!ID.IsNullOrEmpty(child))
                                {
                                    var childDef = provider.GetItemDefinition(child, context);
                                    if (childDef.Name == ns)
                                    {
                                        found = childDef;
                                    }
                                }
                            }

                            if (found == null)
                            {
                                ID newId = ID.NewID;
                                provider.CreateItem(newId, ns, FolderTemplateId, containing, context);
                                found = provider.GetItemDefinition(newId, context);
                            }
                            containing = found;
                        }

                        //create the template in Sitecore
                        string templateName = cls.Value.ClassAttribute.TemplateName;

                        if (string.IsNullOrEmpty(templateName))
                        {
                            templateName = cls.Key.Name;
                        }

                        provider.CreateItem(new ID(cls.Value.TemplateId), templateName, TemplateTemplateId, containing, context);
                        clsTemplate = provider.GetItemDefinition(new ID(cls.Value.TemplateId), context);
                        //Assign the base template
                        var templateItem = Factory.GetDatabase("master").GetItem(clsTemplate.ID);

                        using (new SecurityDisabler())
                        {
                            templateItem.Editing.BeginEdit();
                            templateItem["__Base template"] = "{1930BBEB-7805-471A-A3BE-4858AC7CF696}";
                            templateItem.Editing.EndEdit();
                        }
                    }

                    BaseTemplateChecks(clsTemplate, provider, context, cls.Value);

                    //initialize sections and children
                    foreach (ID sectionId in this.GetChildIDsTemplate(cls.Value, clsTemplate, context))
                    {
                        this.GetChildIDsSection(SectionTable.First(s => s.SectionId == sectionId), context);
                    }
                }

                if (global::Sitecore.Configuration.Settings.GetBoolSetting("AutomaticallyRemoveDeletedTemplates", true))
                {
                    RemoveDeletedClasses(glassFolder, provider, context);
                }

                global::Sitecore.Diagnostics.Log.Info("Finished CodeFirst setup", this);

                _setupComplete = true;
            }
        }
Пример #32
0
        /// <summary>
        /// Setups the specified context.
        /// </summary>
        /// <param name="db">The db.</param>
        public void Initialise(Database db)
        {
            if (_setupComplete || _setupProcessing)
            {
                return;
            }

            lock (_setupLock)
            {
                try
                {
                    if (_setupComplete || _setupProcessing)
                    {
                        return;
                    }

                    Sitecore.Diagnostics.Log.Info("Started CodeFirst setup " + db.Name, this);
                    _setupProcessing = true;
                    var manager = new DataManager(db);
                    var context = new CallContext(manager, db.GetDataProviders().Count());

                    var sqlProvider = GetSqlProvider(db);
                    var glassFolder = GetGlassTemplateFolder(sqlProvider, context);

                    if (CurrentContext != null)
                    {
                        foreach (var cls in TypeConfigurations.Where(x => x.Value.CodeFirst))
                        {
                            var templateDefinition = sqlProvider.GetItemDefinition(cls.Value.TemplateId, context);

                            if (templateDefinition == ItemDefinition.Empty || templateDefinition == null)
                            {
                                var containingFolder = GetTemplateFolder(cls.Key.Namespace, glassFolder, sqlProvider, context);
                                templateDefinition = CreateTemplateItem(db, cls.Value, cls.Key, sqlProvider, containingFolder, context);
                            }

                            BaseTemplateChecks(templateDefinition, cls.Value, db);

                            //initialize sections and children
                            foreach (ID sectionId in GetChildIDsTemplate(cls.Value, templateDefinition, context, sqlProvider))
                            {
                                GetChildIDsSection(SectionTable.First(s => s.SectionId == sectionId), context, sqlProvider);
                            }
                        }

                        if (Settings.GetBoolSetting("AutomaticallyRemoveDeletedTemplates", true))
                        {
                            RemoveDeletedClasses(glassFolder, sqlProvider, context);
                        }

                        ClearCaches(db);
                    }

                    Sitecore.Diagnostics.Log.Info("Finished CodeFirst setup " + db.Name, this);
                }
                catch (Exception ex)
                {
                    Sitecore.Diagnostics.Log.Error("CodeFirst error " + ex.Message, ex, this);
                    throw;
                }
                finally
                {
                    _setupComplete = true;
                }
            }
        }
Пример #33
0
        private void LoadSectionTable()
        {
            if (_nt_headers == null)
                LoadNTHeaders();

            long offset = _nt_headers.Location.Offset + _nt_headers.Location.Size;

            _stream.Seek(offset,SeekOrigin.Begin);

            List<IMAGE_SECTION_HEADER> headers = new List<IMAGE_SECTION_HEADER>();

            for(var i = 0; i < _nt_headers.FileHeader.NumberOfSections; i++)
            {
                IMAGE_SECTION_HEADER header = Utils.Read<IMAGE_SECTION_HEADER>(_stream,SectionTableEntry.Size);

                headers.Add(header);
            }

            long size = headers.Count * SectionTableEntry.Size;
            StreamLocation location = new StreamLocation(offset,size);

            _section_table = new SectionTable(this,location,headers);
        }
Пример #34
0
        /// <summary>
        /// Setups the specified context.
        /// </summary>
        /// <param name="db">The db.</param>
        public  void Initialise(Database db)
        {
            var manager = new DataManager(db);
            var context = new CallContext(manager, db.GetDataProviders().Count());
            
            lock (_setupLock)
            {
                try
                {
                    if (_setupComplete) return;

                    global::Sitecore.Diagnostics.Log.Info("Started CodeFirst setup", this);

                    var sqlProvider = GetSqlProvider(db);

                    var glassFolder = GetGlassTemplateFolder(sqlProvider, context);

                    if (Context.Contexts.Keys.Any(x => x == ContextName))
                    {

                        var glsContext = Context.Contexts[ContextName];
                        _typeConfigurations = glsContext.TypeConfigurations
                                                         .Where(x => x.Value is SitecoreTypeConfiguration)
                                                         .ToDictionary(x => x.Key,
                                                                       x => x.Value as SitecoreTypeConfiguration);

                        foreach (var cls in _typeConfigurations.Where(x => x.Value.CodeFirst))
                        {
                            var templateDefinition = sqlProvider.GetItemDefinition(cls.Value.TemplateId, context);

                            if (templateDefinition == ItemDefinition.Empty || templateDefinition == null)
                            {
                                var containingFolder = GetTemplateFolder(cls.Key.Namespace, glassFolder, sqlProvider, context);
                                templateDefinition = CreateTemplateItem(db, cls.Value, cls.Key, sqlProvider, containingFolder, context);
                            }

                            BaseTemplateChecks(templateDefinition, sqlProvider, context, cls.Value);

                            //initialize sections and children
                            foreach (ID sectionId in this.GetChildIDsTemplate(cls.Value, templateDefinition, context))
                            {
                                this.GetChildIDsSection(SectionTable.First(s => s.SectionId == sectionId), context);
                            }
                        }

                        if (global::Sitecore.Configuration.Settings.GetBoolSetting(
                            "AutomaticallyRemoveDeletedTemplates",
                            true))
                            RemoveDeletedClasses(glassFolder, sqlProvider, context);

                        global::Sitecore.Diagnostics.Log.Info("Finished CodeFirst setup", this);
                    }
                    
                    ClearCaches(db);
                   
                }
                finally 
                {
                    _setupComplete = true;
                }

            }
        }
        private void FillSection()
        {
            bool enable = !CheckPositionIsCompleted();

            SectionTable.Controls.Clear();

            RowStyle style = new RowStyle {
                SizeType = SizeType.AutoSize
            };

            SectionTable.Padding   = new Padding(0, 0, SystemInformation.VerticalScrollBarWidth, 0);
            HeaderControls.Padding = new Padding(0, 0, SystemInformation.VerticalScrollBarWidth, 0);

            SectionTable.RowStyles.Add(style);

            foreach (Section s in _currentFeed.Sections)
            {
                SectionTable.Controls.Add(new CheckBox {
                    Anchor = AnchorStyles.Left, Name = "checker" + s.SectionId, AutoSize = true, Checked = (object.ReferenceEquals(s.IsChecked, null) ? false : s.IsChecked), Enabled = enable
                }, 0, row);

                SectionTable.Controls.Add(
                    new Label
                {
                    Text      = s.Title,
                    Anchor    = AnchorStyles.Left,
                    TextAlign = ContentAlignment.MiddleLeft,
                    AutoSize  = true
                }, 1, row);

                ComboBox codes = new ComboBox
                {
                    DropDownStyle = ComboBoxStyle.DropDownList,
                    Anchor        = AnchorStyles.Right,
                    Name          = "codes" + s.SectionId,
                    FlatStyle     = FlatStyle.Flat,
                    Enabled       = enable
                };

                foreach (string code in s.Codes)
                {
                    codes.Items.Add(code);
                }

                if (!object.ReferenceEquals(s.CodeChosen, null))
                {
                    codes.SelectedItem = (s.Codes.Find(x => x.Equals(s.CodeChosen)));
                }

                SectionTable.Controls.Add(codes, 2, row);
                RichTextBox comment = new RichTextBox
                {
                    Anchor  = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top,
                    Name    = "comment" + s.SectionId,
                    Text    = (object.ReferenceEquals(s.Comment, null) ? null : s.Comment),
                    Enabled = enable
                };

                SectionTable.Controls.Add(comment, 1, row + 1);
                SectionTable.SetColumnSpan(comment, 2);
                row++;
                row++;
            }
        }
Пример #36
0
        /// <summary>
        /// 获取节表
        /// </summary>
        private void LoadSectionTable()
        {
            _SectionTable = new SectionTable();
            long Count = GetLong(_PEHeader.NumberOfSections);
            _SectionTable.FileStarIndex = PEFileIndex;
            for (long i = 0; i != Count; i++)
            {
                SectionTable.SectionData Section = new SectionTable.SectionData();

                Loadbyte(ref Section.SectName);
                Loadbyte(ref Section.VirtualAddress);
                Loadbyte(ref Section.SizeOfRawDataRVA);
                Loadbyte(ref Section.SizeOfRawDataSize);
                Loadbyte(ref Section.PointerToRawData);
                Loadbyte(ref Section.PointerToRelocations);
                Loadbyte(ref Section.PointerToLinenumbers);
                Loadbyte(ref Section.NumberOfRelocations);
                Loadbyte(ref Section.NumberOfLinenumbers);
                Loadbyte(ref Section.Characteristics);
                _SectionTable.Section.Add(Section);

            }
            _SectionTable.FileEndIndex = PEFileIndex;
        }