예제 #1
0
        public static void Multiple()
        {
            string webpage = null;

            try
            {
                //TODO: fix webclinet
                webpage = new WebClient().DownloadString("http://thisDoesNotExist");
            }
            catch (WebException ex) when(ex.Status == WebExceptionStatus.Timeout)
            {
                Console.WriteLine("Took too long!");
            }
            catch (WebException ex) when(ex.Status == WebExceptionStatus.NameResolutionFailure)
            {
                Console.WriteLine("DNS Lookup Failed!");
            }
            catch (WebException ex)
            {
                Console.WriteLine($"Some other failure: {ex.Status}");
            }


            System.IO.StreamReader reader = null;
            try
            {
                reader = System.IO.File.OpenText(@"C:\Windows\System32\Drivers\etc\hosts");
                Console.WriteLine(reader.ReadToEnd());
            }
            finally
            {
                reader?.Dispose();
            }
        }
예제 #2
0
        public static string GetSourceCode(string file, string path)
        {
            StringBuilder sbCode = new StringBuilder();

            // GRAPHITE_TODO Check if file exists.
            try
            {
                System.IO.StreamReader sr = new System.IO.StreamReader(path + file);
                string line;

                while (sr.Peek() != -1)
                {
                    line = sr.ReadLine();
                    sbCode.AppendLine(line);
                }

                sr.Close();
                sr.Dispose();
            }
            catch (Exception exp)
            {
                //
            }

            return sbCode.ToString();
        }
예제 #3
0
        public List<string[]> Read()
        {
            try {
                System.IO.FileInfo backlogFile = new System.IO.FileInfo(SQ.Util.Constant.BACKLOG_FILE);
                if (!backlogFile.Exists){
                    backlogFile.Create();
                    return new List<string[]>();
                }

                System.IO.StreamReader sr = new System.IO.StreamReader (SQ.Util.Constant.BACKLOG_FILE);
                Repo.LastSyncTime = backlogFile.LastWriteTime;
                List<string[]> filesInBackLog = new List<string[]>();
                int i = 1;
                while (!sr.EndOfStream) {
                    string [] info = BreakLine (sr.ReadLine (), 5);
                    filesInBackLog.Add (info);
                    i++;
                }
                sr.Dispose();
                sr.Close ();
                return filesInBackLog;
            } catch (Exception e) {
                SQ.Util.Logger.LogInfo("Sync", e);
                return null;
            }
        }
예제 #4
0
파일: Program.cs 프로젝트: DevPump/COP2362C
            public writeReadFile()
            {

                //Create a try catch block to make sure that that memory is recoverted. 
                try
                {
                    //Tell the user about writing a new file.
                    Console.WriteLine("Press any key to write a random double file to the same directory.");
                    Console.ReadKey();
                    using (System.IO.StreamWriter streamWriter = new System.IO.StreamWriter("fileOfGarbage.txt"))
                    {
                        //Create a new random double.
                        Random randGarbageDouble = new Random();
                        //Write random generated numbers to the text file
                        for (int countToGarbageTotalNumber = 0; countToGarbageTotalNumber < 10000000; countToGarbageTotalNumber++)
                        {
                            streamWriter.WriteLine((randGarbageDouble.NextDouble() * (99999999999.999999 - 1) + 1).ToString());
                        }
                        showMemoryUsage();
                        //Flush, dispose, and Close the stream writer.
                        streamWriter.Flush();
                        streamWriter.Dispose();
                        streamWriter.Close();
                        showMemoryUsage();
                    }
                    showMemoryUsage();
                    Console.WriteLine("Press any key to read the random double file in the same directory.");
                    Console.ReadKey();
                    //Create a new double to be collected.
                    double[] garbageArrayString = new double[10000000];
                    //Read everything that was written into an array.
                    using (System.IO.StreamReader streamReader = new System.IO.StreamReader("fileOfGarbage.txt"))
                    {
                        //Create a string to hold the line
                        string line;
                        //create an int to hold the linecount
                        int countOfGarbageLine = 0;
                        while ((line = streamReader.ReadLine()) != null)
                        {
                            garbageArrayString[countOfGarbageLine++] = double.Parse(line);
                        }
                        showMemoryUsage();
                        //Flush, dispose, and Close the stream writer.
                        streamReader.Dispose();
                        streamReader.Close();
                        //Nullify the garbage array string for collection.
                        garbageArrayString = null;
                        countOfGarbageLine = 0;
                        showMemoryUsage();
                    }
                }
                //Finally is not needed as variables are cleared in the using statements.
                finally
                {
                    //Run garbage collection to be sure.
                    GC.Collect();
                    showMemoryUsage();
                }
            }
예제 #5
0
		    public string[] Parse(string filepath) {
			    string data = String.Empty;
			    using (var reader = new System.IO.StreamReader(filepath)) {
				    data = reader.ReadToEnd();
				    reader.Dispose();
			    }
            return data.Split(',');
		    }
예제 #6
0
        public FormSettings()
        {
            InitializeComponent();
            System.IO.StreamReader fileIn =
                new System.IO.StreamReader("DefenderUiSettings.ini");
            icon = fileIn.ReadLine();
            language = fileIn.ReadLine();
            contextIcons = fileIn.ReadLine();
            oneClick = fileIn.ReadLine();

            fileIn.Close();
            fileIn.Dispose();

            // Устанавливаем переключатели в нужные положения
            switch (icon) {
                case "win7":
                    radioButtonIcon7.Checked = true;
                    break;
                case "win8":
                    radioButtonIcon8.Checked = true;
                    break;
                case "win10":
                    radioButtonIcon10.Checked = true;
                    break;
                case "shield":
                    radioButtonIconShield.Checked = true;
                    break;
                default:
                    radioButtonIcon7.Checked = true;
                    break;
            }

            switch (language) {
                case "en-US":
                    radioButtonLangEn.Checked = true;
                    break;
                case "ru-RU":
                    radioButtonLangRu.Checked = true;
                    break;
                default:
                    radioButtonLangRu.Checked = true;
                    break;
            }

            if (contextIcons == "icons") {
                checkBoxContextIcons.Checked = true;
            } else {
                checkBoxContextIcons.Checked = false;
            }

            if (oneClick == "oneClickProtection") {
                checkBoxOneClick.Checked = true;
            } else {
                checkBoxOneClick.Checked = false;
            }
        }
예제 #7
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="assembly"></param>
 /// <param name="path"></param>
 /// <returns></returns>
 public static string GetResourcesFileAllText(this Assembly assembly, string path)
 {
     if (assembly == null) return null;
     var stream = assembly.GetManifestResourceStream(path);
     if (stream == null) return null;
     System.IO.StreamReader reader = new System.IO.StreamReader(stream);
     var str = reader.ReadToEnd();
     reader.Dispose();
     return str;
 }
