Inheritance: Stream
Esempio n. 1
0
        public static bool SaveReport(XLWorkbook Workbook)
        {
            if (Workbook.Worksheets.Count > 0)
            {
                Stream         MyStream;
                SaveFileDialog SaveFileDialog1 = new SaveFileDialog();

                SaveFileDialog1.Filter           = "excel files (*.xlsx)|*.xlsx";
                SaveFileDialog1.FilterIndex      = 2;
                SaveFileDialog1.RestoreDirectory = true;

                if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    if ((MyStream = SaveFileDialog1.OpenFile()) != null)
                    {
                        MyStream.Close();
                    }
                    Workbook.SaveAs(SaveFileDialog1.FileName);
                    MessageBox.Show("Отчёт успешно сформирован");
                }
                return(true);
            }
            else
            {
                MessageBox.Show("Нужно выбрать хотя бы один пункт для формирования отчёта");
                return(false);
            }
        }
        public void Run(String[] args)
        {
            if (!ParseCommandLine(args))
            {
                return;
            }

            SessionOptions sessionOptions = new SessionOptions();

            sessionOptions.ServerHost            = d_serverHost;
            sessionOptions.ServerPort            = d_serverPort;
            sessionOptions.AuthenticationOptions = d_authOptions;

            System.Console.WriteLine("Connecting to " + d_serverHost + ":" + d_serverPort);
            ProviderSession session = new ProviderSession(sessionOptions, ProcessEvent);

            if (!session.Start())
            {
                Console.Error.WriteLine("Failed to start session");
                return;
            }

            Identity identity = null;

            if (d_authOptions.Length != 0)
            {
                if (!Authorize(out identity, session))
                {
                    return;
                }
            }

            TopicList topicList = new TopicList();

            topicList.Add(
                d_serviceName + "/220/660/1",
                new CorrelationID(new MyStream("220/660/1")));

            session.CreateTopics(
                topicList,
                ResolveMode.AUTO_REGISTER_SERVICES,
                identity);

            List <MyStream> myStreams = new List <MyStream>();

            for (int i = 0; i < topicList.Size; ++i)
            {
                if (topicList.StatusAt(i) == TopicList.TopicStatus.CREATED)
                {
                    Topic    topic  = session.GetTopic(topicList.MessageAt(i));
                    MyStream stream = (MyStream)topicList.CorrelationIdAt(i).Object;
                    stream.SetTopic(topic);
                    myStreams.Add(stream);
                }
            }

            PublishEvents(session, myStreams);

            session.Stop();
        }
