Exemplo n.º 1
0
 public override object ToDict(Type rDictType, Type rKeyType, Type rValueType)
 {
     rDictType = ITypeRedirect.GetRedirectType(rDictType);
     if (rDictType.IsGenericType && typeof(IDictionary).IsAssignableFrom(rDictType.GetGenericTypeDefinition()))
     {
         // 特殊处理IDictionary<,>类型
         IDictionary rObject = (IDictionary)ReflectionAssist.CreateInstance(rDictType, BindingFlags.Default);
         foreach (var rItem in this.dict)
         {
             object rKey   = GetKey_ByString(rKeyType, rItem.Key);
             object rValue = rItem.Value.ToObject(rValueType);
             rObject.Add(rKey, rValue);
         }
         return(rObject);
     }
     else if (rDictType.IsGenericType && typeof(IDict).IsAssignableFrom(rDictType.GetGenericTypeDefinition()))
     {
         // 特殊处理IDict<,>的类型
         IDict rObject = (IDict)ReflectionAssist.CreateInstance(rDictType, BindingFlags.Default);
         foreach (var rItem in this.dict)
         {
             object rKey   = GetKey_ByString(rKeyType, rItem.Key);
             object rValue = rItem.Value.ToObject(rValueType);
             rObject.AddObject(rKey, rValue);
         }
         return(rObject);
     }
     return(null);
 }
Exemplo n.º 2
0
        public PrgState execute(PrgState state)
        {
            IDict <String, int> symTable = state.getSymTbl();
            int file_id = this.exp_file_id.eval(symTable);
            MyTuple <String, TextReader> fileTable = state.getFileTable().lookup(file_id);

            if (fileTable == null)
            {
                throw new FileNotOpened();
            }
            String line = fileTable.getSecond().ReadLine();
            int    value;

            Console.WriteLine("\n\nstart" + line + "aici\n\n");
            if (line == null)
            {
                value = 0;
            }
            else
            {
                value = Convert.ToInt32(line);
            }
            if (symTable.isDefined(var_name))
            {
                symTable.update(var_name, value);
            }
            else
            {
                symTable.add(var_name, value);
            }
            return(state);
        }
        public int eval(IDict <string, int> symbolTable)
        {
            int left  = ex1.eval(symbolTable);
            int right = ex2.eval(symbolTable);

            if (oper == '+')
            {
                return(left + right);
            }
            if (oper == '-')
            {
                return(left - right);
            }
            if (oper == '*')
            {
                return(left * right);
            }
            if (oper == '/')
            {
                if (right == 0)
                {
                    throw new Exception("Division by 0!");
                }
                return(left / right);
            }
            throw new Exception("Wrong operator!");
        }
Exemplo n.º 4
0
        public static T GetChild <T>(IOwner owner, string key, bool isDebug = false) where T : class, IElement
        {
            if (owner == null)
            {
                return(null);
            }

            T     child       = null;
            IDict ownerAsDict = owner as IDict;

            if (ownerAsDict != null)
            {
                child = ownerAsDict.Get <IInDictElement>(key, isDebug) as T;
            }
            else
            {
                ITable ownerAsTable = owner as ITable;
                if (ownerAsTable != null)
                {
                    child = ownerAsTable.GetByKey <IInTableElement>(key, isDebug) as T;
                }
            }
            if (child == null)
            {
                owner.ErrorOrDebug(isDebug, "Not Found: {0}", key);
            }
            return(child);
        }
Exemplo n.º 5
0
        public override int eval(IDict <String, int> dict)
        {
            int finalResult = 0;
            int rez1        = this.firstExp.eval(dict);
            int rez2        = this.sndExp.eval(dict);

            switch (op)
            {
            case "+":
                finalResult = rez1 + rez2;
                break;

            case "-":
                finalResult = rez1 - rez2;
                break;

            case "*":
                finalResult = rez1 * rez2;
                break;

            case "//":
                if (rez2 == 0)
                {
                    throw new DivisionByZero();
                }
                finalResult = rez1 / rez2;
                break;

            default:
                throw new OperatorNotFound();
            }
            return(finalResult);
        }
