Exemple #1
0
        public static void TurnOffLCD(System.IO.StreamWriter sw)
        {
            sw.WriteLine("LCD Power Start");
            sw.Flush();

            SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2);

            sw.WriteLine("LCD Power Done");
            sw.Flush();
        }
Exemple #2
0
 public int WriteTo(System.IO.StreamWriter sw, ODataPersistenceEngineAsync engine)
 {
     long position = sw.BaseStream.Position;
     if (!isRoot)
     {
         foreach (KeyValuePair<string, string> header in headers)
             sw.WriteLine(header.Key + ": " + header.Value);
     }
     //MemoryStream ms;
     //StreamWriter msw;
     //ms = new MemoryStream();
     //msw = new StreamWriter(ms);
     //msw.NewLine = sw.NewLine;
     //int length = 0;
     //foreach (Change change in Changes)
     //{
     //    length += ("--changeset_" + Id + "\n").Length;
     //    length += ("Content-Type: application/http" + "\n").Length;
     //    if (change.Expression.Name != null && change.Expression.Name[0] == '$')
     //        length += (change.Method + " " + engine.GetUri(change.Expression).AbsolutePath.Substring(((ODataPersistenceProvider)engine.FactoryAsync).ConnectionString.AbsolutePath.Length) + " HTTP/1.1").Length + sw.NewLine.Length;
     //    else
     //        length += (change.Method + " " + engine.GetUri(change.Expression) + " HTTP/1.1").Length + sw.NewLine.Length;
     //    length += ("Host: " + ((ODataPersistenceProvider)engine.FactoryAsync).ConnectionString.Host + (((ODataPersistenceProvider)engine.FactoryAsync).ConnectionString.Port == 80 ? "" : ":" + ((ODataPersistenceProvider)engine.FactoryAsync).ConnectionString.Port) + "\n").Length;
     //    length += change.WriteTo(msw, engine);
     //}
     //length += ("--changeset_" + Id + "--\n").Length;
     //length += 2;
     //sw.WriteLine("Content-Length: " + length);
     sw.WriteLine();
     sw.Flush();
     //msw.Close();
     foreach (Change change in Changes)
     {
         sw.WriteLine("--changeset_" + Id);
         sw.WriteLine("Content-Type: application/http");
         sw.WriteLine("Content-Transfer-Encoding: binary");
         sw.WriteLine();
         if (change.Expression.Name != null && change.Expression.Name[0] == '$')
             sw.WriteLine(change.Method + " " + engine.GetUri(change.Expression).AbsolutePath.Substring(((ODataPersistenceProvider)engine.FactoryAsync).ConnectionString.AbsolutePath.Length ) + " HTTP/1.1");
         else
             sw.WriteLine(change.Method + " " + engine.GetUri(change.Expression) + " HTTP/1.1");
         sw.WriteLine("Host: " + ((ODataPersistenceProvider)engine.FactoryAsync).ConnectionString.Host + (((ODataPersistenceProvider)engine.FactoryAsync).ConnectionString.Port == 80 ? "" : ":" + ((ODataPersistenceProvider)engine.FactoryAsync).ConnectionString.Port));
         sw.Flush();
         change.WriteTo(sw, engine);
         //sw.WriteLine();
         sw.WriteLine();
     }
     sw.WriteLine("--changeset_" + Id + "--");
     sw.WriteLine();
     sw.Flush();
     return (int)(sw.BaseStream.Length - position);
 }
 public static void WriteStackTrace(System.Exception throwable, System.IO.TextWriter stream)
 {
     //	        stream.WriteLine(throwable.Message);
     //		stream.WriteLine(throwable.StackTrace);
         stream.WriteLine(throwable.ToString());
     stream.Flush();
 }
Exemple #4
0
 public void SetData(ArraySegment<byte> data,System.IO.Stream stream)
 {
     Seek(stream);
     stream.Write(BitConverter.GetBytes(data.Count),0,4);
     stream.Write(data.Array, data.Offset, data.Count);
     stream.Flush();
 }
 static void CopyStream(System.IO.Stream src, System.IO.Stream dest)
 {
     byte[] buffer = new byte[1024];
     int len;
     while ((len = src.Read(buffer, 0, buffer.Length)) > 0)
         dest.Write(buffer, 0, len);
     dest.Flush();
 }
