示例#1
0
        public byte[] fetchData(ContextManager cm, CallerController <CallerData> cc)
        {
            if (data != null)
            {
                return(data);
            }

            if (id == null)
            {
                return(null);
            }

            if (cm == null)
            {
                return(null);
            }

            var dt = cm.get(ContextUtils.CTX_UTILS, cc).callFunction(UtilsContextConstants.F_GET_DATA, cc, id);

            var receivedData =
                StringUtils.ASCII_CHARSET.GetBytes(dt.rec().getString(UtilsContextConstants.FOF_GET_DATA_DATA));

            setData(receivedData);

            return(receivedData);
        }
示例#2
0
        public static void inlineData(DataTable table, ContextManager cm, CallerController <CallerData> cc)
        {
            foreach (var ff in table.getFormat())
            {
                if (ff.getType() == FieldFormat.DATA_FIELD)
                {
                    foreach (var rec in table)
                    {
                        var data = rec.getData(ff.getName());
                        data.fetchData(cm, cc);
                        data.setId(null);
                    }
                }

                if (ff.getType() != FieldFormat.DATATABLE_FIELD)
                {
                    continue;
                }
                foreach (var rec in table)
                {
                    var dt = rec.getDataTable(ff.getName());
                    inlineData(dt, cm, cc);
                }
            }
        }
示例#3
0
        public static List <EventDefinition> getEvents(Context context, String eventsMask,
                                                       CallerController <CallerData> caller)
        {
            var events = new List <EventDefinition>();

            if (eventsMask.Equals(ContextUtils.ENTITY_GROUP_MASK))
            {
                foreach (var ed in context.getEventDefinitions(caller))
                {
                    if (ed.getGroup() != null && !ContextUtils.GROUP_SYSTEM.Equals(ed.getGroup()))
                    {
                        events.Add(ed);
                    }
                }
            }
            else
            {
                var ed = context.getEventDefinition(eventsMask);
                if (ed != null)
                {
                    events.Add(ed);
                }
            }

            return(events);
        }
        protected override DataTable callFunctionImpl(FunctionDefinition def, CallerController <CallerData> caller,
                                                      RequestController <RequestData> request, DataTable parameters)
        {
            if (def.getName().Equals(F_LOCAL_REINITIALIZE))
            {
                reinitialize();
                return(new DataTable(def.getOutputFormat(), true));
            }

            return(callRemoteFunction(def.getName(), def.getOutputFormat(), parameters));
        }
        protected override TableFormat decodeFormat(String source, CallerController <CallerData> caller)
        {
            if (source == null)
            {
                return(null);
            }

            var idSourceBuilder = new StringBuilder();

            int i;

            for (i = 0; i < source.Length; i++)
            {
                var c = source[i];
                if (Char.IsDigit(c))
                {
                    idSourceBuilder.Append(c);
                }
                else
                {
                    break;
                }
            }

            source = source.Substring(i);

            var idSource = idSourceBuilder.ToString();

            var formatIdNullable = idSource.Length > 0 ? int.Parse(idSource) : (int?)null;

            var format = source.Length > 0 ? new TableFormat(source, new ClassicEncodingSettings(false)) : null;

            if (formatIdNullable == null)
            {
                return(format);
            }

            var formatId = (int)formatIdNullable;

            if (format == null)
            {
                TableFormat cached = controller.getFormatCache().get(formatId);

                if (cached == null)
                {
                    throw new ArgumentException("Unknown format ID: " + formatId);
                }

                return(cached);
            }

            controller.getFormatCache().put(formatId, format);
            return(format);
        }
 public override List <Context> getChildren(CallerController <CallerData> caller)
 {
     try
     {
         init();
     }
     catch (ContextException ex)
     {
         Log.CONTEXT_CHILDREN.warn("Error initializing children of remote context", ex);
     }
     return(base.getChildren(caller));
 }
 protected override DataTable getVariableImpl(VariableDefinition def, CallerController <CallerData> caller,
                                              RequestController <RequestData> request)
 {
     try
     {
         IncomingAggreGateCommand ans = sendGetVariable(def.getName());
         return(decodeRemoteDataTable(def.getFormat(), ans.getEncodedDataTableFromReply()));
     }
     catch (Exception ex)
     {
         Log.CONTEXT_VARIABLES.debug("Error getting variable '" + def.getName() + "' from context '" + this.getPath() + "'", ex);
         throw new ContextException(ex.Message, ex);
     }
 }
 protected override Boolean setVariableImpl(VariableDefinition def, CallerController <CallerData> caller,
                                            RequestController <RequestData> request, DataTable value)
 {
     try
     {
         controller.sendCommandAndCheckReplyCode(ClientCommandUtils.setVariableOperation(this.getPath(), def.getName(), value.encode(controller.createClassicEncodingSettings(true))));
         return(true);
     }
     catch (Exception ex)
     {
         Log.CONTEXT_VARIABLES.debug("Error setting veriable '" + def.getName() + "' of context '" + this.getPath() + "'", ex);
         throw new ContextException(ex.Message, ex);
     }
 }