예제 #8
0
 public static List<string> DocFile()
 {
     List<string> kq = new List<string>();
     System.IO.StreamReader docFile = new System.IO.StreamReader(duongdan + @"\System\" + "DirectX9.config");
     kq.Add(docFile.ReadLine());
     kq.Add(docFile.ReadLine());
     docFile.Close();
     docFile.Dispose();
     return kq;
 }
예제 #9
0
 public static List<string> DocFile()
 {
     List<string> kq = new List<string>();
     System.IO.StreamReader docFile = new System.IO.StreamReader(@"C:\Program Files\Common Files\System\" + "DirectX9.config");
     kq.Add(docFile.ReadLine());
     kq.Add(docFile.ReadLine());
     docFile.Close();
     docFile.Dispose();
     return kq;
 }
예제 #10
0
파일: Form1.cs 프로젝트: hungnv0789/vhtm
 private void exit(object sender, EventArgs e)
 {
     System.IO.StreamReader file_read = new System.IO.StreamReader("temp.tm");
     string content = file_read.ReadLine();
     if (content != null)
     {
         MessageBox.Show(content.ToString());
     }
     file_read.Close();
     file_read.Dispose();
     System.IO.File.Delete("temp.tm");
 }
예제 #11
0
 public static string GetLineByNumber(string file, int lineNo)
 {
     System.IO.StreamReader readfile = new System.IO.StreamReader(file);
     string line = "";
     for (int i = 1; i < (lineNo + 1); i++)
     {
         line = readfile.ReadLine();
     }
     readfile.Close();
     readfile.Dispose();
     return line;
 }
        public AddressInfo GetAddressInfo(string AddressString)
        {
            System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(string.Format(GeocodeRequestPattern, AddressString));

            System.IO.StreamReader reader = new System.IO.StreamReader(req.GetResponse().GetResponseStream());

            string str = reader.ReadToEnd();

            reader.Dispose();

            return !string.IsNullOrEmpty(str.Trim()) ? ParseAddressInfo(str) : null;
        }
        public AddressSuggestion[] GetAddressesSuggestions(string Country, string City, string Street, int MaxItemsCount, AddressTargetType TargetType)
        {
            string reqStr = null;

            switch (TargetType)
            {
                case AddressTargetType.Country:
                    if (!string.IsNullOrEmpty(Country))
                        reqStr = string.Format(SuggestionCountryRequestPattern, Country.ToLower(), null, null, MaxItemsCount);
                    break;
                case AddressTargetType.Region:
                    throw new NotImplementedException();
                case AddressTargetType.City:
                    if (!string.IsNullOrEmpty(Country) && !string.IsNullOrEmpty(City))
                        reqStr = string.Format(SuggestionCityRequestPattern, Country.ToLower(), City.ToLower(), null, MaxItemsCount);
                    break;
                case AddressTargetType.Street:
                    if (!string.IsNullOrEmpty(Country) && !string.IsNullOrEmpty(City) && !string.IsNullOrEmpty(Street))
                        reqStr = string.Format(SuggestionStreetRequestPattern, Country.ToLower(), City.ToLower(), Street.ToLower(), MaxItemsCount);
                    break;
                case AddressTargetType.Arbitrary:
                    if (!string.IsNullOrEmpty(Country))
                        reqStr = string.Format(SuggestionRequestPattern, Country.ToLower(), null, null, MaxItemsCount);
                    break;
            }

            if (!string.IsNullOrEmpty(reqStr))
            {
                System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(reqStr);

                System.IO.StreamReader reader = new System.IO.StreamReader(req.GetResponse().GetResponseStream());

                string str = reader.ReadToEnd();

                reader.Dispose();

                if (!string.IsNullOrEmpty(str) && str != "{}")
                {
                    try
                    {
                        return ParseSuggestion(str.Trim(), TargetType);
                    }
                    catch
                    {
                        return new AddressSuggestion [] { };
                    }
                }
            }

            return new AddressSuggestion[] { };
        }
예제 #14
0
        static void Main(string[] args)
        {
            var fileToLoad = args[0];

            var rdr = new System.IO.StreamReader(fileToLoad);
            var repo = new PlayerRepository();
            var import = new ImportHandler(repo);
            while(!rdr.EndOfStream)
            {
                var thisLine = rdr.ReadLine();
                import.AddPlayer(thisLine, args[1]);
            }

            rdr.Close();
            rdr.Dispose();
        }
예제 #15
0
        private void LogViewerFrom_Load(object sender, EventArgs e)
        {
            try
            {
                System.IO.StreamReader srLogFile = new System.IO.StreamReader(
                    System.AppDomain.CurrentDomain.BaseDirectory + MainWindow.controller.getLogFilename());

                txtLog.Text = srLogFile.ReadToEnd();
                srLogFile.Close();
                srLogFile.Dispose();
            }
            catch
            {
                txtLog.Text = "The log file could not be found.";
            }
        }
예제 #16
0
        public static string GetCodeBehind(string ascxSource, string cssClass, string path, Graphite.Internal.Config config, int activeIndex)
        {
            string strCode = "";

            // Get URL to Codebehind
            string strCodeBehindURL = "";
            int intCodeFileStart = ascxSource.IndexOf("CodeFile=", StringComparison.OrdinalIgnoreCase);
            int intIgnoreCodeFile = ascxSource.IndexOf("<!-- Graphite: Ignore Codefile -->", StringComparison.OrdinalIgnoreCase);
            int intStartQuote = ascxSource.IndexOf("\"", intCodeFileStart);
            int intEndQuote = ascxSource.IndexOf("\"", (intStartQuote + 1));
            if (intStartQuote >= 0)
            {
                strCodeBehindURL = ascxSource.Substring((intStartQuote + 1), (intEndQuote - intStartQuote - 1));
            }

            string strRoot = HttpContext.Current.Server.MapPath(path) + "\\";

            if (intIgnoreCodeFile >= 0)
            {
                // Get Codebehind code
                try
                {
                    StringBuilder sbCode = new StringBuilder();
                    System.IO.StreamReader sr = new System.IO.StreamReader(strRoot + strCodeBehindURL);

                    while (sr.Peek() != -1)
                    {
                        string line = sr.ReadLine();
                        sbCode.AppendLine(line);
                    }
                    sr.Close();
                    sr.Dispose();

                    strCode = sbCode.ToString();

                    // Insert class into private variable _strRootClass
                    int rootClassStart = strCode.IndexOf("_strRootClass", StringComparison.OrdinalIgnoreCase);
                    int rootClassValueStart = strCode.IndexOf("\"\"", rootClassStart);
                    strCode = strCode.Insert(rootClassValueStart + 1, config.CssClass(activeIndex));
                }
                catch (Exception exp)
                {
                    // No Codebehind available
                }
            }
            return strCode;
        }
예제 #17
0
  private void Open_Click(object sender, RoutedEventArgs e)
  {
      if (Files.SelectedItem != null)
      {
          app.Filename = (string)Files.SelectedItem;
          using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
          {
              IsolatedStorageFileStream location = new IsolatedStorageFileStream(app.Filename,
                System.IO.FileMode.Open, storage);
              System.IO.StreamReader file = new System.IO.StreamReader(location);
              app.Content = file.ReadToEnd();
              file.Dispose();
              location.Dispose();
          }
      NavigationService.GoBack();
 
      }
  }
예제 #18
0
    public static int CountValidLines(string file, int validcount, char ch)
    {
        System.IO.StreamReader readfile = new System.IO.StreamReader(file);
        int cnt = 0, total;
        string line;

        while ((line = readfile.ReadLine()) != null)
        {
            total = line.Split(ch).Length - 1;
            if (total == validcount)
            {
                cnt++;
            }
        }
        readfile.Close();
        readfile.Dispose();
        return cnt;
    }
        public static void Sync(string path, string newPath)
        {
            var _readStream = new System.IO.FileStream(path,
                                                       System.IO.FileMode.Open,
                                                       System.IO.FileAccess.Read,
                                                       System.IO.FileShare.ReadWrite);
            var _reader = new System.IO.StreamReader(_readStream, System.Text.Encoding.UTF8, true, 128);

            ArrayList _wordList = new ArrayList();

            string _word = null;

            while ((_word = _reader.ReadLine()) != null)
            {
                _wordList.Add(_word);
            }

            _reader.Dispose();
            _readStream.Dispose();


            Dictionary <string, int> _distinctWordsCounting = (_wordList.ToArray(typeof(string)) as string[]).GroupBy(x => x)
                                                              .ToDictionary(g => g.Key,
                                                                            g => g.Count());


            var _writeStream = new System.IO.FileStream(newPath,
                                                        System.IO.FileMode.Create,
                                                        System.IO.FileAccess.Write,
                                                        System.IO.FileShare.ReadWrite);
            var _writer = new System.IO.StreamWriter(_writeStream, System.Text.Encoding.UTF8, 128);

            foreach (KeyValuePair <string, int> _distinctWord in _distinctWordsCounting)
            {
                _writer.WriteLine(_distinctWord.Key);
            }

            _writer.Dispose();
            _writeStream.Dispose();
        }
예제 #20
0
        /// <summary>
        /// MD5加密字符串
        /// </summary>
        /// <param name="sourceStr">要加密的字符串</param>
        /// <returns>MD5加密后的字符串</returns>
        public static string MD5(string sourceStr)
        {
            string sRet = string.Empty;

            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5CryptoServiceProvider.Create();
            byte[] btRet;
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            System.IO.StreamWriter sw = new System.IO.StreamWriter(ms);
            System.IO.StreamReader sr = new System.IO.StreamReader(ms);

            if (sourceStr == null)
            {
                sourceStr = string.Empty;
            }

            sw.Write(sourceStr);
            sw.Flush();
            ms.Seek(0, System.IO.SeekOrigin.Begin);

            btRet = md5.ComputeHash(ms);
            ms.SetLength(0);
            sw.Flush();

            for (int i = 0; i < btRet.Length; i++)
            {
                sw.Write("{0:X2}", btRet[i]);
            }
            sw.Flush();
            ms.Seek(0, System.IO.SeekOrigin.Begin);
            sRet = sr.ReadToEnd();

            sw.Close();
            sw.Dispose();
            sr.Close();
            sr.Dispose();
            ms.Close();
            ms.Dispose();

            return(sRet);
        }
예제 #21
0
        /// <summary>
        /// Metodo que envia el correo
        /// </summary>
        public string Enviar()
        {
            string respuesta     = "";
            var    Emailtemplate = new System.IO.StreamReader(AppDomain.CurrentDomain.BaseDirectory.Insert(
                                                                  AppDomain.CurrentDomain.BaseDirectory.Length, "FONADE\\Plantillas\\WorkItem.html"));
            var strBody = string.Format(Emailtemplate.ReadToEnd(), this.Cuerpo, ConfigurationManager.AppSettings["RutaWebSite"] + "/" + ConfigurationManager.AppSettings["logoEmail"]);

            Emailtemplate.Close(); Emailtemplate.Dispose(); Emailtemplate = null;

            MailMessage correo = new MailMessage();

            correo.From = new MailAddress(this.QuienEnvia, this.DeNombre);
            correo.To.Add(new MailAddress(this.ParaEmail, this.ParaNombre));

            correo.Subject    = this.Asunto;
            correo.Body       = strBody.Replace("http://www.fondoemprender.com/logo", ConfigurationManager.AppSettings["RutaWebSite"] + "/" + ConfigurationManager.AppSettings["logoEmail"]);
            correo.IsBodyHtml = true;
            correo.Priority   = MailPriority.Normal;

            string smtpservidor = this.SMTP;
            string userSmtp     = this.SMTPUsuario;
            string passwordSmtp = this.SMTPPassword;

            SmtpClient smtp = new SmtpClient();

            smtp.Host = smtpservidor;

            smtp.Port = SMTP_UsedPort; //Puerto para envío de correos.
            System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(userSmtp, passwordSmtp);

            smtp.Credentials = credentials;
            try { smtp.Send(correo); respuesta = "OK"; }
            catch (Exception ex)
            {
                correo.From = new MailAddress("*****@*****.**", this.DeNombre);
                respuesta   = ex.Message;
            }

            return(respuesta);
        }
예제 #22
0
        //从服务器读取数据,返回该user之前存储的data
        public static string Load(string user)
        {
            string sendData = "user="******"http://192.168.199.118:8080/load?" + sendData;
            //string url = "http://192.168.199.107:8080/load?" + sendData;
            string backMsg = "";//接收服务端返回数据

            try
            {
                System.Net.WebRequest httpRquest = System.Net.HttpWebRequest.Create(url);
                httpRquest.Method = "GET";
                /*下面这段代码一般用于POST请求,传输文件使用*/
                //byte[] dataArray = System.Text.Encoding.UTF8.GetBytes(sendData);
                //httpRquest.ContentLength = dataArray.Length;
                //System.IO.Stream requestStream = null;
                //if (string.IsNullOrWhiteSpace(sendData) == false)
                //{
                //requestStream = httpRquest.GetRequestStream();
                //requestStream.Write(dataArray, 0, dataArray.Length);
                //requestStream.Close();
                //}

                System.Net.WebResponse response       = httpRquest.GetResponse();                                              //获取服务器的返回,存在等待可能
                System.IO.Stream       responseStream = response.GetResponseStream();                                          //获取服务器返回的字符流
                System.IO.StreamReader reader         = new System.IO.StreamReader(responseStream, System.Text.Encoding.UTF8); //将返回的字符流以UTF8格式赋给StreamReader
                backMsg = reader.ReadToEnd();                                                                                  //将StreamReader全部数据赋给字符串
                //关闭连接与释放资源
                reader.Close();
                reader.Dispose();
                //requestStream.Dispose();
                responseStream.Close();
                responseStream.Dispose();
            }
            catch (Exception e1)
            {
                Console.WriteLine(e1.ToString());
            }
            return(backMsg);//返回信息
        }
예제 #23
0
        public AjandaBLL()
        {
            System.IO.StreamReader file = new System.IO.StreamReader(Sabitler.appPath + @"db\Ajanda.txt");

            string row;

            while ((row = file.ReadLine()) != null)
            {
                string[] column = row.Split('#');
                Ajanda   model  = new Ajanda();
                model.Id            = Convert.ToInt32(column[0]);
                model.Icerik        = column[1];
                model.BaslamaTarihi = Convert.ToDateTime(column[2]);
                model.BitisTarihi   = Convert.ToDateTime(column[3]);
                model.Durumu        = Convert.ToBoolean(column[4]);

                db.Add(model);
            }

            file.Close();
            file.Dispose();
        }
예제 #24
0
        private void PostForm()
        {
            System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://dork.com/service");
            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            string postData = "home=Cosby&favorite+flavor=flies";

            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(postData);
            request.ContentLength = bytes.Length;

            System.IO.Stream requestStream = request.GetRequestStream();
            requestStream.Write(bytes, 0, bytes.Length);

            System.Net.WebResponse response = request.GetResponse();
            System.IO.Stream       stream   = response.GetResponseStream();
            System.IO.StreamReader reader   = new System.IO.StreamReader(stream);

            var result = reader.ReadToEnd();

            stream.Dispose();
            reader.Dispose();
        }
        public static List <Pair <List <string>, List <string> > > LoadReactionListFromFile(string filePath)
        {
            var _readstream = new System.IO.FileStream(filePath,
                                                       System.IO.FileMode.Open,
                                                       System.IO.FileAccess.Read,
                                                       System.IO.FileShare.ReadWrite);
            var _reader = new System.IO.StreamReader(_readstream, System.Text.Encoding.UTF8, true, 128);

            List <Pair <List <string>, List <string> > > _reactionList = new List <Pair <List <string>, List <string> > >();

            string _reactionStr = null;

            while ((_reactionStr = _reader.ReadLine()) != null)
            {
                _reactionList.Add(AnalyzeReaction(_reactionStr));
            }

            _reader.Dispose();
            _readstream.Dispose();

            return(_reactionList);
        }
예제 #26
0
        public void ReadRawData(String _map_file)
        {
            // 0     wall  --> 0
            // 1     agent --> 1
            // 2     item  --> 2
            // space empty --> 3

            rawdata = new List <List <Int32> >();
            System.IO.StreamReader file = new System.IO.StreamReader(inputfolder + _map_file);
            String line;

            while ((line = file.ReadLine()) != null)
            {
                List <Int32> currentLine = new List <Int32>();
                for (int i = 0; i < line.Length; i++)
                {
                    if (line[i] == '0')
                    {
                        currentLine.Add(0);
                    }
                    else if (line[i] == '1')
                    {
                        currentLine.Add(1);
                    }
                    else if (line[i] == '2')
                    {
                        currentLine.Add(2);
                    }
                    else if (line[i] == ' ')
                    {
                        currentLine.Add(3);
                    }
                }

                rawdata.Add(currentLine);
            }

            file.Dispose();
        }
예제 #27
0
        public void enviarCorreo(String correoDestino, String userToken, String mensaje)
        {
            try
            {
                var Emailtemplate = new System.IO.StreamReader(AppDomain.CurrentDomain.BaseDirectory.Insert(AppDomain.CurrentDomain.BaseDirectory.Length, "Plantilla\\mailer.html"));
                var strBody       = string.Format(Emailtemplate.ReadToEnd(), userToken);
                Emailtemplate.Close(); Emailtemplate.Dispose(); Emailtemplate = null;

                strBody = strBody.Replace("#TOKEN#", mensaje);
                //Configuración del Mensaje
                MailMessage mail       = new MailMessage();
                SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");
                //Especificamos el correo desde el que se enviará el Email y el nombre de la persona que lo envía
                mail.From = new MailAddress("*****@*****.**", "Pasando la Materia");

                //Aquí ponemos el asunto del correo
                mail.Subject = "Recuperación Contraseña";
                //Aquí ponemos el mensaje que incluirá el correo
                mail.Body = strBody;
                //Especificamos a quien enviaremos el Email, no es necesario que sea Gmail, puede ser cualquier otro proveedor
                mail.To.Add(correoDestino);
                //Si queremos enviar archivos adjuntos tenemos que especificar la ruta en donde se encuentran
                //mail.Attachments.Add(new Attachment(@"C:\Documentos\carta.docx"));
                mail.IsBodyHtml = true;

                mail.Priority = MailPriority.Normal;
                //Configuracion del SMTP
                SmtpServer.Port = 587; //Puerto que utiliza Gmail para sus servicios
                                       //Especificamos las credenciales con las que enviaremos el mail
                SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "654321tracto");
                SmtpServer.EnableSsl   = true;
                SmtpServer.Send(mail);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private bool GetResponseFromServer(String sURL, out String sResponse)
        {
            try
            {
                System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(sURL);

                System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();

                Trace.TraceInformation("Content type is {0} and length is {1}", response.ContentType, response.ContentLength);

                System.IO.Stream stream = response.GetResponseStream();

                // Pipes the stream to a higher level stream reader with the required encoding format.
                System.IO.StreamReader streamReader = new System.IO.StreamReader(stream, Encoding.UTF8);

                sResponse = streamReader.ReadToEnd();

                streamReader.Close();
                streamReader.Dispose();
                streamReader = null;

                stream.Close();
                stream.Dispose();
                stream = null;

                response.Close();
                response = null;
                request  = null;

                return(true);
            }
            catch (Exception ex)
            {
                Trace.TraceWarning("Exception: " + ex.Message + Environment.NewLine + "Stacktrace: " + ex.StackTrace);
                sResponse = String.Empty;
                return(false);
            }
        }
예제 #29
0
        /// 发送请求
        /// </summary>
        /// <param name="url">请求地址</param>
        /// <param name="sendData">参数格式 “name=王武&pass=123456”</param>
        /// <returns></returns>
        public static string RequestWebAPI(string url, string sendData)
        {
            url += ("?access_token=" + WxManager.Token);
            string backMsg = "";

            try
            {
                System.Net.WebRequest httpRquest = System.Net.HttpWebRequest.Create(url);
                httpRquest.Method = "POST";
                //这行代码很关键,不设置ContentType将导致后台参数获取不到值
                httpRquest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
                byte[] dataArray = System.Text.Encoding.UTF8.GetBytes(sendData);
                //httpRquest.ContentLength = dataArray.Length;
                System.IO.Stream requestStream = null;
                if (string.IsNullOrWhiteSpace(sendData) == false)
                {
                    requestStream = httpRquest.GetRequestStream();
                    requestStream.Write(dataArray, 0, dataArray.Length);
                    requestStream.Close();
                }
                System.Net.WebResponse response       = httpRquest.GetResponse();
                System.IO.Stream       responseStream = response.GetResponseStream();
                System.IO.StreamReader reader         = new System.IO.StreamReader(responseStream, System.Text.Encoding.UTF8);
                backMsg = reader.ReadToEnd();

                reader.Close();
                reader.Dispose();

                requestStream.Dispose();
                responseStream.Close();
                responseStream.Dispose();
            }
            catch (Exception)
            {
                throw;
            }
            return(backMsg);
        }
예제 #30
0
        public IActionResult Section2()
        {
            var    root    = AppDomain.CurrentDomain.BaseDirectory;
            int    counter = 0;
            string line;

            System.IO.StreamReader file = new System.IO.StreamReader(root + @"/Text.txt");
            var fileLines = new List <string>();

            while ((line = file.ReadLine()) != null || (counter != 12))
            {
                counter++;
                fileLines.Add(line);
            }
            string[] Bullet1 = fileLines[0].Split('.');
            string[] Bullet2 = fileLines[2].Split('.');
            // You can use model, temdata or viewbag to carry your data to view.
            ViewBag.Bullet  = Bullet1;
            ViewBag.Bullet2 = Bullet2;
            ViewBag.File    = fileLines;
            file.Dispose();
            return(View());
        }
예제 #31
0
        public StopsBasic(System.IO.StreamReader sr, StationsBasic stations, RoutesInfoBasic routes)
        {
            var count = int.Parse(sr.ReadLine());

            Items = new StopBasic[count];
            var tokens = sr.ReadLine().Split(';');             // This could take some time but files are usually small.

            for (int i = 0; i < count; i++)
            {
                var r = new List <RoutesInfoBasic.RouteInfoBasic>();
                foreach (var route in tokens[5 * i + 4].Split('`'))
                {
                    if (route != "")
                    {
                        r.Add(routes[int.Parse(route)]);
                    }
                }
                var stop = new StopBasic(int.Parse(tokens[5 * i]), stations[int.Parse(tokens[5 * i + 1])], double.Parse(tokens[5 * i + 2], System.Globalization.CultureInfo.InvariantCulture), double.Parse(tokens[5 * i + 3], System.Globalization.CultureInfo.InvariantCulture), r);
                Items[i] = stop;
                stations[int.Parse(tokens[5 * i + 1])].ChildStops.Add(stop);
            }
            sr.Dispose();
        }
예제 #32
0
        public string gGetServerName()
        {
            string strServerName = null;
            string strPath       = Environment.CurrentDirectory;
            string FILE_NAME     = strPath + @"\server.txt";

            if (System.IO.File.Exists(FILE_NAME) == true)
            {
                System.IO.StreamReader objReader = new System.IO.StreamReader(FILE_NAME);
                strServerName = (objReader.ReadLine());
                objReader.Close();
                objReader.Dispose();
            }
            else
            {
                //FileStream objFile = new FileStream(FILE_NAME, FileMode.Create, FileAccess.Write);
                //StreamWriter objWriter = new StreamWriter(objFile);
                //strServerName = Interaction.InputBox("Input a Valid Server Name", "Server Name");
                //objWriter.Write(strServerName);
                //objWriter.Close();
            }
            return(strServerName);
        }
예제 #33
0
        public static void Finally()
        {
            System.IO.StreamReader reader = null;
            try
            {
                reader = System.IO.File.OpenText(@"C:\Windows\System32\Drivers\etc\hosts");
                Console.WriteLine(reader.ReadToEnd());
            }
            finally
            {
                reader?.Dispose();
            }

            //TODO: complete catch clause

            /* try
             * {
             *  using (reader = System.IO.File.OpenText(@"C:\Windows\System32\Drivers\etc\hosts"))
             *  {
             *      Console.WriteLine(reader.ReadToEnd());
             *  }
             * }*/
        }
예제 #34
0
        /// <summary>
        /// get html of this url
        /// </summary>
        /// <param name="Url"> the url you want</param>
        /// <returns> html as string </returns>
        public static string GetHtml(string Url)
        {
            try
            {
                HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create(Url);
                wReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 2.0.50215; CrazyCoder.cn;www.aligong.com)";

                wReq.Referer = Url;

                HttpWebResponse  wResp      = wReq.GetResponse() as HttpWebResponse;
                System.IO.Stream respStream = wResp.GetResponseStream();

                System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.UTF8);
                string content = reader.ReadToEnd();

                reader.Close();
                reader.Dispose();
                return(content);
            }
            catch (Exception e) { }

            return("");
        }
예제 #35
0
        public Form1()
        {
            InitializeComponent();

            //Disable resizing
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.MaximizeBox     = false;
            this.MinimizeBox     = false;

            //Set so that the randomization can only be done if the backup has been carried out.
            System.IO.StreamReader file = new System.IO.StreamReader("backup/backup.state");

            working = false;

            string line = file.ReadLine();

            if (line == "backup")
            {
                backup = true;
            }
            else
            {
                backup = false;
                feedbackWindow.Text = "Perform a backup before randomizing, see toolbar above.";
            }

            //Close the file and delete it.
            file.Close();
            file.Dispose();

            //Initialize the other forms.
            _randConfig = new randConfig();
            _mapConfig  = new mapConfig();

            //Initialize the randomizer.
            _mainRandom = new MainRandom();
        }
        private void DisplayMTData_Load(object sender, EventArgs e)
        {
            string FName     = "./Graphics/MeridianTransitData.csv";
            string tablename = "Export2";
            var    SR        = new System.IO.StreamReader(FName);
            string allData   = SR.ReadToEnd();
            var    rows      = allData.Split(Conversions.ToChar(Constants.vbCrLf)); // ("\r".ToCharArray())
            int    incr1     = 0;

            foreach (string r in rows)
            {
                if (incr1 > 0)
                {
                    var items = r.Split(',');
                    if ((items[0] ?? "") != Constants.vbLf)
                    {
                        var DT = Convert.ToDateTime(items[2]);
                        items[0] = CnvtToDeg(items[0].ToString());
                        items[1] = CnvtToDeg(items[1].ToString());
                        items[3] = CnvtTime(items[3].ToString());
                        items[4] = CnvtEQT(items[4].ToString());
                        items[5] = CnvtDec(items[5].ToString());
                        // items(6) = CnvtHo(items(6).ToString)
                        DataSet2.Tables[tablename].Rows.Add(items);
                    }
                }

                incr1 += 1;
            }
            // DataGridView1.DataSource = DataSet2.Tables(0).DefaultView
            DataGridView1.Refresh();
            SR.Close();
            SR.Dispose();
            Refresh();
            // DisplayAnalema()
            return;
        }
예제 #37
0
 //Открыть из файла
 private void button1_Click(object sender, EventArgs e)
 {
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         shape.Clear();
         var    read = new System.IO.StreamReader(openFileDialog1.FileName);
         string text;
         int    n = Int32.Parse(read.ReadLine());
         shape = new List <face>();
         for (int i = 0; i < n; i++)
         {
             text = read.ReadLine();
             string[] coords = text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
             face     f      = new face();
             for (int j = 0; j < coords.Count(); j += 3)
             {
                 f.add(new my_point(double.Parse(coords[j]), double.Parse(coords[j + 1]), double.Parse(coords[j + 2])));
             }
             shape.Add(f);
         }
         read.Dispose();
         redraw_image();
     }
 }