Exemple #6
0
 public override void send(System.Net.Sockets.NetworkStream ns)
 {
     if (data == null) {
         getBytes ();
     }
     ns.Write (data, 0, data.Length);
     ns.Flush ();
 }
        public override bool Write(System.IO.BinaryWriter bw)
        {
            base.Write(bw);

            bw.Write((byte)_num);
            bw.Flush();

            return true;
        }
 public void PingPong(String buf, System.IO.TextWriter output)
 {
     //Send pong reply to any ping messages
     if (buf.Contains("PING"))
     {
         output.Write(buf.Replace("PING", "PONG") + "\r\n");
         output.Flush();
     }
 }
 protected override void WriteFile(System.Web.HttpResponseBase response)
 {
     response.Clear();
     response.AddHeader("content-disposition", "attachment; filename=" + DownloadedFilename);
     response.ContentType = this.ContentType;
     response.WriteFile(Path);
     response.Flush();
     System.IO.File.Delete(Path);
     response.End();
 }
Exemple #10
0
 public static void CopyStream(System.IO.Stream input, System.IO.Stream output)
 {
     byte[] buffer = new byte[1000000]; // 1MB buffer, should be sufficient
     int len;
     while ((len = input.Read(buffer, 0, 1000000)) > 0)
     {
         output.Write(buffer, 0, len);
     }
     output.Flush();
 }
Exemple #11
0
 public static void CopyStream(System.IO.Stream input, System.IO.Stream output)
 {
     byte[] buffer = new byte[2000];
     int len;
     while ((len = input.Read(buffer, 0, 2000)) > 0)
     {
         output.Write(buffer, 0, len);
     }
     output.Flush();
 }
        public override System.Threading.Tasks.Task WriteToStreamAsync(Type type, object value, System.IO.Stream stream, System.Net.Http.Headers.HttpContentHeaders contentHeaders, System.Net.TransportContext transportContext)
        {
            var task = Task.Factory.StartNew(() =>
                {
                    var array = value as byte[];
                    stream.Write(array, 0, array.Length);
                    stream.Flush();
                });

            return task;
        }
        public override bool Write(System.IO.BinaryWriter bw)
        {
            base.Write(bw);

            bw.Write(aid);
            bw.Write(gid);
            bw.Write(auth);
            bw.Write(0);
            bw.Write(sex);
            bw.Flush();

            return true;
        }
        public override bool Write(System.IO.BinaryWriter bw)
        {
            base.Write(bw);

            bw.Write(aid);
            bw.Write(lig1);
            bw.Write(lig2);
            bw.Write((short)0);
            bw.Write(sex);
            bw.Flush();

            return true;
        }
 public override void Generate(
     System.Xml.XmlWriter xmlWriter
     )
 {
     this._WrittenRootNode = false;
     xmlWriter.WriteStartDocument(true);
     if (this.RootElement is ICatalog)
         this.Write(xmlWriter, this.RootElement as XCRI.Interfaces.XCRICAP12.ICatalog);
     if (this.RootElement is IProvider)
         this.Write(xmlWriter, this.RootElement as XCRI.Interfaces.XCRICAP12.IProvider);
     if (this.RootElement is ICourse)
         this.Write(xmlWriter, this.RootElement as XCRI.Interfaces.XCRICAP12.ICourse);
     xmlWriter.Flush();
 }
Exemple #16
0
        public int WriteTo(System.IO.StreamWriter sw, ODataPersistenceEngineAsync engine)
        {
            long position = sw.BaseStream.Position;
            if (!isRoot)
                foreach (KeyValuePair<string, string> header in headers)
                    sw.WriteLine(header.Key + ": " + header.Value);
            MemoryStream ms;
            StreamWriter msw;
            ms = new MemoryStream();
            msw = new StreamWriter(ms);
            msw.NewLine = sw.NewLine;
            int length = 0;
            foreach (IOperation change in Operations)
            {
                length += ("--batch_" + Id + "\n").Length;
                length += change.WriteTo(msw, engine);
            }
            length += ("--batch_" + Id + "--\n").Length;
            msw.Flush();
            if (!isRoot)
            {
                sw.WriteLine("Content-Length: " + length);
                sw.WriteLine();
            }
            sw.Flush();
            foreach (IOperation change in Operations)
            {
                sw.WriteLine("--batch_" + Id);
                sw.Flush();
                change.WriteTo(sw, engine);
            }
            sw.Write("--batch_" + Id + "--");
            //sw.WriteLine();
            sw.Flush();
            return (int)(sw.BaseStream.Length - position);

        }