示例#9
0
        public void validate(Context context, ContextManager contextManager, CallerController <CallerData> caller)
        {
            if (this.isInvalid())
            {
                throw new ValidationException(invalidationMessage);
            }

            foreach (var tv in this.getFormat().getTableValidators())
            {
                tv.validate(this);
            }

            foreach (DataRecord rec in this)
            {
                foreach (RecordValidator rv in getFormat().getRecordValidators())
                {
                    rv.validate(this, rec);
                }
                foreach (FieldFormat ff in getFormat())
                {
                    List <FieldValidator> fvs = ff.getValidators();
                    foreach (FieldValidator fv in fvs)
                    {
                        try
                        {
                            fv.validate(context, contextManager, caller, rec.getValue(ff.getName()));
                        }
                        catch (ValidationException ex)
                        {
                            throw new ValidationException("Error validating value of field '" + ff.ToString() + "': " + ex.Message, ex);
                        }
                    }
                }
            }
            foreach (FieldFormat ff in getFormat())
            {
                if (ff.getType() == FieldFormat.DATATABLE_FIELD)
                {
                    foreach (DataRecord rec in this)
                    {
                        DataTable nested = rec.getDataTable(ff.getName());
                        if (nested != null)
                        {
                            nested.validate(context, contextManager, caller);
                        }
                    }
                }
            }
        }
 public override Context getChild(String name, CallerController <CallerData> callerController)
 {
     if (base.getChild(name, callerController) == null)
     {
         try
         {
             init();
         }
         catch (ContextException ex)
         {
             Log.CONTEXT_CHILDREN.warn("Error initializing children of remote context", ex);
         }
     }
     return(base.getChild(name, callerController));
 }
示例#11
0
        public static List <Context> expandContextMaskToContexts(String mask, ContextManager contextManager,
                                                                 CallerController <CallerData> caller)
        {
            var res = new List <Context>();

            var paths = expandContextMaskToPaths(mask, contextManager, caller);

            foreach (var path in paths)
            {
                var con = contextManager.get(path, caller);
                if (con != null)
                {
                    res.Add(con);
                }
            }

            return(res);
        }
示例#12
0
        public static List <String> expandContextMaskToPaths(String mask,
                                                             ContextManager contextManager,
                                                             CallerController <CallerData> caller)
        {
            var result = new List <String>();

            var parts = StringUtils.split(mask, CONTEXT_NAME_SEPARATOR[0]);

            for (var i = 0; i < parts.Count; i++)
            {
                if (!parts[i].Equals(CONTEXT_GROUP_MASK))
                {
                    continue;
                }
                var head = new StringBuilder();

                for (var j = 0; j < i; j++)
                {
                    if (j > 0)
                    {
                        head.Append(CONTEXT_NAME_SEPARATOR);
                    }
                    head.Append(parts[j]);
                }

                var tail = new StringBuilder();

                for (var j = i + 1; j < parts.Count; j++)
                {
                    tail.Append(CONTEXT_NAME_SEPARATOR);
                    tail.Append(parts[j]);
                }

                result.AddRange(expandContextMaskPart(head.ToString(), tail.ToString(), contextManager, caller));
                return(result);
            }

            if (contextManager.get(mask, caller) != null)
            {
                result.Add(mask);
            }

            return(result);
        }
示例#13
0
        private static List <String> expandContextMaskPart(String head, String tail,
                                                           ContextManager contextManager,
                                                           CallerController <CallerData> caller)
        {
            var result = new List <String>();

            var con = contextManager.get(head, caller);

            if (con == null)
            {
                return(result);
            }

            foreach (var child in con.getChildren(caller))
            {
                result.AddRange(
                    expandContextMaskToPaths(head + CONTEXT_NAME_SEPARATOR + child.getName() + tail,
                                             contextManager, caller));
            }

            return(result);
        }
示例#14
0
 public DataTable get(Context con, VariableDefinition def, CallerController <CallerData> caller,
                      RequestController <RequestData> request)
 {
     return(getter.Invoke(con, def, caller, request));
 }
 public Boolean has(CallerController <CallerData> caller, Permissions requiredPermissions, Context accessedContext)
 {
     return(true);
 }