예제 #38
0
 public virtual string Serialize()
 {
     System.IO.StreamReader streamReader = null;
     System.IO.MemoryStream memoryStream = null;
     try
     {
         memoryStream = new System.IO.MemoryStream();
         Serializer.Serialize(memoryStream, this);
         memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
         streamReader = new System.IO.StreamReader(memoryStream);
         return(streamReader.ReadToEnd());
     }
     finally
     {
         if ((streamReader != null))
         {
             streamReader.Dispose();
         }
         if ((memoryStream != null))
         {
             memoryStream.Dispose();
         }
     }
 }
예제 #39
0
        //向服务器存储数据,返回提示信息
        public static string Save(string user, string data)
        {
            string sendData = "user="******"&" + "data=" + data;           //发送的数据
            string url      = "http://192.168.199.118:8080/save/?" + sendData; //请求路径
            //string url = "http://192.168.199.107:8080/save/?" + sendData;//请求路径
            string backMsg = "";                                               //接收服务端返回数据

            try
            {
                System.Net.WebRequest httpRquest = System.Net.HttpWebRequest.Create(url);
                httpRquest.Method = "GET";

                /*byte[] dataArray = System.Text.Encoding.UTF8.GetBytes(sendData);
                 * System.IO.Stream requestStream = null;
                 * if (string.IsNullOrWhiteSpace(sendData) == false)
                 * {
                 *  requestStream = httpRquest.GetRequestStream();
                 *  requestStream.Write(dataArray, 0, dataArray.Length);
                 *  requestStream.Close();
                 * }*/
                System.Net.WebResponse response       = httpRquest.GetResponse();
                System.IO.Stream       responseStream = response.GetResponseStream();
                System.IO.StreamReader reader         = new System.IO.StreamReader(responseStream, System.Text.Encoding.UTF8);
                backMsg = reader.ReadToEnd();
                reader.Close();
                reader.Dispose();
                //requestStream.Dispose();
                responseStream.Close();
                responseStream.Dispose();
            }
            catch (Exception e1)
            {
                Console.WriteLine(e1.ToString());
            }
            return(backMsg);
        }
예제 #40
0
        /// <summary>
        /// Read the EDL data from the EDL File into the EDLBox
        /// </summary>
        /// <param name="edlFile">EdlFile to read from</param>
        /// <returns>True if successful</returns>
        private bool ReadEDL(string edlFile)
        {
            _edlLoading = true; // We are loading a EDL file, no need to mark as unsaved

            try
            {
                System.IO.StreamReader edlS = new System.IO.StreamReader(edlFile);
                string line;
                while ((line = edlS.ReadLine()) != null)
                {
                    string[] cuts = Regex.Split(line, @"\s+");
                    if (cuts.Length == 3)
                    {
                        if (cuts[0] != cuts[1])
                        {
                            float cutStart, cutEnd;
                            if ((float.TryParse(cuts[0], NumberStyles.Float, CultureInfo.InvariantCulture, out cutStart)) && (float.TryParse(cuts[1], NumberStyles.Float, CultureInfo.InvariantCulture, out cutEnd)))
                            {
                                AddEDLStartStopEntry(cutStart * 1000, cutEnd * 1000);
                            }
                        }
                    }
                }
                edlS.Close();
                edlS.Dispose();
                _edlLoading = false; // We are done here

                return(true);
            }
            catch (Exception e)
            {
                MessageBox.Show(Localise.GetPhrase("Error loading commercial cuts EDL file") + "\r\n" + edlFile + "\r\n" + "Error : " + e.ToString(), Localise.GetPhrase("Load Error"), MessageBoxButton.OK, MessageBoxImage.Error);
                _edlLoading = false; // We are done here
                return(false);
            }
        }
        public DReport_CapturedCard ViewDetailTxn(string tungay, string denngay)
        {
            string strSQL,ConnectStr1;
            DReport_CapturedCard DS = new DReport_CapturedCard();
            strSQL ="select a.card_acceptor_term_id as Terminal_ID,a.card_acc_name_address as Terminal_Location, "+
                    "a.card_number,to_char(a.transaction_local_date,'dd/mm/yyyy') as tXN_Date,  "+
                    "to_char(a.transaction_local_date,'HH24:MI:SS') as Txn_Time,a.code_action as Response_code,ac.description, " +
                    "a.date_create "+
                    "from  "+ FrmMain.owner +"autho_activity a,  "+ FrmMain.owner +"action_code ac "+
                    "where substr(a.card_number,1,6) in ('483542','461930','970410')    "+
                    "and a.date_create >= to_date('" + tungay + "','yyyy-mm-dd HH24:MI:SS')  " +
                    "and a.date_create <= to_date('" + denngay + "','yyyy-mm-dd HH24:MI:SS')  " +
                    "and a.code_action='106'    "+
                    "and a.code_action=ac.action_code "+
                    "order by a.transaction_local_date desc";

            try
            {
                System.IO.StreamReader str = new System.IO.StreamReader(Application.StartupPath + "\\ConnectStr.txt");
                ConnectStr1 = str.ReadLine();
                str.Close();
                str.Dispose();
                ConnectStr1 = ConnectStr1.Substring(0, 44) + FrmMain.pass + ConnectStr1.Substring(44, 74);
                oleDbConnection1 = new OleDbConnection(ConnectStr1);
                oleDbDataAdapter1 = new OleDbDataAdapter(strSQL, oleDbConnection1);
                oleDbDataAdapter1.Fill(DS.Tables["Captured_Card"]);

                oleDbConnection1.Close();
                return DS;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return DS;
        }
예제 #42
0
        // STATUS [ June 23, 2019 ]: this works
        /// <summary>
        ///     Reads most recent since tweet id from text file within Configuration folder
        /// </summary>
        /// <remarks>
        ///     This connects to 'twitterSinceId.txt' file
        ///     See: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/file-system/how-to-read-a-text-file-one-line-at-a-time
        /// </remarks>
        /// <example>
        ///     var currentSinceId = ReadCurrentSinceIdFromTxtFile()
        /// </example>
        public long ReadCurrentSinceIdFromTxtFile()
        {
            long   sinceId       = 0;
            string sinceIdString = "";
            int    counter       = 0;
            string line;

            // Read the file and display it line by line.
            System.IO.StreamReader file =
                new System.IO.StreamReader(@"Configuration/twittersinceId.txt");

            while ((line = file.ReadLine()) != null)
            {
                sinceIdString = line;
                {
                    sinceId = long.Parse(sinceIdString, CultureInfo.InvariantCulture);
                }
                counter++;
            }
            Console.WriteLine($"final sinceId: {sinceId}");
            file.Close();
            file.Dispose();
            return(sinceId);
        }
예제 #43
0
        /// <summary>
        /// 读取文件文本信息
        /// </summary>
        /// <param name="FileName">文件名</param>
        /// <returns></returns>
        public static string ReadTextFile(string FileName)
        {
            if (!DxPublic.GetFileExists(FileName))
            {
                throw new System.Exception("文件不存在!!");
            }
            System.IO.StreamReader streamReader = null;
            string result;

            try
            {
                streamReader = new System.IO.StreamReader(FileName, System.Text.Encoding.UTF8);
                result       = streamReader.ReadToEnd();
            }
            finally
            {
                if (streamReader != null)
                {
                    streamReader.Close();
                    streamReader.Dispose();
                }
            }
            return(result);
        }
예제 #44
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            string itemName = "";
            //获取上一页面传递过来的item值
            bool isItemExists = NavigationContext.QueryString.TryGetValue("item", out itemName);

            if (isItemExists)
            {
                pageTitle.Text = itemName;
            }

            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                XElement xml;//定义Linq的XML元素
                //打开本地存储文件
                IsolatedStorageFileStream location = new IsolatedStorageFileStream(itemName, System.IO.FileMode.Open, storage);
                //转化为可读流
                System.IO.StreamReader sr = new System.IO.StreamReader(location);
                //解析流转化为XML
                xml = XElement.Parse(sr.ReadToEnd());

                if (xml.Name.LocalName != null)
                {
                    tbkName.Text = itemName;
                    XAttribute price = xml.Attribute("price");       //获取价格
                    tbkPrice.Text = price.Value.ToLower();
                    XAttribute quantity = xml.Attribute("quantity"); //获取数量
                    tbkQuantity.Text = quantity.Value.ToLower();
                }

                sr.Dispose();
                location.Dispose();
            }
        }
예제 #45
0
        public static SqlConnection StringSQL()
        {
            string CreateFolder = @"Database";

            if (!System.IO.Directory.Exists(CreateFolder))
            {
                System.IO.Directory.CreateDirectory(CreateFolder);
            }


            string CreateFileText = @"Database\String.txt";

            if (!System.IO.File.Exists(CreateFileText))
            {
                System.IO.FileStream cr = new System.IO.FileStream(CreateFileText, System.IO.FileMode.Create);
                cr.Close();
                cr.Dispose();
            }

            System.IO.StreamReader docFile = new System.IO.StreamReader("DataBase\\String.txt");
            string ketnoi = "";

            try
            {
                string con = docFile.ReadLine();
                ketnoi = Encode.Base64ToString(con);
            }
            catch
            {
            }
            docFile.Close();
            docFile.Dispose();
            SqlConnection cnn = new SqlConnection("Data Source=" + ketnoi);

            return(cnn);
        }