Exemple #17
0
		void IXmlSerializable.WriteXml(System.Xml.XmlWriter writer)
		{
			// Open the file.
			FileStream fs = new FileStream(serverFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
			long length = fs.Length;

			// Write file name.
			writer.WriteElementString("fileName", ns, Path.GetFileName(serverFilePath));

			// Write file size (useful for determining progress.)
			writer.WriteElementString("size", ns, length.ToString());

			// Start the file content.
			writer.WriteStartElement("content", ns);

			// Read 4 KB chunks and write that (Base64 encoded).
			int bufferSize = 4096;
			byte[] fileBytes = new byte[bufferSize];
			int readBytes = bufferSize;

			while (readBytes > 0)
			{
				readBytes = fs.Read(fileBytes, 0, bufferSize);
				writer.WriteStartElement("chunk", ns);
				writer.WriteBase64(fileBytes, 0, readBytes);
				writer.WriteEndElement();
				writer.Flush();

			}

			fs.Close();

			// End the XML.
			writer.WriteEndElement();
			writer.Flush();

		}
 public override Task WriteToStreamAsync(
     Type type,
     object value,
     System.IO.Stream writeStream,
     System.Net.Http.HttpContent content,
     System.Net.TransportContext transportContext)
 {
     return Task.Factory.StartNew(() =>
     {
         var xml = SerializerHelper.ObjectToXml(value); 
         var buffer = Encoding.UTF8.GetBytes(xml);
         writeStream.Write(buffer, 0, buffer.Length);
         writeStream.Flush();
     });
 }
        protected override Task OnWriteToStreamAsync(Type type, object value,
                                                     System.IO.Stream stream,
                                                     System.Net.Http.Headers.HttpContentHeaders contentHeaders,
                                                     FormatterContext formatterContext,
                                                     System.Net.TransportContext transportContext) {
            return
                Task.Factory.StartNew(() => {
                                          var serializer = new JavaScriptSerializer();
                                          var sb = new StringBuilder();

                                          serializer.Serialize(value, sb);

                                          var buffer = Encoding.UTF8.GetBytes(sb.ToString());
                                          stream.Write(buffer, 0, buffer.Length);
                                          stream.Flush();
                                      });
        }
        // Disable the obsolete warning since we must use FileStream.Handle
        // because Mono does not support FileSystem.SafeFileHandle at present.
#pragma warning disable 618

        /// <summary>
        /// Flushes the specified file stream. Ensures that all buffered
        /// data is actually written to the file system.
        /// </summary>
        /// <param name="fileStream">The file stream.</param>
        public static void Sync(System.IO.FileStream fileStream)
        {
            if (fileStream == null)
                throw new ArgumentNullException("fileStream");

            fileStream.Flush();

            //if (OS.IsWindows)
            //{
            //    if (!FlushFileBuffers(fileStream.Handle))
            //        throw new System.IO.IOException();
            //}
            //else if (OS.IsUnix)
            //{
            //    if (fsync(fileStream.Handle) != IntPtr.Zero)
            //    throw new System.IO.IOException();
            //}
            //else
            //{
            //    throw new NotImplementedException();
            //}
        }
Exemple #21
0
        public void WriteXML(System.Xml.XmlWriter x, System.Data.DataTable datatable)
        {

            this.Table.DataTable = datatable;
            // ---------------
            
            x.WriteStartDocument();
            x.WriteStartFlowDocument();
            x.WriteTextStyleAttributes(this.TextStyle);


            x.WriteX(this.ReportHeaderDefinition.ReportTitle);

            x.WriteX(this.ReportHeaderDefinition.HeaderText);

            
            x.WriteX(this.Table);

            x.WriteX(this.ReportFooterDefinition.FooterText);

            x.WriteEndFlowDocument();
            x.WriteEndDocument();
            x.Flush();
        }
Exemple #22
0
 /*
 * Write the contents of the stream to an OutputStream.
 *
 * @param os the OutputStream to write to.
 *
 * @exception C#.io.IOException if there is an error writing to
 * the OutputStream.
 **/
 public virtual void writeTo(System.IO.Stream os)
 {
     os.Write(buf, 0, _count);
     os.Flush();
 }
        /*******************************/
        /// <summary>
        /// Writes the exception stack trace to the received stream
        /// </summary>
        /// <param name="throwable">Exception to obtain information from</param>
        /// <param name="stream">Output sream used to write to</param>
        public static void WriteStackTrace(System.Exception throwable, System.IO.TextWriter stream)
		{
			stream.Write(throwable.StackTrace);
			stream.Flush();
		}
Exemple #24
0
		/// <summary>
		/// Put the contents of the error and warning information to the
		/// passed in xml text writer.
		/// </summary>
		/// <param name="xmlOutput"></param>
		public void FlushTo(System.Xml.XmlTextWriter xmlOutput)
		{
			xmlOutput.Flush();
			int ttlWarnings = m_Warnings.Count + m_sfmsWithOutData;	// warnings and sfm's w/o data
			int ttlErrors = m_FatalErrors.Count + m_Errors.Count;	// fatal and reg errors

			if (ttlErrors + ttlWarnings == 0)
				xmlOutput.WriteComment(" There were No errors or warnings during the creation of this file");

			// put out the root error element
			xmlOutput.WriteComment(" This element contains error, warning and sfm data related information ");
			xmlOutput.WriteStartElement("ErrorLog");

			OutputErrorElement(xmlOutput);					// errors
			OutputWarningElement(xmlOutput);				// warnings
			OutputOOOInfo(xmlOutput);						// out of order cautions
			OutputDuplicateSfmWarnErrElement(xmlOutput);	// duplicate SFM errors and warnings
			OutputSfmInfo(xmlOutput);						// general statistics on sfm usage
			xmlOutput.WriteEndElement();					// end the "ErrorLog" element

			// remove all the errors and warnings
			m_Errors.Clear();
			m_Warnings.Clear();
			m_sfmWarningsAndErrors.Clear();
			m_FatalErrors.Clear();
			m_uniqueMsgs.Clear();
			m_sfmsWithOutData = 0;
			m_sfmsWithData = 0;
			m_sfmData.Clear();
			m_OOO.Clear();
			m_OOOCnt = 0;
			m_OOOEntries.Clear();
			m_OOOEntriesKEYS.Clear();
			m_OOOEntriesOrdered.Clear();
		}
Exemple #25
0
 private string GetStringFromMemoryStream(System.IO.MemoryStream m)
 {
     if (m == null || m.Length == 0)
         return null;
     m.Flush();
     m.Position = 0;
     System.IO.StreamReader sr = new System.IO.StreamReader(m);
     string s = sr.ReadToEnd();
     return s;
 }
Exemple #26
0
 /// <summary>
 /// Outputs the Json representation of a ViewDataPayload containing the ViewData and (optionally) the ViewName that was passed in on construction.
 /// </summary>
 /// <param name="viewContext">The ViewContext that contains the ViewData to be rendered.</param>
 /// <param name="writer">The object that receives the Json representation</param>
 public void Render(ViewContext viewContext, System.IO.TextWriter writer)
 {
     writer.Write(JsonConvert.SerializeObject(new ViewDataPayload(viewContext.ViewData, this.ViewName), Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }));
     writer.Flush();
 }
