Esempio n. 1
0
 private void WriteToStream(Stream stream, string msg)
 {
     if (stream != null)
     {
         stream.Write(uniEncoding.GetBytes(msg),
                      0, uniEncoding.GetByteCount(msg));
     }
 }
Esempio n. 2
0
            public bool setCharacterComplement(string sCharacterComplement)
            {
                bool bResult = true;

                System.Text.UnicodeEncoding ue = new System.Text.UnicodeEncoding();

                if (ue.GetByteCount(sCharacterComplement) != 8)
                {
                    bResult = false;
                    throw new ArrayTypeMismatchException("CharacterComplement should have a length of 8 characters.");
                }

                m_CharacterComplement = ue.GetBytes(sCharacterComplement);

                return(bResult);
            }
Esempio n. 3
0
            public bool setFileName(string sFileName)
            {
                bool bResult = true;

                System.Text.UnicodeEncoding ue = new System.Text.UnicodeEncoding();

                if (ue.GetByteCount(sFileName) != 6)
                {
                    bResult = false;
                    throw new ArrayTypeMismatchException("FileName is should have a length of 6 characters.");
                }

                m_FileName = ue.GetBytes(sFileName);

                return(bResult);
            }
Esempio n. 4
0
            public bool setFileName( string sFileName )
            {
                bool bResult = true;

                System.Text.UnicodeEncoding ue = new System.Text.UnicodeEncoding();
            
                if( ue.GetByteCount( sFileName ) != 6 )
                {
                    bResult = false;
                    throw new ArrayTypeMismatchException( "FileName is should have a length of 6 characters." );
                }

                m_FileName = ue.GetBytes( sFileName );

                return bResult;
            }
Esempio n. 5
0
            public bool setCharacterComplement( string sCharacterComplement )
            {
                bool bResult = true;

                System.Text.UnicodeEncoding ue = new System.Text.UnicodeEncoding();
            
                if( ue.GetByteCount( sCharacterComplement ) != 8 )
                {
                    bResult = false;
                    throw new ArrayTypeMismatchException( "CharacterComplement should have a length of 8 characters." );
                }

                m_CharacterComplement = ue.GetBytes( sCharacterComplement );

                return bResult;
            }