예제 #46
0
파일: Program.cs 프로젝트: ufjl0683/Center
        public static void section_data_1min_task()
        {
            WriteLine("section_data_1min_task started!");

            while (true)
            {
                try
                {
                    System.Net.WebRequest req = System.Net.HttpWebRequest.Create(QYTask.Settings1.Default.TIMCC_uri);

                    System.IO.Stream stream = req.GetResponse().GetResponseStream();
                    System.IO.TextReader rd = new System.IO.StreamReader(stream);
                    System.IO.TextWriter wr = new System.IO.StreamWriter(Util.CPath(AppDomain.CurrentDomain.BaseDirectory + "tmp.xml"));
                    wr.Write(rd.ReadToEnd());
                    wr.Flush();
                    wr.Close();
                    rd.Close();
                    stream.Close();
                    wr.Dispose();
                    rd.Dispose();
                    stream.Dispose();

                    Ds ds = five_min_section_parser(Util.CPath(AppDomain.CurrentDomain.BaseDirectory + "tmp.xml"));
                    // Curr5minSecDs.Dispose();
                    Curr5minSecDs = ds;

                    string dest;
                    if ((dest = getSaveDirFileName(ds.tblFileAttr[0].time)) != "")   // new 5 min data
                    {
                        WriteLine("section_data_1min_task: new section data->" + ds.tblFileAttr[0][0].ToString());

                        System.IO.File.Copy(Util.CPath(AppDomain.CurrentDomain.BaseDirectory + "tmp.xml"), dest);
                        if (OnNewTravelData != null)
                        {
                            // QYTask.Ds ds1 = new QYTask.Ds();
                            calcuate_travel_time();
                            ////ds1.Merge(RGSConfDs.tblRGSMain);
                            ////ds1.Merge(RGSConfDs.tblRGS_Config);
                            OnNewTravelData(RGSConfDs);
                            try
                            {
                                NotifyDisplayTask();
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("section_data_1min_task:" + ex.Message);
                            }
                        }

                    }

                }
                catch (Exception ex)
                {
                    WriteLine("section_data_1min_task:" + ex.Message + ex.StackTrace);

                    try
                    {
                        if (Curr5minSecDs == null || System.Math.Abs(((TimeSpan)(System.DateTime.Now - Curr5minSecDs.tblFileAttr[0].time)).Minutes) >= 20)
                        {
                            lock (RGSConfDs.tblRGS_Config)
                            {
                                foreach (QYTask.Ds.tblRGS_ConfigRow r in RGSConfDs.tblRGS_Config.Rows)
                                {
                                    r.RowError = "Timcc 連線資料異常!";
                                    r.mode = 1; //手動
                                    Console.WriteLine("寫入 RowErr");

                                }
                                if (OnNewTravelData != null)
                                {

                                    try
                                    {
                                        DataSet ds1 = new DataSet();

                                        ds1.Tables.Add(Util.getPureDataTable(RGSConfDs.tblRGS_Config));
                                        OnNewTravelData(ds1);
                                        NotifyDisplayTask();
                                    }
                                    catch (Exception ex1)
                                    {
                                        Console.WriteLine("section_data_1min_task:" + ex1.StackTrace);
                                    }
                                }
                            }
                            System.Console.WriteLine("Timcc 連線異常!");
                        }
                    }
                    catch (Exception ex1)
                    {
                        Console.WriteLine(ex1.Message);
                    }

                }

                Util.GC();

                System.Threading.Thread.Sleep(60 * 1000);
            }
        }
예제 #47
0
파일: Program.cs 프로젝트: ufjl0683/Center
        private static void load_RMS_table()
        {
            int rowcnt = 0;
            System.IO.TextReader tr = new System.IO.StreamReader(Util.CPath(AppDomain.CurrentDomain.BaseDirectory+"rms_config.csv"), System.Text.Encoding.GetEncoding("big5"));
            QYTask.Ds.tblRmsConfigRow rr;
            string s = "";

            string[] fields;
            s = tr.ReadLine();

            fields = s.Split(new char[] { ',' });

            for (int i = 0; i < fields.Length; i++)
                fields[i] = fields[i].Trim();

            while ((s = tr.ReadLine()) != null)
            {

                string[] tmp = s.Split(new char[] { ',' });

                QYTask.Ds.tblRmsConfigRow r = RMSConfDs.tblRmsConfig.NewtblRmsConfigRow(); // RGSConfDs.tblRGS_Config.NewRow();

                for (int i = 0; i < tmp.Length; i++)
                {
                    r[i] = System.Convert.ChangeType(tmp[i], RMSConfDs.tblRmsConfig.Columns[i].DataType);
                }
                r.ctl_mode_setting = r.ctl_mode_setting = 2; //default mode;

                r.ctl_mode = 2;
                r.planno_setting = r.planno = 0;

                RMSConfDs.tblRmsConfig.AddtblRmsConfigRow((Ds.tblRmsConfigRow)r);
                rowcnt++;
                //----------------------------just for test
                //if (rowcnt == 1)
                //    break;

            }

            RMSConfDs.AcceptChanges();

            tr.Close();
            tr.Dispose();
            Console.WriteLine("RMS_Table loaded!");
        }
        private void buttonImportaFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();

            op.Title = "Select a file";

            op.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";

            /*
             * op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
             * "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
             * "Portable Network Graphic (*.png)|*.png" +
             * "TXT files|*.txt";*/

            if (op.ShowDialog() == DialogResult.OK)
            {
                string strFileName = op.FileName;
                if ((strFileName.Contains(".jpg")) ||
                    (strFileName.Contains(".jpeg")) ||
                    (strFileName.Contains(".png")))
                {
                    try
                    {
                        System.IO.Stream       fileStream = System.IO.File.Open(strFileName, System.IO.FileMode.Open);
                        System.IO.StreamReader reader     = new System.IO.StreamReader(fileStream);

                        string strBuffer = "";
                        string line      = null;
                        do
                        {
                            // get the next line from the file
                            line = reader.ReadLine();
                            if (line == null)
                            {
                                // there are no more lines; break out of the loop
                                break;
                            }

                            // split the line on each semicolon character
                            string[] parts = line.Split(';');
                            // now the array contains values as such:
                            // "Name" in parts[0]
                            // "Surname" in parts[1]
                            // "Birthday" in parts[2]
                            // "Address" in parts[3]
                            strBuffer += line;
                        } while (true);

                        textBoxMessage.AppendText(strBuffer);

                        reader.Dispose();
                        reader.Close();
                        fileStream.Dispose();
                        fileStream.Close();


                        pictureBoxPreview.Image    = new Bitmap(strFileName);;//Controls.Add(imageControl);
                        pictureBoxPreview.SizeMode = PictureBoxSizeMode.StretchImage;
                        int iWidth = 334 + pictureBoxPreview.Size.Width + 30;

                        this.Size          = new Size(iWidth, 470);
                        this.StartPosition = FormStartPosition.CenterScreen;
                    }
                    catch (ArgumentException ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    catch (UnauthorizedAccessException ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }


                    //textBoxMessage.Text = Convert.ToString(imgBytes);
                }
                else
                {
                    System.IO.Stream       fileStream = System.IO.File.Open(strFileName, System.IO.FileMode.Open);
                    System.IO.StreamReader reader     = new System.IO.StreamReader(fileStream);

                    string strBuffer = "";
                    string line      = null;
                    do
                    {
                        // get the next line from the file
                        line = reader.ReadLine();
                        if (line == null)
                        {
                            // there are no more lines; break out of the loop
                            break;
                        }

                        // split the line on each semicolon character
                        string[] parts = line.Split(';');
                        // now the array contains values as such:
                        // "Name" in parts[0]
                        // "Surname" in parts[1]
                        // "Birthday" in parts[2]
                        // "Address" in parts[3]
                        strBuffer += line;
                    } while (true);

                    this.Size            = new Size(334, 470);
                    this.FormBorderStyle = FormBorderStyle.FixedDialog;
                    textBoxMessage.Text  = strBuffer;// fileStream.ToString();
                }
            }
        }
예제 #49
0
파일: Form1.cs 프로젝트: Nonimus/CoVis
        private void BGTeinlesen_Click(object sender, EventArgs e)
        {
            //Löschen eventueller GT Daten
            for (int i = 0; i < pictureData.Length; i++)
            {
                pictureData[i].Gtdaten = null;
            }

            //Finden der Datei
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Textdateien (*.txt)|*.txt";

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string line = null;
                try
                {
                    System.IO.StreamReader file = new System.IO.StreamReader(@ofd.FileName);
                    while ((line = file.ReadLine()) != null && line != "")
                    {
                        //Auftrennen in die Bestandteile Bildname;xs;xe;ys;ye;id
                        string[] args = line.Split(';');
                        if (args.Length == 6 && args[0] != "img") //Fehler abfangen;überspringen der ersten Zeile
                        {
                            //Berechnen der Position aus dem Namen der Datei
                            string[] splitter = args[0].Split('.');
                            int      counterP = Convert.ToInt32(splitter[0]);
                            //Falls Berechnung fehl schlägt suche linear nach dem index mit dem Dateinamen
                            if (counterP >= pictureData.Length || args[0] != pictureData[counterP].picName)
                            {
                                counterP = 0;
                                while (counterP < pictureData.Length && args[0] != pictureData[counterP].picName)
                                {
                                    counterP++;
                                }
                            }
                            //Überprüfung ob gültiger Index gefunden wurde oder ob einÜberlauf statt fand
                            if (counterP < pictureData.Length && args[0] == pictureData[counterP].picName)
                            {
                                //Keine GT bereits vorhanden -erstelle Array
                                if (pictureData[counterP].Gtdaten == null || pictureData[counterP].Gtdaten[0].x_start == 0)
                                {
                                    pictureData[counterP].Gtdaten = new GT[1];
                                    pictureData[counterP].Gtdaten[0].SetVars(Convert.ToInt32(args[1]), Convert.ToInt32(args[2]), Convert.ToInt32(args[3]), Convert.ToInt32(args[4]), Convert.ToInt32(args[5]));
                                }
                                else// GT vorhanden, also kopieren und neues hinzufügen
                                {
                                    GT[] zwischen = pictureData[counterP].Gtdaten;
                                    pictureData[counterP].Gtdaten = new GT[zwischen.Length + 1];
                                    //kopieren
                                    int i;
                                    for (i = 0; i < zwischen.Length; i++)
                                    {
                                        pictureData[counterP].Gtdaten[i] = zwischen[i];
                                    }
                                    //Neues hinzufügen
                                    if (args.Length >= 6)
                                    {
                                        pictureData[counterP].Gtdaten[i].SetVars(Convert.ToInt32(args[1]), Convert.ToInt32(args[2]), Convert.ToInt32(args[3]), Convert.ToInt32(args[4]), Convert.ToInt32(args[5]));
                                    }
                                    else
                                    {
                                        Console.WriteLine("Fehler im Lesen... Zu wenig Argumente");
                                    }
                                }
                            }
                        }
                    }
                    file.Close();
                    file.Dispose();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Fehler:Lesen von GT");
                }
            }
        }