Exemple #27
0
        public void Emit(System.IO.StreamWriter writer)
        {
            writer.WriteLine("[Quips compiled by Conversation Compiler]");

            foreach (var quip in AllQuips)
            {
                writer.WriteLine("");

                writer.Write(quip.ID + " is a privately-named ");
                if (quip.Repeatable) writer.Write("repeatable ");
                if (quip.Restrictive) writer.Write("restrictive ");
                switch (quip.Type)
                {
                    case QuipType.Questioning:
                        writer.WriteLine("questioning quip.");
                        break;
                    case QuipType.Informative:
                        writer.WriteLine("informative quip.");
                        break;
                    case QuipType.Performative:
                        writer.WriteLine("performative quip.");
                        break;
                    case QuipType.NpcDirected:
                        writer.WriteLine("npc-directed quip.");
                        break;
                }

                if (quip.Type != QuipType.NpcDirected)
                {
                    writer.WriteLine("The printed name is \"" + quip.Name + "\".");
                    var nameTokens = quip.Name.Split(new char[] { ' ' });
                    writer.Write("Understand ");
                    for (var i = 0; i < nameTokens.Length; ++i)
                    {
                        writer.Write("\"" + nameTokens[i].TrimEnd('.') + "\"");
                        if (i != nameTokens.Length - 1) writer.Write(", ");
                    }
                    writer.WriteLine(" as " + quip.ID + ".");

                    if (!String.IsNullOrEmpty(quip.Comment))
                        writer.WriteLine("The comment is \"" + Escape(quip.Comment) + "\".");

                    if (!String.IsNullOrEmpty(quip.Response))
                        writer.WriteLine("The response is \"" + Escape(quip.Response) + "\".");

                    if (!String.IsNullOrEmpty(quip.Nag))
                        writer.WriteLine("The nag is \"" + Escape(quip.Nag) + "\".");

                    if (quip.Supplies != null && quip.Supplies.Count > 0)
                    {
                        writer.Write("It quip-supplies ");
                        for (var i = 0; i < quip.Supplies.Count; ++i)
                        {
                            writer.Write(quip.Supplies[i]);
                            if (i != quip.Supplies.Count - 1) writer.Write(", ");
                        }
                        writer.WriteLine(".");
                    }

                    if (quip.Follows != null && quip.Follows.Count > 0)
                    {
                        writer.Write("It indirectly-follows ");
                        for (var i = 0; i < quip.Follows.Count; ++i)
                        {
                            writer.Write(quip.Follows[i].ID + " [" + quip.Follows[i].Name + "]");

                            if (i != quip.Follows.Count - 1) writer.Write(", ");
                        }
                        writer.WriteLine(".");
                    }

                    if (quip.Directly != null && quip.Directly.Count > 0)
                    {
                        writer.Write("It directly-follows ");
                        for (var i = 0; i < quip.Directly.Count; ++i)
                        {
                            writer.Write(quip.Directly[i].ID + " [" + quip.Directly[i].Name + "]");

                            if (i != quip.Directly.Count - 1) writer.Write(", ");
                        }
                        writer.WriteLine(".");
                    }

                    if (quip.OffLimitsRules != null && quip.OffLimitsRules.Count > 0)
                    {
                        writer.WriteLine("An availability rule for " + quip.ID + ":");
                        foreach (var entry in quip.OffLimitsRules)
                            writer.WriteLine("\tIf " + entry + ", it is off-limits;");
                        writer.WriteLine();
                    }
                }
                else
                {
                    if (!String.IsNullOrEmpty(quip.Response))
                        writer.WriteLine("The response is \"" + Escape(quip.Response) + "\".");

                    if (!String.IsNullOrEmpty(quip.Nag))
                        writer.WriteLine("The nag is \"" + Escape(quip.Nag) + "\".");
                }
            }

            writer.Flush();
        }
