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(); }
/// 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); }
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); }
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(); } }
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); }
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"); } } }
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); }
public MultipartFormDataReader(HttpConnection p) { bstream = new BackableStream(p.inputDataStream); myStream = MyStream.FromStream(bstream); this.p = p; Boundary = GetBoundary(p); }
/// <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); }
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); }
/// 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); }
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); }
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); }
/// 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); }
//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]); } } }
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)); }
public void DeveRetornarPrimeiraVogalDoFimStream() { string input = "aAbBABacfe"; IStream myStream = new MyStream(input.ToString()); char caractere = ValidarPrimeiroCaractere.FirstChar(myStream); Assert.AreEqual('e', caractere); }
public override void Flush() { AssertInvariants(); if (MyStream != null) { MyStream.Flush(); } AssertInvariants(); }
public void DeveRetornarNullQuandoVogalSomenteNoComecoStream() { string input = "abBBfdg"; IStream myStream = new MyStream(input.ToString()); char caractere = ValidarPrimeiroCaractere.FirstChar(myStream); Assert.AreEqual('\0', caractere); }
public void DeveRetornarNullQuandoExistemSomenteVogais() { string input = "aaeeiioouu"; IStream myStream = new MyStream(input.ToString()); char caractere = ValidarPrimeiroCaractere.FirstChar(myStream); Assert.AreEqual('\0', caractere); }
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; }
/// <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); }
public override void WriteByte(byte value) { AssertInvariants(); Contracts.Check(!_disposed, "Stream already disposed"); if (IsMemory && _memStream.Position >= _overflowBoundary) { EnsureOverflow(); } MyStream.WriteByte(value); AssertInvariants(); }
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(); }
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); }
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); }
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); }
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; }
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); }
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); }