Example #1
0
        /// <summary>
        /// Calls Recompute on each row in the daton
        /// </summary>
        public void Recompute(DatonDef datondef)
        {
            var r = RecurPoint.FromDaton(datondef, this);

            if (r is RowRecurPoint rr)
            {
                Recompute(rr);
            }
            else if (r is TableRecurPoint rt)
            {
                Recompute(rt);
            }
        }
        /// <summary>
        /// determine which cols are not visible
        /// </summary>
        private List <FieldInfo> GetInvisibleFields(Daton daton, RecurPoint r)
        {
            var invisibleFields = new List <FieldInfo>();

            foreach (var coldef in r.TableDef.Cols)
            {
                var colLev = FinalLevel(daton, r.TableDef.Name, coldef.Name);
                if (!CanView(colLev))
                {
                    invisibleFields.Add(r.TableDef.RowType.GetField(coldef.Name));
                }
            }
            return(invisibleFields);
        }
Example #3
0
        /// <summary>
        /// determine which cols are not visible
        /// </summary>
        private List <ColDef> GetInvisibleCols(Daton daton, RecurPoint r)
        {
            var invisibles = new List <ColDef>();

            foreach (var coldef in r.TableDef.Cols)
            {
                var colLev = FinalLevel(daton, r.TableDef.Name, coldef.Name);
                if (!CanView(colLev))
                {
                    invisibles.Add(coldef);
                }
            }
            return(invisibles);
        }
Example #4
0
        /// <summary>
        /// Convert daton to JSON wire format
        /// </summary>
        public static string ToWire(DataDictionary dbdef, Daton daton, bool compatibleFormat)
        {
            var datondef  = dbdef.FindDef(daton);
            var buf       = new StringBuilder(1000);
            var writerOLD = new StringWriter(buf);
            var writer    = new JsonTextWriter(writerOLD);

            writer.WriteStartObject();
            writer.WritePropertyName("key");
            writer.WriteValue(daton.Key.ToString());
            writer.WritePropertyName("version");
            writer.WriteValue(daton.Version);
            if (daton is Viewon viewon && !viewon.IsCompleteLoad)
            {
                writer.WritePropertyName("isComplete");
                writer.WriteValue(false);
            }
            var r = RecurPoint.FromDaton(datondef, daton);

            if (compatibleFormat)
            {
                if (r is TableRecurPoint rt)
                {
                    WriteToCompatibleWire(writer, rt);
                }
                if (r is RowRecurPoint rr)
                {
                    writer.WritePropertyName(CamelCasify(datondef.MainTableDef.Name));
                    WriteToCompatibleWire(writer, rr);
                }
            }
            else //dense
            {
                writer.WritePropertyName("content");
                if (r is TableRecurPoint rt)
                {
                    WriteToDenseWire(writer, rt);
                }
                if (r is RowRecurPoint rr)
                {
                    writer.WriteStartArray();
                    WriteToDenseWire(writer, rr);
                    writer.WriteEndArray();
                }
            }
            writer.WriteEndObject();
            return(buf.ToString());
        }
        /// <summary>
        /// Modify the given daton by setting fields to null if the user does not have permission to view
        /// </summary>
        public void HidePrivateParts(Daton daton)
        {
            var datondef = Dbdef.FindDef(daton);
            var recur    = RecurPoint.FromDaton(datondef, daton);

            if (recur is TableRecurPoint rt)
            {
                HidePrivateParts(daton, rt);
            }
            else if (recur is RowRecurPoint rr)
            {
                //clear out the invisible cols in the single main row
                var invisibleFields = GetInvisibleFields(daton, rr);
                ClearInvisibleFields(invisibleFields, rr.Row);

                HidePrivateParts(daton, rr);
            }
        }
Example #6
0
        /// <summary>
        /// Validate the persiston and populate Errors in this instance with the problems found.
        /// </summary>
        public async Task ValidatePersiston(DatonDef datondef, Persiston daton)
        {
            Errors = new List <string>();

            //built-in validation
            var r = RecurPoint.FromDaton(datondef, daton);

            if (r is RowRecurPoint rr)
            {
                Validate(rr);
            }
            else if (r is TableRecurPoint rt)
            {
                Validate(rt);
            }

            //custom validation
            await daton.Validate(User, message => Errors.Add(message));
        }
Example #7
0
        /// <summary>
        /// if persiston was new, figure out new main row's key and set Modified.Key
        /// </summary>
        private static void AssignPersistonKey(SaveItem item)
        {
            if (!item.Modified.Key.IsNew)
            {
                return;
            }
            var mainTdef = item.DatonDef.MainTableDef;
            var r        = RecurPoint.FromDaton(item.DatonDef, item.Modified);

            if (r is RowRecurPoint rr)
            {
                object pk       = mainTdef.RowType.GetField(mainTdef.PrimaryKeyColName).GetValue(rr.Row);
                var    pkdef    = mainTdef.Cols.Single(c => c.Name == mainTdef.PrimaryKeyColName);
                string pkString = Retrovert.FormatRawJsonValue(pkdef, pk);
                item.Modified.Key = new PersistonKey(item.Modified.Key.Name, pkString, false);
                return;
            }

            //if reached here, client semantics was unexpected: it should have sent a new persiston only for a daton type
            //that defines a single main row; in all other cases the client should have loaded then modified an existing
            //persiston, even if it had no rows in it.
            throw new Exception("Cannot save a whole-table persiston with a daton-key identifying a primary key");
        }