Esempio n. 6
0
        private UInt32 Update( string FullPathToFile )
        {
            unchecked
            {
                // Creates an encoder that will map each Unicode character to 2 bytes
                System.Text.UnicodeEncoding myEncoder = new System.Text.UnicodeEncoding();

                // Include file name only, strip off path information
                // This is done so we get the same CRC no matter if the CD is in drive G
                // on one machine and drive F on another, kappish?

                int index = FullPathToFile.LastIndexOf( '\\' );
                string strFileName = FullPathToFile.Substring( index + 1 );

                // Convert file name to byte array

                int count = myEncoder.GetByteCount( strFileName );
                byte[] buffer = new byte[count];
                buffer = myEncoder.GetBytes(strFileName);

                UInt32 crc = HighBitMask;

                //ProcessBuffer( ref buffer, ref crc );
                for (int i = 0; i < count; i++)
                    crc = ((crc) >> 8) ^ CRCTable[(buffer[i]) ^ ((crc) & 0x000000FF)];

                crc = ~crc;
                LifetimeCRC ^= crc;

                return crc;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Calls method IdeaRS.ConnectionLink.ConnectionLink.OpenIdeaConnection to run Idea Connection
        /// </summary>
        /// <param name="iomFilename">IOM filename - includes geometry of the connection (connected members)</param>
        /// <param name="templateFileName">Idea connection template or connection project file name</param>
        /// <param name="isHiddenCalculation">Set true to run hidden calculation </param>
        private void OpenIOMInIdeaCon(string iomFilename, string templateFileName, bool isHiddenCalculation)
        {
            FileStream fs  = new FileStream(iomFilename, FileMode.Open, FileAccess.Read);
            FileStream fsr = null;

            string filenameRes = iomFilename + "R";

            if (System.IO.File.Exists(filenameRes))
            {
                fsr = new FileStream(filenameRes, FileMode.Open, FileAccess.Read);
            }

            FileStream   connTemplateStream   = null;
            FileStream   connProjectStream    = null;
            MemoryStream importSettingsStream = null;

            if (!string.IsNullOrEmpty(templateFileName) && File.Exists(templateFileName))
            {
                string fileExt      = System.IO.Path.GetExtension(templateFileName);
                bool   isConProject = fileExt.Equals(".ideacon", StringComparison.InvariantCultureIgnoreCase);

                if (isConProject)
                {
                    connProjectStream = new FileStream(templateFileName, FileMode.Open, FileAccess.Read);
                }
                else
                {
                    connTemplateStream = new FileStream(templateFileName, FileMode.Open, FileAccess.Read);
                }
            }

            if (!string.IsNullOrEmpty(importSettingsTextBox.Text))
            {
                importSettingsStream = new System.IO.MemoryStream();
                var encoding = new System.Text.UnicodeEncoding();
                importSettingsStream.Write(encoding.GetBytes(importSettingsTextBox.Text), 0, encoding.GetByteCount(importSettingsTextBox.Text));
                importSettingsStream.Flush();
                importSettingsStream.Seek(0, SeekOrigin.Begin);
            }

            if (dynLinkLazy.Value != null)
            {
                if (!isHiddenCalculation)
                {
                    dynLinkLazy.Value.OpenIdeaConnection(fs, fsr, connProjectStream, connTemplateStream, importSettingsStream, true);
                }
                else
                {
                    dynLinkLazy.Value.RunHiddenAnalysis(fs, fsr, connProjectStream, connTemplateStream, importSettingsStream, true);
                    if (!dynLinkLazy.Value.IsProjectCalculated())
                    {
                        this.resultBrowser.NavigateToString("Results doesn't exist");
                        return;
                    }

                    string conCheckResFilename = dynLinkLazy.Value.GetCheckResultsFilename();
                    this.resultBrowser.Navigate(conCheckResFilename);
                }

                OnProjOpened();
            }
        }
Esempio n. 8
0
        public static void Write(string message, Exception sourceException)
        {
            byte   logLevel = Byte.Parse(ConfigurationManager.AppSettings["LOG_LEVEL"]);
            string time     = System.DateTime.Now.ToString();

            if (logLevel > 0)
            {
                try
                {
                    // Genera debug sulla finestra di output

                    System.Diagnostics.Debug.WriteLine("[Message] " + time + " " + message);

                    if (sourceException != null)
                    {
                        System.Diagnostics.Debug.WriteLine("[Exception] " + sourceException.ToString());
                    }

                    if (logLevel == 2)
                    {
                        // Apri il file relativo al debug
                        XmlDocument xmlDocument  = new XmlDocument();
                        string      DebugLogPath = ConfigurationManager.AppSettings["DEBUG_PATH"];
                        DebugLogPath = DebugLogPath.Replace("%DATA", DateTime.Now.ToString("yyyyMMdd"));
                        //DebugLogPath = Path.Combine (DebugLogPath, "debug_log");
                        DebugLogPath = Path.Combine(DebugLogPath, DateTime.Now.Hour.ToString("D2"));

                        if (!Directory.Exists(DebugLogPath))
                        {
                            Directory.CreateDirectory(DebugLogPath);
                        }

                        if (!File.Exists(Path.Combine(DebugLogPath, "logger.xsl")))
                        {
                            // Copia il file XSL nella directory
                            string sourceFileXsl = AppDomain.CurrentDomain.BaseDirectory + @"\xml\logger.xsl";
                            if (File.Exists(sourceFileXsl))
                            {
                                File.Copy(sourceFileXsl, DebugLogPath + @"\logger.xsl");
                            }


                            //File.Copy(Path.Combine (AppDomain.CurrentDomain.BaseDirectory, Path.Combine ("xml", "logger.xsl")), Path.Combine (DebugLogPath, "logger.xsl"));
                            //							File.Copy(AppDomain.CurrentDomain.BaseDirectory + @"\xml\logger.xsl", DebugLogPath + @"\logger.xsl");
                        }

                        DebugLogPath = Path.Combine(DebugLogPath, "logger.xml");
                        Console.WriteLine(DebugLogPath);

                        //se il file non esiste, viene creato
                        if (!File.Exists(DebugLogPath))
                        {
                            // Crea un nuovo file XML
                            XmlDeclaration xmlDeclaration = xmlDocument.CreateXmlDeclaration("1.0", "UTF-16", "yes");
                            xmlDocument.InnerXml = xmlDeclaration.OuterXml + "<?xml-stylesheet type='text/xsl' href='logger.xsl'?><DEBUG>\r\n</DEBUG>";
                            xmlDocument.Save(DebugLogPath);
                        }

                        // Aggiungi messaggi al file XML
                        FileStream file = new FileStream(DebugLogPath, System.IO.FileMode.Open, System.IO.FileAccess.Write);
                        if (file != null)
                        {
                            file.Seek(-Utf16.GetByteCount("\r\n</DEBUG>"),
                                      System.IO.SeekOrigin.End);

                            string b = "<LOGENTRY date=\"" + DateTime.Now.ToString() + "\">";
                            b += "\r\n<MESSAGE>";
                            if (message != null)
                            {
                                b += "\r\n" + "<![CDATA[" + message + "]]>";
                            }
                            b += "\r\n</MESSAGE>\r\n";
                            b += "<EXCEPTION>";
                            if (sourceException != null)
                            {
                                b += "\r\n" + "<![CDATA[" + sourceException + "]]>";
                            }
                            b += "\r\n</EXCEPTION>\r\n";
                            b += "</LOGENTRY>\r\n</DEBUG>";
                            WriteString(file, b);
                            file.Close();
                        }
                    }
                }
                catch (Exception exception)
                {
                    System.Diagnostics.Debug.WriteLine("Errore nella scrittura del file di debug (segue descrizione errore):");
                    System.Diagnostics.Debug.WriteLine(exception.ToString());
                }
            }
        }