Exemplo n.º 6
0
 public static T GetOrNewDescendant <TO, T>(IDict owner, string type, string relPath)
     where TO : class, IDict, IInDictElement
     where T : class, IInDictElement
 {
     return(GetOrCreateDescendant <TO, T>(owner, relPath,
                                          (IDict parent, String key) => parent.GetOrNew <T>(type, key)));
 }
Exemplo n.º 7
0
        private static T GetOrCreateDescendant <TO, T>(IDict owner, string relPath, Func <IDict, string, T> func)
            where TO : class, IDict, IInDictElement
            where T : class, IInDictElement
        {
            string[] keys    = relPath.Split(PathConsts.PathSeparator);
            IDict    current = owner;

            for (int i = 0; i < keys.Length; i++)
            {
                if (i < keys.Length - 1)
                {
                    if (current.Has(keys[i]))
                    {
                        current = Object.As <IDict>(current.Get <IInDictElement>(keys[i]));
                    }
                    else
                    {
                        current = current.Add <TO>(keys[i]);
                    }
                }
                else
                {
                    return(func(current, keys[i]));
                }
                if (current == null)
                {
                    return(null);
                }
            }
            return(null);
        }
Exemplo n.º 8
0
        public static void ForEachDescendants <T>(ITable owner, Action <T> callback)
            where T : class, IElement
        {
            owner.ForEach((IInTableElement element) => {
                T elementAsT = element as T;
                if (elementAsT != null)
                {
                    callback(elementAsT);
                }

                IDict elementAsDict = element as IDict;
                if (elementAsDict != null)
                {
                    ForEachDescendants <T>(elementAsDict, callback);
                }
                else
                {
                    ITable elementAsTable = element as ITable;
                    if (elementAsTable != null)
                    {
                        ForEachDescendants <T>(elementAsTable, callback);
                    }
                }
            });
        }
Exemplo n.º 9
0
        public override object ToDict(Type rDictType, Type rKeyType, Type rValueType)
        {
#if ILRUNTIME_USE
            rDictType = rDictType is ILRuntime.Reflection.ILRuntimeWrapperType ? ((ILRuntime.Reflection.ILRuntimeWrapperType)rDictType).CLRType.TypeForCLR : rDictType;
#endif
            if (rDictType.IsGenericType && typeof(IDictionary).IsAssignableFrom(rDictType.GetGenericTypeDefinition()))
            {
                // 特殊处理IDictionary<,>类型
                IDictionary rObject = (IDictionary)ReflectionAssist.CreateInstance(rDictType, BindingFlags.Default);
                foreach (var rItem in this.dict)
                {
                    object rKey   = GetKey_ByString(rKeyType, rItem.Key);
                    object rValue = rItem.Value.ToObject(rValueType);
                    rObject.Add(rKey, rValue);
                }
                return(rObject);
            }
            else if (rDictType.IsGenericType && typeof(IDict).IsAssignableFrom(rDictType.GetGenericTypeDefinition()))
            {
                // 特殊处理IDict<,>的类型
                IDict rObject = (IDict)ReflectionAssist.CreateInstance(rDictType, BindingFlags.Default);
                foreach (var rItem in this.dict)
                {
                    object rKey   = GetKey_ByString(rKeyType, rItem.Key);
                    object rValue = rItem.Value.ToObject(rValueType);
                    rObject.AddObject(rKey, rValue);
                }
                return(rObject);
            }
            return(null);
        }
Exemplo n.º 10
0
        public override int Eval(com.IDict <string, int> dict, IDict <int, int> heap)
        {
            Console.Write("Give int: ");
            int v = GetInputInt();

            return(v);
        }
