Esempio n. 1
0
        internal static void SerializeDataObjectsToStrings(IConfigurationAndLogAccessor accessor, string id, DataDictionary extendedData)
        {
            if (extendedData == null)
            {
                return;
            }

            // pre-serialize extended data objects so that we won't fail if we can't serialize them
            // also this allows us to log the exact one that caused an issue.
            var keys = new List <string>(extendedData.Keys);

            foreach (string key in keys)
            {
                if (key.AnyWildcardMatches(accessor.Configuration.DataExclusions, true))
                {
                    continue;
                }

                object data = extendedData[key];
                if (data is string)
                {
                    continue;
                }

                try {
                    extendedData[key] = ModelSerializer.Current.SerializeToString(data, excludedPropertyNames: accessor.Configuration.DataExclusions);
                } catch (Exception ex) {
                    accessor.Log.FormattedError(typeof(QueueManager), ex, "Unable to serialize extended data entry for '{0}' with key '{1}': {2}", id, key, ex.Message);
                    extendedData[key] = String.Format("Unable to serialize extended data key \"{0}\" of type \"{1}\". {2}", key, extendedData[key].GetType(), ex);
                }
            }
        }
Esempio n. 2
0
        internal static void SerializeErrorExtendedData(IConfigurationAndLogAccessor accessor, Error error) {
            if (error == null)
                return;

            if (error.Modules != null) {
                foreach (Module m in error.Modules)
                    SerializeExtendedDataObjectsToStrings(accessor, error.Id, m.ExtendedData);
            }

            if (error.RequestInfo != null)
                SerializeExtendedDataObjectsToStrings(accessor, error.Id, error.RequestInfo.ExtendedData);

            if (error.EnvironmentInfo != null)
                SerializeExtendedDataObjectsToStrings(accessor, error.Id, error.EnvironmentInfo.ExtendedData);

            ErrorInfo current = error;
            while (current != null) {
                SerializeExtendedDataObjectsToStrings(accessor, error.Id, current.ExtendedData);

                if (current.StackTrace != null) {
                    foreach (StackFrame s in current.StackTrace) {
                        SerializeExtendedDataObjectsToStrings(accessor, error.Id, s.ExtendedData);
                        if (s.Parameters != null) {
                            foreach (Parameter p in s.Parameters)
                                SerializeExtendedDataObjectsToStrings(accessor, error.Id, p.ExtendedData);
                        }
                    }
                }

                current = current.Inner;
            }
        }