Esempio n. 3
0
        /// Function - VariableEquationHandler
        /// <summary>
        /// Handling the variable equation part in the function "ChecksInSyntaxCheck" by
        /// make sure every variable is exist in the code and that their type of the equation
        /// is the same.
        /// </summary>
        /// <param name="threadNumber"> the number of the current thread.</param>
        /// <param name="sr"> buffer type MyStream.</param>
        /// <param name="codeLine"> the code line type string.</param>
        /// <param name="blocksAndNames"> ArrayList of variables.</param>
        /// <returns>returns if the variable equation is good.</returns>
        static bool VariableEquationHandler(MyStream sr, string codeLine, ArrayList blocksAndNames, int threadNumber)
        {
            char[] trimChars  = { '\t', ' ' };
            bool   isSameType = true;
            //splits the equation to 2 lines before the '=' and after it.
            string temp = Regex.Split(codeLine, GeneralConsts.EQUAL_SIGN)[0].Trim(trimChars);
            //takes the first param name.
            ParametersType result   = GetParameterNameFromLine(temp);
            string         varName1 = result.parameterName;

            temp = Regex.Split(codeLine, GeneralConsts.EQUAL_SIGN)[1];
            char[] searchingChars = { ';' };
            //takes the second param name.
            string varName2 = temp.Substring(0, temp.IndexOfAny(searchingChars));

            varName2 = varName2.Trim(trimChars);
            //takes the whole parameterType type by the function - "getVariableTypeParameterFromArrayList".
            ParametersType var1 = GetVariableTypeParameterFromArrayList(blocksAndNames, varName1.Trim(GeneralConsts.ASTERIX));
            ParametersType var2 = GetVariableTypeParameterFromArrayList(blocksAndNames, varName2.Trim(GeneralConsts.ASTERIX));

            //make sures the variable 2 is exist.
            if (var2 == null)
            {
                Server.ConnectionServer.CloseConnection(threadNumber, "There is no parameter named " + varName2 + " in row : " + sr.curRow, GeneralConsts.ERROR);
                CompileError = true;
                isSameType   = false;
            }
            //checks if their type is the same.
            if (isSameType && var1.parameterType != var2.parameterType)
            {
                isSameType = false;
            }
            return(isSameType);
        }
        /// Function - FunctionLength
        /// <summary>
        /// gets the function line and buffer returns the function length.
        /// </summary>
        /// <param name="sr"> Buffer type MyStream.</param>
        /// <param name="codeLine"> Code line type string</param>
        /// <returns> returns the function length type int.</returns>
        public static int FunctionLength(MyStream sr, string codeLine)
        {
            int   count   = 0;
            uint  curPos  = sr.Pos;
            Stack myStack = new Stack();

            codeLine = sr.ReadLine();
            myStack.Push(codeLine);
            bool found = false;

            while ((codeLine != null && myStack.Count > 0))
            {
                count++;
                codeLine = sr.ReadLine();
                if (codeLine.IndexOf("{") != NOT_FOUND_STRING)
                {
                    myStack.Push(codeLine);
                }
                if (codeLine.IndexOf("}") != NOT_FOUND_STRING)
                {
                    myStack.Pop();
                }
            }
            if (myStack.Count == 0)
            {
                found = true;
            }
            count = count - 1;
            myStack.Clear();
            //returns the buffer to the start of the function.
            sr.Seek(curPos);
            return(count);
        }
Esempio n. 5
0
        public static bool IsPdf(HttpPostedFileBase DocumentUpload)
        {
            var pdfString = "%PDF-";
            var pdfBytes  = Encoding.ASCII.GetBytes(pdfString);
            var len       = pdfBytes.Length;

            int FileLen;

            System.IO.Stream MyStream;

            FileLen = DocumentUpload.ContentLength;
            byte[] buffer = new byte[len];

            // Initialize the stream.
            MyStream = DocumentUpload.InputStream;

            // Read the file into the byte array.
            if (FileLen >= len)
            {
                MyStream.Read(buffer, 0, len);
            }
            else
            {
                MyStream.Read(buffer, 0, FileLen);
            }



            return(pdfBytes.SequenceEqual(buffer));
        }
        /// Function - FunctionCode
        /// <summary>
        /// function gets a buffer and a refference to the code line and returns all the function code.
        /// in the scope.
        /// </summary>
        /// <param name="sr"> buffer type MyStream.</param>
        /// <param name="codeLine"> code line type string.</param>
        /// <returns> returns the whole function code. </returns>
        public static string FunctionCode(MyStream sr, ref string codeLine)
        {
            uint   curPos         = sr.Pos;
            int    functionLength = 0;
            string finalCode      = GeneralConsts.EMPTY_STRING;
            Stack  myStack        = new Stack();

            codeLine = sr.ReadLine();
            myStack.Push(codeLine);
            while ((codeLine != null && myStack.Count > 0))
            {
                codeLine   = sr.ReadLine();
                finalCode += codeLine + GeneralConsts.NEW_LINE;
                functionLength++;
                if (OpenBlockPattern.IsMatch(codeLine))
                {
                    myStack.Push(codeLine);
                }
                if (CloseBlockPattern.IsMatch(codeLine))
                {
                    myStack.Pop();
                }
            }
            myStack.Clear();
            return(finalCode);
        }
Esempio n. 7
0
    private void Page_Load(Object sender, EventArgs e)
    {
        HttpFileCollection MyFileCollection;
        HttpPostedFile     MyFile;
        int FileLen;

        System.IO.Stream MyStream;

        MyFileCollection = Request.Files;
        MyFile           = MyFileCollection[0];

        FileLen = MyFile.ContentLength;
        byte[] input = new byte[FileLen];

        // Initialize the stream.
        MyStream = MyFile.InputStream;

        // Read the file into the byte array.
        MyStream.Read(input, 0, FileLen);

        // Copy the byte array into a string.
        for (int Loop1 = 0; Loop1 < FileLen; Loop1++)
        {
            MyString = MyString + input[Loop1].ToString();
        }
    }