Exemplo n.º 11
0
        public override object ToObject(Type rType)
        {
#if ILRUNTIME_USE
            rType = rType is ILRuntime.Reflection.ILRuntimeWrapperType ? ((ILRuntime.Reflection.ILRuntimeWrapperType)rType).CLRType.TypeForCLR : rType;
#endif
            if (rType.IsGenericType && typeof(IDictionary).IsAssignableFrom(rType.GetGenericTypeDefinition()))
            {
                // 特殊处理IDictionary<,>类型
                IDictionary rObject    = (IDictionary)ReflectionAssist.CreateInstance(rType, ReflectionAssist.flags_all);
                Type[]      rArgsTypes = rType.GetGenericArguments();
                foreach (var rItem in this.dict)
                {
                    object rKey   = GetKey_ByString(rArgsTypes[0], rItem.Key);
                    object rValue = rItem.Value.ToObject(rArgsTypes[1]);
                    rObject.Add(rKey, rValue);
                }
                return(rObject);
            }
            else if (rType.IsGenericType && typeof(IDict).IsAssignableFrom(rType.GetGenericTypeDefinition()))
            {
                // 特殊处理IDict<,>的类型
                IDict  rObject    = (IDict)ReflectionAssist.CreateInstance(rType, ReflectionAssist.flags_all);
                Type[] rArgsTypes = rType.GetGenericArguments();
                foreach (var rItem in this.dict)
                {
                    object rKey   = GetKey_ByString(rArgsTypes[0], rItem.Key);
                    object rValue = rItem.Value.ToObject(rArgsTypes[1]);
                    rObject.AddObject(rKey, rValue);
                }
                return(rObject);
            }
            else if (rType.IsClass)
            {
                BindingFlags rBindFlags = ReflectionAssist.flags_all;
                object       rObject    = ReflectionAssist.CreateInstance(rType, rBindFlags);
                foreach (var rItem in this.dict)
                {
                    Type      rMemberType = null;
                    FieldInfo rFieldInfo  = rType.GetField(rItem.Key, rBindFlags);
                    if (rFieldInfo != null)
                    {
                        rMemberType = rFieldInfo.FieldType;
                        object rValueObj = rItem.Value.ToObject(rMemberType);
                        rFieldInfo.SetValue(rObject, rValueObj);
                        continue;
                    }
                    PropertyInfo rPropInfo = rType.GetProperty(rItem.Key, rBindFlags);
                    if (rPropInfo != null)
                    {
                        rMemberType = rPropInfo.PropertyType;
                        object rValueObj = rItem.Value.ToObject(rMemberType);
                        rPropInfo.SetValue(rObject, rValueObj, null);
                        continue;
                    }
                }
                return(rObject);
            }
            return(null);
        }
Exemplo n.º 12
0
 public DictController(IDict dict)
 {
     bll = dict;
     BusinessServices = new List <object>()
     {
         dict
     };
 }
Exemplo n.º 13
0
        public DeltaDict(IDict <TKey, TValue> baseDict, Dict <TKey, TValue> deltaDict)
        {
            m_baseDict  = baseDict;
            m_deltaDict = deltaDict;
            var dictDepth = baseDict as IDictDepth;

            m_depth = dictDepth != null ? dictDepth.Depth + 1 : 1;
        }
Exemplo n.º 14
0
 /**
  * Constructor
  * @param stk - execution stack
  * @param symtbl - symbol table
  * @param ot - output list
  */
 public ProgState(IList <int> o, IDict <string, int> s, IStack <IStmt> e, IDict <int, int> hp)
 {
     this.output   = o;
     this.symTable = s;
     this.exeStack = e;
     this.heap     = hp;
     this.id       = rnd.Next(1, 1000);
 }
Exemplo n.º 15
0
 public override int eval(IDict <String, int> dict)
 {
     if (!dict.isDefined(this.id))
     {
         throw new VariableNotFound();
     }
     return(dict.lookup(this.id));
 }
Exemplo n.º 16
0
 public int eval(IDict <string, int> symbolTable)
 {
     if (symbolTable.contains(varName))
     {
         return(symbolTable.getValue(varName));
     }
     throw new Exception("Variable not found!");
 }