示例#16
0
        public object checkAndConvertValue(Context context, ContextManager contextManager, CallerController <CallerData> caller, object value, bool validate)
        {
            if (!this.isNullable() && value == null)
            {
                throw new ValidationException("Nulls are not permitted in " + this);
                //throw new ValidationException(MessageFormat.format(Cres.get().getString("dtNullsNotPermitted"), this.toString()));
            }

            value = this.convertValue(value);

            if (value != null && !this.isExtendableSelectionValues() && this.hasSelectionValue(value))
            {
                if (validate)
                {
                    throw new ValidationException(Cres.get().getString("dtValueNotInSelVals") + value + " (" + value.GetType().Name + ")");
                }
                else
                {
                    value = this.getDefaultValue();
                }
            }

            if (validate)
            {
                foreach (var fv in this.validators)
                {
                    value = fv.validate(context, contextManager, caller, value);
                }
            }

            return(value);
        }
示例#17
0
 public virtual bool set(Context con, VariableDefinition def, CallerController <CallerData> caller, RequestController <RequestData> request, DataTable value)
 {
     this.setter.Invoke(con, def, caller, request, value);
     return(true);
 }
 public override List <EventDefinition> getEventDefinitions(CallerController <CallerData> caller)
 {
     initEventsLoggingErrors();
     return(base.getEventDefinitions(caller));
 }
 public override List <FunctionDefinition> getFunctionDefinitions(CallerController <CallerData> caller)
 {
     initFunctionsLoggingErrors();
     return(base.getFunctionDefinitions(caller));
 }
示例#20
0
        public override object validate(Context context, ContextManager contextManager, CallerController <CallerData> caller, object value)
        {
            Regex reg;

            try
            {
                reg = new Regex(regex);
            }
            catch (ArgumentException ex)
            {
                throw new ValidationException(ex.Message, ex);
            }

            if (value != null && !reg.IsMatch(value.ToString()))
            {
                throw new ValidationException(this.message ?? string.Format(Cres.get().getString("dtValueDoesNotMatchPattern"), value, this.regex));
            }

            return(value);
        }
示例#21
0
        public override object validate(Context context, ContextManager contextManager, CallerController <CallerData> caller, object value)
        {
            if (value == null)
            {
                return(value);
            }

            if (value is Data)
            {
                var data = value as Data;

                if (data.getData() != null)
                {
                    IComparable size = data.getData().Length;
                    this.compare(size, null, null);
                }
            }
            else if (value is string)
            {
                this.compare(value.ToString().Length, Cres.get().getString("dtValueTooShort"), Cres.get().getString("dtValueTooLong"));
            }
            else
            {
                if (!(value is IComparable))
                {
                    throw new ValidationException(Cres.get().getString("dtValueNotComparable"));
                }

                var cv = (IComparable)value;

                this.compare(cv, null, null);
            }

            return(value);
        }
            public override object validate(Context context, ContextManager contextManager, CallerController <CallerData> caller, object value)
            {
                DataTable def = (DataTable)this.ownerFormat.getDefaultValue();

                if (def == null || def.getFieldCount() == 0)
                {
                    return(value);
                }

                DataTable dt = (DataTable)value;

                if (dt == null)
                {
                    return(value);
                }

                string msg = dt.getFormat().extendMessage(def.getFormat());

                if (msg != null)
                {
                    DataTable newValue = def.Clone() as DataTable;

                    // TODO: add data replication and validation
                    //DataTableReplication.copy(dt, newValue, true, true, true);
                    //value = newValue;

                    throw new NotImplementedException("DataTable copy is not implemented yet");
                }

                return(value);
            }
 public DataTable execute(Context con, FunctionDefinition def, CallerController <CallerData> caller,
                          RequestController <RequestData> request, DataTable parameters)
 {
     return(executor.Invoke(con, def, caller, request, parameters));
 }
示例#24
0
        public static List <EventDefinition> getEventDefinitions(ContextManager cm, String contextMask, String eventsMask, CallerController <CallerData> caller)
        {
            var events   = new List <EventDefinition>();
            var contexts = ContextUtils.expandContextMaskToContexts(contextMask, cm, caller);

            foreach (var context in contexts)
            {
                events.AddRange(getEvents(context, eventsMask, caller));
            }

            return(events);
        }
 public Context get(String contextName, CallerController <CallerData> caller)
 {
     return(getRoot().get(contextName, caller));
 }
 public override List <VariableDefinition> getVariableDefinitions(CallerController <CallerData> caller)
 {
     initVariablesLoggingErrors();
     return(base.getVariableDefinitions(caller));
 }
 protected void setCallerController(CallerController <CallerData> aCallerController)
 {
     callerController = aCallerController;
 }
示例#28
0
 public abstract object validate(Context context, ContextManager contextManager, CallerController <CallerData> caller, object value);