Esempio n. 8
0
        public static int FunctionLength(MyStream sr, string s)
        {
            int   count   = 0;
            uint  curPos  = sr.Pos;
            Stack myStack = new Stack();

            s = sr.ReadLine();
            myStack.Push(s);
            bool found = false;

            while ((s != null && myStack.Count > 0))
            {
                count++;
                s = sr.ReadLine();
                if (s.IndexOf("{") != -1)
                {
                    myStack.Push(s);
                }
                if (s.IndexOf("}") != -1)
                {
                    myStack.Pop();
                }
            }
            if (myStack.Count == 0)
            {
                found = true;
            }
            count = count - 1;
            myStack.Clear();
            sr.Seek(curPos);
            return(count);
        }
Esempio n. 9
0
        protected virtual async Task HandleAcceptedTcp(TcpClient tcpClient)
        {
            EPPair         epPair     = new EPPair();
            HttpConnection connection = null;

            try {
                epPair = EPPair.FromSocket(tcpClient.Client);
                var myStream = MyStream.FromSocket(tcpClient.Client);
                var stream   = myStream.ToStream();
                connection = this.CreateHttpConnectionObject(tcpClient, stream, epPair);
                if (connection == null)
                {
                    try {
                        tcpClient.Close();
                    } catch (Exception) { }
                    return;
                }
            } catch (Exception e) {
                Logger.exception(e, Logging.Level.Error, $"({epPair}) httpConnection creating");
                return;
            }
            try {
                await connection.Process();
            } catch (Exception e) {
                try {
                    this.OnHttpConnectionException(e, connection);
                } catch (Exception e2) {
                    Logger.exception(e2, Logging.Level.Error, "In OnHttpConnectionExceptionExit");
                }
            }
        }
Esempio n. 10
0
        public static bool NextScopeLength(MyStream sr, ref string s, ref int count)
        {
            Stack myStack = new Stack();

            s = sr.ReadLine();
            myStack.Push(s);
            bool found = false;

            while ((s != null && myStack.Count > 0))
            {
                count++;
                s = sr.ReadLine();
                if (s.IndexOf("{") != -1)
                {
                    myStack.Push(s);
                }
                if (s.IndexOf("}") != -1)
                {
                    myStack.Pop();
                }
            }
            if (myStack.Count == 0)
            {
                found = true;
            }
            count = count - 1;
            myStack.Clear();
            return(found);
        }
Esempio n. 11
0
 public MultipartFormDataReader(HttpConnection p)
 {
     bstream  = new BackableStream(p.inputDataStream);
     myStream = MyStream.FromStream(bstream);
     this.p   = p;
     Boundary = GetBoundary(p);
 }
Esempio n. 12
0
        /// <summary>
        /// Set the Description by Language
        /// </summary>
        public static string SetStreamDescription(MyStream ms)
        {
            var desc         = "";
            var localization = ServiceRegistration.Get <ILocalization>().CurrentCulture.Name.Substring(0, 2);

            // is the original language available
            foreach (var d in ms.Descriptions)
            {
                if (d.Languagecode.Contains(localization))
                {
                    return(d.Txt);
                }
            }

            // is English available
            foreach (var d in ms.Descriptions)
            {
                if (d.Languagecode.Contains("en") & d.Txt != "")
                {
                    return(d.Txt);
                }
            }

            // is any language available
            foreach (var d in ms.Descriptions)
            {
                if (d.Txt != "")
                {
                    return(d.Txt);
                }
            }

            return(desc);
        }
Esempio n. 13
0
        public static string FunctionCode(MyStream sr, ref string s)
        {
            uint   curPos         = sr.Pos;
            int    functionLength = 0;
            string finalCode      = "";
            Stack  myStack        = new Stack();

            s = sr.ReadLine();
            myStack.Push(s);
            while ((s != null && myStack.Count > 0))
            {
                s          = sr.ReadLine();
                finalCode += s + "\n\r";
                functionLength++;
                if (OpenBlockPattern.IsMatch(s))
                {
                    myStack.Push(s);
                }
                if (CloseBlockPattern.IsMatch(s))
                {
                    myStack.Pop();
                }
                //here will be where i will store the function code.
            }
            myStack.Clear();
            return(finalCode);
        }
