Ejemplo n.º 1
0
        /// <summary>
        /// Purges the specified queue.
        /// </summary>
        static public void Purge(string queue)
        {
            try
            {
                var messageQueue = new MSMQ.MessageQueue(queue)
                {
                    Formatter = new ActiveXMessageFormatter()
                };
                messageQueue.Purge();
                ErrorLog.DebugLog(String.Format("Purge called for: {0}", queue), Segment);
            }
            catch (MessageQueueException ex)
            {
                ErrorLog.LogError("Purge() MessageQueueException: " + ex.Message, Segment);
            }

            // Handle invalid serialization format.
            catch (InvalidOperationException ex)
            {
                ErrorLog.LogError("Purge() InvalidOperationException: " + ex.Message, Segment);
            }

            catch (Exception ex)
            {
                ErrorLog.LogError("Purge() Exception: " + ex.Message, Segment);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="threshold"></param>
        /// <returns></returns>
        public static bool IsProcessMemoryTight(uint threshold)
        {
            string component = "ProcessMemory";
            bool   results   = false;

            try
            {
                IntPtr handle = Process.GetCurrentProcess().Handle;
                PPROCESS_MEMORY_COUNTERS counters = new PPROCESS_MEMORY_COUNTERS();
                if (GetProcessMemoryInfo(handle, counters, counters.cb))
                {
                    ErrorLog.DebugLog("Page Fault Count: " + counters.PageFaultCount, component);
                    ErrorLog.DebugLog("Page File Usage: " + counters.PagefileUsage, component);
                    ErrorLog.DebugLog("Peak Page File Usage: " + counters.PeakPagefileUsage, component);
                    ErrorLog.DebugLog("Peak Working Set Size: " + counters.PeakWorkingSetSize, component);
                    ErrorLog.DebugLog("Private Usage: " + counters.PrivateUsage, component);
                    ErrorLog.DebugLog("Working Set Size: " + counters.WorkingSetSize, component);

                    results = counters.PagefileUsage > threshold;
                }
            }
            catch (Exception ex)
            {
                ErrorLog.LogError(ex.Message, new CallingMethod());
            }
            return(results);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sends the message.
        /// </summary>
        /// <param name="queueName">Name of the queue.</param>
        /// <param name="message">The message.</param>
        /// <param name="label">The label.</param>
        /// <returns></returns>
        static public bool SendMessage(string queueName, string message, string label)
        {
            var results = false;

            try
            {
                ErrorLog.DebugLog(String.Format("SendMessage sending to {0}", queueName), Segment);
                var queue = new MSMQ.MessageQueue(queueName)
                {
                    Formatter = new ActiveXMessageFormatter()
                };
                // Set the formatter.

                queue.Send(message, label);
                results = true;
                ErrorLog.DebugLog(String.Format("SendMessage sent from {0}", queueName), Segment);
            }
            catch (MessageQueueException ex)
            {
                ErrorLog.LogError("SendMessage() MessageQueueException: " + ex.Message, Segment);
            }

            // Handle invalid serialization format.
            catch (InvalidOperationException ex)
            {
                ErrorLog.LogError("SendMessage() InvalidOperationException: " + ex.Message, Segment);
            }

            catch (Exception ex)
            {
                ErrorLog.LogError("SendMessage() Exception: " + ex.Message, Segment);
            }
            return(results);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Determines whether [is between maintenance time] [the specified dayofweek].
        /// N.B. really should not be here...JJG
        /// </summary>
        /// <param name="dayofweek">The dayofweek.</param>
        /// <param name="starttime">The starttime.</param>
        /// <param name="endtime">The endtime.</param>
        /// <returns></returns>
        public static bool IsBetweenMaintenanceTime(string dayofweek, string starttime, string endtime)
        {
            // Get the current server time since the zone conversion logic, first converts it to UTC and then to desired time zone.
            var      currentUtcDateTime   = DateTime.UtcNow.ToUniversalTime();
            DateTime?rentalBranchTimeZone = currentUtcDateTime.ToLocalTime();

            //Central
            rentalBranchTimeZone = TimeZoneInformation.ConvertDateTimeToTimeZone("u", rentalBranchTimeZone.ToString(), "Central Standard Time");
            ErrorLog.DebugLog("IsBetweenMaintenanceTime RentalBranchTime: " + rentalBranchTimeZone + "starttime: " + starttime + " end times: " + endtime, "test");

            // Current day of the week:
            //DayOfWeek day = RentalBranchTimeZone.Value.DayOfWeek;
            if (rentalBranchTimeZone != null && rentalBranchTimeZone.Value.DayOfWeek.Equals((DayOfWeek)Enum.Parse(typeof(DayOfWeek), dayofweek)))
            {
                TimeSpan startinterval;
                TimeSpan endinterval;

                if ((TimeSpan.TryParse(starttime, out startinterval)) && TimeSpan.TryParse(endtime, out endinterval))
                {
                    if (endinterval == startinterval)
                    {
                        return(true);
                    }
                    if (endinterval < startinterval)
                    {
                        return(rentalBranchTimeZone.Value.TimeOfDay <= endinterval && rentalBranchTimeZone.Value.TimeOfDay >= startinterval);
                    }
                    return(rentalBranchTimeZone.Value.TimeOfDay >= startinterval && rentalBranchTimeZone.Value.TimeOfDay <= endinterval);
                }
            }
            return(false);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the app config value.
        /// </summary>
        public static string GetAppConfigValue(string name)
        {
            var results =
                GetSettingFromNonProductionDatabase(name) ?? GetSetting(name);

            ErrorLog.DebugLog(string.Format("Retrieving {0} = {1}", name, results), "GetAppConfigValue");
            return(results);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the global app config value.
        /// Use this to get a config setting regardless
        /// of whether or not it is a production instance. (OPM)
        /// </summary>
        /// <returns></returns>
        public static string GetGlobalAppConfigValue(string name, string instance)
        {
            var results =
                GetSettingFromDatabase(name, instance) ?? GetSetting(name);

            ErrorLog.DebugLog(string.Format("Retrieving {0} = {1} from {2}", name, results, instance), "GetGlobalAppConfigValue");
            return(results);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the DSN from instance.
        /// </summary>
        /// <param name="request">the requested instance</param>
        /// <returns></returns>
        static public string GetDsnFromInstance(string request)
        {
            var instance = request.ToUpper();
            var results  = String.Format("DSN={0};UID=FNSOWNER;PWD={1};SERVER={2}", instance,
                                         GetPasswordFromInstance(instance), instance);

            ErrorLog.DebugLog(String.Format("GetDsnFromInstance returning {0}", results), Source);
            return(results);
        }
 /// <summary>
 /// Remotes the certificate validate.
 /// </summary>
 private static bool RemoteCertificateValidate(
     object sender, X509Certificate cert,
     X509Chain chain, SslPolicyErrors error)
 {
     ErrorLog.DebugLog(string.Format("ServerCertificateValidationCallback sender: {0}, error: {1}",
                                     sender, error), "CertificateValidationCallback");
     // trust any certificate!!!
     return(true);
 }
Ejemplo n.º 9
0
        private static string GetSettingFromDatabase(string key, string instance)
        {
            try
            {
                using (var settings = new DbClassLibrary.ActiveRecords.ConfigSettings
                {
                    Instance = instance,
                    Query = "select * from config_settings where KEY = :key"
                })
                {
                    settings.AddParameter("key", key);

                    var weakKey    = ErrorLog.GetProcessName().ToUpper();
                    var machineKey = Environment.MachineName.ToUpper();
                    var strongKey  = machineKey + "." + weakKey;

                    var listResults =
                        settings.Results().Where(a => a.Application.ToUpper().Contains(weakKey) ||
                                                 a.Application.ToUpper().Contains(machineKey)).ToList();

                    if (listResults.Count == 0)
                    {
                        return(default(string));
                    }

                    return
                        (listResults
                         .Where(a => a.Application.ToUpper() == strongKey)
                         .Select(a => a.ConfigValue).FirstOrDefault() ??
                         listResults
                         .Where(a => a.Application.ToUpper() == machineKey)
                         .Select(a => a.ConfigValue).FirstOrDefault() ??
                         listResults
                         .Where(a => a.Application.ToUpper() == weakKey)
                         .Select(a => a.ConfigValue).FirstOrDefault());
                }
            }
            catch (Exception ex)
            {
                ErrorLog.DebugLog(ex.Message, "GetAppConfigValue");
                return(default(string));
            }
        }
Ejemplo n.º 10
0
        static internal void Log2ClaimSubmissionLog(ClaimSubmissionLogger.LoggerPackage package)
        {
            if (string.IsNullOrEmpty(package.RquId))
            {
                ErrorLog.LogWarning("LogResponseBody must have valid rquid", ServiceName);
                return;
            }

            var claimLog = new ClaimSubmissionLog
            {
                RquId     = package.RquId,
                Instance  = package.Instance,
                TimeStamp = package.TimeStamp.ToString(DatabaseInstance.DatabaseDateFormat)
            };
            var results = package.Prefix == ClaimSubmissionLogger.LogType.Request
          ? claimLog.SetRequest(package.Document)
          : claimLog.SetResponse(package.Document);

            ErrorLog.DebugLog(String.Format("claimLog.SetResponse returned {0}", results), ServiceName);
        }
Ejemplo n.º 11
0
 private static string[] GetFtpFileList(string source, string pattern)
 {
     string[] files = null;
     try
     {
         clsFTP ftp = OpenFtp(source);
         try
         {
             files = ftp.GetFileList(pattern);
         }
         finally
         {
             ftp.CloseConnection();
         }
     }
     catch (Exception ex)
     {
         ErrorLog.DebugLog(ex.Message, "FileUtility");
     }
     return(files ?? new string[] { });
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Determines whether [has response body] [the specified rq id].
        /// </summary>
        /// <param name="rqId">The rq id.</param>
        /// <param name="instance">The database instance.</param>
        /// <returns></returns>
        static public string HasResponseBody(string rqId, string instance)
        {
            var results = string.Empty;

            if (rqId.Length == 0)
            {
                ErrorLog.LogWarning("HasResponseBody must have valid rquid", ServiceName);
                return(results);
            }
            var claimLog = new ClaimSubmissionLog {
                RquId = rqId, Instance = instance
            };

            results = claimLog.GetResponse();

            ErrorLog.DebugLog(
                results.Length > 0
          ? "claimLog.HasResponseBody returned results"
          : "claimLog.HasResponseBody returned no results", ServiceName);

            return(results);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Gets the next message.
        /// </summary>
        static internal String GetNextMessage(string queueName, TimeSpan span)
        {
            var results = string.Empty;

            try
            {
                ErrorLog.DebugLog(String.Format("GetNextMessage getting from {0}", queueName), Segment);
                var queue = new MSMQ.MessageQueue(queueName)
                {
                    Formatter = new ActiveXMessageFormatter()
                };
                // Set the formatter.
                var message = queue.Receive(span);
                if (message != null)
                {
                    results = message.Body as string;
                }
                ErrorLog.DebugLog(String.Format("GetNextMessage received from {0}", queueName), Segment);
            }
            catch (MessageQueueException ex)
            {
                if (ex.MessageQueueErrorCode != MessageQueueErrorCode.IOTimeout)
                {
                    ErrorLog.LogError(string.Format("GetNextMessage({0}) MessageQueueException: ", queueName) + ex.Message, Segment);
                }
            }

            // Handle invalid serialization format.
            catch (InvalidOperationException ex)
            {
                ErrorLog.LogError(string.Format("GetNextMessage({0}) InvalidOperationException: ", queueName) + ex.Message, Segment);
            }

            catch (Exception ex)
            {
                ErrorLog.LogError(string.Format("GetNextMessage({0}) Exception: ", queueName) + ex.Message, Segment);
            }
            return(results);
        }
Ejemplo n.º 14
0
 public static string GetConfigNameValuePair(string name, string key)
 {
     try
     {
         using (var settings = new DbClassLibrary.ActiveRecords.ConfigSettings
         {
             Query = "select * from config_settings where APPLICATION = :app and KEY = :key"
         })
         {
             settings.AddParameter("app", name);
             settings.AddParameter("key", key);
             var setting = settings.Results().FirstOrDefault();
             if (setting != null)
             {
                 return(setting.ConfigValue);
             }
         }
     }
     catch (Exception ex)
     {
         ErrorLog.DebugLog(ex.Message, "GetAppConfigValue");
     }
     return(default(string));
 }
Ejemplo n.º 15
0
        private static string [] GetReferencedAssemblies()
        {
            var evalType   = new Eval().GetType();
            var assemblies = evalType.Assembly
                             .GetReferencedAssemblies()
                             .Select(a => a.FullName);

            var assemblyLocations =
                assemblies.Select(a => Assembly.ReflectionOnlyLoad(a).Location)
                .Where(a => !a.ToLower().Contains("\\fnsnet\\bin\\"))
                .ToList();

            assemblyLocations.Add(evalType.Assembly.Location);

            var results = new HashSet <string>();

            foreach (var set in assemblyLocations)
            {
                results.Add(set);
                ErrorLog.DebugLog("adding " + set, "FnsUtility.Eval");
            }

            return(results.ToArray());
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Executes the method.
        /// </summary>
        /// <param name="method">The method.</param>
        /// <param name="parms">The parms.</param>
        /// <returns></returns>
        static public string ExecuteMethod(string method, string parms)
        {
            var results = String.Empty;

            try
            {
                const string delimiter           = ".";
                var          program             = method.Split(delimiter.ToCharArray(), 6, StringSplitOptions.RemoveEmptyEntries);
                object[]     requestedParameters = { parms };

                try
                {
                    ErrorLog.DebugLog(String.Format("ExecuteMethod entered for {0}", method), Source);
                    if (program.Length < 3)
                    {
                        throw new ArgumentException(String.Format("ExecuteMethod requires Assemby.Class.Method format: {0},", method));
                    }

                    var requestedAssembly = Assembly.Load(program[0]);
                    Assert.Test(requestedAssembly != null, string.Format("could not locate assembly: {0},", program[0]));

                    ErrorLog.DebugLog(String.Format("Assembly loaded: {0}", program[0]), Source);
                    var typeName = new StringBuilder();
                    for (var i = 0; i < (program.Length - 1); ++i)
                    {
                        if (i > 0)
                        {
                            typeName.Append(".");
                        }

                        typeName.Append(program[i]);
                    }
                    if (requestedAssembly != null)
                    {
                        var requestedType = requestedAssembly.GetType(typeName.ToString());
                        Assert.Test(requestedType != null, string.Format("could not locate assembly type: {0},", typeName));

                        ErrorLog.DebugLog(String.Format("Type loaded: {0}", typeName), Source);
                        const BindingFlags bf = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance |
                                                BindingFlags.Static | BindingFlags.ExactBinding;

                        if (requestedType != null)
                        {
                            var    requestedConstructor = requestedType.GetConstructor(Type.EmptyTypes);
                            object request = null;
                            if (requestedConstructor != null)
                            {
                                request = requestedConstructor.Invoke(null);
                                Assert.Test(request != null, string.Format("could not Invoke: {0},", typeName));
                            }
                            var methodIndex = program.Length - 1;
                            ErrorLog.DebugLog(String.Format("Constructor Invoked: {0}", typeName), Source);

                            var classType = request == null ? requestedType : request.GetType();
                            var methInfo  = classType.GetMethod(program[methodIndex], bf, null, new[] { typeof(string) }, null);

                            Assert.Test(methInfo != null,
                                        string.Format("could not find method: {0} for type: {1},", program[methodIndex], typeName));

                            ErrorLog.DebugLog(String.Format("Method {0} retrieved.", program[methodIndex]), Source);
                            if (methInfo != null)
                            {
                                var returnObject = methInfo.Invoke(request, requestedParameters);
                                ErrorLog.DebugLog(String.Format("Method {0} Invoked.", program[methodIndex]), Source);

                                if (returnObject != null)
                                {
                                    results = returnObject as string;
                                }
                            }
                        }
                    }
                }
                catch (TargetInvocationException ex)
                {
                    throw ex.InnerException;
                }
            }
            catch (Exception ex)
            {
                var errorMessage = ex.Message.Substring(0, Math.Min(ex.Message.Length, 255));
                results = String.Format("<ERROR>{0}</ERROR>", errorMessage);
                ErrorLog.LogError(String.Format("Error in ExecuteMethod({0}): {1}", method, errorMessage), Source);
            }
            return(results);
        }
Ejemplo n.º 17
0
 public override bool Stop()
 {
     ErrorLog.DebugLog("PerformanceMonitor Stop called.", "IPerformanceMonitor");
     return(true);
 }