Пример #1
0
        public void ExportMetadataTables(string FileName, string[] TablesSelected, bool UseSquareBrackets)
        {
            if (System.IO.File.Exists(FileName))
            {
                System.IO.File.Delete(FileName);
            }

            TextFile tf = new TextFile();

            tf.Open(enmOpenMode.Writing, FileName);

            string[] Tables = GetTablesInOrder(UseSquareBrackets);
            for (int i = 0; i < Tables.Length; i++)
            {
                if (!Utility.ItemInList(Tables[i], TablesSelected))
                {
                    continue;
                }

                if (ScriptProgress != null)
                {
                    bool Cancel;
                    ScriptProgress(Tables[i], i, Tables.Length, out Cancel);
                    if (Cancel)
                    {
                        tf.Close();
                        break;
                    }
                }

                string table = Tables[i];
                if (UseSquareBrackets)
                {
                    table = string.Format("[{0}]", table);
                }

                DataTable dt = GetQuery("select * from " + table, Tables[i], 1);
                if (dt == null)
                {
                    continue;
                }

                FillSchema(dt);
                tf.WriteLine(GetMetadataTable(dt, UseSquareBrackets));
                tf.WriteLine(" ");
            }

            tf.WriteLine(DbScript.COMMIT_COMMAND);
            tf.Close();
        }
Пример #2
0
        private static string[] GetCityUrlList(string cityUrlPath)
        {
            TextFile urlFile = new TextFile(cityUrlPath);

            string[] url_City = urlFile.ReadToEnd().Split('\r');
            urlFile.Close();
            return(url_City);
        }
Пример #3
0
        public void SalveScriptDelete(string TableName, string FileName)
        {
            TextFile tf = new TextFile();

            tf.Open(enmOpenMode.Writing, FileName);
            SalveScriptDelete(TableName, tf);
            tf.Close();
        }
Пример #4
0
        public void SalveScriptInsert(DataTable tb, string FileName, bool UseInsertIdentity, bool UseSquareBrackets)
        {
            TextFile tf = new TextFile();

            tf.Open(enmOpenMode.Writing, FileName);
            SalveScriptInsert(tb, tf, UseInsertIdentity, UseSquareBrackets);
            tf.Close();
        }
Пример #5
0
        public void Close()
        {
            // Act
            _textFile.Close();

            // Verify
            Assert.False(_memoryStream.CanRead);
            Assert.False(_memoryStream.CanWrite);
        }
Пример #6
0
        public void ExportLogs(string FileName)
        {
            TextFile tf = new TextFile();

            tf.Open(enmOpenMode.Writing, FileName);
            for (int i = 0; i < Log.Count; i++)
            {
                tf.WriteLine(string.Format("UPDATE_NUMBER:{0}, UPDATE_MESSAGE:{1}", Log[i].Number.ToString("000000"), Log[i].Message));
            }
            tf.Close();
        }
Пример #7
0
        private static void WriteToFile(string[] texts, string path)
        {
            TextFile textFile = new TextFile(path);

            //textFile.WriteLine(GetShortDateTime());
            foreach (var item in texts)
            {
                textFile.WriteLine(item);
            }

            textFile.Close();
        }
Пример #8
0
        public void ExportFieldList(string FileName)
        {
            if (System.IO.File.Exists(FileName))
            {
                System.IO.File.Delete(FileName);
            }

            lib.Class.TextFile tf = new TextFile();
            tf.Open(enmOpenMode.Writing, FileName);
            tf.Write(Indent((new JSON()).Serialize(this.DbColumns)));
            tf.Close();
        }
Пример #9
0
        /// <summary>
        /// Salva no arquivo os itens não bloqueados
        /// </summary>
        public void Save()
        {
            TextFile TextFile = new TextFile();

            TextFile.Open(enmOpenMode.Writing, this.FileName);
            for (int i = 0; i < Items.Count; i++)
            {
                if (!Items[i].Block)
                {
                    TextFile.WriteLine(Items[i].GetHeader("/*[UPDATE]{0}*/"));
                    TextFile.WriteLine(Items[i].GetContent());
                }
            }
            TextFile.Close();
        }
