Example #1
0
 public void Delete()
 {
     object[] testFields;
     if (_recordType == RecordType.NormalMarker)
     {
         testFields = _fields;
     }
     else if (_recordType == RecordType.Updated)
     {
         testFields = _fieldsOld;
     }
     else
     {
         throw new AttemptDeleteNotNormalOrNotUpdatedRecordException();
     }
     if (_table.IsRecordWithBLOB)
     {
         for (int i = 0; i < testFields.Length; i++)
         {
             IBLOB colValue = testFields[i] as IBLOB;
             if (colValue != null)
             {
                 colValue.Delete();
             }
         }
     }
     _table.DeleteRecord(_offset, testFields);
     _recordType = RecordType.DeletedMarker;
     _fieldsOld  = null;
 }
Example #2
0
 private void menuItem2_Click(object sender, EventArgs e)
 {
     ListView.SelectedListViewItemCollection list = _properties.SelectedItems;
     foreach (ListViewItem item in list)
     {
         IBLOB blob = item.Tag as IBLOB;
         if (blob != null)
         {
             try
             {
                 new ShowBlobAsText(blob.Stream).Show();
             }
             catch {}
         }
     }
 }
Example #3
0
        private void RepairProps(ITable propTable, PropDataType dataType)
        {
            HashSet resPropTypes = new HashSet();
            int     lastResID    = -1;

            using (IResultSet rs = propTable.CreateResultSet(0))
            {
                IEnumerator enumerator = rs.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        IRecord rec;
                        try
                        {
                            rec = (IRecord)enumerator.Current;
                        }
                        catch (AttemptReadingDeletedRecordException)
                        {
                            ReportError("Deleted record found in index for " + dataType + " property table");
                            continue;
                        }

                        _propCount++;

                        int resID    = rec.GetIntValue(0);
                        int propType = rec.GetIntValue(1);

                        if (resID != lastResID)
                        {
                            lastResID = resID;
                            resPropTypes.Clear();
                        }

                        IRecord resRec = _resources.GetRecordByEqual(0, resID);
                        if (resRec == null)
                        {
                            ReportError("Found a property of a non-existing resource " + resID);
                            if (_fixErrors)
                            {
                                rec.Delete();
                                _fixCount++;
                            }
                            continue;
                        }

                        if (!_propTypeMap.Contains(propType))
                        {
                            ReportError("Found a property with an invalid type " + propType);
                            if (_fixErrors)
                            {
                                rec.Delete();
                                _fixCount++;
                            }
                            continue;
                        }
                        if ((int)_propDataTypes [propType] != (int)dataType)
                        {
                            ReportError("Type of property " + propType + " does not match type of table " + dataType);
                            if (_fixErrors)
                            {
                                rec.Delete();
                                _fixCount++;
                            }
                            continue;
                        }

                        string propTypeName = (string)_propTypeMap [propType];

                        if (dataType != PropDataType.StringList && resPropTypes.Contains(propType))
                        {
                            ReportError("Duplicate property " + propTypeName + " of resource " + resID);
                            if (_fixErrors)
                            {
                                rec.Delete();
                                _fixCount++;
                            }
                            continue;
                        }

                        if (dataType == PropDataType.Blob)
                        {
                            IBLOB  blob = rec.GetBLOBValue(2);
                            Stream stream;
                            try
                            {
                                stream = blob.Stream;
                            }
                            catch (IOException)
                            {
                                ReportError("Missing blob stream for property " + propTypeName + " of resource " + resID);
                                if (_fixErrors)
                                {
                                    rec.Delete();
                                    _fixCount++;
                                }
                                continue;
                            }
                            try
                            {
                                long   length = stream.Length;
                                byte[] buffer = new byte[4096];
                                for (long bytesRead = 0; bytesRead < length; bytesRead += 4096)
                                {
                                    int bytesToRead = Math.Min(4096, (int)(length - bytesRead));
                                    stream.Read(buffer, 0, bytesToRead);
                                }
                            }
                            catch (IOException)
                            {
                                ReportError("Failed to read blob stream for property " + propTypeName + " of resource " + resID);
                                if (_fixErrors)
                                {
                                    rec.Delete();
                                    _fixCount++;
                                }
                            }
                            stream.Close();
                        }
                        else if (dataType == PropDataType.String || dataType == PropDataType.LongString)
                        {
                            try
                            {
                                rec.GetStringValue(2);
                            }
                            catch (IOException ex)
                            {
                                ReportError("Failed to read string value for property " + propTypeName + " of resource " + resID);
                                if (_fixErrors)
                                {
                                    rec.Delete();
                                    _fixCount++;
                                }
                            }
                        }

                        resPropTypes.Add(propType);
                    }
                }
                finally
                {
                    IDisposable disp = enumerator as IDisposable;
                    if (disp != null)
                    {
                        disp.Dispose();
                    }
                }
            }
        }