Exemplo n.º 1
0
        internal static void RegisterUniqueRestriction(string resourceType, int propId)
        {
            if (resourceType == null)
            {
                throw new ArgumentNullException("resourceType");
            }
            if (!MyPalStorage.Storage.ResourceTypes.Exist(resourceType))
            {
                throw new ArgumentException("Invalid resource type " + resourceType, resourceType);
            }

            PropDataType dataType = MyPalStorage.Storage.PropTypes [propId].DataType;

            if (dataType != PropDataType.Int && dataType != PropDataType.String && dataType != PropDataType.Date)
            {
                throw new StorageException("Unique restrictions may only be registered for int, string or date properties");
            }

            UniqueRestriction restriction = new UniqueRestriction(resourceType, propId);

            if (AddResourceRestriction(restriction))
            {
                restriction.SaveToResourceStore();
            }
        }
Exemplo n.º 2
0
 private void FillSortMenuText(JetListViewColumn column, ColumnDescriptor desc, int[] propIds)
 {
     column.SortMenuText = GetColumnText(propIds);
     if (desc.SortMenuAscText != null)
     {
         column.SortMenuAscText  = desc.SortMenuAscText;
         column.SortMenuDescText = desc.SortMenuDescText;
     }
     else
     {
         for (int i = 0; i < propIds.Length; i++)
         {
             PropDataType propType = Core.ResourceStore.PropTypes [propIds [i]].DataType;
             if (propType == PropDataType.Date)
             {
                 column.SortMenuAscText  = "Oldest on top";
                 column.SortMenuDescText = "Newest on top";
                 break;
             }
             if (propType == PropDataType.String || propType == PropDataType.LongString ||
                 propType == PropDataType.Link)
             {
                 column.SortMenuAscText  = "A on top";
                 column.SortMenuDescText = "Z on top";
                 break;
             }
         }
     }
 }
Exemplo n.º 3
0
Arquivo: Contact.cs Projeto: mo5h/omeo
        public void SetProp(int prop, object value)
        {
            bool         needUpdate = false;
            PropDataType type       = Core.ResourceStore.PropTypes[prop].DataType;

            if (type == PropDataType.String || type == PropDataType.LongString)
            {
                if (_resource.GetPropText(prop) != value as string)
                {
                    needUpdate = true;
                }
            }
            else
            {
                object val = _resource.GetProp(prop);
                if ((val == null && value != null) || (val != null && !val.Equals(value)))
                {
                    needUpdate = true;
                }
            }
            _changed = _changed || needUpdate;
            if (needUpdate)
            {
                if (Core.ResourceStore.IsOwnerThread())
                {
                    _resource.SetProp(prop, value);
                }
                else
                {
                    new ResourceProxy(_resource).SetPropAsync(prop, value);
                }
            }
        }
Exemplo n.º 4
0
        public void EditCustomPropertyTypes()
        {
            IResourceList customPropTypes = Core.ResourceStore.FindResources("PropType", "Custom", 1);

            foreach (IResource res in customPropTypes)
            {
                string       name     = res.GetStringProp(Core.Props.Name);
                PropDataType dataType = Core.ResourceStore.PropTypes [name].DataType;
                if (dataType != PropDataType.Link)
                {
                    if (name.StartsWith("Custom."))
                    {
                        name = name.Substring(7);
                    }
                    ListViewItem lvItem = _lvTypes.Items.Add(name);
                    lvItem.SubItems.Add(GetDataTypeName(dataType));
                    lvItem.Tag = new PropTypeTag(res.GetIntProp("ID"), dataType);
                    if (lvItem.Index == 0)
                    {
                        lvItem.Selected = true;
                    }
                }
            }
            UpdateButtonState();
            if (ShowDialog(Core.MainWindow) == DialogResult.OK)
            {
                Core.ResourceAP.RunJob(new MethodInvoker(SaveCustomPropertyTypes));
            }
        }