Esempio n. 14
0
        /// Function - skipDocumentation
        /// <summary>
        /// skips the documentation in c file in a buffer.
        /// </summary>
        /// <param name="sr"> buffer type MyStream</param>
        /// <param name="codeLine"> string </param>
        /// <returns> returns the amount of rows the documentation was.</returns>
        public static int skipDocumentation(MyStream sr, string codeLine)
        {
            int  count = 0;
            uint pos   = sr.Pos;

            if (codeLine.IndexOf("//") != GeneralConsts.NOT_FOUND_STRING)
            {
                while ((codeLine.IndexOf("//") != GeneralConsts.NOT_FOUND_STRING))
                {
                    pos = sr.Pos;
                    count++;
                    codeLine = sr.ReadLine();
                }
                sr.Seek(pos);
                count--;
            }
            if (codeLine.IndexOf("/*") != GeneralConsts.NOT_FOUND_STRING)
            {
                while (!(codeLine.IndexOf("*/") != GeneralConsts.NOT_FOUND_STRING))
                {
                    count++;
                    codeLine = sr.ReadLine();
                }
            }
            return(count);
        }
Esempio n. 15
0
 public override void Close()
 {
     AssertInvariants();
     if (MyStream != null)
     {
         MyStream.Close();
     }
 }
 /// <summary>
 /// Creates a pair of streams that can be passed to two parties
 /// to allow for interaction with each other.
 /// </summary>
 /// <returns>A pair of streams.</returns>
 public static Tuple<Stream, Stream> CreateStreams()
 {
     var stream1 = new MyStream();
     var stream2 = new MyStream();
     stream1.SetOtherStream(stream2);
     stream2.SetOtherStream(stream1);
     return Tuple.Create<Stream, Stream>(stream1, stream2);
 }
Esempio n. 17
0
        public static ArrayList AddStructNames(MyStream sr, string s)
        {
            ArrayList results = new ArrayList();
            int       count   = 0;

            char[] trimArr = { ' ', '{', '}', ';', '*', '&', '\t' };
            int    temp;

            string[] tempSplit;
            string   tempString;
            string   tempNewVariableName;

            if (s.IndexOf("typedef") != -1)
            {
                if (!TypedefOneLine.IsMatch(s))
                {
                    if (NextScopeLength(sr, ref s, ref count))
                    {
                        s = s.Trim(trimArr);

                        tempSplit = Regex.Split(s, @",");
                        for (int i = 0; i < tempSplit.Length; i++)
                        {
                            tempSplit[i] = tempSplit[i].Trim(trimArr);
                            if (!keywords.ContainsKey(CreateMD5(tempSplit[i])))
                            {
                                keywords.Add(CreateMD5(tempSplit[i]), tempSplit[i]);
                                results.Add(CreateMD5(tempSplit[i]));
                            }
                        }
                    }
                }
                else
                {
                    temp                = s.IndexOf(" ") + 1;
                    tempString          = tempNewVariableName = s.Substring(temp);
                    tempString          = tempString.TrimEnd(' ').Remove(tempString.LastIndexOf(' ') + 1);
                    tempString          = tempString.Trim(trimArr);
                    tempNewVariableName = CutBetween2Strings(s, tempString, ";");
                    tempNewVariableName = tempNewVariableName.Trim(trimArr);
                    if (keywords.Contains(CreateMD5(tempString)) && !keywords.Contains(CreateMD5(tempNewVariableName)))
                    {
                        keywords.Add(CreateMD5(tempNewVariableName), tempNewVariableName);
                        results.Add(CreateMD5(tempNewVariableName));
                    }
                }
            }
            else
            {
                s = s.Trim(trimArr);
                if (!keywords.Contains(CreateMD5(s)))
                {
                    keywords.Add(CreateMD5(s), s);
                    results.Add(CreateMD5(s));
                }
            }
            return(results);
        }