Exemple #28
0
        protected override System.Threading.Tasks.Task OnWriteToStreamAsync(Type type, object value, System.IO.Stream stream, System.Net.Http.Headers.HttpContentHeaders contentHeaders, FormatterContext formatterContext, System.Net.TransportContext transportContext)
        {
            var task = Task.Factory.StartNew(() =>
            {
                var settings = new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore,
                };

                string json = JsonConvert.SerializeObject(value, Formatting.Indented,
                                                          new JsonConverter[1] { new IsoDateTimeConverter() });

                byte[] buf = System.Text.Encoding.Default.GetBytes(json);
                stream.Write(buf, 0, buf.Length);
                stream.Flush();
            });

            return task;
        }
Exemple #29
0
        public override void Emit(System.IO.TextWriter outputWriter)
        {
            StringBuilder columnsBuilder   = new StringBuilder();
            StringBuilder constraintBuilder = new StringBuilder();

            foreach (Column c in _tableHelper.Columns.Values)
            {
                string columnName = c.Properties["Name"];
                string columnType = c.Properties["Type"];
                bool isNullable = c.Properties.ContainsKey("IsNullable")
                                        ? Convert.ToBoolean(c.Properties["IsNullable"])
                                        : false;

                bool isIdentity = _tableHelper.IsIdentityColumn(columnName);

                columnsBuilder.AppendFormat(
                    "\t[{0}] {1}{2}{3},\n",
                    columnName,
                    columnType,
                    isIdentity ? " IDENTITY(1,1)" : "",
                    isNullable ? "" : " NOT NULL"
                );
            }

            StringBuilder simpleConstraintBuilder = new StringBuilder();

            // Primary Key Constraints
            int constraintCount = 0;
            foreach (Constraint c in _tableHelper.Constraints)
            {
                if (c is SimpleConstraint)
                {
                    string cString;
                    Message.Trace(Severity.Debug,"Found Constraint {0}", c.Name);
                    ConstraintEmitter ce = new ConstraintEmitter(VulcanPackage, c, _tableHelper);
                    ce.Emit(out cString);
                    simpleConstraintBuilder.AppendFormat("{0},\n", cString);
                    constraintCount++;
                }
            }

            if (constraintCount > 0)
            {
                simpleConstraintBuilder.Replace(",", "", simpleConstraintBuilder.Length - 2, 2);
            }

            TemplateEmitter te = new TemplateEmitter(
                "CreateTable", 
                VulcanPackage,
                _tableHelper.Name,
                columnsBuilder.ToString(),
                simpleConstraintBuilder.ToString());
            te.Emit(outputWriter);
            outputWriter.Flush();


            //Remove the extra Comma, Leave it in if a _constraint is there...
            if (constraintCount == 0)
            {
                columnsBuilder.Replace(",", "", columnsBuilder.Length - 2, 2);
            }

            //Foreign Key Constraints
            foreach (Constraint c in _tableHelper.Constraints)
            {
                Message.Trace(Severity.Debug,"Found constraint {0}", c.Name);
                if(c is ForeignKeyConstraint)
                {
                    Message.Trace(Severity.Debug,"Found FKC {0}", c.Name);
                    ConstraintEmitter ce = new ConstraintEmitter(VulcanPackage, c, _tableHelper);
                    outputWriter.Write("\n");
                    ce.Emit(outputWriter);
                }
            }

            //Indexes
            IndexEmitter ie = new IndexEmitter(_tableHelper.Name, _tableHelper.TableNavigator, VulcanPackage);
            ie.Emit(outputWriter);

            InsertDefaultValuesEmitter ide = new InsertDefaultValuesEmitter(_tableHelper.Name, _tableHelper.TableNavigator, _tableHelper, VulcanPackage);
            ide.Emit(outputWriter);

            outputWriter.Write("\n");
        }