Exemplo n.º 17
0
        public SingleDeltaDict(IDict <TKey, TValue> baseDict, TKey key, TValue value)
        {
            m_baseDict = baseDict;
            m_key      = key;
            m_value    = value;
            var dictDepth = baseDict as IDictDepth;

            m_depth = dictDepth != null ? dictDepth.Depth + 1 : 1;
        }
Exemplo n.º 18
0
 public PrgState(IStack <IStmt> stk, IDict <String, int> symtbl, IList <int> output, IDictRandIntKey <MyTuple <String, TextReader> > fileTable, IStmt stmt)
 {
     this.exeStack             = stk;
     this.symTable             = symtbl;
     this.output               = output;
     this.fileTable            = fileTable;
     this.originalProgramState = stmt;
     this.exeStack.push(stmt);
 }
Exemplo n.º 19
0
        public PrgState execute(PrgState state)
        {
            IList <int>         output = state.getOutput();
            IDict <String, int> symTbl = state.getSymTbl();
            int val = exp.eval(symTbl);

            output.add(val);
            return(null);
        }
Exemplo n.º 20
0
        public TranslateWindow()
        {
            InitializeComponent();

            _isShowSource = true;
            _isLocked     = false;

            _gameTextHistory = new Queue <string>();

            this.Topmost = true;
            UI_Init();
            IsOCRingFlag = false;


            _wordSpliter = WordSpliterAuto(Common.appSettings.WordSpliter);

            _textSpeechHelper = new TextSpeechHelper();
            if (Common.appSettings.ttsVoice == "")
            {
                Growl.InfoGlobal(Application.Current.Resources["TranslateWin_NoTTS_Hint"].ToString());
            }
            else
            {
                _textSpeechHelper.SetTTSVoice(Common.appSettings.ttsVoice);
                _textSpeechHelper.SetVolume(Common.appSettings.ttsVolume);
                _textSpeechHelper.SetRate(Common.appSettings.ttsRate);
            }

            if (Common.appSettings.xxgPath != string.Empty)
            {
                _dict = new XxgJpzhDict();
                _dict.DictInit(Common.appSettings.xxgPath, string.Empty);
            }

            IsPauseFlag  = true;
            _translator1 = TranslatorAuto(Common.appSettings.FirstTranslator);
            _translator2 = TranslatorAuto(Common.appSettings.SecondTranslator);

            _beforeTransHandle = new BeforeTransHandle(Convert.ToString(Common.GameID), Common.UsingSrcLang, Common.UsingDstLang);
            _afterTransHandle  = new AfterTransHandle(_beforeTransHandle);

            _artificialTransHelper = new ArtificialTransHelper(Convert.ToString(Common.GameID));

            if (Common.transMode == 1)
            {
                Common.textHooker.Sevent += DataRecvEventHandler;
            }
            else if (Common.transMode == 2)
            {
                MouseKeyboardHook_Init();
            }

            toggleRec.ToolTip = Common.appSettings.ATon ? REC_OFF: REC_ON;
            updateToggleRecDisplay(false);
        }
Exemplo n.º 21
0
 public UserEmailBuilder(IPsaContextService contextService, IConnClientService ConnClientService, IMasterOrganizationRepository masterOrganizationRepository, IDict dictionary, IAppSettings settings, IFeatureService featureService, IEmailTemplateService emailTemplateService, IDistributorHelperService distributorHelperService)
 {
     ContextService               = contextService;
     ConnClientService            = ConnClientService;
     MasterOrganizationRepository = masterOrganizationRepository;
     Dictionary               = dictionary;
     Settings                 = settings;
     FeatureService           = featureService;
     EmailTemplateService     = emailTemplateService;
     DistributorHelperService = distributorHelperService;
 }