Esempio n. 18
0
        /// Function - SyntaxCheck
        /// <summary>
        /// that function uses the Function "ChecksInSyntaxCheck" if that is in a scope
        /// or outside a scope according to the situation.
        /// </summary>
        /// <param name="path"> The path of the c code type string.</param>
        /// <param name="keywords"> keywords type Hashtable that conatins the code keywords.</param>
        public static bool SyntaxCheck(string path, ArrayList globalVariable, Hashtable keywords, Dictionary <string, ArrayList> funcVariables, int threadNumber)
        {
            MyStream sr = null;

            try
            {
                sr = new MyStream(path, System.Text.Encoding.UTF8);
            }
            catch (Exception e)
            {
                Server.ConnectionServer.CloseConnection(threadNumber, FILE_NOT_FOUND, GeneralConsts.ERROR);
            }
            if (sr != null)
            {
                //in order to delete struct keywords when they come in a function at the end of the function.
                ArrayList parameters     = new ArrayList();
                ArrayList blocksAndNames = new ArrayList();
                ArrayList variables      = new ArrayList();
                //adds an ArrayList inside blocksAndNames ArrayList for the action outside the scopes.
                blocksAndNames.Add(new ArrayList());
                string codeLine;
                int    scopeLength  = 0;
                string lastFuncLine = "";
                while ((codeLine = sr.ReadLine()) != null && !CompileError)
                {
                    scopeLength = 0;
                    //handling the scopes.
                    if (OpenBlockPattern.IsMatch(codeLine))
                    {
                        NextScopeLength(sr, ref codeLine, ref scopeLength, true);
                        ChecksInSyntaxCheck(path, sr, codeLine, true, keywords, threadNumber, variables, globalVariable, blocksAndNames, parameters, scopeLength + 1);
                        parameters.Clear();
                    }
                    // if there is a function it saves its parameters.
                    else if (FunctionPatternInC.IsMatch(codeLine))
                    {
                        parameters.AddRange(GeneralRestApiServerMethods.FindParameters(codeLine));
                        if (lastFuncLine != "")
                        {
                            funcVariables.Add(lastFuncLine, new ArrayList(variables));
                            variables.Clear();
                        }
                        lastFuncLine = codeLine;
                    }
                    //handling outside the scopes.
                    else
                    {
                        ChecksInSyntaxCheck(path, sr, codeLine, false, keywords, threadNumber, variables, globalVariable, blocksAndNames);
                    }
                }
                if (lastFuncLine != "")
                {
                    funcVariables.Add(lastFuncLine, new ArrayList(variables));
                    variables.Clear();
                }
            }
            return(CompileError);
        }
Esempio n. 19
0
        //the checks that are being mad in syntax Check are being written here.
        public static void ChecksInSyntaxCheck(MyStream sr, ref string s, bool IsFunction, int functionLength = 1)
        {
            ArrayList tempStructInFunc = new ArrayList();
            string    temp;
            int       loopCount;

            char[]    cutChars = { '*', '&' };
            int       pos      = 0;
            bool      found;
            int       i, j;
            ArrayList results = new ArrayList();

            for (i = 0; i < functionLength; i++)
            {
                if (IsFunction)
                {
                    s = sr.ReadLine();
                }
                pos   = 0;
                found = true;
                if (StructPattern.IsMatch(s) || TypedefOneLine.IsMatch(s))
                {
                    results = AddStructNames(sr, s);
                    tempStructInFunc.Add(s);
                }
                if (VariableDecleration.IsMatch(s) && !(s.IndexOf("typedef") != -1))
                {
                    loopCount = KeywordsAmountOnVariableDeclaration(s);
                    for (j = 0; j < loopCount; j++)
                    {
                        found = found && CheckIfStringInHash(keywords, s.Substring(pos, s.Substring(pos, s.Length - pos).IndexOf(' ')).Trim(cutChars));
                        pos   = s.IndexOf(' ', pos + 1) + 1;
                    }
                    if (loopCount == 0)
                    {
                        found = found && CheckIfStringInHash(keywords, s.Substring(pos, s.Substring(pos, s.Length - pos).IndexOf(' ')).Trim(cutChars));
                    }
                    if (s.IndexOf("struct") != -1)
                    {
                        pos   = s.IndexOf("struct");
                        temp  = s.Substring(pos, s.IndexOf(" ", pos + 7) - pos);
                        found = CheckIfStringInHash(keywords, temp.Trim(cutChars));
                    }
                }
                if (!found)
                {
                    Console.WriteLine(s.Trim() + " is written wrong (bad keyword usage).");
                }
            }
            if (IsFunction)
            {
                for (i = 0; i < results.Count; i++)
                {
                    keywords.Remove(results[i]);
                }
            }
        }
