public static void UnpackFromFlex(FlexEvent mainFlex, ref CSVTableParser inittbl,
            ref List<CSVTableParser> tables, ref string name)
        {
            inittbl.Rows = new List<Row>();
            for (int i = 0; i < tables.Count; i++)
                tables[i].Rows = new List<Row>();

            try {
                var inittblFlex = (FlexEvent) mainFlex.Arguments[InitTblFlexName];
                name = mainFlex.Operation.Split('.').Last();
                foreach (var initTblPath in inittblFlex.Arguments) {
                    var tbIndex = Int32.Parse(initTblPath.Key);
                    var tbName = (string) initTblPath.Value;
                    var tableFlex = (FlexEvent) mainFlex.Arguments[tbName];

                    var inittblRow = new Row();
                    inittblRow.Cell.Add(inittbl.Description[0].ColumnName, tbIndex);
                    inittblRow.Cell.Add(inittbl.Description[1].ColumnName, tbName);
                    inittbl.Rows.Add(inittblRow);

                    foreach (var trfObj in tableFlex.Arguments) {
                        var tableRowFlex = (FlexEvent) trfObj.Value;
                        var tableRow = new Row();
                        foreach (var columnPath in tables[tbIndex].Description)
                            tableRow.Cell.Add(columnPath.ColumnName, tableRowFlex.Arguments[columnPath.ColumnName]);
                        tables[tbIndex].Rows.Add(tableRow);
                    }
                }
            }
            catch (Exception e) {
                InstantLogger.err("CSVTP_FlexEventConverter.UnpackFromFlex:\n{0}", e.ToString());
            }
        }
        public static void ResponceGenerator(FlexEvent flx, Requester.Result result)
        {
            var command = flx.Arguments.ContainsKey(ArgCommandName) ? (string)flx.Arguments[ArgCommandName] : "";
            var fex = CreateRespFex(flx);
            var count = 0;
            foreach (var collumn in result.ResultData)
            {
                fex.AddComplexArg(collumn.Key,collumn.Value);

                if (count == 0) {
                    foreach (var row in collumn.Value) {
                        count++;
                    }
                }
            }
            foreach (var argument in flx.Arguments) {
                if (!argument.Key.StartsWith("@")) {
                    fex.AddArg(String.Format("<{0}>",argument.Key), argument.Value);
                }
            }
            fex.AddArg(ArgCountName,count);
            fex.AddArg(ArgCommandName, command);
            fex.AddArg(ArgErrorCodeName, result.ErrorCode.ToString());
            fex.AddArg(ArgErrorStringName, result.ErrorStr);
            fex.Fire(MainGate);
            InstantLogger.msg(fex.evt.ToString());
        }
 public static FlexEvent PackToFlex(string name, CSVTableParser inittbl, List<CSVTableParser> tables)
 {
     var mainFlex = new FlexEvent(AppName + ".Tables." + name);
     var inittblFlex = new FlexEvent(InitTblFlexName);
     var tablesFlexList = new List<FlexEvent>();
     for (int i = 0; i < tables.Count; i++)
         tablesFlexList.Add(new FlexEvent());
     foreach (var row in inittbl.Rows) {
         var keyIndex = inittbl.Description[0].ColumnName;
         var keyName = inittbl.Description[1].ColumnName;
         var tbIndex = (int) row.Cell[keyIndex];
         inittblFlex.Arguments.Add(tbIndex.ToString(), row.Cell[keyName]);
         var tableFlex = new FlexEvent((string) row.Cell[keyName]);
         for (int index = 0; index < tables[tbIndex].Rows.Count; index++) {
             var tableRow = tables[tbIndex].Rows[index];
             var tableRowFlex = new FlexEvent(index.ToString());
             foreach (var columnPath in tables[tbIndex].Description) {
                 var keyCollumn = columnPath.ColumnName;
                 tableRowFlex.Arguments.Add(keyCollumn, tableRow.Cell[keyCollumn]);
             }
             tableFlex.Arguments.Add(index.ToString(), tableRowFlex);
         }
         mainFlex.Arguments.Add(tableFlex.Operation, tableFlex);
     }
     mainFlex.Arguments.Add(inittblFlex.Operation, inittblFlex);
     return mainFlex;
 }
        private static void Main(string[] argv)
        {
            using (var l = new Logger("PipeCatcher"))
            {
                try
                {
                    var o = new FlexEvent("dummy"); /// нужно чтобы сборка загрузилась
                    CoreGate = new ConnectionProvider.Client();
                    var conf = ConfigurationManager.OpenExeConfiguration("");
                    var settings = conf.AppSettings.Settings;
                    var dbrlist = new List<DBReader>();
                    foreach (KeyValueConfigurationElement pipe in settings)
                    {
                        if (!pipe.Key.StartsWith("pipe")) continue;
                        foreach (KeyValueConfigurationElement kvel in settings)
                        {
                            if (kvel.Key.StartsWith("connectionString"))
                            {
                                dbrlist.Add(new DBReader(kvel.Value, pipe.Value));
                            }
                        }
                    }
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);

                    Application.Run(new Catcher(dbrlist, Application.ExecutablePath));
                }
                catch (Exception e)
                {
                    l.err("PipeCatcher.Main exception {0}", e);
                }
            }
        }
        public void CarbonEventHandler(FlexEvent felexE, int id, string prefix)
        {
            var evtName = String.Format("{0}.Result", prefix);
            if (felexE.Operation.StartsWith(evtName)) {
                var key = "C";
                try {
                    Program.ModelList[id].C = (double) felexE.Arguments[key];
                    Program.Iterate();
                }
                catch (Exception e) {
                    InstantLogger.err("{2} - {1} : \n{0}", e.ToString(), key, evtName);
                }
            }

            evtName = String.Format("{0}.ModelIsStarted", prefix);
            if (felexE.Operation.StartsWith(evtName)) {
                Program.ModelList[id].IsStarted = true;
                Program.Iterate();
            }

            evtName = String.Format("{0}.DataFix", prefix);
            if (felexE.Operation.StartsWith(evtName)) {
                var key = "C";
                try {
                    Program.ModelList[id].C = (double) felexE.Arguments[key];
                    Program.Iterate();
                }
                catch (Exception e) {
                    InstantLogger.err("{2} - {1} : \n{0}", e.ToString(), key, evtName);
                }
                Program.ModelList[id].IsFixed = true;
                Program.Iterate();
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Constructor for FlexEvent recieved by .OnEvent processor
 /// </summary>
 public FlexHelper(FlexEvent evt_)
 {
     evt = new FlexEvent(evt_.Operation);
     evt.Flags = evt_.Flags & (~FlexEventFlag.FlexEventCreated);
     evt.Arguments = evt_.Arguments;
     evt.Id = evt_.Id;
     evt.Time = evt_.Time;
 }
 public static void Init()
 {
     CapturedEvents = new List<CEDataFormat>();
     var o = new FlexEvent();
     MainGate = new Client(new Listener());
     MainGate.Subscribe();
     Load();
     SaveTimer.Elapsed += new ElapsedEventHandler(SaveTimeOut);
     SaveTimer.Enabled = true;
 }
 public static void Job(FlexEvent flx)
 {
     var cfgResult = Cfg.ReadCfg(flx);
     if (cfgResult.ErrorCode != CfgLoader.Result.Es.S_ERROR) {
         var req = new Requester(ConnectionStr);
         req.SQLRequestAsync(cfgResult.SQLStr, flx, ResponceGenerator);
     }
     else {
         var command = flx.Arguments.ContainsKey(ArgCommandName) ? (string)flx.Arguments[ArgCommandName] : "";
         var fex = CreateRespFex(flx);
         fex.AddArg(ArgCommandName, command);
         fex.AddArg(ArgErrorCodeName, cfgResult.ErrorCode.ToString());
         fex.AddArg(ArgErrorStringName, cfgResult.ErrorStr);
         fex.Fire(MainGate);
         InstantLogger.msg(fex.evt.ToString());
     }
 }
 public static void fireFlex(FlexEvent d)
 {
     var fex = new FlexHelper(d.Operation);
     fex.evt.Flags = d.Flags;
     foreach (var a in d.Arguments) {
         var v = ((Element) a.Value).val;
         if (v is byte[]) {
             var vv = v as byte[];
             string s = "";
             for (var i = 0; i < vv.Length; i++) {
                 int c = vv[i];
                 if (c > 127) c += 0x0350;
                 s += Convert.ToChar(c);
             }
             ///!sb.AppendFormat("/{0}", s);
             v = s;
         }
         fex.AddArg(a.Key, v);
     }
     fex.Fire(MainGate);
 }
        public Result ReadCfg(FlexEvent flx)
        {
            var res = new Result();

            #region Init and verify

            var subDir = "";
            var command = "";

            if (flx.Arguments.ContainsKey(Program.ArgEventName)) {
                subDir = (string)flx.Arguments[Program.ArgEventName];
                if (String.IsNullOrWhiteSpace(subDir)) {
                    res.ErrorCode = Result.Es.S_ERROR;
                    res.ErrorStr += Program.ArgEventName + " is not contains value\n";
                }
            }
            else {
                res.ErrorCode = Result.Es.S_ERROR;
                res.ErrorStr += String.Format("Argument {0} is not found\n", Program.ArgEventName);
            }

            if (flx.Arguments.ContainsKey(Program.ArgCommandName))
            {
                command = (string)flx.Arguments[Program.ArgCommandName];
                if (String.IsNullOrWhiteSpace(command))
                {
                    res.ErrorCode = Result.Es.S_ERROR;
                    res.ErrorStr += Program.ArgCommandName + " is not contains value\n";
                }
            }
            else
            {
                res.ErrorCode = Result.Es.S_ERROR;
                res.ErrorStr += String.Format("Argument {0} is not found\n", Program.ArgCommandName);
            }

            if (res.ErrorCode == Result.Es.S_ERROR) return res;

            var currentDir = String.Format("{0}\\{1}", m_mainDir, subDir);

            if (!Directory.Exists(currentDir)) {
                res.ErrorCode = Result.Es.S_ERROR;
                res.ErrorStr += String.Format("Directory {0} is not found\n", currentDir);
                return res;
            }

            var indexFile = String.Format("{0}\\{1}", currentDir, Program.IndexFileName);

            if (!File.Exists(indexFile))
            {
                res.ErrorCode = Result.Es.S_ERROR;
                res.ErrorStr += String.Format("Index file {0} is not found\n", indexFile);
                return res;
            }
            #endregion

            #region Load index file

            string[] indexStrings;

            try {
                indexStrings = File.ReadAllLines(indexFile);
            }
            catch (Exception e ) {
                res.ErrorCode = Result.Es.S_ERROR;
                res.ErrorStr += String.Format("{0}\n", e.Message);
                return res;
            }

            if (!indexStrings.Any()) {
                res.ErrorCode = Result.Es.S_ERROR;
                res.ErrorStr += String.Format("Index file {0} is empty\n", indexFile);
                return res;
            }

            var sqlFileName = "";

            for (int i = 0; i < indexStrings.Count(); i++) {
                var kv = indexStrings[i].Split(Separator);
                if (kv.Length >= 2) {
                    var k = kv[0];
                    var v = kv[1];
                    if (k == (string) flx.Arguments[Program.ArgCommandName]) {
                        sqlFileName = String.Format("{0}\\{1}", currentDir, v);
                    }
                    else {
                        if (!File.Exists(String.Format("{0}\\{1}", currentDir, v))) {
                            res.ErrorCode = Result.Es.S_WARN;
                            res.ErrorStr +=
                                String.Format(
                                    "Index file {0} included the \"{1}\" SQL file, but this SQL file can't be found\n",
                                    indexFile, v);
                        }
                    }
                }
                else {
                    res.ErrorCode = Result.Es.S_WARN;
                    res.ErrorStr += String.Format("Index file {2} have bad string:\n{1}. \"{0}\"\n", indexStrings[i],
                                                  i + 1, indexFile);
                }
            }

            if (String.IsNullOrWhiteSpace(sqlFileName)) {
                    res.ErrorCode = Result.Es.S_ERROR;
                    res.ErrorStr += String.Format("Command {0} or associated file not found\n", (string)flx.Arguments[Program.ArgCommandName]);
                    return res;
                }

               if (!File.Exists(sqlFileName)) {
                    res.ErrorCode = Result.Es.S_ERROR;
                    res.ErrorStr += String.Format("SQL file \"{0}\" do not be found\n", sqlFileName);
                    return res;
                }

            #endregion

            #region Load SQL file

            var sqlFileData = "";

            try {
                sqlFileData = File.ReadAllText(sqlFileName);
            }
            catch (Exception e) {
                res.ErrorCode = Result.Es.S_ERROR;
                res.ErrorStr += String.Format("{0}\n", e.Message);
                return res;
            }

            //sqlFileData = sqlFileData.Replace('\n', ' ');

            if (String.IsNullOrWhiteSpace(sqlFileData)) {
                res.ErrorCode = Result.Es.S_ERROR;
                res.ErrorStr += String.Format("SQL file \"{0}\" is empty\n", sqlFileData);
                return res;
            }

            #endregion

            #region template

            var patterns = new Dictionary<string, string>();

            foreach (var argument in flx.Arguments) {
                if ((argument.Key != Program.ArgEventName) && (argument.Key != Program.ArgCommandName)) {
                    var argstr = argument.Value.ToString();
                    if (argument.Value is double) {
                        argstr = argstr.Replace(',', '.');
                    }
                    patterns.Add(argument.Key, argstr);
                }
            }

            var templateRes = ApplyTemplate(sqlFileData, patterns);

            res.ErrorCode = templateRes.ErrorCode;
            res.ErrorStr += templateRes.ErrorStr;
            res.SQLStr = templateRes.SQLStr;

            #endregion

            //res.SQLStr = sqlFileData;

            return res;
        }
Exemplo n.º 11
0
 /// <summary>
 /// Constructor for newly created FlexEvent
 /// </summary>
 public FlexHelper(string Operation)
 {
     evt = new FlexEvent(Operation);
 }
 public ThreadPoolData(string sqlStr, FlexEvent flx, CompleteCallback responceGenerator)
 {
     SQLString = sqlStr;
     Flx = flx;
     ResponceGenerator = responceGenerator;
 }
 public void SQLRequestAsync(string SQLString, FlexEvent flx, CompleteCallback responceGenerator)
 {
     var tpData = new ThreadPoolData(SQLString, flx, responceGenerator);
     ThreadPool.QueueUserWorkItem(ThreadPoolCallback, tpData);
 }
Exemplo n.º 14
0
        private static void Init()
        {
            MatrixT = new CSVTableParser();
            MatrixC = new CSVTableParser();
            MainConf = System.Configuration.ConfigurationManager.OpenExeConfiguration("");

            CurrentScheme = Int32.Parse(MainConf.AppSettings.Settings["Scheme"].Value);

            Separator = MainConf.AppSettings.Settings["separator"].Value.ToArray()[0];
            MatrixT.FileName = MainConf.AppSettings.Settings["matrixT"].Value;
            MatrixT.Separator = Separator;

            var o = new FlexEvent();
            MainGate = new ConnectionProvider.Client(new Listener());
            MainGate.Subscribe();

            MatrixTDescription = new List<ColumnPath>();
            MatrixTDescription.Add(new ColumnPath() { ColumnName = "CMin", ColumnType = typeof(double) });
            MatrixTDescription.Add(new ColumnPath() { ColumnName = "CMax", ColumnType = typeof(double) });
            MatrixTDescription.Add(new ColumnPath() { ColumnName = "OxygenOnHeating", ColumnType = typeof(int) });
            MatrixTDescription.Add(new ColumnPath() { ColumnName = "Heating", ColumnType = typeof(int) });
            #if IS_DBFLEX
            ReqScheme(CurrentScheme);
            #else
            MatrixT.Description = MatrixTDescription;
            MatrixT.Load();
            #endif

            MatrixC.FileName = MainConf.AppSettings.Settings["matrixC"].Value;
            MatrixC.Separator = Separator;

            MatrixC.Description.Add(new ColumnPath() {ColumnName = "CMin", ColumnType = typeof (double)});
            MatrixC.Description.Add(new ColumnPath() {ColumnName = "CMax", ColumnType = typeof (double)});
            MatrixC.Description.Add(new ColumnPath() {ColumnName = "OxygenOnCarbon", ColumnType = typeof (int)});

            MatrixC.Load();

            WaitSublanceData = new Timer();
            WaitSublanceData.Elapsed += new ElapsedEventHandler(SublanceDataLost);

            CarbonIterateTimer.Elapsed += new ElapsedEventHandler(CarbonIterator);
            CarbonIterateTimer.Enabled = true;

            Reset();
        }
 public String ProcessNews()
 {
     using (Logger l = new Logger("PipeCatcher"))
     {
         OraCmd.CommandText = ProcName;
         OraCmd.CommandType = System.Data.CommandType.StoredProcedure;
         OraCmd.Parameters.Clear();
         //OraCmd.Parameters.Add(new OracleParameter("NRECID", OracleDbType.Decimal, System.Data.ParameterDirection.Input)).Value = RecId;
         OraCmd.Parameters.Add(new OracleParameter("REFCURSOR", OracleDbType.RefCursor, System.Data.ParameterDirection.Output));
         if (OraCmd.Connection.State != System.Data.ConnectionState.Closed)
         {
             OraCmd.Connection.Close();
         }
         OraCmd.Connection.Open();
         OraReader = OraCmd.ExecuteReader();
         var str = String.Format("\nCALL {0}", ProcName);
     //                var mainevt = new FlexEvent("PipeCatcher.Call." + ProcName);
     //                mainevt.Arguments.Add("@ProcName", ProcName);
         if (OraReader.HasRows)
         {
             var iRow = 0;
             FlexEvent evt = new FlexEvent("PipeCatcher.Call." + ProcName + ".Row." + (++iRow));
             str += "+++";
             while (OraReader.Read())
             {
                 for (int i = 0; i < OraReader.FieldCount; i++)
                 {
                     evt.Arguments.Add(OraReader.GetName(i), OraReader[i]);
                     str += "\n" + OraReader.GetName(i) + "\t: " + OraReader[i];
                 }
                 str += "\n********************";
     //                        mainevt.Arguments.Add(String.Format("Row{0}", ++iRow), evt);
                 Program.CoreGate.PushEvent(evt);
                 evt.Arguments.Clear();
             }
     //                    Program.CoreGate.PushEvent(mainevt);
         }
         else
         {
             str += "---";
         }
         OraReader.Close();
         l.msg(str);
         return str;
     }
 }
        private void ParseFile(string path)
        {
            string[] strings;
            try {
                strings = File.ReadAllLines(path);
            }
            catch {
                strings = new string[0];
                InstantLogger.err("Cannot read the file: {0}", path);
                return;
            }

            try {
                ConfigSections mode = ConfigSections.Undefined;
                var description = new FlexEvent();
                for (int strCnt = 0; strCnt < strings.Count(); strCnt++) {
                    string[] values = strings[strCnt].Split(Separator);
                    if (values.Any()) {
                        if (values[0] != "") {
                            if (values[0] == ParseKeys.ConfFields) mode = ConfigSections.ConfigSection;
                            else if (values[0] == ParseKeys.ArgFields) mode = ConfigSections.ArgumentsSection;
                            else {
                                switch (mode) {
                                    case ConfigSections.ConfigSection:
                                        if (values.Count() >= 2) {
                                            if (values[0] == ParseKeys.FlagsKey)
                                                description.Flags = (FlexEventFlag) Convertion.StrToInt32(values[1]);
                                            if (values[0] == ParseKeys.OperationKey)
                                                description.Operation = values[1];
                                        }
                                        break;
                                    case ConfigSections.ArgumentsSection:
                                        if (values[0] == Destination) {
                                            if (values.Count() >= 3)
                                                description.Arguments.Add(values[1], new Element(values[2]));
                                        }
                                        break;
                                }
                            }
                        }
                    }
                }
                if (description.Arguments.Any()) {
                    description.Id = Guid.NewGuid();
                    description.Time = DateTime.Now;
                    DescriptionFlexList.Add(description);
                }
            }
            catch (Exception e) {
                InstantLogger.err("Cannot parce the file: {0}, bad format call exeption: {1}", path, e.ToString());
                return;
            }
        }
Exemplo n.º 17
0
 public static FlexHelper CreateRespFex(FlexEvent flx)
 {
     var operation = flx.Arguments.ContainsKey(ArgEventName) ? (string)flx.Arguments[ArgEventName] : "DBF.default.responce";
     var fex = new FlexHelper(operation);
     return fex;
 }
 private bool InsertOrUpdateTrends(FlexEvent evt, int unit)
 {
     var sql = CheckInsert("TREND_BALANCE", unit, evt.Time)
                   ? "UPDATE TREND_BALANCE " +
                     "SET  C = :C, T = :T, SI = :SI, MN = :MN, AL = :AL, CR = :CR, P = :P, TI = :TI, V = :V, FE = :FE, " +
                     "CAO = :CAO, FEO = :FEO, SIO2 = :SIO2, MNO = :MNO, MGO = :MGO " +
                     "WHERE CNV_NO = :CNV_NO AND INSERTTIME = :INSERTTIME "
                   : "INSERT INTO TREND_BALANCE (C, T, SI, MN, AL, CR, P, TI, V, FE, CAO, FEO, SIO2, MNO, MGO, CNV_NO, INSERTTIME) " +
                     "VALUES (:C, :T, :SI, :MN, :AL, :CR, :P, :TI, :V, :FE, :CAO, :FEO, :SIO2, :MNO, :MGO, :CNV_NO, :INSERTTIME) ";
     var parametres = new List<OracleParameter>(evt.Arguments.Keys.Select(key => SetParams(key.ToUpper(), (double) evt.Arguments[key])));
     parametres.AddRange(MandatoryParams(unit, evt.Time));
     return ExecuteNonQuery(sql, parametres);
 }
Exemplo n.º 19
0
 public static void Update(FlexEvent flx)
 {
     var isUpdated = false;
     foreach (var capturedEvent in CapturedEvents) {
         if (capturedEvent.Operation == flx.Operation) {
             isUpdated = true;
             capturedEvent.CountTotal++;
             capturedEvent.CountDayAverage = 0;
             capturedEvent.CaptureTime = DateTime.Now;
             for (int arg = 0; arg < flx.Arguments.Count; arg++) {
                 var key = flx.Arguments.ElementAt(arg).Key;
                 var argIsFound = false;
                 var type = flx.Arguments[key].GetType().ToString();
                 var exampleValue = flx.Arguments[key].ToString();
                 foreach (var att in capturedEvent.AttList) {
                     if (att.Key == key) {
                         att.Type = type;
                         att.ExampleValue = exampleValue;
                         argIsFound = true;
                     }
                 }
                 if (!argIsFound) {
                     var att = new AttDataFormat();
                     att.Key = key;
                     att.Type = type;
                     att.ExampleValue = exampleValue;
                     capturedEvent.AttList.Add(att);
                 }
             }
         }
     }
     if (!isUpdated) {
         InstantLogger.msg("Captured new event: {0}", flx.Operation);
         var capturedEvent = new CEDataFormat();
         capturedEvent.Operation = flx.Operation;
         CapturedEvents.Add(capturedEvent);
         Update(flx);
     }
 }
 public bool Insert(FlexEvent evt, int unit)
 {
     return evt.Operation.StartsWith("Model.Dynamic.Output.PerSecond") && InsertOrUpdateTrends(evt, unit);
 }