Exemple #30
0
        /// <summary>
        /// Prints the object to a stream, which can be used for display or logging
        /// </summary>
        /// <returns>The serialized object</returns>
        /// <param name="item">The object to serialize</param>
        public static void PrintSerializeObject(object item, System.IO.TextWriter writer, Func<System.Reflection.PropertyInfo, bool> filter = null)
        {
            foreach(var p in item.GetType().GetProperties())
            {
                if (filter != null && !filter(p))
                    continue;

                if (p.PropertyType.IsPrimitive || p.PropertyType == typeof(string))
                {
                    writer.WriteLine("{0}: {1}", p.Name, p.GetValue(item, null));
                }
                else if (typeof(System.Collections.IEnumerable).IsAssignableFrom(p.PropertyType))
                {
                    var enumerable = (System.Collections.IEnumerable)p.GetValue(item, null);
                    if (enumerable != null)
                    {
                        var enumerator = enumerable.GetEnumerator();
                        if (enumerator != null)
                        {
                            writer.Write("{0}: [", p.Name);
                            if (enumerator.MoveNext())
                            {
                                writer.Write(enumerator.Current);
                                while (enumerator.MoveNext())
                                {
                                    writer.Write(", ");
                                    writer.Write(enumerator.Current);
                                }
                            }
                            writer.WriteLine("]");
                        }
                    }
                }
            }
            writer.Flush();
        }