Esempio n. 20
0
        public void DeveRetornarNullQuandoContemMaisDeUmaVogal()
        {
            string  input    = "aaccadfrii";
            IStream myStream = new MyStream(input.ToString());

            char caractere = ValidarPrimeiroCaractere.FirstChar(myStream);

            Assert.AreEqual('\0', caractere);
        }
        /// <summary>
        /// Creates a pair of streams that can be passed to two parties
        /// to allow for interaction with each other.
        /// </summary>
        /// <returns>A pair of streams.</returns>
        public static Tuple <Stream, Stream> CreateStreams()
        {
            var stream1 = new MyStream();
            var stream2 = new MyStream();

            stream1.SetOtherStream(stream2);
            stream2.SetOtherStream(stream1);
            return(Tuple.Create <Stream, Stream>(stream1, stream2));
        }
Esempio n. 22
0
        public void DeveRetornarPrimeiraVogalDoFimStream()
        {
            string  input    = "aAbBABacfe";
            IStream myStream = new MyStream(input.ToString());

            char caractere = ValidarPrimeiroCaractere.FirstChar(myStream);

            Assert.AreEqual('e', caractere);
        }
Esempio n. 23
0
 public override void Flush()
 {
     AssertInvariants();
     if (MyStream != null)
     {
         MyStream.Flush();
     }
     AssertInvariants();
 }
Esempio n. 24
0
        public void DeveRetornarNullQuandoVogalSomenteNoComecoStream()
        {
            string  input    = "abBBfdg";
            IStream myStream = new MyStream(input.ToString());

            char caractere = ValidarPrimeiroCaractere.FirstChar(myStream);

            Assert.AreEqual('\0', caractere);
        }
Esempio n. 25
0
        public void DeveRetornarNullQuandoExistemSomenteVogais()
        {
            string  input    = "aaeeiioouu";
            IStream myStream = new MyStream(input.ToString());

            char caractere = ValidarPrimeiroCaractere.FirstChar(myStream);

            Assert.AreEqual('\0', caractere);
        }
Esempio n. 26
0
        public void DeveRetornarNullQuandoNaoAcharVogal()
        {
            string  input    = "ccdfr";
            IStream myStream = new MyStream(input.ToString());

            char caractere = ValidarPrimeiroCaractere.FirstChar(myStream);

            Assert.AreEqual('\0', caractere);
        }
 public static void Main() {
 int errors = 0;
 int testcases = 0;
 testcases++;
 MyStream myStream = new MyStream();
 if(! myStream.UseWaitHandle())
   errors++;
 Environment.ExitCode = errors;
 }
Esempio n. 28
0
        /// <summary>
        /// Set the Logo of a Stream or use the DefaultLogo
        /// </summary>
        public static string SetStreamLogo(MyStream ms)
        {
            var s = "DefaultLogo.png";

            if (ms.Logo != "")
            {
                s = ms.Logo;
            }
            return(s);
        }
        /// Function - findFunction
        /// <summary>
        /// find the next function in the code and returns the function line.
        /// </summary>
        /// <param name="sr"> Buffer type MyStream.</param>
        /// <param name="pattern"> Regex Pattern for the function.</param>
        /// <returns></returns>
        public static string findFunction(MyStream sr, Regex pattern)
        {
            string codeLine = sr.ReadLine();

            while ((!pattern.IsMatch(codeLine)) && ((codeLine = sr.ReadLine()) != null))
            {
                ;
            }
            return(codeLine);
        }
Esempio n. 30
0
 public override void WriteByte(byte value)
 {
     AssertInvariants();
     Contracts.Check(!_disposed, "Stream already disposed");
     if (IsMemory && _memStream.Position >= _overflowBoundary)
     {
         EnsureOverflow();
     }
     MyStream.WriteByte(value);
     AssertInvariants();
 }