Exemplo n.º 5
0
 private static IGroupProvider GetGroupProvider(int[] propIds)
 {
     if (propIds.Length > 0)
     {
         int propId = propIds [0];
         if (propId == ResourceProps.Type)
         {
             return(new ResourceTypeGroupProvider());
         }
         if (propId == ResourceProps.DisplayName)
         {
             return(new DisplayNameGroupProvider());
         }
         PropDataType propType = Core.ResourceStore.PropTypes [propId].DataType;
         if (propType == PropDataType.Date)
         {
             return(new DateGroupProvider(propId));
         }
         if (propType == PropDataType.String || propType == PropDataType.LongString || propType == PropDataType.Link)
         {
             return(new PropTextGroupProvider(propId));
         }
     }
     return(null);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Adds a property type to the cache.
        /// </summary>
        internal void AddPropTypeToCache(int ID, string name, PropDataType propType, PropTypeFlags flags)
        {
            if (ID < 0 || ID > 65536)
            {
                throw new BadIndexesException("Invalid property type ID " + ID);
            }

            lock ( _propTypeCache )
            {
                PropTypeItem propTypeItem = new PropTypeItem(ID, name, propType, flags);
                while (_propTypeCache.Count < ID)
                {
                    _propTypeCache.Add(null);
                }

                if (_propTypeCache.Count == ID)
                {
                    _propTypeCache.Add(propTypeItem);
                }
                else
                {
                    _propTypeCache [ID] = propTypeItem;
                }

                _propTypeNameCache [name] = propTypeItem;
            }
        }
Exemplo n.º 7
0
        internal void CreateOrUpdatePropTypeResource(string name, PropDataType dataType, PropTypeFlags flags, IPlugin ownerPlugin, int ID, bool newPropType)
        {
            if (newPropType)
            {
                IResource res;
                try
                {
                    res = CreatePropTypeResource(ID, name, dataType, flags);
                }
                catch (ResourceRestrictionException ex)   // OM-9471
                {
                    MyPalStorage.Storage.OnIndexCorruptionDetected("ResourceRestrictionException when creating PropType resource: " +
                                                                   ex.Message);
                    return;
                }
                _storage.SetOwnerPlugin(res, ownerPlugin);
            }
            else
            {
                IResource res = _storage.FindUniqueResource("PropType", "Name", name);

                if (res != null)
                {
                    res.SetProp("Flags", (int)this [name].Flags);      // ensure OR'ed flags are applied correctly
                    _storage.SetOwnerPlugin(res, ownerPlugin);
                }
                else
                {
                    MyPalStorage.Storage.OnIndexCorruptionDetected("Could not find PropType resource for property type " + name);
                }
            }
        }
Exemplo n.º 8
0
        private void AddPropertyType(PropDataType dataType)
        {
            _lvTypes.LabelEdit = true;
            ListViewItem lvItem = _lvTypes.Items.Add("");

            lvItem.SubItems.Add(GetDataTypeName(dataType));
            lvItem.Tag = new PropTypeTag(-1, dataType);
            lvItem.BeginEdit();
        }
Exemplo n.º 9
0
        public int Register(string name, PropDataType dataType, PropTypeFlags flags, IPlugin ownerPlugin)
        {
            bool newPropType = false;
            int  ID          = RegisterPropTypeInternal(name, dataType, flags, false, out newPropType);

            CreateOrUpdatePropTypeResource(name, dataType, flags, ownerPlugin, ID, newPropType);

            return(ID);
        }
Exemplo n.º 10
0
        public int Register(string name, PropDataType dataType, PropTypeFlags flags)
        {
            _propTypes [name] = dataType;
            int id = _propTypes.Count;

            _idToPropType [id]   = name;
            _propTypeToId [name] = id;
            return(id);
        }
Exemplo n.º 11
0
 internal PropTypeItem(int ID, string name, PropDataType type, PropTypeFlags flags)
 {
     _id                 = ID;
     _name               = name;
     _type               = type;
     _flags              = flags;
     _displayName        = null;
     _reverseDisplayName = null;
     _ownerPluginLoaded  = true;
 }
Exemplo n.º 12
0
        /// <summary>
        /// Creates a resource describing the property type.
        /// </summary>
        private IResource CreatePropTypeResource(int ID, string name, PropDataType propType, PropTypeFlags flags)
        {
            IResource res = _storage.BeginNewResource("PropType");

            res.SetProp(_storage.Props.Name, name);
            res.SetProp(_storage.Props.TypeId, ID);
            res.SetProp(_storage.Props.DataType, (int)propType);
            res.SetProp(_storage.Props.Flags, (int)flags);
            res.EndUpdate();
            return(res);
        }
Exemplo n.º 13
0
        /**
         * Returns the default alignment for the specified column names.
         */

        private static HorizontalAlignment GetDefaultAlignment(int[] propIDs)
        {
            for (int i = 0; i < propIDs.Length; i++)
            {
                PropDataType propType = Core.ResourceStore.PropTypes [propIDs [i]].DataType;
                if (propType == PropDataType.Double)
                {
                    return(HorizontalAlignment.Right);
                }
            }
            return(HorizontalAlignment.Left);
        }
Exemplo n.º 14
0
        private static string GetDataTypeName(PropDataType type)
        {
            switch (type)
            {
            case PropDataType.String: return("text");

            case PropDataType.Int:    return("number");

            case PropDataType.Date:   return("date");

            case PropDataType.Bool:   return("yes/no");

            default: return("other");
            }
        }
Exemplo n.º 15
0
        public static int UpdatePropTypeRegistration(string name, PropDataType dataType, PropTypeFlags flags)
        {
            int       propID;
            IResource propres = Core.ResourceStore.FindUniqueResource("PropType", "Name", name);

            if (propres != null)
            {
                propID = propres.GetIntProp("ID");
                propres.SetProp("Flags", (int)flags);
            }
            else
            {
                propID = Core.ResourceStore.PropTypes.Register(name, dataType, flags);
            }
            return(propID);
        }
Exemplo n.º 16
0
        protected static string GetCustomPropText(IResource res, int propID)
        {
            string       propText;
            PropDataType dataType = Core.ResourceStore.PropTypes [propID].DataType;

            if (dataType == PropDataType.Bool)
            {
                propText = res.HasProp(propID) ? "Yes" : "";
            }
            else if (dataType == PropDataType.Date)
            {
                propText = res.GetDateProp(propID).ToShortDateString();
            }
            else
            {
                propText = res.GetPropText(propID);
            }
            return(propText);
        }
Exemplo n.º 17
0
        /**
         * Checks if any of the resources in the list has the property with
         * the specified ID.
         */

        public virtual bool HasProp(int propID)
        {
            lock (this)
            {
                if (_propertyProviders != null)
                {
                    for (int i = 0; i < _propertyProviders.Count; i++)
                    {
                        if ((_propertyProviders [i] as IPropertyProvider).HasProp(propID))
                        {
                            return(true);
                        }
                    }
                }

                IPropType propType = MyPalStorage.Storage.PropTypes [propID];
                if (propType.HasFlag(PropTypeFlags.Virtual))
                {
                    return(false);
                }

                PropDataType dataType = propType.DataType;
                if (dataType == PropDataType.LongString || dataType == PropDataType.Blob || dataType == PropDataType.Double)
                {
                    Instantiate();
                    for (int i = 0; i < _list.Count; i++)
                    {
                        IResource res = MyPalStorage.Storage.TryLoadResource(_list [i]);
                        if (res != null && res.HasProp(propID))
                        {
                            return(true);
                        }
                    }
                    return(false);
                }
            }
            return(Intersect(MyPalStorage.Storage.FindResourcesWithProp(null, propID)).Count > 0);
        }
Exemplo n.º 18
0
        public static IResource Deserialize(Stream stream, BeforeDeserializationDelegate beforeCheck)
        {
            if (stream.CanSeek)
            {
                stream.Position = 0;
            }
            BinaryReader reader = new BinaryReader(stream);

            using ( reader )
            {
                string    resType = reader.ReadString();
                IResource result  = Core.ResourceStore.BeginNewResource(resType);
                try
                {
                    int propCount = reader.ReadInt32();
                    for (int i = 0; i < propCount; ++i)
                    {
                        PropDataType propType = (PropDataType)reader.ReadInt32();
                        int          propId   = reader.ReadInt32();
                        switch (propType)
                        {
                        case PropDataType.Link:
                        {
                            int count = reader.ReadInt32();
                            for (int j = 0; j < count; ++j)
                            {
                                LinkResource(reader, result, propId, beforeCheck);
                            }
                            break;
                        }

                        case PropDataType.String:
                        case PropDataType.LongString:
                        {
                            result.SetProp(propId, reader.ReadString());
                            break;
                        }

                        case PropDataType.StringList:
                        {
                            int         count  = reader.ReadInt32();
                            IStringList strLst = result.GetStringListProp(propId);
                            using ( strLst )
                            {
                                for (int j = 0; j < count; ++j)
                                {
                                    strLst.Add(reader.ReadString());
                                }
                            }
                            break;
                        }

                        case PropDataType.Int:
                        {
                            result.SetProp(propId, reader.ReadInt32());
                            break;
                        }

                        case PropDataType.Date:
                        {
                            result.SetProp(propId, new DateTime(reader.ReadInt64()));
                            break;
                        }

                        case PropDataType.Bool:
                        {
                            result.SetProp(propId, true);
                            break;
                        }

                        case PropDataType.Double:
                        {
                            result.SetProp(propId, reader.ReadDouble());
                            break;
                        }

                        case PropDataType.Blob:
                        {
                            int    length = reader.ReadInt32();
                            byte[] buffer = new byte[length];
                            reader.Read(buffer, 0, length);
                            result.SetProp(propId, new JetMemoryStream(buffer, true));
                            break;
                        }
                        }
                    }
                }
                finally
                {
                    result.EndUpdate();
                }
                return(result);
            }
        }
Exemplo n.º 19
0
 public PropTypeTag(int propID, PropDataType dataType)
 {
     PropID   = propID;
     DataType = dataType;
 }
Exemplo n.º 20
0
        /**
         * Adds a record for the specified prop type to the DB.
         */

        internal int RegisterPropTypeInternal(string name, PropDataType propType, PropTypeFlags flags,
                                              bool forceType, out bool newPropType)
        {
            _storage.CheckOwnerThread();
            IRecord rec = _propTypeTable.GetRecordByEqual(1, name);

            if (rec != null)
            {
                if (!_propTypeNameCache.ContainsKey(name))
                {
                    throw new BadIndexesException("Property type " + name + " found in PropTypes table but missing in name cache");
                }

                bool recordChanged = false;
                if (rec.GetIntValue(2) != (int)propType)
                {
                    if (forceType)
                    {
                        rec.SetValue(2, IntInternalizer.Intern((int)propType));
                        ((PropTypeItem)this[name]).SetDataType(propType);
                        recordChanged = true;
                    }
                    else
                    {
                        throw new StorageException("Inconsistent registration for property type " + name +
                                                   ": old type " + (PropDataType)rec.GetIntValue(2) + ", new type " + propType);
                    }
                }
                int           propId   = rec.GetIntValue(0);
                PropTypeFlags newFlags = flags | this [propId].Flags;
                if (rec.GetIntValue(3) != (int)newFlags)
                {
                    rec.SetValue(3, (int)newFlags);
                    recordChanged = true;
                }
                if (recordChanged)
                {
                    rec.Commit();
                }

                newPropType = false;
                PropTypeItem propTypeItem = (PropTypeItem)_propTypeCache [propId];
                propTypeItem.SetFlags(newFlags);
                return(propId);
            }

            if ((flags & (PropTypeFlags.DirectedLink | PropTypeFlags.CountUnread)) != 0 &&
                propType != PropDataType.Link)
            {
                throw new StorageException("DirectedLink and CountUnread flags can be used only on Link properties");
            }

            int ID;

            lock ( _propTypeTable )
            {
                IRecord propertyType = _propTypeTable.NewRecord();
                propertyType.SetValue(1, name);
                propertyType.SetValue(2, IntInternalizer.Intern((int)propType));
                propertyType.SetValue(3, (int)flags);
                _storage.SafeCommitRecord(propertyType, "PropTypeCollection.RegisterPropTypeInternal");
                ID = propertyType.GetID();
                if (ID > 65536)
                {
                    MyPalStorage.Storage.OnIndexCorruptionDetected("Invalid next ID in property type table");
                }
            }

            AddPropTypeToCache(ID, name, propType, flags);

            newPropType = true;
            return(ID);
        }
Exemplo n.º 21
0
 internal void SetDataType(PropDataType dataType)
 {
     _type = dataType;
 }
Exemplo n.º 22
0
 public int Register(string name, PropDataType propType, PropTypeFlags flags)
 {
     return(Register(name, propType, flags, null));
 }
Exemplo n.º 23
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();
                    }
                }
            }
        }
Exemplo n.º 24
0
 public int Register(string name, PropDataType dataType, PropTypeFlags flags, IPlugin ownerPlugin)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 25
0
 public int Register(string name, PropDataType dataType)
 {
     return(Register(name, dataType, PropTypeFlags.Normal));
 }