Пример #10
0
        /// <summary>
        /// Carrega o arquivo para o array de itens
        /// </summary>
        public void Load(string FileName)
        {
            this.FileName = FileName;
            TextFile TextFile = new TextFile();

            TextFile.Open(enmOpenMode.Reading, FileName);
            string[] lines = TextFile.GetLines();
            TextFile.Close();

            string buffer = "";

            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].IndexOf(IniStr) != -1)
                {
                    Items.Add(new ItemUpdate(GetNumber(lines[i]), true));
                }
                else
                {
                    if (Items.Count != 0)
                    {
                        buffer += lines[i] + " ";
                        if (lines[i].IndexOf(';') != -1)
                        {
                            Items[Items.Count - 1].Sql.Add(buffer);
                            buffer = "";
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(buffer.Trim()))
            {
                Items[Items.Count - 1].Sql.Add(buffer);
            }
        }
        private void ExportByFileList(ExportHDFToTSOptions opts, DoWorkEventArgs e)
        {
            string config_name = "";
             TextFile cfg = new TextFile();
             ExternalApp app = new ExternalApp();

             //Find a file name for the configuration file.
             bool Found = false;
             int n = 1;
             int tentatives = 0;
             while (!Found)
             {
            config_name = opts.ConfigFile + n + ".cfg";
            if (System.IO.File.Exists(opts.WorkingFolder + config_name))
            {
               n++;
            }
            else
            {
               try
               {
                  cfg.File.FullPath = opts.WorkingFolder + config_name;
                  cfg.OpenNewToWrite();
                  Found = true;
               }
               catch
               {
                  n++;
                  tentatives++;

                  if (tentatives > 20)
                  {
                     MessageBox.Show("Was not possibe to create the configuration file to the HDFExporter tool.", "ATTENTION", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     return;
                  }
               }
            }
             }

             //Create the Config Data File
             cfg.WriteLine("!File created using Mohid Toolbox");

             foreach (string file in opts.List)
             {
            cfg.WriteLine("<BeginHDF5File>");
            cfg.WriteLine("  NAME : " + file);
            cfg.WriteLine("<EndHDF5File>");
             }

             if (opts.Type == ExportHDFToTSType.ByMask) //by Mask
             {
            cfg.WriteLine("EXPORT_TYPE       : 2");
            cfg.WriteLine("MASK_GRID         : " + opts.MaskFile);
            cfg.WriteLine("AREA_FILL_VALUE   : " + opts.AreaFillValue);
            if (opts.UsePoints)
            {
               cfg.WriteLine("USE_POINTS        : 1");
               cfg.WriteLine("WATERPOINTS_NAME  : " + opts.PointsName);
               cfg.WriteLine("WATERPOINTS_GROUP : " + opts.PointsGroup);
            }
            else
               cfg.WriteLine("USE_POINTS        : 0");
             }
             else //By coordinates
             {
            cfg.WriteLine("EXPORT_TYPE       : 1");
            cfg.WriteLine("WATERPOINTS_NAME  : " + opts.PointsName);
            cfg.WriteLine("WATERPOINTS_GROUP : " + opts.PointsGroup);
             }

             if (opts.CheckPropertyName)
            cfg.WriteLine("CHECK_PROPERTY    : 1");
             else
            cfg.WriteLine("CHECK_PROPERTY    : 0");

             if (opts.UseStart)
            cfg.WriteLine("START_TIME        : " + opts.Start.ToString("yyyy MM dd HH mm ss"));
             if (opts.UseEnd)
            cfg.WriteLine("END_TIME          : " + opts.End.ToString("yyyy MM dd HH mm ss"));

             if (opts.Variable)
            cfg.WriteLine("VARIABLE_GRID     : 1");
             else
            cfg.WriteLine("VARIABLE_GRID     : 0");

             if (!string.IsNullOrWhiteSpace(opts.GridFile))
            cfg.WriteLine("GRID_FILENAME     : " + opts.GridFile);

             if (!string.IsNullOrWhiteSpace(opts.TimeGroup))
            cfg.WriteLine("TIME_GROUP        : " + opts.TimeGroup);

             if (!string.IsNullOrWhiteSpace(opts.DecimationFactor))
            cfg.WriteLine("DECIMATION_FACTOR : " + opts.DecimationFactor);

             foreach (TimeseriesBlock ts in opts.TimeSeries)
             {
            cfg.WriteLine("<BeginTimeSerie>");

            if (opts.Type == ExportHDFToTSType.ByMask) //by Mask
            {
               cfg.WriteLine("  NAME              : " + (new FilePath(opts.PathToOutputTimeSeries)).Path + ts.Name);
               if (!string.IsNullOrWhiteSpace(ts.MaskID))
                  cfg.WriteLine("  MASK_ID           : " + ts.MaskID);
               if (!string.IsNullOrWhiteSpace(ts.Layer))
                  cfg.WriteLine("  LAYER             : " + ts.Layer);
            }
            else
            {
               cfg.WriteLine("  NAME              : " + (new FilePath(opts.PathToOutputTimeSeries)).Path + ts.Name);
               if (!string.IsNullOrWhiteSpace(ts.I))
                  cfg.WriteLine("  LOCALIZATION_I    : " + ts.I);
               if (!string.IsNullOrWhiteSpace(ts.J))
                  cfg.WriteLine("  LOCALIZATION_J    : " + ts.J);
               if (!string.IsNullOrWhiteSpace(ts.K))
                  cfg.WriteLine("  LOCALIZATION_J    : " + ts.K);
               if (!string.IsNullOrWhiteSpace(ts.Latitude))
                  cfg.WriteLine("  LATITUDE          : " + ts.Latitude);
               if (!string.IsNullOrWhiteSpace(ts.Longitude))
                  cfg.WriteLine("  LONGITUDE         : " + ts.Longitude);
               if (!string.IsNullOrWhiteSpace(ts.X))
                  cfg.WriteLine("  COORD_X           : " + ts.X);
               if (!string.IsNullOrWhiteSpace(ts.Y))
                  cfg.WriteLine("  COORD_Y           : " + ts.Y);
            }
            cfg.WriteLine("<EndTimeSerie>");
             }

             foreach (ParameterBlock p in opts.Parameters)
             {
            cfg.WriteLine("<BeginParameter>");
            cfg.WriteLine("  PROPERTY          : " + p.Name);
            cfg.WriteLine("  HDF_GROUP         : " + p.Group);
            cfg.WriteLine("<EndParameter>");
             }
             cfg.Close();

             //run HDFExporter Tool
             app.Executable = opts.PathToHDFExporter;
             app.UseShell = false;
             app.WorkingDirectory = opts.WorkingFolder;
             app.Arguments = "-c " + config_name;
             app.CheckSuccessMethod = CheckSuccessMethod.DEFAULTOUTPUT;
             app.TextToCheck = "successfully terminated";
             app.Verbose = false;
             app.Wait = false;
             app.SearchTextOrder = SearchTextOrder.FROMEND;

             Software.AppExitStatus es;

             if ((es = app.Run(this, e)) != AppExitStatus.Finished)
             {
            if (es != AppExitStatus.Canceled)
               MessageBox.Show("HDFExporter tool has failed.", "ATTENTION", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return;
             }

             if (!opts.KeepConfigFile)
             {
            try
            {
               System.IO.File.Delete(opts.WorkingFolder + config_name);
            }
            catch
            {
            }
             }
        }
Пример #12
0
            public void Save(FileName file, List<int> columnsToSave, Interval interval)
            {
                //Check to see if the interval exists
                if (interval.Start < 0 || interval.Start >= instants.Count || interval.End >= instants.Count)
                   throw new Exception("Invalid Interval");

                //Check to see if the columns chosen exists
                foreach (int col in columnsToSave)
                   if (col < 0 || col >= dataColumns.Count)
                  throw new Exception("Invalid column index");

                int endRow;
                if (interval.End < 0)
                   endRow = instants.Count - 1;
                else
                   endRow = interval.End;

                TextFile ts = new TextFile(file);
                ts.OpenNewToWrite();

                string toSave;

                //Save TimeSeries Header
                ts.WriteLines(extraLines);
                ts.WriteLine("SERIE_INITIAL_DATA : " + startInstant.ToString("yyyy M d H m s"));
                ts.WriteLine("TIME_UNITS : " + timeUnits.ToString());
                toSave = timeUnits.ToString();
                foreach(int col in columnsToSave)
                   toSave += " " + dataColumns[col].Header;
                ts.WriteLine(toSave);

                //Save Data
                ts.WriteLine("<BeginTimeSerie>");
                for (int row = interval.Start; row <= endRow; row++)
                {
                   toSave = ((double)instants[row]).ToString(instants.DataFormat);
                   //Save the columns to file
                   foreach (int col in columnsToSave)
                  toSave += " " + string.Format("{0" + dataColumns[col].DataFormat + "}", dataColumns[col][row]);
                   ts.WriteLine(toSave);
                }
                ts.WriteLine("<EndTimeSerie>");

                ts.Close();
            }
        private void ExportByFolderList(ExportHDFToTSOptions opts, DoWorkEventArgs e)
        {
            string config_name = "";
             TextFile cfg = new TextFile();
             ExternalApp app = new ExternalApp();
             List<TimeSeries> outputTS = new List<TimeSeries>();
             bool first = true;

             System.IO.SearchOption so;
             FileName file = new FileName();
             FilePath path = new FilePath();
             List<Mohid.Files.FileInfo> files = new List<Mohid.Files.FileInfo>();

             if (opts.SearchSubFolders)
            so = System.IO.SearchOption.AllDirectories;
             else
            so = System.IO.SearchOption.TopDirectoryOnly;

             foreach (string folder in opts.List)
             {
            path.Path = folder;
            FileTools.FindFiles(ref files, path, Path.GetFileName(opts.File), false, null, so);
             }

             int totalFiles = files.Count;
             int filesProcessed = 0;

             foreach (Mohid.Files.FileInfo fi in files)
             {
            //Find a file name for the configuration file.
            if (this.CancellationPending)
            {
               return;
            }

            bool Found = false;
            int n = 1;
            int tentatives = 0;
            while (!Found)
            {
               config_name = opts.ConfigFile + n + ".cfg";
               if (System.IO.File.Exists(opts.WorkingFolder + config_name))
               {
                  n++;
               }
               else
               {
                  try
                  {
                     cfg.File.FullPath = opts.WorkingFolder + config_name;
                     cfg.OpenNewToWrite();
                     Found = true;
                  }
                  catch
                  {
                     n++;
                     tentatives++;

                     if (tentatives > 20)
                     {
                        MessageBox.Show("Was not possibe to create the configuration file to the HDFExporter tool.", "ATTENTION", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                     }
                  }
               }
            }

            //Create the Config Data File
            cfg.WriteLine("!File created using Mohid Toolbox");

            file.FullPath = fi.FileName.FullPath;
            cfg.WriteLine("<BeginHDF5File>");
            cfg.WriteLine("  NAME : " + file.FullPath);
            cfg.WriteLine("<EndHDF5File>");

            if (opts.Type == ExportHDFToTSType.ByMask) //by Mask
            {
               cfg.WriteLine("EXPORT_TYPE       : 2");
               cfg.WriteLine("MASK_GRID         : " + opts.MaskFile);
               cfg.WriteLine("AREA_FILL_VALUE   : " + opts.AreaFillValue);
               if (opts.UsePoints)
               {
                  cfg.WriteLine("USE_POINTS        : 1");
                  cfg.WriteLine("WATERPOINTS_NAME  : " + opts.PointsName);
                  cfg.WriteLine("WATERPOINTS_GROUP : " + opts.PointsGroup);
               }
               else
                  cfg.WriteLine("USE_POINTS        : 0");
            }
            else //By coordinates
            {
               cfg.WriteLine("EXPORT_TYPE       : 1");
               cfg.WriteLine("WATERPOINTS_NAME  : " + opts.PointsName);
               cfg.WriteLine("WATERPOINTS_GROUP : " + opts.PointsGroup);
            }

            if (opts.CheckPropertyName)
               cfg.WriteLine("CHECK_PROPERTY    : 1");
            else
               cfg.WriteLine("CHECK_PROPERTY    : 0");

            if (opts.UseStart)
               cfg.WriteLine("START_TIME        : " + opts.Start.ToString("yyyy MM dd HH mm ss"));
            if (opts.UseEnd)
               cfg.WriteLine("END_TIME          : " + opts.End.ToString("yyyy MM dd HH mm ss"));

            if (opts.Variable)
               cfg.WriteLine("VARIABLE_GRID     : 1");
            else
               cfg.WriteLine("VARIABLE_GRID     : 0");

            if (!string.IsNullOrWhiteSpace(opts.GridFile))
               cfg.WriteLine("GRID_FILENAME     : " + opts.GridFile);

            if (!string.IsNullOrWhiteSpace(opts.TimeGroup))
               cfg.WriteLine("TIME_GROUP        : " + opts.TimeGroup);

            if (!string.IsNullOrWhiteSpace(opts.DecimationFactor))
               cfg.WriteLine("DECIMATION_FACTOR : " + opts.DecimationFactor);

            foreach (TimeseriesBlock ts in opts.TimeSeries)
            {
               cfg.WriteLine("<BeginTimeSerie>");

               if (opts.Type == ExportHDFToTSType.ByMask) //by Mask
               {
                  cfg.WriteLine("  NAME              : " + file.Path + ts.Name);
                  if (!string.IsNullOrWhiteSpace(ts.MaskID))
                     cfg.WriteLine("  MASK_ID           : " + ts.MaskID);
                  if (!string.IsNullOrWhiteSpace(ts.Layer))
                     cfg.WriteLine("  LAYER             : " + ts.Layer);
               }
               else
               {
                  cfg.WriteLine("  NAME              : " + file.Path + ts.Name);
                  if (!string.IsNullOrWhiteSpace(ts.I))
                     cfg.WriteLine("  LOCALIZATION_I    : " + ts.I);
                  if (!string.IsNullOrWhiteSpace(ts.J))
                     cfg.WriteLine("  LOCALIZATION_J    : " + ts.J);
                  if (!string.IsNullOrWhiteSpace(ts.K))
                     cfg.WriteLine("  LOCALIZATION_J    : " + ts.K);
                  if (!string.IsNullOrWhiteSpace(ts.Latitude))
                     cfg.WriteLine("  LATITUDE          : " + ts.Latitude);
                  if (!string.IsNullOrWhiteSpace(ts.Longitude))
                     cfg.WriteLine("  LONGITUDE         : " + ts.Longitude);
                  if (!string.IsNullOrWhiteSpace(ts.X))
                     cfg.WriteLine("  COORD_X           : " + ts.X);
                  if (!string.IsNullOrWhiteSpace(ts.Y))
                     cfg.WriteLine("  COORD_Y           : " + ts.Y);
               }
               cfg.WriteLine("<EndTimeSerie>");
            }

            foreach (ParameterBlock p in opts.Parameters)
            {
               cfg.WriteLine("<BeginParameter>");
               cfg.WriteLine("  PROPERTY          : " + p.Name);
               cfg.WriteLine("  HDF_GROUP         : " + p.Group);
               cfg.WriteLine("<EndParameter>");
            }
            cfg.Close();

            //run HDFExporter Tool
            app.Executable = opts.PathToHDFExporter;
            app.UseShell = false;
            app.WorkingDirectory = opts.WorkingFolder;
            app.Arguments = "-c " + config_name;
            app.CheckSuccessMethod = CheckSuccessMethod.DEFAULTOUTPUT;
            app.TextToCheck = "successfully terminated";
            app.Verbose = false;
            app.Wait = true;
            app.SearchTextOrder = SearchTextOrder.FROMEND;

            AppExitStatus es;

            if ((es = app.Run(this, e)) != AppExitStatus.Finished)
            {
               if (es != AppExitStatus.Canceled)
                  MessageBox.Show("HDFExporter tool has failed.", "ATTENTION", MessageBoxButtons.OK, MessageBoxIcon.Error);
               return;
            }

            if (!opts.KeepConfigFile)
            {
               try
               {
                  System.IO.File.Delete(opts.WorkingFolder + config_name);
               }
               catch
               {
               }
            }

            if (opts.JoinTimeseries)
            {
               if (first)
               {
                  foreach (TimeseriesBlock tsb in opts.TimeSeries)
                  {
                     TimeSeries new_ts = new TimeSeries();
                     new_ts.Load(new FileName(file.Path + tsb.Name + ".ets"));
                     new_ts.Name = tsb.Name + ".ets";
                     outputTS.Add(new_ts);
                  }

                  first = false;
               }
               else
               {
                  int count = 0;
                  foreach (TimeseriesBlock tsb in opts.TimeSeries)
                  {
                     TimeSeries new_ts = new TimeSeries();
                     new_ts.Load(new FileName(file.Path + tsb.Name + ".ets"));
                     TimeSeries this_ts = outputTS[count];
                     this_ts.AddTimeSeries(new_ts);
                     new_ts = null;
                     if (!opts.KeepIntermediateTSFiles)
                     {
                        try
                        {
                           System.IO.File.Delete(file.Path + tsb.Name + ".ets");
                        }
                        catch
                        {
                        }
                     }
                     count++;
                  }
               }
            }

            if (this.WorkerReportsProgress)
            {
               filesProcessed++;
               int percentComplete = (int)((float)filesProcessed / (float)totalFiles * 100);
               this.ReportProgress(percentComplete);
            }
             }

             if (opts.JoinTimeseries)
             {
            foreach (TimeSeries ts in outputTS)
            {
               ts.Save(new FileName(new FilePath(opts.PathToOutputTimeSeries).Path + ts.Name + ".ets"));
            }
             }
        }
Пример #14
0
        public void Execute(string ReportTitle, bool StyleDetail, int ReportStyleIndex, string[] Fields, string[] Counters)
        {
            bool   PossuiTot    = false;
            String sCols        = "";
            String sColsRep     = "";
            String sColsRepForm = "";
            String sColsTot     = "";

            //String sLines = "";

            for (int i = 0; i < Fields.Length; i++)
            {
                String xCssS = "class='sum'";
                String xCssT = "class='tit'";
                String xCss  = "";

                SqlWebReport.FieldType ft = SqlWebReport.SwrUtility.GetFieldType(Table.Columns[Fields[i]].DataType);

                #region [formata xCssT, xCss e xCssS]
                #region if (ft == enmFieldType.Int || ft == enmFieldType.Decimal)
                if (ft == SqlWebReport.FieldType.Int || ft == SqlWebReport.FieldType.Decimal)
                {
                    if (StyleDetail)
                    {
                        xCssS = "class='sum vlr'";
                        xCssT = "class='tit vlr'";
                        xCss  = "class='vlr'";
                    }
                    else
                    {
                        xCssS = "class='sum'";
                        xCssT = "class='tit'";
                        xCss  = "class='vlr'";
                    }
                }
                #endregion
                #region else if (ft == enmFieldType.Date || ft == enmFieldType.Time || ft == enmFieldType.DateTime || ft == enmFieldType.Bool)
                else if (ft == SqlWebReport.FieldType.Date || ft == SqlWebReport.FieldType.Time || ft == SqlWebReport.FieldType.DateTime || ft == SqlWebReport.FieldType.Bool)
                {
                    if (StyleDetail)
                    {
                        xCssS = "class='sum cen'";
                        xCssT = "class='tit cen'";
                        xCss  = "class='cen'";
                    }
                    else
                    {
                        xCssS = "class='sum'";
                        xCssT = "class='tit'";
                        xCss  = "class='vlr'";
                    }
                }
                #endregion
                #endregion

                #region Cria linhas dos totais
                if (Utility.ItemInList(Fields[i], Counters))
                {
                    PossuiTot     = true;
                    sCols        += "      <?$T_" + Fields[i] + ".mov(0)?>\n";
                    sColsRep     += "      <?$T_" + Fields[i] + ".add(D." + Fields[i] + ")?>\n";
                    sColsRepForm += "      <?$T_" + Fields[i] + ".add(D." + Fields[i] + ")?>\n";
                    sColsTot     += "      <td " + xCssS + "><?$T_" + Fields[i] + ".format(\"#,##0.00\")?></td>\n";
                }
                else
                {
                    sColsTot += "      <td " + xCssS + ">&nbsp;</td>\n";
                }
                #endregion

                #region Cria colunas e linhas para os modelos detail e form
                sCols        += string.Format("      <td {0}>{1}</td>\n", xCssT, Fields[i]);
                sColsRep     += string.Format("      <td {0}><?{1}?></td>\n", xCss, GetFieldValue(Fields[i], ft));
                sColsRepForm += string.Format("    <tr><td {0}>{1}</td><td {2}><?{3}?></td></tr>\n", xCssT, Fields[i], xCss, GetFieldValue(Fields[i], ft));
                #endregion
            }

            string sql = LastSqlQuery;
            sql = sql.Replace("\n", "\n      ");
            String lnTot = "";

            if (PossuiTot)
            {
                if (StyleDetail)
                {
                    lnTot =
                        "  <!-- Rodapé do Relatório -->\n" +
                        "    <tr><td>&nbsp;</td></tr>\n" +
                        "    <tr>\n" + sColsTot +
                        "    </tr>\n";
                }
                else
                {
                    lnTot =
                        "  <!-- Rodapé do Relatório -->\n" +
                        "    <tr><td>&nbsp;</td></tr>\n" +
                        "    <tr><td class='sum'>Total</td>\n" + sColsTot +
                        "    </tr>\n";
                }
            }

            String lnCols    = "";
            String lnColsRep = "";

            if (StyleDetail)
            {
                lnCols = "    <tr>\n" + sCols + "    </tr>\n";
            }

            if (StyleDetail)
            {
                lnColsRep = "    <tr>\n" + sColsRep + "    </tr>\n";
            }
            else
            {
                lnColsRep = "    <tr><td><br /></td></tr>\n" + sColsRepForm;
            }

            String strCode =
                "<?\n" +
                "  $sc = \"" + db.ConnectionString + "\";\n" +
                "  connection.add(\"Database\",\"" + db.ConnectionType.ToString() + "\",$sc);\n" +
                "  D.new(\"Database\");\n" +
                "  D.sql(\n      \"" + sql + "\"\n  );\n" +
                "?>\n" +
                "<?band1?>\n" +
                "  <style type=\"text/css\" media=\"screen\">\n" +
                "    body\n" +
                "    {\n" +
                "      background-color:#aaa;\n" +
                "      padding:20px 20px 0 20px;\n" +
                "    }\n" +
                "    .page\n" +
                "    {\n" +
                "      background-color:White;\n" +
                "      border:1px solid #777;\n" +
                "      padding:60px 40px 40px 60px;\n" +
                "    }\n" +
                "  </style>\n" +
                "  <style type=\"text/css\" media=\"all\">\n" +
                ReportStyleList[ReportStyleIndex].Style +
                "  </style>\n\n" +
                "<div class='page'>\n" +
                "  <!-- Cabeçalho do Relatório -->\n" +
                "  <h1>" + ReportTitle + "</h1>\n" +
                "  <p>Emissao : <?sys.now()?></p>\n" +
                "  <table>\n" +
                lnCols +
                "  <!-- Conteúdo do Relatório -->\n" +
                "<?band2:band1?>\n" +
                "  <?band.dst(D)?>\n" +
                lnColsRep +
                "<?endband1?>\n" +
                lnTot +
                "  </table>\n" +
                "</div>";

            if (System.IO.File.Exists(ReportFile))
            {
                System.IO.File.Delete(ReportFile);
            }

            TextFile tf = new TextFile();
            tf.Open(enmOpenMode.Writing, ReportFile);
            tf.Write(strCode);
            tf.Close();

            SqlWebReport.SwrReport sr = new SqlWebReport.SwrReport();
            sr.AddConnection(new SqlWebReport.ItemConnection("Database", db));
            SwrForms.Report.ShowReport(sr, ReportFile, new List <SqlWebReport.ParamQuery>());
        }
Пример #15
0
            public void Load(FileName file)
            {
                string line;
                string[] seps = new string[1];
                string[] tokens;
                string[] header;

                TextFile ts = new TextFile(file);
                ts.OpenToRead();

                try
                {
                   dataColumns.Clear();
                   extraLines.Clear();
                   instants.Clear();

                   //Find Header and columns
                   while ((line = ts.ReadLine()) != null)
                   {
                  line = line.Trim();

                  if (line == "") continue;
                  if (line[0] == '!')
                  {
                     extraLines.Add(line);
                     continue;
                  }

                  seps[0] = ":";
                  tokens = line.Split(seps, 2, StringSplitOptions.RemoveEmptyEntries);

                  if (tokens[0].Trim() == "SERIE_INITIAL_DATA")
                  {
                     string[] tseps = { ".", " " };
                     string[] ttokens = tokens[1].Trim().Split(tseps, StringSplitOptions.RemoveEmptyEntries);
                     startInstant = new DateTime((int)float.Parse(ttokens[0]),
                                                 (int)float.Parse(ttokens[1]),
                                                 (int)float.Parse(ttokens[2]),
                                                 (int)float.Parse(ttokens[3]),
                                                 (int)float.Parse(ttokens[4]),
                                                 (int)float.Parse(ttokens[5])); //DateTime.ParseExact(temp, "yyyy M d H m s", null);
                  }
                  else if (tokens[0].Trim() == "TIME_UNITS")
                  {
                     timeUnits = (TimeUnits)Enum.Parse(typeof(TimeUnits), tokens[1].Trim(), true);
                  }
                  else
                  {
                     seps[0] = " ";
                     tokens = line.Trim().Split(seps, StringSplitOptions.RemoveEmptyEntries);

                     if (tokens[0].Trim() == "<BeginTimeSerie>")
                     {
                        if (extraLines.Count < 1)
                        {
                           ts.Close();
                           throw new Exception("The '" + file.FullName + "' is not a valid time series");
                        }

                        header = extraLines.Last().Trim().Split(seps, StringSplitOptions.RemoveEmptyEntries);
                        instants.Header = header[0];

                        for (int i = 1; i < header.Length; i++)
                        {
                           Column column = new Column();
                           dataColumns.Add(column);
                           column.Header = header[i];
                        }

                        extraLines.Remove(extraLines.Last());
                        break;
                     }
                     else if (tokens[0].Trim() == "<BeginResidual>")
                     {
                        while ((line = ts.ReadLine()) != null)
                        {
                           if (line.Trim() == "<EndResidual>")
                              break;
                        }

                        if (line == null)
                           throw new Exception("Invalid TimeSeries file.");
                     }
                     else
                     {
                        extraLines.Add(line);
                     }
                  }
                   }

                   int index;
                   seps[0] = " ";

                   line = ts.ReadLine();
                   if (line == null)
                  throw new Exception ("Invalid TimeSeries file.");

                   tokens = line.Trim().Split(seps, StringSplitOptions.RemoveEmptyEntries);
                   if (tokens == null)
                  throw new Exception("Invalid TimeSeries file.");

                   index = AddInstant(double.Parse(tokens[0], CultureInfo.InvariantCulture));

                   for (int i = 1; i < tokens.Length; i++)
                   {
                  dataColumns[i - 1].ColumnType = GetColumnType(tokens[i]);

                  if (dataColumns[i - 1].ColumnType == typeof(double))
                     dataColumns[i - 1][index] = double.Parse(tokens[i], CultureInfo.InvariantCulture);
                  else
                     dataColumns[i - 1][index] = tokens[i];
                   }

                   while ((line = ts.ReadLine()) != null)
                   {
                  //line = ts.ReadLine();
                  if (line == null)
                     throw new Exception("Invalid TimeSeries file.");

                  tokens = line.Trim().Split(seps, StringSplitOptions.RemoveEmptyEntries);

                  if (tokens == null)
                     throw new Exception("Invalid TimeSeries file.");

                  if (tokens[0][0] == '<')
                     break;
                  else
                  {
                     index = AddInstant(double.Parse(tokens[0], CultureInfo.InvariantCulture));

                     for (int i = 1; i < tokens.Length; i++)
                        if (dataColumns[i - 1].ColumnType == typeof(double))
                           dataColumns[i - 1][index] = double.Parse(tokens[i], CultureInfo.InvariantCulture);
                        else
                           dataColumns[i - 1][index] = tokens[i];
                  }
                   }

                   while ((line = ts.ReadLine()) != null)
                  extraLines.Add(line);

                   ts.Close();
                }
                catch
                {
                   ts.Close();
                   throw;
                }
            }
Пример #16
0
            private string LoadCSharpScript(FileName scriptFileName)
            {
                TextFile scriptFile;

                try
                {
                   scriptFile = new TextFile(scriptFileName);
                }
                catch (Exception ex)
                {
                   throw new Exception ("Error when creating script text object. " + ex.Message);
                }

                try
                {
                   scriptFile.OpenToRead();
                }
                catch (Exception ex)
                {
                   throw new Exception("Error when opening script file. " + ex.Message);
                }

                List<string> script = scriptFile.ReadLines();

                int lineNumber = 0;
                string line;
                string[] dllName;
                string[] seps = { ":" };

                for (lineNumber = 0; lineNumber < script.Count; lineNumber++)
                {
                   line = script[lineNumber].Trim();
                   if (line == "") continue;

                   if (line.StartsWith("//DLLNAME:"))
                   {
                  dllName = line.Split(seps, StringSplitOptions.RemoveEmptyEntries);
                  if (!dllName[1].Trim().EndsWith(".dll"))
                     dllName[1] = dllName[1].Trim() + ".dll";

                  dllList.Add(dllName[1].Trim());
                   }
                }

                StringBuilder temp = new StringBuilder();
                for (lineNumber = 0; lineNumber < script.Count; lineNumber++)
                   temp.AppendLine(script[lineNumber]);

                scriptFile.Close();

                Console.WriteLine("Finished reading script file.");

                return temp.ToString();
            }
Пример #17
0
            public static int Replace(string old_file, string new_file, ref Dictionary<string, string> replace_list, bool warning_on_exception = true)
            {
                try
                {
                   TextFile input = null;
                   TextFile output = null;
                   int NumberOfChanges = 0;

                   input = new TextFile(old_file);
                   output = new TextFile(new_file);

                   input.Open(FileMode.Open, FileAccess.Read, FileShare.Read);
                   output.Open(FileMode.Create, FileAccess.Write, FileShare.None);

                   string line = "";
                   string new_line = "";

                   line = input.ReadLine();

                   while (line != null)
                   {
                  foreach (KeyValuePair<string, string> keyPair in replace_list)
                  {
                     new_line = line.Replace(keyPair.Key, replace_list[keyPair.Key]);
                     if (new_line != line) NumberOfChanges++;
                     line = new_line;
                  }

                  output.WriteLine(line);
                  line = input.ReadLine();
                   }

                   input.Close();
                   output.Close();

                   return NumberOfChanges;
                }
                catch (Exception ex)
                {
                   if (warning_on_exception)
                   {
                  Console.WriteLine();
                  while (ex != null)
                  {
                     Console.WriteLine("=> {0}", ex.Message);
                     ex = ex.InnerException;
                  }
                  Console.WriteLine();
                   }

                   return -1;
                }
            }
Пример #18
0
        static void Main(string[] args)
        {
            DateTime start, end;
             FilePath rootResultsPath;
             FileName hdfResultsFile;
             List<FilePath> timeseriesOutputPath = new List<FilePath>();
             FileName exporterEXE;
             FilePath exporterWorkingPath;
             bool joinTimeseries = false;
             bool useDateOnTimeseriesName = true;
             string folderFormat, startFormat, endFormat;
             StringBuilder exporterCFGBase = new StringBuilder();
             StringBuilder exporterCFG = new StringBuilder();
             List<ConfigNode> nodes;
             double runLenght;
             bool verbose;
             List<FileInfo> tsFileInfoList = new List<FileInfo>();
             Dictionary<string, TimeSeries> outTS = new Dictionary<string,TimeSeries>();
             TimeSeries newTS = new TimeSeries();
             TextFile txtFile, errors;
             int timeseriesSaveCounter = 1, saveCounter;
             int timeseriesNameCounter;
             errors = new TextFile("errors.log");
             errors.OpenNewToWrite();
             verbose = true;
             FilePath path;
             bool dateAndTimeInOutputFolder;
             string outputFolderFormat = "", outputFolderStartFormat = "", outputFolderEndFormat = "", outputPath, outputPath2;
             bool useCounter;

             try
             {
            CmdArgs cmdArgs = new CmdArgs(args);

            if (cmdArgs.HasOption("v"))
               verbose = true;
            else
               verbose = false;

            if (cmdArgs.HasParameter("cfg"))
            {
               if (verbose)
                  Console.Write("Reading configuration file...");

               Config conf = new Config(cmdArgs.Parameters["cfg"]);
               conf.Load();

               if (verbose)
                  Console.WriteLine("[OK]");

               if (verbose)
                  Console.Write("Looking for 'timeseries.to.extract' blocks...");

               List<ConfigNode> tsList = conf.Root.ChildNodes.FindAll(delegate(ConfigNode node) { return node.Name == "timeseries.to.extract"; });

               if (tsList == null || tsList.Count <= 0)
                  throw new Exception("No 'timeseries.to.extract' block found in configuration file.");

               if (verbose)
               {
                  Console.WriteLine("[OK]");
                  Console.WriteLine("{0} 'timeseries.to.extract' block(s) found.", tsList.Count);
               }

               dateAndTimeInOutputFolder = conf.Root["user.def.output.folder", false].AsBool();
               if (dateAndTimeInOutputFolder)
               {
                   outputFolderFormat = conf.Root["user.def.output.folder.format", "start-end"].AsString();
                   outputFolderStartFormat = conf.Root["user.def.output.start.format", "yyyyMMddHH"].AsString();
                   outputFolderEndFormat = conf.Root["user.def.output.end.format", "yyyyMMddHH"].AsString();
               }

               int tscCount = 1;
               foreach (ConfigNode tsc in tsList)
               {
                  timeseriesNameCounter = 1;

                  if (verbose)
                     Console.Write("Processing 'timeseries.to.extract' block {0}...", tscCount);

                  start                   = tsc["start"].AsDateTime();
                  end                     = tsc["end"].AsDateTime();
                  rootResultsPath         = tsc["root.results.path", @".\"].AsFilePath();
                  hdfResultsFile          = tsc["hdf.results.file"].AsFileName();
                  if (tsc.Contains("backup_path"))
                  {
                      path = tsc["backup_path"].AsFilePath();
                      timeseriesOutputPath.Add(path);
                  }
                  if (tsc.Contains("storage_path"))
                  {
                      path = tsc["storage_path"].AsFilePath();
                      timeseriesOutputPath.Add(path);
                  }
                  if (tsc.Contains("publish_path"))
                  {
                      path = tsc["publish_path"].AsFilePath();
                      timeseriesOutputPath.Add(path);
                  }

                  if (timeseriesOutputPath.Count <= 0)
                  {
                      throw new Exception("An error was found in the configuration file. Missing keyword." + "At least ONE of the following keywords must be provided:" +
                                          "BACKUP_PATH, STORAGE_PATH, PUBLISH_PATH");
                  }
                  exporterEXE             = tsc["exporter.exe"].AsFileName();
                  exporterWorkingPath     = tsc["exporter.working.path"].AsFilePath();
                  joinTimeseries          = tsc["join.timeseries", true].AsBool();
                  if (joinTimeseries && dateAndTimeInOutputFolder)
                  {
                      throw new Exception("join.timeseries can't be used with user.def.output.folder");
                  }
                  folderFormat            = tsc["folder.format", "start-end"].AsString();
                  startFormat             = tsc["start.format", "yyyyMMddHH"].AsString();
                  endFormat               = tsc["end.format", "yyyyMMddHH"].AsString();
                  runLenght               = tsc["run.lenght"].AsDouble();
                  useCounter              = tsc["use.counter.on.names", false].AsBool();

                  if (joinTimeseries)
                  {
                     outTS = new Dictionary<string, TimeSeries>();
                     newTS = new TimeSeries();

                     timeseriesSaveCounter = tsc["save.counter"].AsInt();
                  }
                  else
                  {
                     useDateOnTimeseriesName = tsc["use.date.on.timeseries.name", true].AsBool();
                  }

                  exporterCFGBase.Append("EXPORT_TYPE      : "); exporterCFGBase.AppendLine(tsc["export.type", 1].AsString());
                  exporterCFGBase.Append("COMPUTE_RESIDUAL : "); exporterCFGBase.AppendLine(tsc["compute.residual", 0].AsString());
                  exporterCFGBase.Append("VARIABLE_GRID    : "); exporterCFGBase.AppendLine(tsc["variable.grid", 0].AsString());
                  exporterCFGBase.Append("WATERPOINTS_NAME : "); exporterCFGBase.AppendLine(tsc["points.name", "WaterPoints2D"].AsString());
                  exporterCFGBase.Append("GRID_FILENAME    : "); exporterCFGBase.AppendLine(tsc["grid.file.name", "grid.dat"].AsString());

                  nodes = tsc.ChildNodes.FindAll(delegate(ConfigNode node) { return node.Name == "timeseries"; });

                  if (nodes == null || nodes.Count <= 0)
                     throw new Exception("No 'timeseries' block found in configuration file.");

                  foreach (ConfigNode param in nodes)
                  {
                     exporterCFGBase.AppendLine();
                     exporterCFGBase.AppendLine("<BeginTimeSerie>");
                     exporterCFGBase.Append("  NAME            : "); exporterCFGBase.AppendLine(param["name"].AsString());

                     if (param.NodeData.ContainsKey("coord.y"))
                     {
                        exporterCFGBase.Append("  COORD_Y        : ");
                        exporterCFGBase.AppendLine(param["coord.y"].AsString());
                     }
                     if (param.NodeData.ContainsKey("coord.x"))
                     {
                        exporterCFGBase.Append("  COORD_X        : ");
                        exporterCFGBase.AppendLine(param["coord.x"].AsString());
                     }
                     if (param.NodeData.ContainsKey("depth.level"))
                     {
                        exporterCFGBase.Append("  DEPTH_LEVEL    : ");
                        exporterCFGBase.AppendLine(param["depth.level"].AsString());
                     }
                     if (param.NodeData.ContainsKey("localization.i"))
                     {
                        exporterCFGBase.Append("  LOCALIZATION_I : ");
                        exporterCFGBase.AppendLine(param["localization.i"].AsString());
                     }
                     if (param.NodeData.ContainsKey("localization.j"))
                     {
                        exporterCFGBase.Append("  LOCALIZATION_J : ");
                        exporterCFGBase.AppendLine(param["localization.j"].AsString());
                     }
                     if (param.NodeData.ContainsKey("localization.k"))
                     {
                        exporterCFGBase.Append("  LOCALIZATION_K : ");
                        exporterCFGBase.AppendLine(param["localization.k"].AsString());
                     }
                     if (param.NodeData.ContainsKey("latitude"))
                     {
                        exporterCFGBase.Append("  LATITUDE       : ");
                        exporterCFGBase.AppendLine(param["latitude"].AsString());
                     }
                     if (param.NodeData.ContainsKey("longitude"))
                     {
                        exporterCFGBase.Append("  LONGITUDE      : ");
                        exporterCFGBase.AppendLine(param["longitude"].AsString());
                     }

                     exporterCFGBase.AppendLine("<EndTimeSerie>");

                     if (joinTimeseries)
                     {
                        outTS[param["name"].AsString()] = new TimeSeries();
                     }
                  }

                  nodes = tsc.ChildNodes.FindAll(delegate(ConfigNode node) { return node.Name == "parameter"; });

                  if (nodes == null || nodes.Count <= 0)
                     throw new Exception("No 'parameter' block found in configuration file.");

                  foreach (ConfigNode param in nodes)
                  {
                     exporterCFGBase.AppendLine();
                     exporterCFGBase.AppendLine("<BeginParameter>");
                     exporterCFGBase.Append("  HDF_GROUP : "); exporterCFGBase.AppendLine(param["hdf.group"].AsString());
                     exporterCFGBase.Append("  PROPERTY  : "); exporterCFGBase.AppendLine(param["hdf.property"].AsString());
                     exporterCFGBase.AppendLine("<EndParameter>");
                  }

                  txtFile = new TextFile(exporterWorkingPath.Path + "nomfich.dat");
                  txtFile.OpenNewToWrite();
                  txtFile.WriteLine("IN_MODEL : hdfexporter.dat");
                  txtFile.Close();

                  ExternalApp hdf5exporter = new ExternalApp();
                  hdf5exporter.CheckSuccessMethod = CheckSuccessMethod.DEFAULTOUTPUT;
                  hdf5exporter.TextToCheck = "Program HDF5Exporter successfully terminated";
                  hdf5exporter.Wait = true;
                  hdf5exporter.WorkingDirectory = exporterWorkingPath.Path;
                  hdf5exporter.Executable = exporterEXE.FullPath;

                  bool fail;
                  DateTime actual = start;
                  FilePath hdfResultsPath = new FilePath();
                  saveCounter = 1;
                  while (actual.AddDays(runLenght) <= end)
                  {
                     fail = false;

                     hdfResultsPath.Path = rootResultsPath.Path +
                           (folderFormat.Replace("start", actual.ToString(startFormat)).Replace("end", actual.AddDays(runLenght).ToString(endFormat)));

                     if (System.IO.Directory.Exists(hdfResultsPath.Path))
                     {

                        exporterCFG.Clear();
                        exporterCFG.Append("START_TIME : "); exporterCFG.AppendLine(actual.ToString("yyyy M d H m s"));
                        exporterCFG.Append("END_TIME : "); exporterCFG.AppendLine(actual.AddDays(runLenght).ToString("yyyy M d H m s"));
                        exporterCFG.AppendLine();
                        exporterCFG.AppendLine("<BeginHDF5File>");
                        exporterCFG.Append("  NAME : "); exporterCFG.AppendLine(hdfResultsPath.Path + hdfResultsFile.FullName);
                        exporterCFG.AppendLine("<EndHDF5File>");

                        txtFile.File.FullPath = exporterWorkingPath.Path + "hdfexporter.dat";
                        txtFile.OpenNewToWrite();
                        txtFile.Write(exporterCFGBase.ToString());
                        txtFile.Write(exporterCFG.ToString());
                        txtFile.Close();

                        try
                        {
                           bool res = hdf5exporter.Run();
                           if (!res)
                           {
                              throw new Exception("Unsuccessfull HDF5Exporter run");
                           }
                        }
                        catch (Exception e_run)
                        {
                           errors.WriteLine("[" + DateTime.Now.ToString() + "] HDF5Exporter Run Exception when processing '" + hdfResultsFile + "' on results folder '" + hdfResultsPath.Path + "'");
                           errors.WriteLine("[" + DateTime.Now.ToString() + "] The exception returned this message: " + e_run.Message);
                           fail = true;
                        }

                        if (!fail)
                        {
                           FileTools.FindFiles(ref tsFileInfoList, exporterWorkingPath, "*.ets", true, "", System.IO.SearchOption.TopDirectoryOnly);

                           if (joinTimeseries)
                           {
                              foreach (FileInfo file in tsFileInfoList)
                              {
                                 if (outTS[file.FileName.Name].NumberOfInstants > 0)
                                 {
                                    saveCounter++;

                                    try
                                    {
                                       newTS.Load(file.FileName);
                                       outTS[file.FileName.Name].AddTimeSeries(newTS);
                                    }
                                    catch
                                    {
                                       errors.WriteLine("[" + DateTime.Now.ToString() + "] Was not possible to read timeseries '" + file.FileName.FullName + "' from HDF file '" + hdfResultsFile + "' on results folder '" + hdfResultsPath.Path + "'");
                                    }

                                    System.IO.File.Delete(file.FileName.FullPath);

                                    if (saveCounter > timeseriesSaveCounter)
                                    {
                                       try
                                       {
                                           if (dateAndTimeInOutputFolder)
                                           {
                                               outputPath = timeseriesOutputPath[0].Path +
                                                   (outputFolderFormat.Replace("start", actual.ToString(outputFolderStartFormat)).Replace("end", actual.AddDays(runLenght).ToString(outputFolderEndFormat))) + System.IO.Path.DirectorySeparatorChar;
                                           }
                                           else
                                           {
                                               outputPath = timeseriesOutputPath[0].Path;
                                           }
                                           if (!System.IO.Directory.Exists(outputPath))
                                               System.IO.Directory.CreateDirectory(outputPath);

                                          outTS[file.FileName.Name].Save(new FileName(outputPath + file.FileName.FullName));
                                          saveCounter = 1;
                                          if (timeseriesOutputPath.Count > 1)
                                          {
                                              for (int i = 1; i < timeseriesOutputPath.Count; i++)
                                              {
                                                  outputPath2 = timeseriesOutputPath[i].Path +
                                                   (outputFolderFormat.Replace("start", actual.ToString(outputFolderStartFormat)).Replace("end", actual.AddDays(runLenght).ToString(outputFolderEndFormat))) + System.IO.Path.DirectorySeparatorChar;
                                                  if (!System.IO.Directory.Exists(outputPath2))
                                                      System.IO.Directory.CreateDirectory(outputPath2);
                                                  FileTools.CopyFile(new FileName(outputPath + file.FileName.FullName),
                                                                     new FileName(outputPath2 + file.FileName.FullName), CopyOptions.OVERWRIGHT);
                                              }
                                          }

                                       }
                                       catch (Exception ex)
                                       {
                                          errors.WriteLine("[" + DateTime.Now.ToString() + "] Was not possible to save joined timeseries '" + file.FileName.FullName + "' from HDF file '" + hdfResultsFile + "' when processing results folder '" + hdfResultsPath.Path + "'");
                                          errors.WriteLine("[" + DateTime.Now.ToString() + "] The exception returned this message: " + ex.Message);
                                       }
                                    }
                                 }
                                 else
                                 {
                                    outTS[file.FileName.Name].Load(file.FileName);
                                    System.IO.File.Delete(file.FileName.FullPath);
                                 }
                              }
                           }
                           else
                           {
                              FileName timeseriesTarget = new FileName();

                              foreach (FileInfo file in tsFileInfoList)
                              {
                                  if (dateAndTimeInOutputFolder)
                                  {
                                      outputPath = timeseriesOutputPath[0].Path +
                                          (outputFolderFormat.Replace("start", actual.ToString(outputFolderStartFormat)).Replace("end", actual.AddDays(runLenght).ToString(outputFolderEndFormat))) + System.IO.Path.DirectorySeparatorChar;
                                  }
                                  else
                                  {
                                      outputPath = timeseriesOutputPath[0].Path;
                                  }
                                  timeseriesTarget.Path = outputPath;
                                  if (!System.IO.Directory.Exists(outputPath))
                                      System.IO.Directory.CreateDirectory(outputPath);
                                  if (useDateOnTimeseriesName)
                                 {

                                    timeseriesTarget.FullName = file.FileName.FullName.Insert(file.FileName.FullName.LastIndexOf('.'), actual.ToString(startFormat) + "_" + actual.AddDays(runLenght).ToString(endFormat));
                                 }
                                  else if (useCounter)
                                  {
                                      timeseriesTarget.FullName = file.FileName.FullName.Insert(file.FileName.FullName.LastIndexOf('.'), timeseriesNameCounter.ToString());
                                      timeseriesNameCounter++;
                                  }
                                  else
                                  {
                                      timeseriesTarget.FullName = file.FileName.FullName;
                                  }
                                 FileTools.CopyFile(file.FileName, timeseriesTarget, CopyOptions.OVERWRIGHT);
                                 if (timeseriesOutputPath.Count > 1)
                                 {
                                     for (int i = 1; i < timeseriesOutputPath.Count; i++)
                                     {
                                         outputPath2 = timeseriesOutputPath[i].Path +
                                          (outputFolderFormat.Replace("start", actual.ToString(outputFolderStartFormat)).Replace("end", actual.AddDays(runLenght).ToString(outputFolderEndFormat))) + System.IO.Path.DirectorySeparatorChar;
                                         if (!System.IO.Directory.Exists(outputPath2))
                                             System.IO.Directory.CreateDirectory(outputPath2);
                                         FileTools.CopyFile(new FileName(outputPath + file.FileName.FullName),
                                                            new FileName(outputPath2 + file.FileName.FullName), CopyOptions.OVERWRIGHT);
                                     }
                                 }
                              }
                           }
                        }
                     }

                     actual = actual.AddDays(runLenght);
                  }

                  tscCount++;

                  if (joinTimeseries)
                  {
                     foreach (KeyValuePair<string, TimeSeries> pair in outTS)
                     {
                         if (dateAndTimeInOutputFolder)
                         {
                             outputPath = timeseriesOutputPath[0].Path +
                                 (outputFolderFormat.Replace("start", actual.ToString(outputFolderStartFormat)).Replace("end", actual.AddDays(runLenght).ToString(outputFolderEndFormat))) + System.IO.Path.DirectorySeparatorChar;
                         }
                         else
                         {
                             outputPath = timeseriesOutputPath[0].Path;
                         }
                         if (!System.IO.Directory.Exists(outputPath))
                             System.IO.Directory.CreateDirectory(outputPath);
                         pair.Value.Save(new FileName(outputPath + pair.Key + ".ets"));
                         for (int i = 1; i < timeseriesOutputPath.Count; i++)
                         {
                             outputPath2 = timeseriesOutputPath[i].Path +
                              (outputFolderFormat.Replace("start", actual.ToString(outputFolderStartFormat)).Replace("end", actual.AddDays(runLenght).ToString(outputFolderEndFormat))) + System.IO.Path.DirectorySeparatorChar;
                             if (!System.IO.Directory.Exists(outputPath2))
                                 System.IO.Directory.CreateDirectory(outputPath2);
                             FileTools.CopyFile(new FileName(outputPath + pair.Key + ".ets"),
                                                new FileName(outputPath2 + pair.Key + ".ets"), CopyOptions.OVERWRIGHT);
                         }
                     }
                  }

               }
            }
            Console.WriteLine("[OK]");
             }
             catch(Exception ex)
             {
            if (verbose)
            {
               Console.WriteLine("[FAIL]");
               Console.WriteLine("");
               Console.WriteLine("An EXCEPTION was raised. The message returned was:");
               Console.WriteLine(ex.Message);
            }
             }

             Console.WriteLine("GetTSFromModelResultsHDF finished.");
             errors.Close();
        }
Пример #19
0
            public void Save(FileName file)
            {
                TextFile f = new TextFile(file);

                f.OpenNewToWrite(FileShare.None);

                foreach (string line in Header)
                   f.WriteLine(line);

                int i = 0;

                if (HorizGrid != null)
                {
                   f.WriteLine("<BeginXX>");
                   for (i = 0; i < HorizGrid.XX.Count; i++)
                  f.WriteLine(HorizGrid.XX[i].ToString(DataFormat));
                   f.WriteLine("<EndXX>");
                   f.WriteLine("<BeginYY>");
                   for (i = 0; i < HorizGrid.YY.Count; i++)
                  f.WriteLine(HorizGrid.YY[i].ToString(DataFormat));
                   f.WriteLine("<EndYY>");
                }

                f.WriteLine("<BeginGridData2D>");
                for (i = 0; i < Data.Count; i++)
                   f.WriteLine(Data[i].ToString(DataFormat));
                f.WriteLine("<EndGridData2D>");
                f.Close();
            }
        bool IMohidTask.Run(ConfigNode cfg)
        {
            last_exception = null;
             this.cfg = cfg;
             bool result = true;

             if (!LoadGlobalConfig())
            return false;

             files_to_process.Clear();

             for (; ; )
             {
            if (!CreateFileList())
            {
               if (last_exception == null)
               {
                  result = true;
                  break;
               }
               else
               {
                  result = false;
                  break;
               }
            }

            if (!RunForFileList())
            {
               result = false;
               break;
            }
             }

             if (do_log && log.Length > 0)
             {
            try
            {
               if (add_date_time)
                  log_file.FullName = log_file.Name + "_" + DateTime.Now.ToString(log_dateonfile_format) + "." + log_file.Extension;

               TextFile log_f = new TextFile(log_file);
               log_f.OpenNewToWrite();

               log_f.Write(log);

               log_f.Close();
            }
            catch (Exception ex)
            {
               last_exception = ex;
               result = false;
            }
             }

             return result;
        }
Пример #21
0
        public void ExecBackup(string FileName, List <string> NaoCopiarTabelas, bool UseInsertIdentity, bool UseSquareBrackets)
        {
            try
            {
                btnGerarBackup.Enabled = false;
                btnFechar.Enabled      = false;
                grpOpcoes.Enabled      = false;

                if (System.IO.File.Exists(FileName))
                {
                    System.IO.File.Delete(FileName);
                }

                DbScript DbScript = new DbScript(Cnn, UseSquareBrackets);
                DbScript.OnScriptWriting += new lib.Database.DbScript.ScriptWriting_Handle(DbScript_ScriptWriting);
                DbScript.DbScriptTypeList.Clear();
                DbScript.DbScriptTypeList.AddRange(DbScriptTypeList.CreateItems());
                DbScript.DbScriptTypeList.Add(new DbScriptType(typeof(UInt64), "BOOLEAN", lib.Database.Drivers.enmFieldType.Bool));

                string[] TablesInOrder = DbScript.GetTablesInOrder(100);

                if (System.IO.File.Exists(ArqScript))
                {
                    System.IO.File.Copy(ArqScript, FileName);
                }

                TextFile tf = new TextFile();
                tf.Open(enmOpenMode.Writing, FileName, Encoding.UTF8);
                tf.WriteLine("");

                pbBackup.Maximum = TablesInOrder.Length * 2;
                pbBackup.Value   = 0;

                estimatedTime.Start();

                // Script de Limpeza
                for (int i = (TablesInOrder.Length - 1); i >= 0; i--)
                {
                    if ((i % 100) == 0)
                    {
                        this.Refresh();
                    }

                    pbBackup.Value += 1;
                    if (NaoCopiarTabelas.IndexOf(TablesInOrder[i].ToUpper()) == -1)
                    {
                        DbScript.SalveScriptDelete(TablesInOrder[i], tf);
                    }
                }

                tf.WriteLine(DbScript.COMMIT_COMMAND);

                // Desabilita chaves
                //for (int i = (TablesInOrder.Length - 1); i >= 0; i--)
                //{ tf.WriteLine(Cnn.GetDisableKey(TablesInOrder[i])); }

                // Script de Inserção
                for (int i = 0; i < TablesInOrder.Length; i++)
                {
                    this.Percent = (i + 1) * 100 / TablesInOrder.Length;
                    if ((i % 100) == 0)
                    {
                        this.Refresh();
                    }

                    pbBackup.Value += 1;
                    if (NaoCopiarTabelas.IndexOf(TablesInOrder[i].ToUpper()) == -1)
                    {
                        DbScript.SalveScriptInsert(TablesInOrder[i], tf, UseInsertIdentity, UseSquareBrackets);
                    }
                }

                // Habilita chaves
                //for (int i = (TablesInOrder.Length - 1); i >= 0; i--)
                //{ tf.WriteLine(Cnn.GetEnableKey(TablesInOrder[i])); }

                lblTempoEstimado.Text = "";
                tf.Close();
            }
            finally
            {
                btnGerarBackup.Enabled = true;
                btnFechar.Enabled      = true;
                grpOpcoes.Enabled      = true;
            }
        }
Пример #22
0
            public virtual bool Load()
            {
                ConfigNode n = Root;
                Dictionary<string, string> defines = new Dictionary<string, string>();
                string [] defSeps = { "=" };
                string value;

                TextFile cf = new TextFile(ConfigFile);
                cf.OpenToRead();
                bool newBlockFound = false;
                bool newArrayBlockFound = false;

                int line = 0;

                try
                {
                   List<string> lines = cf.ReadLines();

                   string toRead = "";
                   string temp;
                   string t;

                   foreach (string t_l in lines)
                   {
                  line++;

                  if ((temp = t_l.Trim()) == "")
                     continue;
                  else if (temp.EndsWith(" _"))
                  {
                     toRead += temp.Substring(0, temp.Length - 2);
                     continue;
                  }
                  else if(temp == "{")
                  {
                     if (newBlockFound)
                     {
                        newBlockFound = false;
                        continue;
                     }
                     else if (newArrayBlockFound)
                     {
                        newArrayBlockFound = false;
                        continue;
                     }
                     else
                     {
                        throw new Exception("Found unexpected '{'");
                     }
                  }
                  else
                     toRead += temp;

                  if (toRead[0] == '.') //it's a new block
                  {
                     ConfigNode newNode = new ConfigNode(toRead.Substring(1).Trim().ToLower());
                     newNode.NodeType = NodeType.COMMON;
                     n.ChildNodes.Add(newNode);
                     newNode.Father = n;
                     n = newNode;
                     newBlockFound = true;
                     //Console.WriteLine("New '.' found on line {0}", line.ToString());
                  }
                  else if (toRead[0] == '+')
                  {
                     ConfigNode newNode = new ConfigNode(toRead.Substring(1).Trim().ToLower());
                     newNode.NodeType = NodeType.ARRAY;
                     n.ChildNodes.Add(newNode);
                     newNode.Father = n;
                     n = newNode;
                     newArrayBlockFound = true;
                     //Console.WriteLine("New '+' found on line {0}", line.ToString());
                  }
                  else if (toRead == "}") //it's the end of the current block
                  {
                     n = n.Father;
                  }
                  else if (toRead[0] == '#') //it's a pre-processing directive
                  {
                     if (toRead.StartsWith("#define "))
                     {
                        string[] tokens = toRead.Substring(8).Split(defSeps, StringSplitOptions.RemoveEmptyEntries);
                        if (tokens.Length == 2)
                        {
                           defines[tokens[0].Trim()] = tokens[1].Trim();
                        }
                     }
                  }
                  else if(toRead[0] != '!') //it's a keyword
                  {
                     if (n.NodeType == NodeType.COMMON)
                     {
                        string[] tokens = toRead.Split(keywordSplit, 2, StringSplitOptions.RemoveEmptyEntries);
                        value = tokens[1].Trim();

                        foreach (KeyValuePair<string, string> def in defines)
                        {
                           t = value.Replace(def.Key, def.Value);
                           value = t;
                        }
                        n.NodeData[tokens[0].Trim().ToLower()] = new KeywordData(value.Trim());
                     }
                     else if (n.NodeType == NodeType.ARRAY)
                     {
                        value = toRead.Trim();
                        foreach (KeyValuePair<string, string> def in defines)
                        {
                           t = value.Replace(def.Key, def.Value);
                           value = t;
                        }
                        n.NodeData[(n.NodeData.Count + 1).ToString()] = new KeywordData(value);
                     }
                  }

                  toRead = "";
                   }

                   cf.Close();

                   return true;
                }
                catch(Exception ex)
                {
                   exceptionMessage = "Error on line " + line.ToString() + ": " + ex.Message;
                   cf.Close();
                   return false;
                }
            }
Пример #23
0
            public virtual bool Save()
            {
                TextFile cf = new TextFile(ConfigFile);
                cf.OpenNewToWrite();

                bool result = false;

                try
                {
                   result = SaveToConfigFile(ref cf, Root);
                }
                catch(Exception ex)
                {
                   exceptionMessage = ex.Message;
                   cf.Close();
                   return false;
                }

                cf.Close();
                return result;
            }
Пример #24
0
            public int Glue()
            {
                if (filesToGlue != null && filesToGlue.Count <= 0)
                   return ThrowException(-3, "No files to glue.");

                if (filesToGlue2 != null && filesToGlue2.Count <= 0)
                   return ThrowException(-3, "No files to glue.");

                try
                {
                   TextFile datafile = new TextFile();

                   if (Verbose)
                  Console.WriteLine("Creating input file: {0}", fWorkingDirectory + GlueInpuFile);

                   datafile.File = new FileName(fWorkingDirectory + GlueInpuFile);

                   datafile.OpenNewToWrite(System.IO.FileShare.None);

                   if (!String.IsNullOrEmpty(fOutwatch) && fOutwatch.Trim() != "")
                  datafile.WriteLine("OUTWATCH         : " + fOutwatch.Trim());
                   datafile.WriteLine("<begin_file>");
                   datafile.WriteLine("  ACTION           : GLUES HDF5 FILES");
                   datafile.WriteLine("  OUTPUTFILENAME   : " + fOutput);
                   if (Is3DFile)
                  datafile.WriteLine("  3D_FILE          : 1");
                   else
                  datafile.WriteLine("  3D_FILE          : 0");
                   datafile.WriteLine("  BASE_GROUP       : " + BaseGroup);
                   datafile.WriteLine("  TIME_GROUP       : " + TimeGroup);
                   datafile.WriteLine("  <<begin_list>>");
                   if (filesToGlue != null)
                   {
                  foreach (string file in filesToGlue)
                     datafile.WriteLine("      " + file);
                   }
                   else if (filesToGlue2 != null)
                   {
                  foreach (FileName file in filesToGlue2)
                     datafile.WriteLine("      " + file.FullPath);
                   }
                   datafile.WriteLine("  <<end_list>>");
                   datafile.WriteLine("<end_file>");
                   datafile.Close();
                }
                catch (Exception ex)
                {
                   return ThrowException(-1, ex.Message);
                }

                TextToCheck = "successfully terminated";
                if (!ExecuteApp())
                   return ThrowException(-2);

                return 0;
            }
Пример #25
0
        //allows derived classes to override the default streaming
        //and save method
        protected virtual bool StreamAndSaveObservation()
        {
            HasGoodObservationFile = false;
            if (this.ObsCalculatorParams.AnalyzerParms.FileOrFolderPaths == null)
            {
                this.ObsCalculatorParams.ErrorMessage
                    = Errors.MakeStandardErrorMsg("OBSERVATIONS_NOFILES_SAVETEXT");
                return(false);
            }
            else
            {
                if (this.ObsCalculatorParams.AnalyzerParms.FileOrFolderPaths.Count <= 0)
                {
                    this.ObsCalculatorParams.ErrorMessage
                        = Errors.MakeStandardErrorMsg("OBSERVATIONS_NOFILES_SAVETEXT");
                    return(false);
                }
            }
            bool bHasInitialColumnDictionary = InitColumnDictionary();

            this.ObsCalculatorParams.AnalyzerParms.ObservationsPath
                = GetObservationFilePath(this.ObsCalculatorParams.ExtensionDocToCalcURI.URIDataManager.TempDocPath);
            if (!string.IsNullOrEmpty(this.ObsCalculatorParams.AnalyzerParms.ObservationsPath))
            {
                if (bHasInitialColumnDictionary)
                {
                    TextFile = new StreamWriter(
                        this.ObsCalculatorParams.AnalyzerParms.ObservationsPath);
                    //write the column headings
                    WriteColumnNameRow();
                }
                //+1 because the first column holds the stats for all comparisons
                //int iFileComparisonsCount = fileOrFolderPaths.Count + 1;
                //subscribers set a "Files" attribute property using this property
                this.ObsCalculatorParams.AnalyzerParms.FilesComparisonsCount
                    = this.ObsCalculatorParams.AnalyzerParms.FileOrFolderPaths.Count + 1;
                string sId            = string.Empty;
                string sFileToAnalyze = string.Empty;
                int    i = 0;
                //file order is not relevant in this addin,
                //but parallel won't work (yet) because of the way
                //the observationRoot gets built
                foreach (KeyValuePair <string, string> kvp
                         in this.ObsCalculatorParams.AnalyzerParms.FileOrFolderPaths)
                {
                    sId            = kvp.Key;
                    sFileToAnalyze = kvp.Value;
                    if (CalculatorHelpers.URIAbsoluteExists(
                            this.ObsCalculatorParams.ExtensionDocToCalcURI,
                            sFileToAnalyze))
                    {
                        this.ObsCalculatorParams.AnalyzerParms.ObservationFile   = sFileToAnalyze;
                        this.ObsCalculatorParams.AnalyzerParms.FilePositionIndex = i;
                        //stream and add the calculation (observation)
                        //to the observationsRoot
                        if (!CalculatorHelpers.URIAbsoluteExists(
                                this.ObsCalculatorParams.ExtensionDocToCalcURI,
                                this.ObsCalculatorParams.AnalyzerParms.ObservationFile))
                        {
                            return(HasGoodObservationFile);
                        }
                        this.ObsCalculatorParams.DocToCalcReader
                            = DevTreks.Data.Helpers.FileStorageIO.GetXmlReader(
                                  this.ObsCalculatorParams.ExtensionDocToCalcURI.URIDataManager.InitialDocToCalcURI,
                                  this.ObsCalculatorParams.AnalyzerParms.ObservationFile);
                        if (this.ObsCalculatorParams.DocToCalcReader != null)
                        {
                            using (this.ObsCalculatorParams.DocToCalcReader)
                            {
                                this.ObsCalculatorParams.DocToCalcReader.MoveToContent();
                                this.ObsCalculatorParams.AnalyzerParms.Ancestors.Clear();
                                this.ObsCalculatorParams.CurrentElementNodeName
                                    = string.Empty;
                                this.ObsCalculatorParams.ParentElementNodeName
                                                = string.Empty;
                                LinkedViewCount = 0;
                                AddObservations(bHasInitialColumnDictionary);
                            }
                        }
                        if (this.ObsCalculatorParams.ErrorMessage != string.Empty)
                        {
                            //fix all errors before running an analysis
                            this.ObsCalculatorParams.ErrorMessage
                                = this.ObsCalculatorParams.ErrorMessage;
                            break;
                        }
                        i++;
                    }
                }
                if (this.ObsCalculatorParams.ErrorMessage == string.Empty)
                {
                    if (bHasInitialColumnDictionary)
                    {
                        //save the observations file
                        if (TextFile != null)
                        {
                            //2 passes means using syntax can't be used
                            TextFile.Flush();
                            TextFile.Close();
                            HasGoodObservationFile = true;
                        }
                    }
                    else
                    {
                        //second pass builds the observations
                        StreamAndSaveObservation();
                    }
                }
            }
            return(HasGoodObservationFile);
        }
Пример #26
0
            public int Extract()
            {
                if (Parameters.Count <= 0)
                   return ThrowException(-1);
                if (string.IsNullOrEmpty(Input))
                   return ThrowException(-2);
                if (string.IsNullOrEmpty(Output))
                   return ThrowException(-3);
                if (string.IsNullOrEmpty(fAppPath))
                   return ThrowException(-4);
                if (string.IsNullOrEmpty(fExtractorInputFileName))
                   return ThrowException(-5);
                if (string.IsNullOrEmpty(fGlobalInputFileName))
                   return ThrowException(-6);
                if (string.IsNullOrEmpty(AppName))
                   return ThrowException(-7);

                if (string.IsNullOrEmpty(fWorkingDirectory))
                   fWorkingDirectory = fAppPath;

                try
                {
                   TextFile nomfich = new TextFile();
                   TextFile datafile = new TextFile();

                   nomfich.File = new FileName(fWorkingDirectory + fGlobalInputFileName);
                   nomfich.OpenNewToWrite(System.IO.FileShare.None);
                   nomfich.WriteLine("IN_MODEL : " + fExtractorInputFileName);
                   nomfich.Close();

                   datafile.File = new FileName(fWorkingDirectory + fExtractorInputFileName);
                   datafile.OpenNewToWrite(System.IO.FileShare.None);
                   datafile.WriteLine("FILENAME         : " + fInput);
                   datafile.WriteLine("OUTPUTFILENAME   : " + fOutput);
                   datafile.WriteLine("START_TIME       : " + Start.ToString("yyyy MM dd HH mm ss"));
                   datafile.WriteLine("END_TIME         : " + End.ToString("yyyy MM dd HH mm ss"));
                   if (ExtractWindow)
                   {
                  datafile.WriteLine("XY_WINDOW_OUTPUT : 1");
                  datafile.WriteLine("XY_WINDOW_LIMITS : " + WindowILB.ToString() + " " + WindowJLB.ToString() + " " + WindowIUB.ToString() + " " + WindowJUB.ToString());
                   }
                   else
                  datafile.WriteLine("XY_WINDOW_OUTPUT : 0");
                   if (ExtractSpecificLayers)
                   {
                  datafile.WriteLine("LAYERS_OUTPUT    : 1");
                  datafile.WriteLine("LAYERS_MIN_MAX   : " + LayerKLB.ToString() + " " + LayerKUB.ToString());
                   }
                   else
                  datafile.WriteLine("LAYERS_OUTPUT    : 0");
                   if (ExtractByInterval)
                   {
                  datafile.WriteLine("INTERVAL         : 1");
                  datafile.WriteLine("DT_INTERVAL      : " + DTInterval.ToString());
                   }
                   else
                  datafile.WriteLine("INTERVAL         : 0");
                   if (ConvertV3ToV4)
                  datafile.WriteLine("CONVERT_V3_TO_V4 : 1");
                   else
                  datafile.WriteLine("CONVERT_V3_TO_V4 : 0");
                   foreach (HDFParameter p in Parameters)
                   {
                  datafile.WriteLine("<BeginParameter>");
                  if (ConvertV3ToV4)
                  {
                     datafile.WriteLine("HDF_GROUP_V3     :" + p.GroupV3);
                     datafile.WriteLine("PROPERTY_V3      :" + p.PropertyV3);
                  }
                  datafile.WriteLine("HDF_GROUP        : " + p.Group);
                  datafile.WriteLine("PROPERTY         : " + p.Property);
                  datafile.WriteLine("<EndParameter>");
                   }
                   datafile.Close();
                }
                catch (Exception ex)
                {
                   ThrowException(-8, ex.Message);
                }

                TextToCheck = "Operation was successfull";
                if (!ExecuteApp())
                   return -9;

                return 0;
            }
Пример #27
0
            public void Load(FileName file, bool loadHG)
            {
                TextFile f = new TextFile(file);
                string [] seps = new string[] {":", " "};
                string [] tokens;
                int i = 0, j = 0, elements = 0, pos = 0;
                string line, line_u;

                if (loadHG && HorizGrid == null)
                   HorizGrid = new MohidHorizontalGrid();

                f.OpenToRead(FileShare.Read);
                Header.Clear();

                for(;;)
                {
                   line = f.ReadLine();

                   if (line == null)
                  break;

                   line = line.Trim();

                   if (string.IsNullOrWhiteSpace(line))
                  continue;

                   line_u = line.ToUpper();

                   if (line_u == "<BEGINXX>")
                   {
                  if (loadHG)
                  {
                     pos = 0;

                     for(;;)
                     {
                        line = f.ReadLine();

                        if (line == null)
                           throw new Exception("Invalid GridData file.");

                        line = line.Trim();
                        if (line.ToUpper() == "<ENDXX>")
                           break;

                        HorizGrid.XX.Add(double.Parse(line, CultureInfo.InvariantCulture));
                        pos = pos + 1;
                     }
                  }
                   }
                   else if (line_u == "<BEGINYY>")
                   {
                  if (loadHG)
                  {
                     pos = 0;
                     for(;;)
                     {
                        line = f.ReadLine();
                        if (line == null)
                           throw new Exception("Invalid GridData file");

                        line = line.Trim();
                        if (line.ToUpper() == "<ENDYY>")
                           break;

                        HorizGrid.YY.Add(double.Parse(line, CultureInfo.InvariantCulture));
                        pos = pos + 1;
                     }
                  }
                   }
                   else if (line_u == "<BEGINGRIDDATA2D>")
                   {
                  pos = 0;
                  for(;;)
                  {
                     line = f.ReadLine();
                     if (line == null)
                        throw new Exception("Invalid GridData file.");

                     line = line.Trim();
                     if (line.ToUpper() == "<ENDGRIDDATA2D>")
                        break;

                     Data.Add(double.Parse(line, CultureInfo.InvariantCulture));
                     pos = pos + 1;
                  }
                   }
                   else
                   {
                  Header.Add(line);
                  tokens = line.ToUpper().Split(seps, StringSplitOptions.RemoveEmptyEntries);
                  switch (tokens[0])
                  {
                     case "ILB_IUB":
                        i = int.Parse(tokens[2]) - int.Parse(tokens[1]) + 1;
                        elements = i * j;
                        if (loadHG)
                        {
                           HorizGrid.ILB = int.Parse(tokens[1]);
                           HorizGrid.IUB = int.Parse(tokens[2]);
                           HorizGrid.Elements = elements;
                        }
                        break;
                     case "JLB_JUB":
                        j = int.Parse(tokens[2]) - int.Parse(tokens[1]) + 1;
                        elements = i * j;
                        if (loadHG)
                        {
                           HorizGrid.JLB = int.Parse(tokens[1]);
                           HorizGrid.JUB = int.Parse(tokens[2]);
                           HorizGrid.Elements = elements;
                        }
                        break;
                   }
                   }
                }

                f.Close();
            }
Пример #28
0
        //Criar mais versões desta função
        public void SalveScriptUpdate(DataTable tb, string FileName, string[] ColumnsConditions)
        {
            TextFile tf = new TextFile();

            tf.Open(enmOpenMode.Writing, FileName);

            DataSource ds = new DataSource(tb);

            for (int i = 0; i < ds.Count; i++)
            {
                if (OnScriptWriting != null)
                {
                    OnScriptWriting(i, ds.Count);
                }

                string Condition = "";
                #region Gera condição
                if (ColumnsConditions.Length != 0)
                {
                    Condition = "WHERE ";
                    for (int j = 0; j < ColumnsConditions.Length; j++)
                    {
                        string       col_name = ColumnsConditions[j];
                        enmFieldType ft       = cnn.dbu.GetFieldType(GetDataType(col_name, ds));
                        switch (ft)
                        {
                        case enmFieldType.Int:
                        {
                            Condition += col_name + " = " + ds.GetField(i, col_name).ToString();
                            break;
                        }

                        case enmFieldType.Decimal:
                        {
                            Condition += col_name + " = " + ds.GetField(i, col_name).ToDecimal().ToString(cnn.dbu.dbFormat.Decimal).Replace(",", ".");
                            break;
                        }

                        case enmFieldType.DateTime:
                        {
                            DateTime val      = ds.GetField(i, col_name).ToDateTime();
                            bool     IsDate   = val.ToString("dd/MM/yyyy") != DateTime.MinValue.ToString("dd/MM/yyyy");
                            bool     IsTime   = val.ToString("HH:mm:ss") != "00:00:00";
                            string   DtFormat = cnn.dbu.dbFormat.DateTime;
                            if (IsDate && !IsTime)
                            {
                                DtFormat = cnn.dbu.dbFormat.Date;
                            }
                            if (!IsDate && IsTime)
                            {
                                DtFormat = cnn.dbu.dbFormat.Date;
                            }
                            Condition += col_name + " = " + ds.GetField(i, col_name).ToString(DtFormat);
                            break;
                        }

                        case enmFieldType.Bool:
                        {
                            Condition += col_name + " = " + (ds.GetField(i, col_name).ToBool() ? "1" : "0");
                            break;
                        }

                        default:
                        {
                            Condition += col_name + " = " + cnn.dbu.Quoted(ds.GetField(i, col_name).ToString());
                            break;
                        }
                        }

                        if (j != (ColumnsConditions.Length - 1))
                        {
                            Condition += " AND ";
                        }
                    }
                }
                #endregion

                sb.Clear();
                sb.Table = tb.TableName;
                AtribuiCampos(i, ds, ColumnsConditions, true);
                tf.WriteLine(sb.getUpdate(Condition) + ";");
            }

            tf.Close();
        }
Пример #29
0
        static void Main(string[] args)
        {
            #region 字符常量
            const string PATH_CITY_CHINAHR = "urls_chinahr.txt";

            const string PATH_DATA_UNITY_CHINAHR   = "datas_unity_chinahr.txt";
            const string PATH_DATA_PHP_CHINAHR     = "datas_php_chinahr.txt";
            const string PATH_DATA_ANDROID_CHINAHR = "datas_android_chinahr.txt";
            const string PATH_DATA_JAVA_CHINAHR    = "datas_java_chinahr.txt";
            const string PATH_DATA_CPP_CHINAHR     = "datas_cpp_chinahr.txt";
            const string PATH_DATA_HTML_CHINAHR    = "datas_html_chinahr.txt";

            const string UNITY_SUFFIX   = "job/pn{0}/pve_5356_5/?key=unity";
            const string ANDROID_SUFFIX = "job/pn{0}/pve_5356_5/?key=android";
            const string PHP_SUFFIX     = "job/pn{0}/pve_5356_5/?key=php";
            const string JAVA_SUFFIX    = "job/pn{0}/pve_5356_5/?key=java";
            const string CPP_SUFFIX     = "job/pn{0}/pve_5356_5/?key=c++";
            const string HTML_SUFFIX    = "job/pn{0}/pve_5356_5/?key=html";

            #endregion

            //获取城市列表
            //ChinnahrSpider.GetCityUrls(PATH_CITY_CHINAHR);

            File.Delete(PATH_DATA_JAVA_CHINAHR);
            File.Delete(PATH_DATA_PHP_CHINAHR);
            File.Delete(PATH_DATA_UNITY_CHINAHR);

            //WageSpider htmlSpider = new ChinnahrSpider(PathAddTime(PATH_DATA_HTML_CHINAHR));
            //WageSpider javaSpider = new ChinnahrSpider(PATH_DATA_JAVA_CHINAHR);
            WageSpider phpSpider   = new ChinnahrSpider(PATH_DATA_PHP_CHINAHR);
            WageSpider unitySpider = new ChinnahrSpider(PATH_DATA_UNITY_CHINAHR);
            //WageSpider cppSpider = new ChinnahrSpider(PathAddTime(PATH_DATA_CPP_CHINAHR));
            WageSpider androidSpider = new ChinnahrSpider(PathAddTime(PATH_DATA_ANDROID_CHINAHR));

            //spider.GetUrlsToFile(PATH_CITY_CHINAHR); //获取城市列表到文件
            //htmlSpider.AddUrlsFromFile(PATH_CITY_CHINAHR, HTML_SUFFIX); //添加要跑的url
            //javaSpider.AddUrlsFromFile(PATH_CITY_CHINAHR, JAVA_SUFFIX); //添加要跑的url
            phpSpider.AddUrlsFromFile(PATH_CITY_CHINAHR, PHP_SUFFIX);         //添加要跑的url
            unitySpider.AddUrlsFromFile(PATH_CITY_CHINAHR, UNITY_SUFFIX);     //添加要跑的url
            //cppSpider.AddUrlsFromFile(PATH_CITY_CHINAHR, CPP_SUFFIX); //添加要跑的url
            androidSpider.AddUrlsFromFile(PATH_CITY_CHINAHR, ANDROID_SUFFIX); //添加要跑的url

            #region 正则匹配规则和裁剪
            string[] patternes_chainahr =                        //正则规则
            {
                "\"job-company\" title='.+?'",                   //公司
                "\"job-salary\"> .+?</li",                       //薪资
                "class=\"job-name\" title=\".+?\"",              //标题
                "</li></ul><p class=\"l3\">.+?</p><ul class=\"", //内容
                "<li class=\"job-address\">.+?<span"
            };
            string[] startTrim_chainahr = //前面剔除文本
            {
                "\"job-company\" title='",
                "\"job-salary\"> ",
                "class=\"job-name\" title=\"",
                "</li></ul><p class=\"l3\">",
                "<li class=\"job-address\">"
            };
            string[] endTrim_chainahr =
            {
                "'", "</li", "\"", "</p><ul class=\"", "<span"
            };
            #endregion

            //组织正则表达式和剪裁规则
            Pattern[] pattern_chainahr = GetPattern(patternes_chainahr, startTrim_chainahr, endTrim_chainahr);

            //运行爬虫
            //htmlSpider.Run(pattern_chainahr);
            phpSpider.Run(pattern_chainahr);
            unitySpider.Run(pattern_chainahr);
            //javaSpider.Run(pattern_chainahr);
            //cppSpider.Run(pattern_chainahr);
            androidSpider.Run(pattern_chainahr);
#if false //对文字进行细分析,格式化
            string[] dataPathes =
            {
                PATH_DATA_UNITY_CHINAHR,
                PATH_DATA_PHP_CHINAHR,
                PATH_DATA_ANDROID_CHINAHR,
                PATH_DATA_JAVA_CHINAHR
            };

            string[] types =
            {
                "Unity", "PHP", "Android", "Java"
            };

            for (int i = 0; i < dataPathes.Length; i++)
            {
                string   item     = dataPathes[i];
                TextFile textFile = new TextFile(item);
                TextFile outFile  = new TextFile("out_" + item);
                string[] contexts = textFile.ReadToEnd().Split('\n');
                for (int j = 0; j < contexts.Length - 2; j += 3)
                {
                    Console.WriteLine("{0}-{1}-{2}", types[i], j, contexts.Length);
                    if (contexts[j + 1].LastIndexOf(" 元/月") == -1)
                    {
                        continue;
                    }

                    string   wage  = contexts[j + 1].Trim("", " 元/月");
                    string[] wages = contexts[j + 1].Split('-');

                    WageData wageData = new WageData
                    {
                        company = contexts[j].TrimEnd('\r'),
                        minWage = wages.Length > 0 ? wages[0] : wage,
                        maxWage = wages.Length > 0 ? wages[1] : wage,
                        city    = contexts[j + 2].Split('|')[0].Split('-')[0]
                    };
                    outFile.WriteLine(types[i] +
                                      "-" + wageData.company +
                                      "-" + wageData.city +
                                      "-" + wageData.minWage +
                                      "-" + wageData.maxWage);
                }
                outFile.Close();
                textFile.Close();
            }
#endif

            Console.ReadKey();
        }
Пример #30
0
        static void Main(string[] args)
        {
            bool verbose = false;

             try
             {

            CmdArgs cmdArgs = new CmdArgs(args);

            if (cmdArgs.HasOption("v"))
               verbose = true;
            else
               verbose = false;

            if (cmdArgs.HasParameter("cfg"))
            {
               if (verbose)
               {
                  Console.WriteLine("");
                  Console.Write("Reading configuration file...");
               }

               Config conf = new Config(cmdArgs.Parameters["cfg"]);
               conf.Load();

               if (verbose)
                  Console.WriteLine("[OK]");

               if (verbose)
                  Console.Write("Looking for 'xyz.to.process' blocks...");

               List<ConfigNode> bkList = conf.Root.ChildNodes.FindAll(delegate(ConfigNode node) { return node.Name == "xyz.to.process"; });

               if (bkList == null || bkList.Count <= 0)
                  throw new Exception("No 'xyz.to.process' block found in configuration file.");

               if (verbose)
               {
                  Console.WriteLine("[OK]");
                  Console.WriteLine("{0} 'xyz.to.process' block(s) found.", bkList.Count);
               }

               int bkCount = 1;
               foreach (ConfigNode bk in bkList)
               {
                  if (verbose)
                     Console.Write("Processing 'xyz.to.process' block #{0}...", bkCount);

                  FileName input = bk["input.file"].AsFileName();
                  FileName output = bk["output.file"].AsFileName();
                  bool eraseNoData = bk["erase.no.data", true].AsBool();
                  double noData = -99.0;
                  if (eraseNoData)
                     noData = bk["no.data.value", -99.0].AsDouble();
                  bool applyScaleFator = bk["apply.scale.fator", true].AsBool();
                  double scaleFactor = 1.0;
                  if (applyScaleFator)
                     scaleFactor = bk["scale.factor", 1.0].AsDouble();

                  Dictionary<string, string> lookupTable = new Dictionary<string, string>();
                  List<ConfigNode> lookupTables = bk.ChildNodes.FindAll(delegate(ConfigNode node) { return node.Name == "lookup.table"; });

                  foreach (ConfigNode lt in lookupTables)
                  {
                     foreach (KeyValuePair<string, KeywordData> kp in lt.NodeData)
                        lookupTable[kp.Key] = kp.Value.AsString();
                  }

                  //Start processing XYZ
                  TextFile file_i = new TextFile(input); file_i.OpenToRead();
                  TextFile file_o = new TextFile(output); file_o.OpenNewToWrite();

                  string line_i = null;
                  string line_o = null;
                  string [] tokens;
                  string [] sep = {" "};
                  double res;
                  while ((line_i = file_i.ReadLine()) != null)
                  {
                     tokens = line_i.Split(sep, StringSplitOptions.RemoveEmptyEntries);
                     if (tokens.Length == 3)
                     {
                        foreach (KeyValuePair<string, string> kp in lookupTable)
                           if (double.Parse(tokens[2]) == double.Parse(kp.Key))
                           {
                              tokens[2] = kp.Value;
                              break;
                           }

                        res = double.Parse(tokens[2]);

                        if (eraseNoData && res == noData)
                           continue;

                        if (applyScaleFator)
                           res *= scaleFactor;

                        line_o = string.Format("{0} {1} {2}  ", tokens[0], tokens[1], res);
                     }
                     else
                        line_o = line_i;

                     file_o.WriteLine(line_o);
                  }

                  file_i.Close();
                  file_o.Close();

                  bkCount++;
                  if (verbose)
                     Console.WriteLine("[OK]");
               }
            }
             }
             catch (Exception ex)
             {
            if (verbose)
            {
               Console.WriteLine("[FAIL]");
               Console.WriteLine("");
               Console.WriteLine("An EXCEPTION was raised. The message returned was:");
               Console.WriteLine(ex.Message);
            }
             }
             if (verbose)
             {
            Console.WriteLine("Process finished.");
            Console.WriteLine("");
             }
        }
Пример #31
0
        static void Main(string[] args)
        {
            string stepMessage = "";
             List<ConfigNode> timeseries, parameters;
             List<string> cfg = new List<string>();
             List<string> blocks = new List<string>();
             DateTime start, end, actual;
             FilePath root;
             bool hasFolders;
             TextFile config, errors;
             string hdfTag;
             FileName hdf5EXE = new FileName();
             FilePath workingFolder = new FilePath();
             FilePath tsPath;
             Dictionary<string, TimeSeries> outTS = new Dictionary<string, TimeSeries>();
             TimeSeries newTS = new TimeSeries();
             List<string> failedPeriods = new List<string>();
             int count_to_save;
             bool use_year_on_path;
             bool join_time_series;
             string startFormat, endFormat, folderFormat;

             errors = new TextFile("errors.log");
             errors.OpenNewToWrite();
             count_to_save = 0;

             try
             {
            stepMessage = "command line arguments loading.";
            CmdArgs cmdArgs = new CmdArgs(args);

            if (cmdArgs.HasParameter("cfg"))
            {
               stepMessage = "configuration file loading.";
               Config conf = new Config(cmdArgs.Parameters["cfg"]);
               conf.Load();

               stepMessage = "configuration file parsing.";
               ConfigNode tsc = conf.Root.ChildNodes.Find(delegate(ConfigNode node) { return node.Name == "timeseries.to.extract"; });

               if (tsc == null)
                  throw new Exception("block 'timeseries.to.extract' is missing.");

               start = tsc["start.date"].AsDateTime();
               end = tsc["end.date"].AsDateTime();
               hdfTag = tsc["hdf.tag"].AsString();
               hdf5EXE = tsc["exporter.exe"].AsFileName();
               workingFolder = tsc["exporter.working"].AsFilePath();
               tsPath = tsc["timeseries.output.path"].AsFilePath();
               //root = tsc["root", ".\\"].AsFilePath();
               hasFolders = tsc["has.folders", true].AsBool();
               use_year_on_path = tsc["use.year.on.path", true].AsBool();
               join_time_series = tsc["join.timeseries", true].AsBool();
               folderFormat = tsc["folder.format", "{start}_{end}"].AsString();
               startFormat = tsc["start.format", "yyyyMMddHH"].AsString();
               endFormat = tsc["end.format", "yyyyMMddHH"].AsString();

               blocks.Add("EXPORT_TYPE      : " + tsc["export.type", 1].AsString());
               blocks.Add("COMPUTE_RESIDUAL : " + tsc["compute.residual", 0].AsString());
               blocks.Add("VARIABLE_GRID    : " + tsc["variable.grid", 0].AsString());
               blocks.Add("WATERPOINTS_NAME : " + tsc["points.name", "WaterPoints2D"].AsString());
               blocks.Add("GRID_FILENAME    : " + tsc["grid.name", "grid.dat"].AsString());
               blocks.Add("");

               timeseries = tsc.ChildNodes.FindAll(delegate(ConfigNode node) { return node.Name == "timeseries"; });
               if (timeseries.Count < 1)
                  throw new Exception("Block 'timeseries' is missing. There must be at least one.");

               //Creates the blocks of timeseries
               foreach (ConfigNode n in timeseries)
               {
                  blocks.Add("<BeginTimeSerie>");
                  blocks.Add("  NAME    : " + n["name"].AsString());
                  blocks.Add("  COORD_Y : " + n["y"].AsString());
                  blocks.Add("  COORD_X : " + n["x"].AsString());
                  blocks.Add("<EndTimeSerie>");
                  blocks.Add("");

                  outTS[n["name"].AsString()] = new TimeSeries();
                  if (System.IO.File.Exists(tsPath.Path + n["name"].AsString() + ".ets"))
                  {
                     outTS[n["name"].AsString()].Load(new FileName(tsPath.Path + n["name"].AsString() + ".ets"));
                  }
               }

               parameters = tsc.ChildNodes.FindAll(delegate(ConfigNode node) { return node.Name == "parameters"; });
               if (parameters.Count < 1)
                  throw new Exception("Block 'parameters' is missing. There must be at least one.");

               //Creates the blocks of parameters
               foreach (ConfigNode n in parameters)
               {
                  blocks.Add("<BeginParameter>");
                  blocks.Add("  HDF_GROUP : " + n["group"].AsString());
                  blocks.Add("  PROPERTY  : " + n["property"].AsString());
                  blocks.Add("<EndParameter>");
                  blocks.Add("");
               }

               config = new TextFile();
               config.File.FullPath = workingFolder.Path + "HDF5Exporter.dat";

               bool quit = false;
               actual = start;
               FilePath yearFolder = new FilePath();
               ExternalApp hdf5exporter = new ExternalApp();
               hdf5exporter.CheckSuccessMethod = CheckSuccessMethod.DEFAULTOUTPUT;
               hdf5exporter.TextToCheck = "Program HDF5Exporter successfully terminated";
               hdf5exporter.Wait = true;
               hdf5exporter.WorkingDirectory = workingFolder.Path;
               hdf5exporter.Executable = hdf5EXE.FullPath;

               FilePath wp = workingFolder;
               List<FileInfo> tsList = new List<FileInfo>();
               bool failed, res;
               do
               {
                  failed = false;
                  if (use_year_on_path)
                     yearFolder.Path = root.Path + actual.Year.ToString();
                  else
                     yearFolder.Path = root.Path;

                  if (FileTools.FolderExists(yearFolder))
                  {
                     if (System.IO.File.Exists(yearFolder.Path + hdfTag + actual.ToString("yyyyMMddHH") + "_" + actual.AddHours(5).ToString("yyyyMMddHH") + ".hdf5"))
                     {
                        config.OpenNewToWrite();

                        cfg.Clear();
                        cfg.Add("");
                        cfg.Add("START_TIME : " + actual.ToString("yyyy M d H m s"));
                        cfg.Add("END_TIME   : " + actual.AddHours(5).ToString("yyyy M d H m s"));
                        cfg.Add("");
                        cfg.Add("<BeginHDF5File>");
                        cfg.Add("  NAME : " + yearFolder.Path + hdfTag + actual.ToString("yyyyMMddHH") + "_" + actual.AddHours(5).ToString("yyyyMMddHH") + ".hdf5");
                        cfg.Add("<EndHDF5File>");
                        cfg.Add("");
                        config.WriteLines(cfg);
                        config.WriteLines(blocks);

                        config.Close();

                        //executes HDF5Exporter
                        try
                        {
                           Console.Write("Running HDF5Exporter to file " + hdfTag + actual.ToString("yyyyMMddHH") + "_" + actual.AddHours(5).ToString("yyyyMMddHH") + ".hdf5 ...");
                           res = hdf5exporter.Run();
                           if (!res)
                           {
                              errors.WriteLine("Unsuccessfull HDF5Exporter run on file '" + hdfTag + actual.ToString("yyyyMMddHH") + "_" + actual.AddHours(5).ToString("yyyyMMddHH") + ".hdf5'");
                              failed = true;
                              Console.WriteLine("[Failed]");
                           }
                           else
                           {
                              Console.WriteLine("[OK]");
                           }
                        }
                        catch(Exception e_run)
                        {
                           errors.WriteLine("HDF5Exporter Run Exception on file '" + hdfTag + actual.ToString("yyyyMMddHH") + "_" + actual.AddHours(5).ToString("yyyyMMddHH") + ".hdf5'");
                           errors.WriteLine("Exception returned this message: " + e_run.Message);
                           failed = true;
                           Console.WriteLine("[Exception]");
                        }

                        if (!failed)
                        {
                           FileTools.FindFiles(ref tsList, wp, "*.ets", true, "", System.IO.SearchOption.TopDirectoryOnly);
                           foreach (FileInfo file in tsList)
                           {
                              if (outTS[file.FileName.Name].NumberOfInstants > 0)
                              {
                                 try
                                 {
                                    newTS.Load(file.FileName);
                                    //outTS.Load(new FileName(tsPath.Path + file.FileName.FullName));
                                    outTS[file.FileName.Name].AddTimeSeries(newTS);
                                 }
                                 catch
                                 {
                                    errors.WriteLine("Was not possible to read timeseries '" + file.FileName + "' from HDF file '" + hdfTag + actual.ToString("yyyyMMddHH") + "_" + actual.AddHours(5).ToString("yyyyMMddHH") + ".hdf5'");
                                 }
                                 //outTS.Save(new FileName(tsPath.Path + file.FileName.FullName));
                                 System.IO.File.Delete(file.FileName.FullPath);
                              }
                              else
                              {
                                 //FileTools.CopyFile(file.FileName, new FileName(tsPath.Path + file.FileName.FullName), CopyOptions.OVERWRIGHT);
                                 //outTS[file.FileName.Name].Load(new FileName(tsPath.Path + file.FileName.FullName));

                                 outTS[file.FileName.Name].Load(file.FileName);
                                 System.IO.File.Delete(file.FileName.FullPath);
                              }
                           }

                           count_to_save++;
                           if (count_to_save >= 60)
                           {
                              count_to_save = 0;
                              foreach (FileInfo file in tsList)
                              {
                                 Console.Write("Saving Timeseries '" + file.FileName.Name + "' ...");
                                 try
                                 {
                                    outTS[file.FileName.Name].Save(new FileName(tsPath.Path + file.FileName.Name + ".ets"));
                                    Console.WriteLine("[OK]");
                                    FileTools.CopyFile(new FileName(tsPath.Path + file.FileName.Name + ".ets"), new FileName((new FilePath(tsPath.Path + "bkp")).Path + file.FileName.Name + ".ets"), CopyOptions.OVERWRIGHT);
                                 }
                                 catch(Exception e_run)
                                 {
                                    Console.WriteLine("[FAILED]");
                                    errors.WriteLine("Was not possible to save timeseries '" + file.FileName.Name + ".ets'");
                                    errors.WriteLine("Exception returned this message: " + e_run.Message);
                                 }
                              }
                           }
                        }
                     }
                  }

                  actual = actual.AddHours(6);
                  if (actual >= end)
                     quit = true;
               }
               while (!quit);

               foreach (KeyValuePair<string, TimeSeries> pair in outTS)
               {
                  pair.Value.Save(new FileName(tsPath.Path + pair.Key + ".ets"));
               }

               //TimeUnits timeUnits = (TimeUnits)Enum.Parse(typeof(TimeUnits), conf.Root["time.units", "seconds"].AsString(), true);

               //   List<FileName> list = new List<FileName>();
               //   foreach (KeyValuePair<string, KeywordData> item in nodeList.NodeData)
               //      list.Add(item.Value.AsFileName());

               //   if (list.Count <= 1)
               //      throw new Exception("Block 'timeseries.to.join' must contain at least 2 entries");

               //   stepMessage = "loading timeseries.";
               //   List<TimeSeries> timeSeries = new List<TimeSeries>();

               //   foreach (FileName ts in list)
               //   {
               //      TimeSeries newTS = new TimeSeries();
               //      newTS.Load(ts);
               //      timeSeries.Add(newTS);
               //   }

               //   start = timeSeries[0].StartInstant;
               //   for (int i = 1; i < timeSeries.Count; i++)
               //   {
               //      if (timeSeries[i].StartInstant < start)
               //         start = timeSeries[i].StartInstant;
               //   }

               //   stepMessage = "creating output timeseries.";
               //   TimeSeries outTS = new TimeSeries();
               //   outTS.StartInstant = start;
               //   outTS.TimeUnits = timeUnits;

               //   foreach (Column col in timeSeries[0].Columns)
               //   {
               //      Column newCol = new Column(col.ColumnType);
               //      newCol.Header = col.Header;
               //      outTS.AddColumn(newCol);
               //   }

               //   foreach (TimeSeries toJoin in timeSeries)
               //      outTS.AddTimeSeries(toJoin);

               //   stepMessage = "saving output timeseries.";
               //   outTS.Save(outputFileName);

               //   Console.WriteLine("Process complete with success.");
               //}
               //else
               //{
               //   Console.WriteLine("Parameter --cfg is missing.");
               //   Console.WriteLine("Execution aborted.");
               //   return;
               //}
            }
             }
             catch (Exception ex)
             {
            Console.WriteLine("An exception was raised while {0}", stepMessage);
            Console.WriteLine("Exception message: {0}", ex.Message);
             }

             errors.Close();
        }
Пример #32
0
        public string ExecFile(string FileName)
        {
            TextFile tf = new TextFile();

            tf.Open(enmOpenMode.Reading, FileName);

            string buffer          = "";
            int    CountInstrucoes = 0;
            bool   Cancel          = false;
            long   bytes           = 0;
            long   total_bytes     = tf.GetSize();
            string line            = "";

            List <string> identity_tables = DbCurrent.GetIdentityTables();

            DbCurrent.BeginTransaction();

            while ((line = tf.ReadLine()) != null)
            {
                if (Cancel)
                {
                    break;
                }

                bytes += line.Length;

                if (line.Trim() == DbScript.COMMIT_COMMAND || line.Trim() == "GO")
                {
                    DbCurrent.CommitTransaction();
                    DbCurrent.BeginTransaction();
                    continue;
                }

                if (line.Contains("SET IDENTITY_INSERT"))
                {
                    int idx_start = line.IndexOf("SET IDENTITY_INSERT");
                    int idx_end   = line.IndexOf(" ON ");

                    string sub_string   = line.Substring(idx_start, idx_end + 4).ToUpper();
                    string table_script = sub_string.Replace("SET IDENTITY_INSERT ", "").Replace(" ON ", "").Replace("[", "").Replace("]", "");

                    if (DbCurrent.dbType == enmConnection.SqlServer)
                    {
                        string tabela_localizada = identity_tables.FirstOrDefault(q => q.ToUpper() == table_script);
                        if (string.IsNullOrEmpty(tabela_localizada))
                        {
                            line = line.Replace(sub_string, "");
                        }
                    }
                    else
                    {
                        line = line.Replace(sub_string, "");
                    }

                    /*
                     * PrimaryKey[] primaryKey = primarykeys.Where(q => q.Table.ToUpper() == table_script).ToArray();
                     *
                     * if (primaryKey.Length != 1) {
                     *  line = line.Replace(sub_string, "");
                     * }
                     */
                }

                //buffer += " " + line;

                bool PodeExecutar = line.IndexOf(";") != -1;

                if (string.IsNullOrEmpty(buffer))
                {
                    if (PodeExecutar && line.Count(q => q == '\'') % 2 == 1)
                    {
                        PodeExecutar = false;
                    }
                }
                else
                {
                    if (PodeExecutar && (buffer + line).Count(q => q == '\'') % 2 == 1)
                    {
                        PodeExecutar = false;
                    }
                }

                if (PodeExecutar)
                {
                    buffer += " " + (line.Trim() == "GO" ? "" : line);

                    string comando = "";
                    try
                    {
                        string prefix = "";
                        if (DbCurrent.dbType == enmConnection.SqlServer)
                        {
                            prefix = "set dateformat ymd";
                        }

                        comando = prefix + buffer;

                        DbCurrent.Exec(comando);

                        buffer = "";
                        CountInstrucoes++;
                        ScriptProgress("SQL executado:" + CountInstrucoes, (int)(bytes * 1000 / total_bytes), 1000, out Cancel);
                    }
                    catch (Exception ex)
                    {
                        return(GetSqlError(ex));
                    }
                }
                else
                {
                    buffer += " " + line;
                }

                if (Cancel)
                {
                    break;
                }
            }

            DbCurrent.CommitTransaction();
            tf.Close();

            return(string.Format("Nr de instruções executadas : {0} \r\n", CountInstrucoes));
        }