Esempio n. 3
0
        internal static void SerializeErrorExtendedData(IConfigurationAndLogAccessor accessor, Error error)
        {
            if (error == null)
            {
                return;
            }

            if (error.Modules != null)
            {
                foreach (Module m in error.Modules)
                {
                    SerializeDataObjectsToStrings(accessor, error.Id, m.ExtendedData);
                }
            }

            if (error.RequestInfo != null)
            {
                SerializeDataObjectsToStrings(accessor, error.Id, error.RequestInfo.ExtendedData);
            }

            if (error.EnvironmentInfo != null)
            {
                SerializeDataObjectsToStrings(accessor, error.Id, error.EnvironmentInfo.ExtendedData);
            }

            ErrorInfo current = error;

            while (current != null)
            {
                SerializeDataObjectsToStrings(accessor, error.Id, current.ExtendedData);

                if (current.StackTrace != null)
                {
                    foreach (StackFrame s in current.StackTrace)
                    {
                        SerializeDataObjectsToStrings(accessor, error.Id, s.ExtendedData);
                        if (s.Parameters != null)
                        {
                            foreach (Parameter p in s.Parameters)
                            {
                                SerializeDataObjectsToStrings(accessor, error.Id, p.ExtendedData);
                            }
                        }
                    }
                }

                current = current.Inner;
            }
        }
        internal static void ProcessServerConfigResponse(IConfigurationAndLogAccessor accessors, ConfigurationDictionary serverConfig, string storeId)
        {
            if (serverConfig == null)
            {
                return;
            }

            try {
                // only allow one save at a time
                using (new SingleGlobalInstance(String.Concat(storeId, CachedServerConfigFile).GetHashCode().ToString(), 500)) {
                    // retry loop
                    for (int retry = 0; retry < 2; retry++)
                    {
                        using (var dir = new IsolatedStorageDirectory(storeId)) {
                            try {
                                dir.WriteFile(CachedServerConfigFile, serverConfig);
                                break;
                            } catch (Exception ex) {
                                // File is being used by another process or thread or the file does not exist.
                                accessors.Log.FormattedError(ex, "Unable to save server config to local storage: {0}", ex.Message);
                                Thread.Sleep(50);
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                accessors.Log.Error(ex, "An error occurred while saving client configuration");
            }

            // apply the config values from the server to the current client configuration
            foreach (string k in serverConfig.Keys)
            {
                accessors.Configuration[k] = serverConfig[k];
            }

            // if a set of data exclusions are not sent down, then it means that there aren't any exclusions.
            if (!serverConfig.ContainsKey("@@DataExclusions"))
            {
                accessors.Configuration["@@DataExclusions"] = String.Empty;
            }
        }
        internal static void ProcessServerConfigResponse(IConfigurationAndLogAccessor accessors, ConfigurationDictionary serverConfig, string storeId) {
            if (serverConfig == null)
                return;

            try {
                // only allow one save at a time
                using (new SingleGlobalInstance(String.Concat(storeId, CachedServerConfigFile).GetHashCode().ToString(), 500)) {
                    // retry loop
                    for (int retry = 0; retry < 2; retry++) {
                        using (var dir = new IsolatedStorageDirectory(storeId)) {
                            try {
                                dir.WriteFile(CachedServerConfigFile, serverConfig);
                                break;
                            } catch (Exception ex) {
                                // File is being used by another process or thread or the file does not exist.
                                accessors.Log.FormattedError(ex, "Unable to save server config to local storage: {0}", ex.Message);
                                Thread.Sleep(50);
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                accessors.Log.Error(ex, "An error occurred while saving client configuration");
            }

            // apply the config values from the server to the current client configuration
            foreach (string k in serverConfig.Keys)
                accessors.Configuration[k] = serverConfig[k];

            // if a set of data exclusions are not sent down, then it means that there aren't any exclusions.
            if (!serverConfig.ContainsKey("@@DataExclusions"))
                accessors.Configuration["@@DataExclusions"] = String.Empty;
        }
Esempio n. 6
0
 public QueueManager(IConfigurationAndLogAccessor accessors, IQueueStore store) : this(accessors) {
     _store = store;
 }
Esempio n. 7
0
 public QueueManager(IConfigurationAndLogAccessor accessors)
 {
     _accessors = accessors;
 }
Esempio n. 8
0
        internal static void SerializeExtendedDataObjectsToStrings(IConfigurationAndLogAccessor accessor, string id, ExtendedDataDictionary extendedData) {
            if (extendedData == null)
                return;

            // pre-serialize extended data objects so that we won't fail if we can't serialize them
            // also this allows us to log the exact one that caused an issue.
            var keys = new List<string>(extendedData.Keys);
            foreach (string key in keys) {
                if (key.AnyWildcardMatches(accessor.Configuration.DataExclusions, true))
                    continue;

                object data = extendedData[key];
                if (data is string)
                    continue;

                try {
                    extendedData[key] = ModelSerializer.Current.SerializeToString(data, excludedPropertyNames: accessor.Configuration.DataExclusions);
                } catch (Exception ex) {
                    accessor.Log.FormattedError(typeof(QueueManager), ex, "Unable to serialize extended data entry for '{0}' with key '{1}': {2}", id, key, ex.Message);
                    extendedData[key] = String.Format("Unable to serialize extended data key \"{0}\" of type \"{1}\". {2}", key, extendedData[key].GetType(), ex);
                }
            }
        }
Esempio n. 9
0
 public QueueManager(IConfigurationAndLogAccessor accessors, IQueueStore store) : this(accessors) {
     _store = store;
 }
Esempio n. 10
0
 public QueueManager(IConfigurationAndLogAccessor accessors) {
     _accessors = accessors;
 }