Ejemplo n.º 1
0
        protected void LogInSystemLog(object caller, string level, object o)
        {
            try
            {
                using (var connection = new SqlConnection(_connectionString))
                {
                    connection.Open();
                    using (var insertCommand = new SqlCommand("INSERT INTO RIFF.SystemLog( [Timestamp], [Hostname], [Level], [Source], [Message], [Content], [Thread], [AppDomain] ) VALUES " +
                                                              "( @Timestamp, @Hostname, @Level, @Source, @Message, @Content, @Thread, @AppDomain )", connection))
                    {
                        insertCommand.Parameters.AddWithValue("@Timestamp", new DateTimeOffset(DateTime.Now));
                        insertCommand.Parameters.AddWithValue("@Hostname", Environment.MachineName.ToLower());
                        insertCommand.Parameters.AddWithValue("@Level", level);
                        insertCommand.Parameters.AddWithValue("@Source", caller != null ? caller.ToString() : String.Empty);
                        insertCommand.Parameters.AddWithValue("@Message", o.GetType().Name);
                        insertCommand.Parameters.AddWithValue("@Content", RFXMLSerializer.SerializeContract(o));
                        insertCommand.Parameters.AddWithValue("@Thread", System.Threading.Thread.CurrentThread.ManagedThreadId);
                        insertCommand.Parameters.AddWithValue("@AppDomain", AppDomain.CurrentDomain.FriendlyName);

                        insertCommand.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                Exception(this, ex, "Error logging in System Log");
            }
        }
Ejemplo n.º 2
0
        public void Write(Message message, object obj)
        {
            message.BodyStream = new MemoryStream();
            var writer = new StreamWriter(message.BodyStream);

            writer.WriteLine(obj.GetType().FullName);
            writer.WriteLine(RFXMLSerializer.SerializeContract(obj));
            writer.Flush();
        }
Ejemplo n.º 3
0
        /*[DataMember]
         * public RFEvent Event { get; protected set; }*/
        /*
         * public static RFInstruction Create(/*RFEvent e)
         * {
         *  return new RFInstruction { Event = e };
         * }*/

        public int CompareTo(object obj)
        {
            // this is really slow
            return(string.Compare(RFXMLSerializer.SerializeContract(this), RFXMLSerializer.SerializeContract(obj), StringComparison.Ordinal));
        }
Ejemplo n.º 4
0
        public override Dictionary <RFGraphInstance, RFCatalogKey> GetKeyInstances(RFCatalogKey key)
        {
            var    t       = key.GetType();
            var    keys    = new Dictionary <RFGraphInstance, RFCatalogKey>();
            string keyType = t.FullName;

            Log.Debug(this, "GetKeyInstances {0}", keyType);
            try
            {
                var dataTable = new DataTable();
                using (var connection = new SqlConnection(_connectionString))
                {
                    connection.Open();

                    string getKeysSQL = "RIFF.GetKeyInstances";
                    using (var getCommand = CreateCommand(getKeysSQL, connection))
                    {
                        var rootHash = RFStringHelpers.QuickHash(key.RootKey().ToString());

                        getCommand.CommandType = CommandType.StoredProcedure;
                        getCommand.Parameters.AddWithValue("@KeyType", keyType);
                        getCommand.Parameters.AddWithValue("@SerializedKey", RFXMLSerializer.SerializeContract(key));
                        getCommand.Parameters.AddWithValue("@RootHash", rootHash);
                        using (var reader = getCommand.ExecuteReader(System.Data.CommandBehavior.SingleResult))
                        {
                            dataTable.Load(reader);
                        }
                    }
                }
                if (dataTable != null && dataTable.Rows != null && dataTable.Rows.Count > 0)
                {
                    // cache deserializer if key is explicit
                    foreach (DataRow dataRow in dataTable.Rows)
                    {
                        try
                        {
                            var catalogKeyID      = (long)dataRow["CatalogKeyID"];
                            var retrievedKeyType  = dataRow["KeyType"].ToString();
                            var serializedKey     = dataRow["SerializedKey"].ToString();
                            var graphInstanceName = dataRow["GraphInstanceName"].ToString();
                            var graphInstanceDate = new RFDate((int)dataRow["GraphInstanceDate"]);
                            var deserializedKey   = RFXMLSerializer.DeserializeContract(retrievedKeyType, serializedKey);

                            keys.Add(
                                new RFGraphInstance
                            {
                                Name      = graphInstanceName,
                                ValueDate = graphInstanceDate
                            },
                                deserializedKey as RFCatalogKey);
                        }
                        catch (Exception ex)
                        {
                            Log.Exception(this, ex, "Error deserializing key {0}", dataRow["SerializedKey"].ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception(this, "Error retrieving key instances", ex);
            }

            return(keys);
        }
Ejemplo n.º 5
0
 public override string ToString()
 {
     return(RFXMLSerializer.SerializeContract(this));
 }
Ejemplo n.º 6
0
 private string RootString()
 {
     return(RFXMLSerializer.SerializeContract(RootKey()));
 }
        /*
         * public virtual RFEngineProcessorParam ExtractFrom(RFInstruction i)
         * {
         *  return new RFEngineProcessorParam();
         * }*/

        public override int GetHashCode()
        {
            return(RFXMLSerializer.SerializeContract(this).GetHashCode());
        }
Ejemplo n.º 8
0
        private void Update(string dispatchKey, string processName, string instanceName, RFDate?valueDate, DispatchState state, long?weight, RFProcessingResult result, RFInstruction instruction)
        {
            try
            {
                using (var conn = new SqlConnection(_context.SystemConfig.DocumentStoreConnectionString))
                {
                    conn.Open();
                    using (var cmd = new SqlCommand("RIFF.UpdateDispatchQueue", conn))
                    {
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@Environment", RFStringHelpers.StringToSQL(_context.SystemConfig.Environment, false, 10, false));
                        cmd.Parameters.AddWithValue("@ItemType", (int)ItemType.GraphProcessInstruction);
                        cmd.Parameters.AddWithValue("@DispatchKey", RFStringHelpers.StringToSQL(dispatchKey, false, 140, false));
                        cmd.Parameters.AddWithValue("@ProcessName", RFStringHelpers.StringToSQL(processName, true, 100, false));
                        cmd.Parameters.AddWithValue("@GraphInstance", RFStringHelpers.StringToSQL(instanceName, true, 20, false));
                        if (valueDate != null && valueDate.Value.IsValid())
                        {
                            cmd.Parameters.AddWithValue("@ValueDate", valueDate.Value.Date);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@ValueDate", DBNull.Value);
                        }
                        if (weight.HasValue)
                        {
                            cmd.Parameters.AddWithValue("@Weight", weight.Value);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@Weight", DBNull.Value);
                        }
                        cmd.Parameters.AddWithValue("@DispatchState", (int)state);
                        if (state == DispatchState.Started)
                        {
                            cmd.Parameters.AddWithValue("@LastStart", DateTimeOffset.Now);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@LastStart", DBNull.Value);
                        }
                        if (result?.Messages != null)
                        {
                            cmd.Parameters.AddWithValue("@Message", RFStringHelpers.StringToSQL(String.Join("|", result.Messages), true, 200, false));
                        }
                        else if (state == DispatchState.Finished || state == DispatchState.Skipped || state == DispatchState.Started)
                        {
                            cmd.Parameters.AddWithValue("@Message", String.Empty); // clear past error messages
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@Message", DBNull.Value);
                        }
                        if (result != null)
                        {
                            cmd.Parameters.AddWithValue("@ShouldRetry", result.ShouldRetry);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@ShouldRetry", false);
                        }
                        if (state == DispatchState.Queued && instruction != null)
                        {
                            cmd.Parameters.AddWithValue("@InstructionType", RFStringHelpers.StringToSQL(instruction.GetType().FullName, false, 200, false));
                            cmd.Parameters.AddWithValue("@InstructionContent", RFXMLSerializer.SerializeContract(instruction));
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@InstructionType", DBNull.Value);
                            cmd.Parameters.AddWithValue("@InstructionContent", DBNull.Value);
                        }

                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                _context.Log.Exception(this, "Error updating Dispatch Store", ex);
            }
        }