Esempio n. 31
0
 public ReverseProxyTest()
 {
     _request = new HttpTestRequest {
         HttpVersion = "HTTP/1.1"
     };
     _stream   = new MyStream();
     _context  = new HttpResponseContext();
     _response = _request.CreateResponse(_context);
     _module   = new ReverseProxyModule("http://localhost/", "http://localhost:4210/");
     _server   = new HttpServer();
 }
Esempio n. 32
0
        public static string findFunction(MyStream sr, Regex pattern)
        {
            bool   found = false;
            string s     = sr.ReadLine();

            while ((!pattern.IsMatch(s)) && ((s = sr.ReadLine()) != null))
            {
                ;
            }
            return(s);
        }
Esempio n. 33
0
        public IPRunner(World world, GameEngine engine, Player player)
        {
            m_player = player;
            m_scriptOutputStream = new MyStream(player.Send);

            m_scriptEngine = IronPython.Hosting.Python.CreateEngine();

            InitRuntime(m_scriptEngine.Runtime);

            m_exprScope = m_scriptEngine.CreateScope();
            InitScope(m_exprScope, world, engine, player);

            m_scriptScope = m_scriptEngine.CreateScope();
            InitScope(m_scriptScope, world, engine, player);
        }
Esempio n. 34
0
        public IPRunner(Action<string> sender)
        {
            m_sender = sender;
            m_scriptOutputStream = new MyStream(sender);

            m_scriptEngine = IronPython.Hosting.Python.CreateEngine();
            m_scriptEngine.Runtime.IO.SetOutput(m_scriptOutputStream, System.Text.Encoding.Unicode);
            m_scriptEngine.Runtime.IO.SetErrorOutput(m_scriptOutputStream, System.Text.Encoding.Unicode);

            m_scriptScope = m_scriptEngine.CreateScope();

            m_scriptEngine.Execute("import clr", m_scriptScope);
            m_scriptEngine.Execute("clr.AddReference('Dwarrowdelf.Common')", m_scriptScope);
            m_scriptEngine.Execute("import Dwarrowdelf", m_scriptScope);
        }
Esempio n. 35
0
        public IPRunner(User user, GameEngine engine)
        {
            m_user = user;
            m_scriptOutputStream = new MyStream(user.Send);

            m_scriptEngine = IronPython.Hosting.Python.CreateEngine();

            InitRuntime(m_scriptEngine.Runtime);

            m_scopeVars = new Dictionary<string, object>()
            {
                { "engine", engine },
                { "world", engine.World },
                { "get", new Func<object, BaseObject>(engine.World.IPGet) },
            };

            m_exprScope = m_scriptEngine.CreateScope(m_scopeVars);
            InitScopeImports(m_exprScope);
        }
 /// <summary>
 /// Sets the stream to copy written data to.
 /// </summary>
 /// <param name="other">The other stream.</param>
 internal void SetOtherStream(MyStream other)
 {
     Requires.NotNull(other, nameof(other));
     Assumes.Null(this.other);
     this.other = other;
 }
Esempio n. 37
0
		public void ExplicitFlush ()
		{
			// Tests that explicitly calling Flush does not call Flush in the underlying stream
			MyStream ms = new MyStream ();
			using (CryptoStream cs = new CryptoStream (ms, SHA1.Create (), CryptoStreamMode.Read)) {
				ms.FlushCounterEnabled = true;
				cs.Flush ();
				ms.FlushCounterEnabled = false;
			}
			Assert.IsTrue (ms.FlushCounter == 0);
		}
Esempio n. 38
0
		public void ImplicitFlushCascade ()
		{
			// Tests that Dispose() calls FlushFinalBlock() on the underlying stream
			MyStream ms = new MyStream ();
			ms.FlushCounterEnabled = true;
			CryptoStream cs1 = new CryptoStream (ms, SHA1.Create (), CryptoStreamMode.Read);
			using (CryptoStream cs = new CryptoStream (cs1, SHA1.Create (), CryptoStreamMode.Read)) {
			}
			Assert.IsTrue (ms.FlushCounter == 1);
		}