Ejemplo n.º 1
0
 /// <summary>
 /// Replaces the all files content with some new content
 /// </summary>
 /// <param name="file"></param>
 /// <param name="newContent"></param>
 public static void SetNewContent(this IFile file, string newContent)
 {
     using (C1StreamWriter sw = new C1StreamWriter(GetNewWriteStream(file)))
     {
         sw.Write(newContent);
     }
 }
Ejemplo n.º 2
0
        public static string Encrypt(string value)
        {
            Verify.ArgumentNotNullOrEmpty(value, "value");

            // Declare the streams used
            // to encrypt to an in memory
            // array of bytes.
            MemoryStream msEncrypt = null;
            CryptoStream csEncrypt = null;
            C1StreamWriter swEncrypt = null;

            // Declare the RijndaelManaged object
            // used to encrypt the data.
            RijndaelManaged rima = null;

            try
            {
                // Create a RijndaelManaged object
                // with the specified key and IV.
                rima = new RijndaelManaged();
                rima.Key = _encryptionKey;
                rima.IV = RijndaelIV;

                // Create a decrytor to perform the stream transform.
                ICryptoTransform encryptor = rima.CreateEncryptor();

                // Create the streams used for encryption.
                msEncrypt = new MemoryStream();
                csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);
                swEncrypt = new C1StreamWriter(csEncrypt);

                //Write all data to the stream.
                swEncrypt.Write(value);
            }
            finally
            {
                if (swEncrypt != null) swEncrypt.Close();
                if (csEncrypt != null) csEncrypt.Close();
                if (msEncrypt != null) msEncrypt.Close();
                if (rima != null) rima.Clear();
            }

            // Return the encrypted bytes from the memory stream.
            return ByteToHexString(msEncrypt.ToArray());
        }
Ejemplo n.º 3
0
        /// <exclude />
        public static string GetDocumentAsString(this XDocument document)
        {
            Verify.ArgumentNotNull(document, "document");

            using (var ms = new MemoryStream())
            {
                using (var sw = new C1StreamWriter(ms))
                {
                    document.Save(sw);

                    ms.Seek(0, SeekOrigin.Begin);

                    using (var sr = new C1StreamReader(ms))
                    {
                        return sr.ReadToEnd();
                    }
                }
            }
        }
Ejemplo n.º 4
0
            public static void Initialize(Resources resources)
            {
                LoggingSettings section = null;
                if (ConfigurationServices.ConfigurationSource != null)
                {
                    section = ConfigurationServices.ConfigurationSource.GetSection(LoggingSettings.SectionName) as LoggingSettings; ;
                }

                if (section != null)
                {
                    resources.Factory = new LogWriterFactory(ConfigurationServices.ConfigurationSource);
                    resources.Writer = resources.Factory.Create();
                }
                else
                {
                    string path = Path.Combine(PathUtil.BaseDirectory, string.Format("logging{0}.config", Guid.NewGuid()));

                    using (C1StreamWriter writer = new C1StreamWriter(path))
                    {
                        Type type = typeof(LoggingService).Assembly
                            .GetType("Composite.Plugins.Logging.LogTraceListeners.TcpLogTraceListener.TcpLogTraceListener", false);

                        if ((type != null) && (RuntimeInformation.IsUnittest == false))
                        {
                            #region config file
                            writer.WriteLine(@"<?xml version=""1.0"" encoding=""utf-8""?>
  <configuration>
  <configSections>
    <section name=""loggingConfiguration"" type=""Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0"" />
  </configSections>
  <loggingConfiguration name=""Logging Application Block"" tracingEnabled=""true""
    defaultCategory=""General"" logWarningsWhenNoCategoriesMatch=""true"">
    <listeners>
        <add listenerDataType=""Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0""
            traceOutputOptions=""None"" type=""Composite.Plugins.Logging.LogTraceListeners.TcpLogTraceListener.TcpLogTraceListener, Composite, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null""
            name=""Tcp Custom Trace Listener"" initializeData="""" formatter=""Text Formatter"" />
      </listeners>
    <formatters>
     <add template=""Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title: {title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}""
        type=""Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0""
        name=""Text Formatter"" />
     </formatters>
    <categorySources>
      <add switchValue=""All"" name=""General"" />
    </categorySources>
    <specialSources>
      <allEvents switchValue=""All"" name=""All Events"">
        <listeners>
          <add name=""Tcp Custom Trace Listener"" />
        </listeners>
      </allEvents>
      <notProcessed switchValue=""All"" name=""Unprocessed Category"" />
      <errors switchValue=""All"" name=""Logging Errors &amp; Warnings"" />
    </specialSources>
  </loggingConfiguration>
</configuration>");
                            #endregion
                        }
                        else
                        {
                            #region config file
                            writer.WriteLine(@"<?xml version=""1.0"" encoding=""utf-8""?>
  <configuration>
  <configSections>
    <section name=""loggingConfiguration"" type=""Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0"" />
  </configSections>s
  <loggingConfiguration name=""Logging Application Block"" tracingEnabled=""true""
    defaultCategory=""General"" logWarningsWhenNoCategoriesMatch=""true"">
    <listeners>
      <add listenerDataType=""Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.CustomTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0""
        traceOutputOptions=""None"" type=""Composite.Core.Logging.NullLogTraceListener, Composite, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null""
        name=""NullLogTraceListener"" initializeData="""" formatter=""Text Formatter"" />
    </listeners>
    <formatters>
      <add template=""Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}""
        type=""Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.0.0.0""
        name=""Text Formatter"" />
    </formatters>
    <categorySources>
      <add switchValue=""All"" name=""General"" />
    </categorySources>
    <specialSources>
      <allEvents switchValue=""All"" name=""All Events"">
        <listeners>
          <add name=""NullLogTraceListener"" />
        </listeners>
      </allEvents>
      <notProcessed switchValue=""All"" name=""Unprocessed Category"" />
      <errors switchValue=""All"" name=""Logging Errors &amp; Warnings"" />
    </specialSources>
  </loggingConfiguration>
</configuration>");
                            #endregion
                        }
                    }

                    resources.Factory = new LogWriterFactory(new FileConfigurationSource(path));
                    resources.Writer = resources.Factory.Create();
                }
            }