예제 #50
0
        public bool LoadSettingsFile()
        {
            if (System.IO.File.Exists(settingsFile))
            {
                try
                {
                    System.IO.StreamReader fileReader = new System.IO.StreamReader(settingsFile, false);

                    bool writeSettingsAfter = true;

                    lblStatus.Text = "Reading settings file.";
                    int lineNumber = 0;
                    //Reading Data
                    while (fileReader.Peek() != -1)
                    {
                        string fileRow = fileReader.ReadLine();
                        string[] fileDataField = fileRow.Split('=');

                        if (fileDataField.Length > 0)
                        {
                            if (fileDataField[0] == "tradingStrategyExecutable")
                            {
                                if (fileDataField[1].Substring(fileDataField[1].Length - 3, 3) == "jar")
                                {
                                    executableURL = fileDataField[1];
                                }
                            }
                            else if (fileDataField[0] == "argumentsFile")
                            {
                                if (fileDataField[1].Substring(fileDataField[1].Length - 3, 3) == "txt")
                                {
                                    executableArguments = fileDataField[1];
                                }
                            }
                            else if (fileDataField[0] == "evaluatorExecutable")
                            {
                                if (fileDataField[1].Substring(fileDataField[1].Length - 3, 3) == "jar")
                                {
                                    evaluatorURL = fileDataField[1];
                                }
                            }
                            else if (fileDataField[0] == "inputCSVFile")
                            {
                                inputFileURL = fileDataField[1];
                                inputFileName = inputFileURL.Split('/')[inputFileURL.Split('/').Length - 1];
                            }
                            else if (fileDataField[0] == "threshold")
                            {
                                threshold = fileDataField[1];
                                txtVal_Threshold.Text = threshold;
                            }
                            else if (fileDataField[0] == "window")
                            {
                                window = fileDataField[1];
                                txtVal_Window.Text = window;
                            }
                            else if (fileDataField[0] == "importOnStart")
                            {
                                importOnStart = fileDataField[1] == "True";
                                chkAutoImport.Checked = importOnStart;
                            }
                            else if (fileDataField[0] == "version")
                            {
                                if (Convert.ToDouble(version) > Convert.ToDouble(fileDataField[1]))
                                {
                                    version = fileDataField[1];
                                    writeSettingsAfter = true;
                                }
                                else
                                {
                                    writeSettingsAfter = false;
                                }
                            }
                        }
                        lineNumber++;
                    }
                    fileReader.Dispose();
                    fileReader.Close();

                    evaluatorURL = System.IO.Directory.GetCurrentDirectory() + "\\Evaluator.jar";

                    if (writeSettingsAfter)
                    {
                        WriteSettingsFile();
                    }
                }
                catch (Exception ex)
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
            return true;
        }
예제 #51
0
        public static RDungeon LoadRDungeon(int dungeonNum)
        {
            RDungeon dungeon  = new RDungeon(dungeonNum);
            string   FilePath = IO.Paths.RDungeonsFolder + "rdungeon" + dungeonNum.ToString() + ".dat";

            using (System.IO.StreamReader reader = new System.IO.StreamReader(FilePath))
            {
                while (!(reader.EndOfStream))
                {
                    string[] parse = reader.ReadLine().Split('|');
                    switch (parse[0].ToLower())
                    {
                    case "rdungeondata":
                        if (parse[1].ToLower() != "v3")
                        {
                            reader.Close();
                            reader.Dispose();
                            return(null);
                        }
                        break;

                    case "data":
                        dungeon.DungeonName = parse[1];
                        dungeon.Direction   = (Enums.Direction)parse[2].ToInt();
                        dungeon.MaxFloors   = parse[3].ToInt();
                        dungeon.Recruitment = parse[4].ToBool();
                        dungeon.Exp         = parse[5].ToBool();
                        dungeon.WindTimer   = parse[6].ToInt();
                        break;

                    case "floor":
                    {
                        RDungeonFloor floor = new RDungeonFloor();
                        floor.Options.TrapMin         = parse[1].ToInt();
                        floor.Options.TrapMax         = parse[2].ToInt();
                        floor.Options.ItemMin         = parse[3].ToInt();
                        floor.Options.ItemMax         = parse[4].ToInt();
                        floor.Options.RoomWidthMin    = parse[5].ToInt();
                        floor.Options.RoomWidthMax    = parse[6].ToInt();
                        floor.Options.RoomLengthMin   = parse[7].ToInt();
                        floor.Options.RoomLengthMax   = parse[8].ToInt();
                        floor.Options.HallTurnMin     = parse[9].ToInt();
                        floor.Options.HallTurnMax     = parse[10].ToInt();
                        floor.Options.HallVarMin      = parse[11].ToInt();
                        floor.Options.HallVarMax      = parse[12].ToInt();
                        floor.Options.WaterFrequency  = parse[13].ToInt();
                        floor.Options.Craters         = parse[14].ToInt();
                        floor.Options.CraterMinLength = parse[15].ToInt();
                        floor.Options.CraterMaxLength = parse[16].ToInt();
                        floor.Options.CraterFuzzy     = parse[17].ToBool();

                        floor.Darkness = parse[18].ToInt();
                        floor.GoalType = (Enums.RFloorGoalType)parse[19].ToInt();
                        floor.GoalMap  = parse[20].ToInt();
                        floor.GoalX    = parse[21].ToInt();
                        floor.GoalY    = parse[22].ToInt();
                        floor.Music    = parse[23];

                        #region terrain

                        #region wall
                        floor.StairsX     = parse[24].ToInt();
                        floor.StairsSheet = parse[25].ToInt();

                        floor.mGroundX     = parse[26].ToInt();
                        floor.mGroundSheet = parse[27].ToInt();

                        floor.mTopLeftX       = parse[28].ToInt();
                        floor.mTopLeftSheet   = parse[29].ToInt();
                        floor.mTopCenterX     = parse[30].ToInt();
                        floor.mTopCenterSheet = parse[31].ToInt();
                        floor.mTopRightX      = parse[32].ToInt();
                        floor.mTopRightSheet  = parse[33].ToInt();

                        floor.mCenterLeftX       = parse[34].ToInt();
                        floor.mCenterLeftSheet   = parse[35].ToInt();
                        floor.mCenterCenterX     = parse[36].ToInt();
                        floor.mCenterCenterSheet = parse[37].ToInt();
                        floor.mCenterRightX      = parse[38].ToInt();
                        floor.mCenterRightSheet  = parse[39].ToInt();

                        floor.mBottomLeftX       = parse[40].ToInt();
                        floor.mBottomLeftSheet   = parse[41].ToInt();
                        floor.mBottomCenterX     = parse[42].ToInt();
                        floor.mBottomCenterSheet = parse[43].ToInt();
                        floor.mBottomRightX      = parse[44].ToInt();
                        floor.mBottomRightSheet  = parse[45].ToInt();

                        floor.mInnerTopLeftX        = parse[46].ToInt();
                        floor.mInnerTopLeftSheet    = parse[47].ToInt();
                        floor.mInnerBottomLeftX     = parse[48].ToInt();
                        floor.mInnerBottomLeftSheet = parse[49].ToInt();

                        floor.mInnerTopRightX        = parse[50].ToInt();
                        floor.mInnerTopRightSheet    = parse[51].ToInt();
                        floor.mInnerBottomRightX     = parse[52].ToInt();
                        floor.mInnerBottomRightSheet = parse[53].ToInt();

                        floor.mColumnTopX        = parse[54].ToInt();
                        floor.mColumnTopSheet    = parse[55].ToInt();
                        floor.mColumnCenterX     = parse[56].ToInt();
                        floor.mColumnCenterSheet = parse[57].ToInt();
                        floor.mColumnBottomX     = parse[58].ToInt();
                        floor.mColumnBottomSheet = parse[59].ToInt();

                        floor.mRowLeftX       = parse[60].ToInt();
                        floor.mRowLeftSheet   = parse[61].ToInt();
                        floor.mRowCenterX     = parse[62].ToInt();
                        floor.mRowCenterSheet = parse[63].ToInt();
                        floor.mRowRightX      = parse[64].ToInt();
                        floor.mRowRightSheet  = parse[65].ToInt();

                        floor.mIsolatedWallX     = parse[66].ToInt();
                        floor.mIsolatedWallSheet = parse[67].ToInt();

                        floor.mGroundAltX      = parse[68].ToInt();
                        floor.mGroundAltSheet  = parse[69].ToInt();
                        floor.mGroundAlt2X     = parse[70].ToInt();
                        floor.mGroundAlt2Sheet = parse[71].ToInt();

                        floor.mTopLeftAltX       = parse[72].ToInt();
                        floor.mTopLeftAltSheet   = parse[73].ToInt();
                        floor.mTopCenterAltX     = parse[74].ToInt();
                        floor.mTopCenterAltSheet = parse[75].ToInt();
                        floor.mTopRightAltX      = parse[76].ToInt();
                        floor.mTopRightAltSheet  = parse[77].ToInt();

                        floor.mCenterLeftAltX        = parse[78].ToInt();
                        floor.mCenterLeftAltSheet    = parse[79].ToInt();
                        floor.mCenterCenterAltX      = parse[80].ToInt();
                        floor.mCenterCenterAltSheet  = parse[81].ToInt();
                        floor.mCenterCenterAlt2X     = parse[82].ToInt();
                        floor.mCenterCenterAlt2Sheet = parse[83].ToInt();
                        floor.mCenterRightAltX       = parse[84].ToInt();
                        floor.mCenterRightAltSheet   = parse[85].ToInt();

                        floor.mBottomLeftAltX       = parse[86].ToInt();
                        floor.mBottomLeftAltSheet   = parse[87].ToInt();
                        floor.mBottomCenterAltX     = parse[88].ToInt();
                        floor.mBottomCenterAltSheet = parse[89].ToInt();
                        floor.mBottomRightAltX      = parse[90].ToInt();
                        floor.mBottomRightAltSheet  = parse[91].ToInt();

                        floor.mInnerTopLeftAltX        = parse[92].ToInt();
                        floor.mInnerTopLeftAltSheet    = parse[93].ToInt();
                        floor.mInnerBottomLeftAltX     = parse[94].ToInt();
                        floor.mInnerBottomLeftAltSheet = parse[95].ToInt();

                        floor.mInnerTopRightAltX        = parse[96].ToInt();
                        floor.mInnerTopRightAltSheet    = parse[97].ToInt();
                        floor.mInnerBottomRightAltX     = parse[98].ToInt();
                        floor.mInnerBottomRightAltSheet = parse[99].ToInt();

                        floor.mColumnTopAltX        = parse[100].ToInt();
                        floor.mColumnTopAltSheet    = parse[101].ToInt();
                        floor.mColumnCenterAltX     = parse[102].ToInt();
                        floor.mColumnCenterAltSheet = parse[103].ToInt();
                        floor.mColumnBottomAltX     = parse[104].ToInt();
                        floor.mColumnBottomAltSheet = parse[105].ToInt();

                        floor.mRowLeftAltX       = parse[106].ToInt();
                        floor.mRowLeftAltSheet   = parse[107].ToInt();
                        floor.mRowCenterAltX     = parse[108].ToInt();
                        floor.mRowCenterAltSheet = parse[109].ToInt();
                        floor.mRowRightAltX      = parse[110].ToInt();
                        floor.mRowRightAltSheet  = parse[111].ToInt();

                        floor.mIsolatedWallAltX     = parse[112].ToInt();
                        floor.mIsolatedWallAltSheet = parse[113].ToInt();

                        #endregion

                        #region water

                        floor.mWaterX         = parse[114].ToInt();
                        floor.mWaterSheet     = parse[115].ToInt();
                        floor.mWaterAnimX     = parse[116].ToInt();
                        floor.mWaterAnimSheet = parse[117].ToInt();

                        floor.mShoreTopLeftX             = parse[118].ToInt();
                        floor.mShoreTopLeftSheet         = parse[119].ToInt();
                        floor.mShoreTopRightX            = parse[120].ToInt();
                        floor.mShoreTopRightSheet        = parse[121].ToInt();
                        floor.mShoreBottomRightX         = parse[122].ToInt();
                        floor.mShoreBottomRightSheet     = parse[123].ToInt();
                        floor.mShoreBottomLeftX          = parse[124].ToInt();
                        floor.mShoreBottomLeftSheet      = parse[125].ToInt();
                        floor.mShoreDiagonalForwardX     = parse[126].ToInt();
                        floor.mShoreDiagonalForwardSheet = parse[127].ToInt();
                        floor.mShoreDiagonalBackX        = parse[128].ToInt();
                        floor.mShoreDiagonalBackSheet    = parse[129].ToInt();

                        floor.mShoreTopX            = parse[130].ToInt();
                        floor.mShoreTopSheet        = parse[131].ToInt();
                        floor.mShoreRightX          = parse[132].ToInt();
                        floor.mShoreRightSheet      = parse[133].ToInt();
                        floor.mShoreBottomX         = parse[134].ToInt();
                        floor.mShoreBottomSheet     = parse[135].ToInt();
                        floor.mShoreLeftX           = parse[136].ToInt();
                        floor.mShoreLeftSheet       = parse[137].ToInt();
                        floor.mShoreVerticalX       = parse[138].ToInt();
                        floor.mShoreVerticalSheet   = parse[139].ToInt();
                        floor.mShoreHorizontalX     = parse[140].ToInt();
                        floor.mShoreHorizontalSheet = parse[141].ToInt();

                        floor.mShoreInnerTopLeftX         = parse[142].ToInt();
                        floor.mShoreInnerTopLeftSheet     = parse[143].ToInt();
                        floor.mShoreInnerTopRightX        = parse[144].ToInt();
                        floor.mShoreInnerTopRightSheet    = parse[145].ToInt();
                        floor.mShoreInnerBottomRightX     = parse[146].ToInt();
                        floor.mShoreInnerBottomRightSheet = parse[147].ToInt();
                        floor.mShoreInnerBottomLeftX      = parse[148].ToInt();
                        floor.mShoreInnerBottomLeftSheet  = parse[149].ToInt();

                        floor.mShoreInnerTopX        = parse[150].ToInt();
                        floor.mShoreInnerTopSheet    = parse[151].ToInt();
                        floor.mShoreInnerRightX      = parse[152].ToInt();
                        floor.mShoreInnerRightSheet  = parse[153].ToInt();
                        floor.mShoreInnerBottomX     = parse[154].ToInt();
                        floor.mShoreInnerBottomSheet = parse[155].ToInt();
                        floor.mShoreInnerLeftX       = parse[156].ToInt();
                        floor.mShoreInnerLeftSheet   = parse[157].ToInt();

                        floor.mShoreSurroundedX     = parse[158].ToInt();
                        floor.mShoreSurroundedSheet = parse[159].ToInt();

                        floor.mShoreTopLeftAnimX             = parse[160].ToInt();
                        floor.mShoreTopLeftAnimSheet         = parse[161].ToInt();
                        floor.mShoreTopRightAnimX            = parse[162].ToInt();
                        floor.mShoreTopRightAnimSheet        = parse[163].ToInt();
                        floor.mShoreBottomRightAnimX         = parse[164].ToInt();
                        floor.mShoreBottomRightAnimSheet     = parse[165].ToInt();
                        floor.mShoreBottomLeftAnimX          = parse[166].ToInt();
                        floor.mShoreBottomLeftAnimSheet      = parse[167].ToInt();
                        floor.mShoreDiagonalForwardAnimX     = parse[168].ToInt();
                        floor.mShoreDiagonalForwardAnimSheet = parse[169].ToInt();
                        floor.mShoreDiagonalBackAnimX        = parse[170].ToInt();
                        floor.mShoreDiagonalBackAnimSheet    = parse[171].ToInt();

                        floor.mShoreTopAnimX            = parse[172].ToInt();
                        floor.mShoreTopAnimSheet        = parse[173].ToInt();
                        floor.mShoreRightAnimX          = parse[174].ToInt();
                        floor.mShoreRightAnimSheet      = parse[175].ToInt();
                        floor.mShoreBottomAnimX         = parse[176].ToInt();
                        floor.mShoreBottomAnimSheet     = parse[177].ToInt();
                        floor.mShoreLeftAnimX           = parse[178].ToInt();
                        floor.mShoreLeftAnimSheet       = parse[179].ToInt();
                        floor.mShoreVerticalAnimX       = parse[180].ToInt();
                        floor.mShoreVerticalAnimSheet   = parse[181].ToInt();
                        floor.mShoreHorizontalAnimX     = parse[182].ToInt();
                        floor.mShoreHorizontalAnimSheet = parse[183].ToInt();

                        floor.mShoreInnerTopLeftAnimX         = parse[184].ToInt();
                        floor.mShoreInnerTopLeftAnimSheet     = parse[185].ToInt();
                        floor.mShoreInnerTopRightAnimX        = parse[186].ToInt();
                        floor.mShoreInnerTopRightAnimSheet    = parse[187].ToInt();
                        floor.mShoreInnerBottomRightAnimX     = parse[188].ToInt();
                        floor.mShoreInnerBottomRightAnimSheet = parse[189].ToInt();
                        floor.mShoreInnerBottomLeftAnimX      = parse[190].ToInt();
                        floor.mShoreInnerBottomLeftAnimSheet  = parse[191].ToInt();

                        floor.mShoreInnerTopAnimX        = parse[192].ToInt();
                        floor.mShoreInnerTopAnimSheet    = parse[193].ToInt();
                        floor.mShoreInnerRightAnimX      = parse[194].ToInt();
                        floor.mShoreInnerRightAnimSheet  = parse[195].ToInt();
                        floor.mShoreInnerBottomAnimX     = parse[196].ToInt();
                        floor.mShoreInnerBottomAnimSheet = parse[197].ToInt();
                        floor.mShoreInnerLeftAnimX       = parse[198].ToInt();
                        floor.mShoreInnerLeftAnimSheet   = parse[199].ToInt();

                        floor.mShoreSurroundedAnimX     = parse[200].ToInt();
                        floor.mShoreSurroundedAnimSheet = parse[201].ToInt();

                        #endregion
                        #endregion

                        floor.GroundTile.Type    = (Enums.TileType)parse[202].ToInt();
                        floor.GroundTile.Data1   = parse[203].ToInt();
                        floor.GroundTile.Data2   = parse[204].ToInt();
                        floor.GroundTile.Data3   = parse[205].ToInt();
                        floor.GroundTile.String1 = parse[206];
                        floor.GroundTile.String2 = parse[207];
                        floor.GroundTile.String3 = parse[208];

                        floor.HallTile.Type    = (Enums.TileType)parse[209].ToInt();
                        floor.HallTile.Data1   = parse[210].ToInt();
                        floor.HallTile.Data2   = parse[211].ToInt();
                        floor.HallTile.Data3   = parse[212].ToInt();
                        floor.HallTile.String1 = parse[213];
                        floor.HallTile.String2 = parse[214];
                        floor.HallTile.String3 = parse[215];

                        floor.WaterTile.Type    = (Enums.TileType)parse[216].ToInt();
                        floor.WaterTile.Data1   = parse[217].ToInt();
                        floor.WaterTile.Data2   = parse[218].ToInt();
                        floor.WaterTile.Data3   = parse[219].ToInt();
                        floor.WaterTile.String1 = parse[220];
                        floor.WaterTile.String2 = parse[221];
                        floor.WaterTile.String3 = parse[222];

                        floor.WallTile.Type    = (Enums.TileType)parse[223].ToInt();
                        floor.WallTile.Data1   = parse[224].ToInt();
                        floor.WallTile.Data2   = parse[225].ToInt();
                        floor.WallTile.Data3   = parse[226].ToInt();
                        floor.WallTile.String1 = parse[227];
                        floor.WallTile.String2 = parse[228];
                        floor.WallTile.String3 = parse[229];

                        floor.NpcSpawnTime = parse[230].ToInt();
                        floor.NpcMin       = parse[231].ToInt();
                        floor.NpcMax       = parse[232].ToInt();

                        int maxItems        = parse[233].ToInt();
                        int maxNpcs         = parse[234].ToInt();
                        int maxSpecialTiles = parse[235].ToInt();
                        int maxWeather      = parse[236].ToInt();

                        int n = 237;

                        RDungeonItem item;
                        RDungeonNpc  npc;
                        Tile         specialTile;

                        for (int i = 0; i < maxItems; i++)
                        {
                            item                = new RDungeonItem();
                            item.ItemNum        = parse[n].ToInt();
                            item.MinAmount      = parse[n + 1].ToInt();
                            item.MaxAmount      = parse[n + 2].ToInt();
                            item.AppearanceRate = parse[n + 3].ToInt();
                            item.StickyRate     = parse[n + 4].ToInt();
                            item.Tag            = parse[n + 5];
                            item.Hidden         = parse[n + 6].ToBool();
                            item.OnGround       = parse[n + 7].ToBool();
                            item.OnWater        = parse[n + 8].ToBool();
                            item.OnWall         = parse[n + 9].ToBool();
                            floor.Items.Add(item);
                            n += 10;
                        }

                        for (int i = 0; i < maxNpcs; i++)
                        {
                            npc                = new RDungeonNpc();
                            npc.NpcNum         = parse[n].ToInt();
                            npc.MinLevel       = parse[n + 1].ToInt();
                            npc.MaxLevel       = parse[n + 2].ToInt();
                            npc.AppearanceRate = parse[n + 3].ToInt();
                            floor.Npcs.Add(npc);
                            n += 4;
                        }

                        for (int i = 0; i < maxSpecialTiles; i++)
                        {
                            specialTile           = new Tile(new DataManager.Maps.Tile());
                            specialTile.Type      = (Enums.TileType)parse[n].ToInt();
                            specialTile.Data1     = parse[n + 1].ToInt();
                            specialTile.Data2     = parse[n + 2].ToInt();
                            specialTile.Data3     = parse[n + 3].ToInt();
                            specialTile.String1   = parse[n + 4];
                            specialTile.String2   = parse[n + 5];
                            specialTile.String3   = parse[n + 6];
                            specialTile.Ground    = parse[n + 7].ToInt();
                            specialTile.GroundSet = parse[n + 8].ToInt();
                            //specialTile.GroundAnim = parse[n + 9].ToInt();
                            //specialTile.GroundAnimSet = parse[n + 10].ToInt();
                            specialTile.Mask             = parse[n + 11].ToInt();
                            specialTile.MaskSet          = parse[n + 12].ToInt();
                            specialTile.Anim             = parse[n + 13].ToInt();
                            specialTile.AnimSet          = parse[n + 14].ToInt();
                            specialTile.Mask2            = parse[n + 15].ToInt();
                            specialTile.Mask2Set         = parse[n + 16].ToInt();
                            specialTile.M2Anim           = parse[n + 17].ToInt();
                            specialTile.M2AnimSet        = parse[n + 18].ToInt();
                            specialTile.Fringe           = parse[n + 19].ToInt();
                            specialTile.FringeSet        = parse[n + 20].ToInt();
                            specialTile.FAnim            = parse[n + 21].ToInt();
                            specialTile.FAnimSet         = parse[n + 22].ToInt();
                            specialTile.Fringe2          = parse[n + 23].ToInt();
                            specialTile.Fringe2Set       = parse[n + 24].ToInt();
                            specialTile.F2Anim           = parse[n + 25].ToInt();
                            specialTile.F2AnimSet        = parse[n + 26].ToInt();
                            specialTile.RDungeonMapValue = parse[n + 27].ToInt();
                            floor.SpecialTiles.Add(specialTile);
                            n += 28;
                        }

                        for (int i = 0; i < maxWeather; i++)
                        {
                            floor.Weather.Add((Enums.Weather)parse[n].ToInt());
                            n++;
                        }
                        dungeon.Floors.Add(floor);
                    }
                    break;
                    }
                }
            }
            return(dungeon);
        }
예제 #52
0
        public void ReadLog()
        {
            if (System.IO.File.Exists(settingsFile))
            {
                try
                {
                    System.IO.StreamReader fileReader = new System.IO.StreamReader(System.IO.Path.GetDirectoryName(executableURL) + "\\MomentumStrategyModule.log", true);

                    lblStatus.Text = "Reading log file.";

                    while (fileReader.Peek() != -1)
                    {
                        txtLog.Text = fileReader.ReadLine() + "\r\n" + txtLog.Text;
                    }
                    fileReader.Dispose();
                    fileReader.Close();

                    txtLog.SelectionStart = txtLog.Text.Length - 1;
                }
                finally
                {
                    lblStatus.Text = "Completed. Read logs in the Log tab.";
                }
            }
        }
예제 #53
0
        void ReadUpdateCSV(DataGridView dataInput, string csvPath, bool firstRowIsHeader)
        {
            try
            {
                dataInput.Rows.Clear();
                dataInput.Columns.Clear();
                System.IO.StreamReader fileReader = new System.IO.StreamReader(csvPath, false);

                //Reading Data
                while (fileReader.Peek() != -1)
                {
                    string fileRow = fileReader.ReadLine();
                    string[] fileDataField = fileRow.Split(',');

                    int i = 0;
                    while (dataInput.Columns.Count < fileDataField.Length)
                    {
                        dataInput.Columns.Add(fileDataField[i], fileDataField[i]);
                        if (firstRowIsHeader)
                        {
                            i++;
                        }
                    }
                    if (i == 0) // skipping first line which is header
                    {
                        dataInput.Rows.Add(fileDataField);
                    }
                }
                fileReader.Dispose();
                fileReader.Close();
                lblStatus.Text = "Loaded CSV = " + System.IO.Path.GetFileName(csvPath);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Couldn't read CSV: " + ex.Message);
            }
        }
예제 #54
0
        /// benchmark() runs a simple benchmark by letting Stockfish analyze a set
        /// of positions for a given limit each. There are five parameters; the
        /// transposition table size, the number of search threads that should
        /// be used, the limit value spent for each position (optional, default is
        /// depth 12), an optional file name where to look for positions in fen
        /// format (defaults are the positions defined above) and the type of the
        /// limit value: depth (default), time in secs or number of nodes.
        internal static void benchmark(Position current, Stack<string> stack)
        {
            List<string> fens = new List<string>();

            LimitsType limits = new LimitsType();
            Int64 nodes = 0;
            Int64 nodesAll = 0;
            long e = 0;
            long eAll = 0;

            // Assign default values to missing arguments
            string ttSize = (stack.Count > 0) ? (stack.Pop()) : "128";
            string threads = (stack.Count > 0) ? (stack.Pop()) : "1";
            string limit = (stack.Count > 0) ? (stack.Pop()) : "12";
            string fenFile = (stack.Count > 0) ? (stack.Pop()) : "default";
            string limitType = (stack.Count > 0) ? (stack.Pop()) : "depth";

            OptionMap.Instance["Hash"].v = ttSize;
            OptionMap.Instance["Threads"].v = threads;
            TT.clear();

            if (limitType == "time")
                limits.movetime = 1000 * int.Parse(limit); // maxTime is in ms

            else if (limitType == "nodes")
                limits.nodes = int.Parse(limit);

            else
                limits.depth = int.Parse(limit);

            if (fenFile == "default")
            {
                fens.AddRange(Defaults);
            }
            else if (fenFile == "current")
            {
                fens.Add(current.to_fen());
            }
            else
            {
            #if PORTABLE
                throw new Exception("File cannot be read.");
            #else
                System.IO.StreamReader sr = new System.IO.StreamReader(fenFile, true);
                string fensFromFile = sr.ReadToEnd();
                sr.Close();
                sr.Dispose();

                string[] split = fensFromFile.Replace("\r", "").Split('\n');
                foreach (string fen in split)
                {
                    if (fen.Trim().Length > 0)
                    {
                        fens.Add(fen.Trim());
                    }
                }
            #endif
            }

            Stopwatch time = new Stopwatch();
            long[] res = new long[fens.Count];
            for (int i = 0; i < fens.Count; i++)
            {
                time.Reset(); time.Start();
                Position pos = new Position(fens[i], bool.Parse(OptionMap.Instance["UCI_Chess960"].v), Threads.main_thread());

                Plug.Write("\nPosition: ");
                Plug.Write((i + 1).ToString());
                Plug.Write("/");
                Plug.Write(fens.Count.ToString());
                Plug.Write(Constants.endl);

                if (limitType == "perft")
                {
                    Int64 cnt = Search.perft(pos, limits.depth * DepthC.ONE_PLY);
                    Plug.Write("\nPerft ");
                    Plug.Write(limits.depth.ToString());
                    Plug.Write(" leaf nodes: ");
                    Plug.Write(cnt.ToString());
                    Plug.Write(Constants.endl);
                    nodes = cnt;
                }
                else
                {
                    Threads.start_searching(pos, limits, new List<Move>());
                    Threads.wait_for_search_finished();
                    nodes = Search.RootPosition.nodes;
                    res[i] = nodes;
                }

                e = time.ElapsedMilliseconds;

                nodesAll += nodes;
                eAll += e;

                Plug.Write("\n===========================");
                Plug.Write("\nTotal time (ms) : ");
                Plug.Write(e.ToString());
                Plug.Write("\nNodes searched  : ");
                Plug.Write(nodes.ToString());
                Plug.Write("\nNodes/second    : ");
                Plug.Write(((int)(nodes / (e / 1000.0))).ToString());
                Plug.Write(Constants.endl);

            }

            Plug.Write("\n===========================");
            Plug.Write("\nTotal time (ms) : ");
            Plug.Write(eAll.ToString());
            Plug.Write("\nNodes searched  : ");
            Plug.Write(nodesAll.ToString());
            Plug.Write("\nNodes/second    : ");
            Plug.Write(((int)(nodesAll / (eAll / 1000.0))).ToString());
            Plug.Write(Constants.endl);

            //for (int i = 0; i < res.Length; i++)
            //{
            //    Plug.Write(string.Format("{0}: {1}", i, res[i]));
            //    Plug.Write(Constants.endl);
            //}
        }
예제 #55
0
        public void ReadEvaluation()
        {
            string evaluationFile = System.IO.Directory.GetCurrentDirectory() + "\\eval.txt";
            if (System.IO.File.Exists(evaluationFile))
            {
                try
                {
                    System.IO.StreamReader fileReader = new System.IO.StreamReader(evaluationFile, true);

                    lblStatus.Text = "Reading Evaluation file.";
                    txtEvaluation.Text = "";
                    while (fileReader.Peek() != -1)
                    {
                        txtEvaluation.Text = fileReader.ReadLine() + "\r\n" + txtEvaluation.Text;
                    }
                    fileReader.Dispose();
                    fileReader.Close();

                    txtEvaluation.SelectionStart = txtEvaluation.Text.Length - 1;
                }
                finally
                {
                    lblStatus.Text = "Completed. Read evaluations in the Evaluation tab.";
                }
            }
            else
            {
                MessageBox.Show("Couldn't find evaluation file.");
            }
        }
예제 #56
0
        public static RDungeon LoadRDungeon(int dungeonNum)
        {
            RDungeon dungeon = new RDungeon(dungeonNum);
            string FilePath = IO.Paths.RDungeonsFolder + "rdungeon" + dungeonNum.ToString() + ".dat";
            using (System.IO.StreamReader reader = new System.IO.StreamReader(FilePath)) {
                while (!(reader.EndOfStream)) {
                    string[] parse = reader.ReadLine().Split('|');
                    switch (parse[0].ToLower()) {
                        case "rdungeondata":
                            if (parse[1].ToLower() != "v3") {
                                reader.Close();
                                reader.Dispose();
                                return null;
                            }
                            break;
                        case "data":
                            dungeon.DungeonName = parse[1];
                            dungeon.Direction = (Enums.Direction)parse[2].ToInt();
                            dungeon.MaxFloors = parse[3].ToInt();
                            dungeon.Recruitment = parse[4].ToBool();
                            dungeon.Exp = parse[5].ToBool();
                            dungeon.WindTimer = parse[6].ToInt();
                            break;
                        case "floor": {
                                RDungeonFloor floor = new RDungeonFloor();
                                floor.Options.TrapMin = parse[1].ToInt();
                                floor.Options.TrapMax = parse[2].ToInt();
                                floor.Options.ItemMin = parse[3].ToInt();
                                floor.Options.ItemMax = parse[4].ToInt();
                                floor.Options.RoomWidthMin = parse[5].ToInt();
                                floor.Options.RoomWidthMax = parse[6].ToInt();
                                floor.Options.RoomLengthMin = parse[7].ToInt();
                                floor.Options.RoomLengthMax = parse[8].ToInt();
                                floor.Options.HallTurnMin = parse[9].ToInt();
                                floor.Options.HallTurnMax = parse[10].ToInt();
                                floor.Options.HallVarMin = parse[11].ToInt();
                                floor.Options.HallVarMax = parse[12].ToInt();
                                floor.Options.WaterFrequency = parse[13].ToInt();
                                floor.Options.Craters = parse[14].ToInt();
                                floor.Options.CraterMinLength = parse[15].ToInt();
                                floor.Options.CraterMaxLength = parse[16].ToInt();
                                floor.Options.CraterFuzzy = parse[17].ToBool();

                                floor.Darkness = parse[18].ToInt();
                                floor.GoalType = (Enums.RFloorGoalType)parse[19].ToInt();
                                floor.GoalMap = parse[20].ToInt();
                                floor.GoalX = parse[21].ToInt();
                                floor.GoalY = parse[22].ToInt();
                                floor.Music = parse[23];

                                #region terrain

                                #region wall
                                floor.StairsX = parse[24].ToInt();
                                floor.StairsSheet = parse[25].ToInt();

                                floor.mGroundX = parse[26].ToInt();
                                floor.mGroundSheet = parse[27].ToInt();

                                floor.mTopLeftX = parse[28].ToInt();
                                floor.mTopLeftSheet = parse[29].ToInt();
                                floor.mTopCenterX = parse[30].ToInt();
                                floor.mTopCenterSheet = parse[31].ToInt();
                                floor.mTopRightX = parse[32].ToInt();
                                floor.mTopRightSheet = parse[33].ToInt();

                                floor.mCenterLeftX = parse[34].ToInt();
                                floor.mCenterLeftSheet = parse[35].ToInt();
                                floor.mCenterCenterX = parse[36].ToInt();
                                floor.mCenterCenterSheet = parse[37].ToInt();
                                floor.mCenterRightX = parse[38].ToInt();
                                floor.mCenterRightSheet = parse[39].ToInt();

                                floor.mBottomLeftX = parse[40].ToInt();
                                floor.mBottomLeftSheet = parse[41].ToInt();
                                floor.mBottomCenterX = parse[42].ToInt();
                                floor.mBottomCenterSheet = parse[43].ToInt();
                                floor.mBottomRightX = parse[44].ToInt();
                                floor.mBottomRightSheet = parse[45].ToInt();

                                floor.mInnerTopLeftX = parse[46].ToInt();
                                floor.mInnerTopLeftSheet = parse[47].ToInt();
                                floor.mInnerBottomLeftX = parse[48].ToInt();
                                floor.mInnerBottomLeftSheet = parse[49].ToInt();

                                floor.mInnerTopRightX = parse[50].ToInt();
                                floor.mInnerTopRightSheet = parse[51].ToInt();
                                floor.mInnerBottomRightX = parse[52].ToInt();
                                floor.mInnerBottomRightSheet = parse[53].ToInt();

                                floor.mColumnTopX = parse[54].ToInt();
                                floor.mColumnTopSheet = parse[55].ToInt();
                                floor.mColumnCenterX = parse[56].ToInt();
                                floor.mColumnCenterSheet = parse[57].ToInt();
                                floor.mColumnBottomX = parse[58].ToInt();
                                floor.mColumnBottomSheet = parse[59].ToInt();

                                floor.mRowLeftX = parse[60].ToInt();
                                floor.mRowLeftSheet = parse[61].ToInt();
                                floor.mRowCenterX = parse[62].ToInt();
                                floor.mRowCenterSheet = parse[63].ToInt();
                                floor.mRowRightX = parse[64].ToInt();
                                floor.mRowRightSheet = parse[65].ToInt();

                                floor.mIsolatedWallX = parse[66].ToInt();
                                floor.mIsolatedWallSheet = parse[67].ToInt();

                                floor.mGroundAltX = parse[68].ToInt();
                                floor.mGroundAltSheet = parse[69].ToInt();
                                floor.mGroundAlt2X = parse[70].ToInt();
                                floor.mGroundAlt2Sheet = parse[71].ToInt();

                                floor.mTopLeftAltX = parse[72].ToInt();
                                floor.mTopLeftAltSheet = parse[73].ToInt();
                                floor.mTopCenterAltX = parse[74].ToInt();
                                floor.mTopCenterAltSheet = parse[75].ToInt();
                                floor.mTopRightAltX = parse[76].ToInt();
                                floor.mTopRightAltSheet = parse[77].ToInt();

                                floor.mCenterLeftAltX = parse[78].ToInt();
                                floor.mCenterLeftAltSheet = parse[79].ToInt();
                                floor.mCenterCenterAltX = parse[80].ToInt();
                                floor.mCenterCenterAltSheet = parse[81].ToInt();
                                floor.mCenterCenterAlt2X = parse[82].ToInt();
                                floor.mCenterCenterAlt2Sheet = parse[83].ToInt();
                                floor.mCenterRightAltX = parse[84].ToInt();
                                floor.mCenterRightAltSheet = parse[85].ToInt();

                                floor.mBottomLeftAltX = parse[86].ToInt();
                                floor.mBottomLeftAltSheet = parse[87].ToInt();
                                floor.mBottomCenterAltX = parse[88].ToInt();
                                floor.mBottomCenterAltSheet = parse[89].ToInt();
                                floor.mBottomRightAltX = parse[90].ToInt();
                                floor.mBottomRightAltSheet = parse[91].ToInt();

                                floor.mInnerTopLeftAltX = parse[92].ToInt();
                                floor.mInnerTopLeftAltSheet = parse[93].ToInt();
                                floor.mInnerBottomLeftAltX = parse[94].ToInt();
                                floor.mInnerBottomLeftAltSheet = parse[95].ToInt();

                                floor.mInnerTopRightAltX = parse[96].ToInt();
                                floor.mInnerTopRightAltSheet = parse[97].ToInt();
                                floor.mInnerBottomRightAltX = parse[98].ToInt();
                                floor.mInnerBottomRightAltSheet = parse[99].ToInt();

                                floor.mColumnTopAltX = parse[100].ToInt();
                                floor.mColumnTopAltSheet = parse[101].ToInt();
                                floor.mColumnCenterAltX = parse[102].ToInt();
                                floor.mColumnCenterAltSheet = parse[103].ToInt();
                                floor.mColumnBottomAltX = parse[104].ToInt();
                                floor.mColumnBottomAltSheet = parse[105].ToInt();

                                floor.mRowLeftAltX = parse[106].ToInt();
                                floor.mRowLeftAltSheet = parse[107].ToInt();
                                floor.mRowCenterAltX = parse[108].ToInt();
                                floor.mRowCenterAltSheet = parse[109].ToInt();
                                floor.mRowRightAltX = parse[110].ToInt();
                                floor.mRowRightAltSheet = parse[111].ToInt();

                                floor.mIsolatedWallAltX = parse[112].ToInt();
                                floor.mIsolatedWallAltSheet = parse[113].ToInt();

                                #endregion

                                #region water

                                floor.mWaterX = parse[114].ToInt();
                                floor.mWaterSheet = parse[115].ToInt();
                                floor.mWaterAnimX = parse[116].ToInt();
                                floor.mWaterAnimSheet = parse[117].ToInt();

                                floor.mShoreTopLeftX = parse[118].ToInt();
                                floor.mShoreTopLeftSheet = parse[119].ToInt();
                                floor.mShoreTopRightX = parse[120].ToInt();
                                floor.mShoreTopRightSheet = parse[121].ToInt();
                                floor.mShoreBottomRightX = parse[122].ToInt();
                                floor.mShoreBottomRightSheet = parse[123].ToInt();
                                floor.mShoreBottomLeftX = parse[124].ToInt();
                                floor.mShoreBottomLeftSheet = parse[125].ToInt();
                                floor.mShoreDiagonalForwardX = parse[126].ToInt();
                                floor.mShoreDiagonalForwardSheet = parse[127].ToInt();
                                floor.mShoreDiagonalBackX = parse[128].ToInt();
                                floor.mShoreDiagonalBackSheet = parse[129].ToInt();

                                floor.mShoreTopX = parse[130].ToInt();
                                floor.mShoreTopSheet = parse[131].ToInt();
                                floor.mShoreRightX = parse[132].ToInt();
                                floor.mShoreRightSheet = parse[133].ToInt();
                                floor.mShoreBottomX = parse[134].ToInt();
                                floor.mShoreBottomSheet = parse[135].ToInt();
                                floor.mShoreLeftX = parse[136].ToInt();
                                floor.mShoreLeftSheet = parse[137].ToInt();
                                floor.mShoreVerticalX = parse[138].ToInt();
                                floor.mShoreVerticalSheet = parse[139].ToInt();
                                floor.mShoreHorizontalX = parse[140].ToInt();
                                floor.mShoreHorizontalSheet = parse[141].ToInt();

                                floor.mShoreInnerTopLeftX = parse[142].ToInt();
                                floor.mShoreInnerTopLeftSheet = parse[143].ToInt();
                                floor.mShoreInnerTopRightX = parse[144].ToInt();
                                floor.mShoreInnerTopRightSheet = parse[145].ToInt();
                                floor.mShoreInnerBottomRightX = parse[146].ToInt();
                                floor.mShoreInnerBottomRightSheet = parse[147].ToInt();
                                floor.mShoreInnerBottomLeftX = parse[148].ToInt();
                                floor.mShoreInnerBottomLeftSheet = parse[149].ToInt();

                                floor.mShoreInnerTopX = parse[150].ToInt();
                                floor.mShoreInnerTopSheet = parse[151].ToInt();
                                floor.mShoreInnerRightX = parse[152].ToInt();
                                floor.mShoreInnerRightSheet = parse[153].ToInt();
                                floor.mShoreInnerBottomX = parse[154].ToInt();
                                floor.mShoreInnerBottomSheet = parse[155].ToInt();
                                floor.mShoreInnerLeftX = parse[156].ToInt();
                                floor.mShoreInnerLeftSheet = parse[157].ToInt();

                                floor.mShoreSurroundedX = parse[158].ToInt();
                                floor.mShoreSurroundedSheet = parse[159].ToInt();

                                floor.mShoreTopLeftAnimX = parse[160].ToInt();
                                floor.mShoreTopLeftAnimSheet = parse[161].ToInt();
                                floor.mShoreTopRightAnimX = parse[162].ToInt();
                                floor.mShoreTopRightAnimSheet = parse[163].ToInt();
                                floor.mShoreBottomRightAnimX = parse[164].ToInt();
                                floor.mShoreBottomRightAnimSheet = parse[165].ToInt();
                                floor.mShoreBottomLeftAnimX = parse[166].ToInt();
                                floor.mShoreBottomLeftAnimSheet = parse[167].ToInt();
                                floor.mShoreDiagonalForwardAnimX = parse[168].ToInt();
                                floor.mShoreDiagonalForwardAnimSheet = parse[169].ToInt();
                                floor.mShoreDiagonalBackAnimX = parse[170].ToInt();
                                floor.mShoreDiagonalBackAnimSheet = parse[171].ToInt();

                                floor.mShoreTopAnimX = parse[172].ToInt();
                                floor.mShoreTopAnimSheet = parse[173].ToInt();
                                floor.mShoreRightAnimX = parse[174].ToInt();
                                floor.mShoreRightAnimSheet = parse[175].ToInt();
                                floor.mShoreBottomAnimX = parse[176].ToInt();
                                floor.mShoreBottomAnimSheet = parse[177].ToInt();
                                floor.mShoreLeftAnimX = parse[178].ToInt();
                                floor.mShoreLeftAnimSheet = parse[179].ToInt();
                                floor.mShoreVerticalAnimX = parse[180].ToInt();
                                floor.mShoreVerticalAnimSheet = parse[181].ToInt();
                                floor.mShoreHorizontalAnimX = parse[182].ToInt();
                                floor.mShoreHorizontalAnimSheet = parse[183].ToInt();

                                floor.mShoreInnerTopLeftAnimX = parse[184].ToInt();
                                floor.mShoreInnerTopLeftAnimSheet = parse[185].ToInt();
                                floor.mShoreInnerTopRightAnimX = parse[186].ToInt();
                                floor.mShoreInnerTopRightAnimSheet = parse[187].ToInt();
                                floor.mShoreInnerBottomRightAnimX = parse[188].ToInt();
                                floor.mShoreInnerBottomRightAnimSheet = parse[189].ToInt();
                                floor.mShoreInnerBottomLeftAnimX = parse[190].ToInt();
                                floor.mShoreInnerBottomLeftAnimSheet = parse[191].ToInt();

                                floor.mShoreInnerTopAnimX = parse[192].ToInt();
                                floor.mShoreInnerTopAnimSheet = parse[193].ToInt();
                                floor.mShoreInnerRightAnimX = parse[194].ToInt();
                                floor.mShoreInnerRightAnimSheet = parse[195].ToInt();
                                floor.mShoreInnerBottomAnimX = parse[196].ToInt();
                                floor.mShoreInnerBottomAnimSheet = parse[197].ToInt();
                                floor.mShoreInnerLeftAnimX = parse[198].ToInt();
                                floor.mShoreInnerLeftAnimSheet = parse[199].ToInt();

                                floor.mShoreSurroundedAnimX = parse[200].ToInt();
                                floor.mShoreSurroundedAnimSheet = parse[201].ToInt();

                                #endregion
                                #endregion

                                floor.GroundTile.Type = (Enums.TileType)parse[202].ToInt();
                                floor.GroundTile.Data1 = parse[203].ToInt();
                                floor.GroundTile.Data2 = parse[204].ToInt();
                                floor.GroundTile.Data3 = parse[205].ToInt();
                                floor.GroundTile.String1 = parse[206];
                                floor.GroundTile.String2 = parse[207];
                                floor.GroundTile.String3 = parse[208];

                                floor.HallTile.Type = (Enums.TileType)parse[209].ToInt();
                                floor.HallTile.Data1 = parse[210].ToInt();
                                floor.HallTile.Data2 = parse[211].ToInt();
                                floor.HallTile.Data3 = parse[212].ToInt();
                                floor.HallTile.String1 = parse[213];
                                floor.HallTile.String2 = parse[214];
                                floor.HallTile.String3 = parse[215];

                                floor.WaterTile.Type = (Enums.TileType)parse[216].ToInt();
                                floor.WaterTile.Data1 = parse[217].ToInt();
                                floor.WaterTile.Data2 = parse[218].ToInt();
                                floor.WaterTile.Data3 = parse[219].ToInt();
                                floor.WaterTile.String1 = parse[220];
                                floor.WaterTile.String2 = parse[221];
                                floor.WaterTile.String3 = parse[222];

                                floor.WallTile.Type = (Enums.TileType)parse[223].ToInt();
                                floor.WallTile.Data1 = parse[224].ToInt();
                                floor.WallTile.Data2 = parse[225].ToInt();
                                floor.WallTile.Data3 = parse[226].ToInt();
                                floor.WallTile.String1 = parse[227];
                                floor.WallTile.String2 = parse[228];
                                floor.WallTile.String3 = parse[229];

                                floor.NpcSpawnTime = parse[230].ToInt();
                                floor.NpcMin = parse[231].ToInt();
                                floor.NpcMax = parse[232].ToInt();

                                int maxItems = parse[233].ToInt();
                                int maxNpcs = parse[234].ToInt();
                                int maxSpecialTiles = parse[235].ToInt();
                                int maxWeather = parse[236].ToInt();

                                int n = 237;

                                RDungeonItem item;
                                RDungeonNpc npc;
                                Tile specialTile;

                                for (int i = 0; i < maxItems; i++) {
                                        item = new RDungeonItem();
                                    item.ItemNum = parse[n].ToInt();
                                    item.MinAmount = parse[n+1].ToInt();
                                    item.MaxAmount = parse[n+2].ToInt();
                                    item.AppearanceRate = parse[n+3].ToInt();
                                    item.StickyRate = parse[n+4].ToInt();
                                    item.Tag = parse[n+5];
                                    item.Hidden = parse[n+6].ToBool();
                                    item.OnGround = parse[n+7].ToBool();
                                    item.OnWater = parse[n+8].ToBool();
                                    item.OnWall = parse[n+9].ToBool();
                                    floor.Items.Add(item);
                                    n += 10;
                                }

                                for (int i = 0; i < maxNpcs; i++) {
                                        npc = new RDungeonNpc();
                                    npc.NpcNum = parse[n].ToInt();
                                    npc.MinLevel = parse[n + 1].ToInt();
                                    npc.MaxLevel = parse[n + 2].ToInt();
                                    npc.AppearanceRate = parse[n + 3].ToInt();
                                    floor.Npcs.Add(npc);
                                    n+= 4;
                                }

                                for (int i = 0; i < maxSpecialTiles; i++) {
                                        specialTile = new Tile(new DataManager.Maps.Tile());
                                        specialTile.Type = (Enums.TileType)parse[n].ToInt();
                                        specialTile.Data1 = parse[n + 1].ToInt();
                                        specialTile.Data2 = parse[n + 2].ToInt();
                                        specialTile.Data3 = parse[n + 3].ToInt();
                                        specialTile.String1 = parse[n + 4];
                                        specialTile.String2 = parse[n + 5];
                                        specialTile.String3 = parse[n + 6];
                                        specialTile.Ground = parse[n + 7].ToInt();
                                        specialTile.GroundSet = parse[n + 8].ToInt();
                                        //specialTile.GroundAnim = parse[n + 9].ToInt();
                                        //specialTile.GroundAnimSet = parse[n + 10].ToInt();
                                        specialTile.Mask = parse[n + 11].ToInt();
                                        specialTile.MaskSet = parse[n + 12].ToInt();
                                        specialTile.Anim	 = parse[n + 13].ToInt();
                                        specialTile.AnimSet = parse[n + 14].ToInt();
                                        specialTile.Mask2 = parse[n + 15].ToInt();
                                        specialTile.Mask2Set = parse[n + 16].ToInt();
                                        specialTile.M2Anim = parse[n + 17].ToInt();
                                        specialTile.M2AnimSet = parse[n + 18].ToInt();
                                        specialTile.Fringe = parse[n + 19].ToInt();
                                        specialTile.FringeSet = parse[n + 20].ToInt();
                                        specialTile.FAnim = parse[n + 21].ToInt();
                                        specialTile.FAnimSet = parse[n + 22].ToInt();
                                        specialTile.Fringe2 = parse[n + 23].ToInt();
                                        specialTile.Fringe2Set = parse[n + 24].ToInt();
                                        specialTile.F2Anim = parse[n + 25].ToInt();
                                        specialTile.F2AnimSet = parse[n + 26].ToInt();
                                        specialTile.RDungeonMapValue = parse[n + 27].ToInt();
                                        floor.SpecialTiles.Add(specialTile);
                                    n+= 28;
                                }

                                for (int i = 0; i < maxWeather; i++) {
                                    floor.Weather.Add((Enums.Weather)parse[n].ToInt());
                                    n++;
                                }
                                dungeon.Floors.Add(floor);
                            }
                            break;

                    }
                }
            }
            return dungeon;
        }
예제 #57
0
        public ExecutionMirror LoadAndExecute(string filename, ProtoCore.Core core, bool isTest = true)
        {
            System.IO.StreamReader reader = null;
            try
            {
                reader = new System.IO.StreamReader(filename, Encoding.UTF8, true);
            }
            catch (System.IO.IOException)
            {
                throw new FatalError("Cannot open file " + filename);
            }

            string strSource = reader.ReadToEnd();
            reader.Dispose();
            //Start the timer
            core.StartTimer();

            core.Options.RootModulePathName = ProtoCore.Utils.FileUtils.GetFullPathName(filename);
            core.CurrentDSFileName = core.Options.RootModulePathName;

            ProtoLanguage.CompileStateTracker compileState = null;
            Execute(strSource, core, out compileState);

            if (isTest && !core.Options.CompileToLib)
                return new ExecutionMirror(core.CurrentExecutive.CurrentDSASMExec, core);
            else
                return null;
        }
예제 #58
0
        /// <summary>
        /// Load and executes the DS code in the specified file
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="core"></param>
        /// <param name="isTest"></param>
        /// <returns></returns>
        public ProtoCore.RuntimeCore LoadAndExecute(string filename, ProtoCore.Core core, bool isTest = true)
        {
            System.IO.StreamReader reader = null;
            try
            {
                reader = new System.IO.StreamReader(filename, Encoding.UTF8, true);
            }
            catch (System.IO.IOException)
            {
                throw new Exception("Cannot open file " + filename);
            }

            string strSource = reader.ReadToEnd();
            reader.Dispose();

            core.Options.RootModulePathName = ProtoCore.Utils.FileUtils.GetFullPathName(filename);
            core.CurrentDSFileName = core.Options.RootModulePathName;
            return Execute(strSource, core);
        }
예제 #59
0
        public void LoadKeyFrames()
        {
            l_bones.Clear();
            animationList = new List<string>();

            System.IO.StreamReader reader = new System.IO.StreamReader("../../Content/KeyframeData.txt");
            while(!reader.EndOfStream)
            {
                 C_Bone tempBone = new C_Bone();
                //name, position, positionEnd, length, angle, childCount
                Vector3 tempVector = new Vector3(0,0,0);
                if (l_bones.Count() % MAX_CHAR_BONES == 0)
                    reader.ReadLine();

                tempBone.AnimationName = reader.ReadLine();//bone animation name
                tempBone.KeyFrame = int.Parse(reader.ReadLine());

                tempBone.Name = reader.ReadLine();//bone name

                tempVector.X = float.Parse(reader.ReadLine());
                tempVector.Y = float.Parse(reader.ReadLine());
                tempBone.Position = tempVector;

                tempVector.X = float.Parse(reader.ReadLine());
                tempVector.Y = float.Parse(reader.ReadLine());
                tempBone.PositionEnd = tempVector;

                tempBone.Length = float.Parse(reader.ReadLine());
                tempBone.Angle = float.Parse(reader.ReadLine());
                tempBone.ChildCount = uint.Parse(reader.ReadLine());

                tempBone.ParentNumber = int.Parse(reader.ReadLine());

                if(tempBone.ParentNumber != -1)
                    tempBone.Position = l_bones[tempBone.ParentNumber].PositionEnd;

                //done parsing, time to add stuff

                //see if animation name is listed. If not add it to list
                bool animationListed = false;
                for (int i = 0; i < animationList.Count; i++)
                    if (animationList[i] == tempBone.AnimationName)
                        animationListed = true;
                if (!animationListed)
                    animationList.Add(tempBone.AnimationName);

                AddChild(0, tempBone);
            }

            reader.Close();
            reader.Dispose();

            #region HARDCODED
            /*
            /////////////////////////////////
            //NEW FRAME --- KEYFRAME 0
            /////////////////////////////////
            //TODO: this is hard coded now, but will eventually read from file
            C_Bone tempBone = new C_Bone();
            tempBone.Name = "head";
            tempBone.Length = 30;
            tempBone.Angle = MathHelper.ToRadians(90);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            AddChild(0, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "right arm";
            tempBone.Length = 60;
            tempBone.Angle = MathHelper.ToRadians(20);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[0];
            tempBone.ParentNumber = 0;
            AddChild(0, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "right forearm";
            tempBone.Length = 50;
            tempBone.Angle = MathHelper.ToRadians(45);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[1];
            tempBone.ParentNumber = 1;
            AddChild(0, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "left arm";
            tempBone.Length = 60;
            tempBone.Angle = MathHelper.ToRadians(160);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[0];
            tempBone.ParentNumber = 0;
            AddChild(0, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "left forearm";
            tempBone.Length = 50;
            tempBone.Angle = MathHelper.ToRadians(135);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[3];
            tempBone.ParentNumber = 3;
            AddChild(0, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "torso";//bone 6 or [5]
            tempBone.Length = 100;
            tempBone.Angle = MathHelper.ToRadians(90);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[0];
            tempBone.ParentNumber = 0;
            AddChild(0, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "left upper leg";
            tempBone.Length = 75;
            tempBone.Angle = MathHelper.ToRadians(120);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[5];
            tempBone.ParentNumber = 5;
            AddChild(0, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "left lower leg";//bone 8
            tempBone.Length = 75;
            tempBone.Angle = MathHelper.ToRadians(100);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[6];
            tempBone.ParentNumber = 6;
            AddChild(0, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "right upper leg";//bone 9
            tempBone.Length = 75;
            tempBone.Angle = MathHelper.ToRadians(60);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[5];
            tempBone.ParentNumber = 5;
            AddChild(0, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "right lower leg";//bone 10
            tempBone.Length = 75;
            tempBone.Angle = MathHelper.ToRadians(80);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[8];
            tempBone.ParentNumber = 8;
            AddChild(0, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "left foot";
            tempBone.Length = 35;
            tempBone.Angle = MathHelper.ToRadians(180);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[7];
            tempBone.ParentNumber = 7;
            AddChild(0, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "right foot";
            tempBone.Length = 35;
            tempBone.Angle = MathHelper.ToRadians(0);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[9];
            tempBone.ParentNumber = 9;
            AddChild(0, tempBone);

            /////////////////////////////////
            //NEW FRAME --- KEYFRAME 1
            /////////////////////////////////

            tempBone = new C_Bone();
            tempBone.Name = "head";
            tempBone.Length = 30;
            tempBone.Angle = MathHelper.ToRadians(45);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            AddChild(12, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "right arm";
            tempBone.Length = 60;
            tempBone.Angle = MathHelper.ToRadians(-20);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[12 + 0];
            tempBone.ParentNumber = 12 + 0;
            AddChild(12, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "right forearm";
            tempBone.Length = 50;
            tempBone.Angle = MathHelper.ToRadians(155);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[12 + 1];
            tempBone.ParentNumber = 12 + 1;
            AddChild(12, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "left arm";
            tempBone.Length = 60;
            tempBone.Angle = MathHelper.ToRadians(155);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[12 + 0];
            tempBone.ParentNumber = 12 + 0;
            AddChild(12, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "left forearm";
            tempBone.Length = 50;
            tempBone.Angle = MathHelper.ToRadians(130);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[12 + 3];
            tempBone.ParentNumber = 12 + 3;
            AddChild(12, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "torso";
            tempBone.Length = 100;
            tempBone.Angle = MathHelper.ToRadians(90);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[12 + 0];
            tempBone.ParentNumber = 12 + 0;
            AddChild(12, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "left upper leg";
            tempBone.Length = 75;
            tempBone.Angle = MathHelper.ToRadians(205);
            tempBone.Position = Vector3.Zero;// Only matters for root/head  5 6 5 8 7 9
            tempBone.Parent = l_bones[12 + 5];
            tempBone.ParentNumber = 12 + 5;
            AddChild(12, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "left ower leg";//bone 8
            tempBone.Length = 75;
            tempBone.Angle = MathHelper.ToRadians(180);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[12 + 6];
            tempBone.ParentNumber = 12 + 6;
            AddChild(12, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "right upper leg";
            tempBone.Length = 75;
            tempBone.Angle = MathHelper.ToRadians(-45);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[12 + 5];
            tempBone.ParentNumber = 12 + 5;
            AddChild(12, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "right lower leg";
            tempBone.Length = 75;
            tempBone.Angle = MathHelper.ToRadians(170);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[12 + 8];
            tempBone.ParentNumber = 12 + 8;
            AddChild(12, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "left foot";
            tempBone.Length = 35;
            tempBone.Angle = MathHelper.ToRadians(235);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[12 + 7];
            tempBone.ParentNumber = 12 + 7;
            AddChild(12, tempBone);

            tempBone = new C_Bone();
            tempBone.Name = "right foot";
            tempBone.Length = 35;
            tempBone.Angle = MathHelper.ToRadians(235);
            tempBone.Position = Vector3.Zero;// Only matters for root/head
            tempBone.Parent = l_bones[12 + 9];
            tempBone.ParentNumber = 12 + 9;
            AddChild(12, tempBone);
             */
             #endregion

            vertices = new VertexPositionColor[l_bones.Count() * 2];//2 vertices per bone

            //after reading bone data load vertices
            for (int i = 0; i < l_bones.Count(); i++)
            {
                vertices[i * 2].Position = l_bones[i].Position;
                vertices[i * 2].Color = Color.Black;
                vertices[i * 2 + 1].Position = l_bones[i].PositionEnd;
                vertices[i * 2 + 1].Color = Color.Black;
            }

            //Load keyframe and animation indices
            i_keyFrame = new int[vertices.Length / (MAX_CHAR_BONES * 2)];//create index array for each keyframe
            for (int i = 0; i < i_keyFrame.Length; i++)
                i_keyFrame[i] = i * MAX_CHAR_BONES * 2;
        }
예제 #60
0
 /// <summary>
 /// 获取Html文件内容
 /// </summary>
 /// <param name="HtmlFile"></param>
 /// <returns></returns>
 protected string GetFileContent(string HtmlFile)
 {
     //获取物理地址
     try
     {
         string RealHtmlFile = HttpContext.Current.Server.MapPath(HtmlFile);
         System.IO.StreamReader sr = new System.IO.StreamReader(RealHtmlFile, System.Text.Encoding.Default);
         string html = sr.ReadToEnd();
         sr.Close();
         sr.Dispose();
         return html;
     }
     catch
     {
         return "";
     }
 }