コード例 #1
0
ファイル: Broadcaster.cs プロジェクト: rexperalta/OCTGN
		internal Broadcaster(Handler handler)
		{ 
			bin = new BinFormatter(this, handler);
		}
コード例 #2
0
ファイル: Broadcaster.cs プロジェクト: totalgit/OCTGN
 internal Broadcaster(Dictionary <TcpClient, Handler.PlayerInfo> to, Handler handler)
 {
     this.to = to; this.handler = handler;
     bin     = new BinFormatter(this, handler);
 }
コード例 #3
0
ファイル: Broadcaster.cs プロジェクト: jaras/OCTGN
 internal Broadcaster(State state)
 {
     _state = state;
     bin    = new BinFormatter(this, _state.Handler);
 }
コード例 #4
0
ファイル: Broadcaster.cs プロジェクト: kellyelton/octgnwlobby
 internal void RefreshTypes()
 {
     bool bBin = false, bXml = false;
     foreach (Handler.PlayerInfo pi in to.Values)
     {
         bBin |= pi.binary == true;
         bXml |= pi.binary == false;
     }
     if (bBin && bin == null) bin = new BinFormatter(this, handler);
     else if (!bBin && bin != null) bin = null;
     if (bXml && xml == null) xml = new XmlFormatter(this, handler);
     else if (!bXml && xml != null) xml = null;
 }
コード例 #5
0
ファイル: Broadcaster.cs プロジェクト: IanWhalen/OCTGN
 internal Broadcaster(Dictionary<TcpClient, Handler.PlayerInfo> to, Handler handler)
 {
     this.to = to; this.handler = handler;
     bin = new BinFormatter(this, handler);
 }
コード例 #6
0
 internal Broadcaster(Handler handler)
 {
     bin = new BinFormatter(this, handler);
 }
コード例 #7
0
 public static DeviceItemProfile Load(Stream streamSrc)
 {
     return(BinFormatter.Deserialize(streamSrc) as DeviceItemProfile);
 }
コード例 #8
0
        public static void Save(DeviceItem deviceItem, Stream streamDest)
        {
            DeviceItemProfile deviceItemProfile = new DeviceItemProfile(deviceItem);

            BinFormatter.Serialize(streamDest, deviceItemProfile);
        }
コード例 #9
0
ファイル: Calculator.cs プロジェクト: minu-calculator/Minu
        public List <string> Calculate(string rawInput)
        {
            IOutputFormatter outputFormatter = new DecFormatter();

            isInputOverflowed = false;
            Variables.Clear();
            Functions.Clear();

            string[] inputs = rawInput.Replace("\r", "").Split('\n');

            var    resultList = new List <string>();
            var    arguments  = new List <Argument>();
            var    functions  = new List <Function>();
            double ans        = 0.0;

            for (int lineNumber = 0; lineNumber < inputs.Length; ++lineNumber)
            {
                string inputLine    = inputs[lineNumber];
                string lineResult   = "";
                string definedToken = "";

                if (inputLine.StartsWith("#"))
                {
                    // comments + settings
                    string trimed = inputLine.Substring(1).TrimStart().ToLower();
                    if (trimed.StartsWith("bin"))
                    {
                        outputFormatter = new BinFormatter();
                    }
                    else if (trimed.StartsWith("oct"))
                    {
                        outputFormatter = new OctFormatter();
                    }
                    else if (trimed.StartsWith("dec"))
                    {
                        outputFormatter = new DecFormatter();
                    }
                    else if (trimed.StartsWith("hex"))
                    {
                        outputFormatter = new HexFormatter();
                    }
                    else if (trimed.StartsWith("sci"))
                    {
                        outputFormatter = new SciFormatter();
                    }
                }
                else if (functionRegex.IsMatch(inputLine))
                {
                    // functions
                    Function func = new Function(inputLine);
                    func.addFunctions(functions.ToArray());
                    if (func.getFunctionName() != null)
                    {
                        bool overrided = functions.RemoveAll(f => f.getFunctionName() == func.getFunctionName()) > 0;
                        functions.Add(func);
                        definedToken = func.getFunctionName();
                        cacheSystem.InvalidateCache(func.getFunctionName());
                        Functions[definedToken] = inputLine.Substring(0, inputLine.IndexOf('='));
                    }
                }
                else if (inputLine.Contains("="))
                {
                    // variables
                    Argument arg;
                    double   res;
                    if (cacheSystem.TryGetResult(inputLine, out var cache)) // try to get from cache first
                    {
                        arg = new Argument(cache.Name, cache.Result);
                        //lineResult = "[#] ";
                    }
                    else
                    {
                        arg = new Argument(inputLine, new Argument("ans", ans));
                        arg.addArguments(arguments.ToArray());
                        arg.addFunctions(functions.ToArray());

                        var argName = arg.getArgumentName();
                        cacheSystem.InvalidateCache(argName);

                        if (argName != null) // arg.argumentExpression.initialTokens
                        {
                            if (typeof(Argument).GetField("argumentExpression",
                                                          BindingFlags.Instance | BindingFlags.NonPublic)
                                ?.GetValue(arg) is Expression expression)
                            {
                                if (typeof(Expression).GetField("initialTokens",
                                                                BindingFlags.Instance | BindingFlags.NonPublic)
                                    ?.GetValue(expression) is List <Token> tks)
                                {
                                    cacheSystem.SetCache(inputLine, tks, argName, arg.getArgumentValue());
                                }
                            }
                        }

                        //lineResult = "[*] ";
                    }

                    bool overrided = arguments.RemoveAll(a => a.getArgumentName() == arg.getArgumentName()) > 0;
                    arguments.Add(arg);
                    res          = arg.getArgumentValue();
                    definedToken = arg.getArgumentName();
                    if (definedToken != null)
                    {
                        Variables[definedToken] = res;
                    }
                    lineResult += outputFormatter.Format(res);
                }
                else if (inputLine != "")
                {
                    // evaluate
                    double result;
                    if (!cacheSystem.TryGetResult(inputLine, out var cache))
                    {
                        var expression = new Expression(inputLine, new Argument("ans", ans));
                        expression.addArguments(arguments.ToArray());
                        expression.addFunctions(functions.ToArray());
                        result = expression.calculate();
                        if (!double.IsNaN(result))
                        {
                            cacheSystem.SetCache(inputLine, expression.getCopyOfInitialTokens(), null, result);
                        }
                        //lineResult = "[*] ";
                    }
                    else
                    {
                        result = cache.Result;
                        //lineResult = "[#] ";
                    }

                    if (!double.IsNaN(result))
                    {
                        ans         = result;
                        lineResult += outputFormatter.Format(result);
                    }
                }

                cacheSystem.InvalidateCache("ans");
                cacheSystem.RegisterDefinedToken(lineNumber, definedToken);
                resultList.Add(lineResult);
            }

            return(resultList);
        }