Exemplo n.º 22
0
        public static bool RemoveFromOwner(this IContext context)
        {
            IDict owner = context.OwnerAsDict;

            if (owner == null)
            {
                return(false);
            }

            return(owner.Remove <IContext>(context.Key) != null);
        }
 public ProgramState(IStack <IStatement> stack,
                     IDict <String, int> symb,
                     ILis <int> outl,
                     IDict <int, FileData> files,
                     IStatement original)
 {
     exeStack    = stack;
     symbolTable = symb;
     outList     = outl;
     fileTable   = files;
     originalPrg = original;
 }
Exemplo n.º 24
0
        public static TType GetOrDefault <TType, TValue>(
            this IDict <Symbol, TValue> dict, TypedSymbol <TType> key)
            where TType : TValue
        {
            TValue value;

            if (dict.TryGetValue(key.Symbol, out value))
            {
                return((TType)value);
            }
            return(default(TType));
        }
Exemplo n.º 25
0
        /// <summary>
        /// Returns an IDict with the supplied key/value pair added. Internally
        /// the supplied dict is not modified, but referenced, and a suitable
        /// DeltaDict is built that contains only the changes.
        /// </summary>
        public static IDict <Symbol, TValue> WithAdded <TValue>(
            this IDict <Symbol, TValue> dict,
            Symbol key, TValue value)
        {
            var sd = dict as SingleDeltaSymbolDict <TValue>;

            if (sd != null && key == sd.m_key)
            {
                return(new SingleDeltaSymbolDict <TValue>(sd.m_baseDict, key, value));
            }
            return(new SingleDeltaSymbolDict <TValue>(dict, key, value));
        }
Exemplo n.º 26
0
        /// <summary>
        /// Returns an IDict with the supplied key/value pair added. Internally
        /// the supplied dict is not modified, but referenced, and a suitable
        /// DeltaDict is built that contains only the changes.
        /// </summary>
        public static IDict <TKey, TValue> WithAdded <TKey, TValue>(
            this IDict <TKey, TValue> dict,
            TKey key, TValue value)
        {
            var sd = dict as SingleDeltaDict <TKey, TValue>;

            if (sd != null && key.Equals(sd.m_key))
            {
                return(new SingleDeltaDict <TKey, TValue>(sd.m_baseDict, key, value));
            }
            return(new SingleDeltaDict <TKey, TValue>(dict, key, value));
        }
Exemplo n.º 27
0
 private static void SetCachedBounds(IArrangedElement element, Rectangle bounds)
 {
     if (bounds != GetCachedBounds(element))
     {
         IDict dictionary = (IDict)element.Container.Properties.GetObject(_cachedBoundsProperty);
         if (dictionary == null)
         {
             dictionary = new HybridDictionary();
             element.Container.Properties.SetObject(_cachedBoundsProperty, dictionary);
         }
         dictionary[element] = bounds;
     }
 }
Exemplo n.º 28
0
        public Task <ServerResponse> GetAsync(string query, IDict variables       = null, string operationName = null,
                                              CancellationToken cancellationToken = default)
        {
            var request = new GraphQLRequest()
            {
                Query = query, Variables = variables, OperationName = operationName
            };
            var reqData = new ClientRequest()
            {
                HttpMethod = "GET", CoreRequest = request, CancellationToken = cancellationToken
            };

            return(SendAsync(reqData));
        }
Exemplo n.º 29
0
        public static List <T> GetDescendants <T>(IDict owner)
            where T : class, IElement
        {
            List <T> result = null;

            ForEachDescendants <T>(owner, (T element) => {
                if (result == null)
                {
                    result = new List <T>();
                }
                result.Add(element);
            });
            return(result);
        }
Exemplo n.º 30
0
        public static bool TryGetValue <TType, TValue>(
            this IDict <Symbol, TValue> dict, TypedSymbol <TType> key, out TType typedValue)
            where TType : TValue
        {
            TValue value;

            if (dict.TryGetValue(key.Symbol, out value))
            {
                typedValue = (TType)value;
                return(true);
            }
            typedValue = default(TType);
            return(false);
        }