Ejemplo n.º 1
0
        /// <summary>Check whether the batch folder exists.</summary>
        /// <param name="configuration">Service configuration.</param>
        /// <returns>Result of the diagnostic check</returns>
        private static DiagTestResult CheckBatchingFolderExists(SyncServiceConfiguration configuration)
        {
            var result = new DiagTestResult();

            try
            {
                if (configuration.IsBatchingEnabled)
                {
                    result.TestResult = Directory.Exists(configuration.BatchSpoolDirectory) ? DiagConstants.SUCCESS : DiagConstants.DIRECTORY_NOT_FOUND;
                }
                else
                {
                    result.TestResult = DiagConstants.BATCHING_NOT_ENABLED;
                }
            }
            catch (DirectoryNotFoundException directoryNotFoundException)
            {
                result.TestResult = DiagConstants.DIRECTORY_NOT_FOUND;

                AddExceptionInfo(directoryNotFoundException, result);
            }
            catch (Exception exception)
            {
                result.TestResult = DiagConstants.UNKNOWN_ERROR;

                AddExceptionInfo(exception, result);
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method tries to look up the service configuration from the MetadataCache.
        /// For the first request, there will be no item in the cache and so, an object of type
        /// SyncServiceConfiguration is created, initialized and added to the MetadataCache.
        /// </summary>
        private void CreateConfiguration(string scope)
        {
            Type serviceType = base.GetType();

            // Check if we already have a configuration for the service in the metadata cache.

            //MetadataCacheItem item = MetadataCache.TryLookup(serviceType);
            MetadataCacheItem item = MetadataCache.TryLookup(serviceType);

            if (null == item)
            {
                SyncTracer.Info("Creating SyncServiceConfiguration for service type {0}", serviceType);

                item = new MetadataCacheItem(serviceType);

                // Initialize the private member since it will then have default values.
                // In case of an error in the static initializer, we can refer to the default values
                // of configuration.
                _syncConfiguration = new SyncServiceConfiguration(typeof(T));

                // This will invoke the static initialization method.
                _syncConfiguration.Initialize(serviceType, scope);

                String conflictPolicy = Common.Logon.GetConflictPolicy(scope);
                if (!String.IsNullOrEmpty(conflictPolicy))
                {
                    String p = conflictPolicy.ToLower();
                    switch (p)
                    {
                    case "serverwins":
                        _syncConfiguration.SetConflictResolutionPolicy(ConflictResolutionPolicy.ServerWins);
                        break;

                    case "clientwins":
                        _syncConfiguration.SetConflictResolutionPolicy(ConflictResolutionPolicy.ClientWins);
                        break;

                    default:
                        throw new Exception("Invalid conflictPolicy value");
                    }
                }

                item.Configuration = _syncConfiguration;

                //MetadataCache.AddCacheItem(serviceType, item);
                MetadataCache.AddCacheItem(serviceType, item);

                SyncTracer.Info("SyncServiceConfiguration for service type {0} created successfully!", serviceType);
            }
            else
            {
                _syncConfiguration = item.Configuration;
            }

            // Invoke the testhook Initialize method.
            // Note: This needs to be called regardless of whether we find the configuration in the
            // cache or not because this is on a per request basis.
            _syncConfiguration.InvokeTestHookInitializeMethod(serviceType);
        }
        protected SyncRequestProcessorBase(SyncServiceConfiguration configuration, HttpContextServiceHost serviceHost)
        {
            WebUtil.CheckArgumentNull(configuration, "configuration");

            Debug.Assert(0 != configuration.ScopeNames.Count);

            _configuration = configuration;
            _scopeName = configuration.ScopeNames[0];
            _serviceHost = serviceHost;

            _serverConnectionString = _configuration.ServerConnectionString;
            _conflictResolutionPolicy = _configuration.ConflictResolutionPolicy;
        }
        protected SyncRequestProcessorBase(SyncServiceConfiguration configuration, HttpContextServiceHost serviceHost)
        {
            WebUtil.CheckArgumentNull(configuration, "configuration");

            Debug.Assert(0 != configuration.ScopeNames.Count);

            _configuration = configuration;
            _scopeName     = configuration.ScopeNames[0];
            _serviceHost   = serviceHost;

            _serverConnectionString   = _configuration.ServerConnectionString;
            _conflictResolutionPolicy = _configuration.ConflictResolutionPolicy;
        }
Ejemplo n.º 5
0
 internal static IRequestProcessor GetRequestProcessorInstance(RequestCommand requestCommand, SyncServiceConfiguration configuration,
     HttpContextServiceHost serviceHost)
 {
     switch (requestCommand)
     {
         case RequestCommand.UploadChanges:
             return new UploadChangesRequestProcessor(configuration, serviceHost);
         case RequestCommand.DownloadChanges:
             return new DownloadChangesRequestProcessor(configuration, serviceHost);
         case RequestCommand.SyncScopes:
             return new SyncScopesRequestProcessor(configuration);
         case RequestCommand.ScopeMetadata:
             return new ScopeSchemaRequestProcessor(configuration);
         default:
             throw new NotSupportedException();
     }
 }
Ejemplo n.º 6
0
        /// <summary>Check if the database is provisioned and has a template/scope that the service is configured for.</summary>
        /// <param name="configuration">Service configuration</param>
        /// <returns>Result of the diagnostic check</returns>
        private static DiagTestResult CheckDbProvisioning(SyncServiceConfiguration configuration)
        {
            Debug.Assert(configuration.ScopeNames.Count > 0, "configuration.ScopeNames.Count > 0");

            var result = new DiagTestResult();

            try
            {
                using (var connection = new SqlConnection(configuration.ServerConnectionString))
                {
                    var provisioning = new SqlSyncScopeProvisioning(connection);

                    // Set the ObjectSchema property. Without this, the TemplateExists and ScopeExists method
                    // always return false if the sync objects are provisioned in a non-dbo schema.
                    if (!String.IsNullOrEmpty(configuration.SyncObjectSchema))
                    {
                        provisioning.ObjectSchema = configuration.SyncObjectSchema;
                    }

                    // Current implementation only supports 1 scope per service head.
                    string scopeName = configuration.ScopeNames[0];

                    if (provisioning.ScopeExists(scopeName) || provisioning.TemplateExists(scopeName))
                    {
                        result.TestResult = DiagConstants.SUCCESS;
                    }
                    else
                    {
                        result.TestResult = DiagConstants.TEMPLATE_OR_SCOPE_DOES_NOT_EXIST;
                    }
                }
            }
            catch (Exception e)
            {
                result.TestResult = DiagConstants.UNKNOWN_ERROR;

                AddExceptionInfo(e, result);
            }

            return(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This method tries to look up the service configuration from the MetadataCache.
        /// For the first request, there will be no item in the cache and so, an object of type
        /// SyncServiceConfiguration is created, initialized and added to the MetadataCache.
        /// </summary>
        private void CreateConfiguration()
        {
            Type serviceType = base.GetType();

            // Check if we already have a configuration for the service in the metadata cache.
            MetadataCacheItem item = MetadataCache.TryLookup(serviceType);

            if (null == item)
            {
                SyncTracer.Info("Creating SyncServiceConfiguration for service type {0}", serviceType);

                item = new MetadataCacheItem(serviceType);

                // Initialize the private member since it will then have default values.
                // In case of an error in the static initializer, we can refer to the default values
                // of configuration.
                _syncConfiguration = new SyncServiceConfiguration(typeof(T));

                // This will invoke the static initialization method.
                _syncConfiguration.Initialize(serviceType);

                item.Configuration = _syncConfiguration;

                MetadataCache.AddCacheItem(serviceType, item);

                SyncTracer.Info("SyncServiceConfiguration for service type {0} created successfully!", serviceType);
            }
            else
            {
                _syncConfiguration = item.Configuration;
            }

            // Invoke the testhook Initialize method.
            // Note: This needs to be called regardless of whether we find the configuration in the
            // cache or not because this is on a per request basis.
            _syncConfiguration.InvokeTestHookInitializeMethod(serviceType);
        }
Ejemplo n.º 8
0
 internal RequestParser(HttpContextServiceHost serviceHost, SyncServiceConfiguration configuration)
 {
     _serviceHost = serviceHost;
     _configuration = configuration;
 }
 public ScopeSchemaRequestProcessor(SyncServiceConfiguration configuration)
 {
     _configuration = configuration;
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Perform diagnostic checks and return an instance of the <see cref="Message" /> class.
        /// </summary>
        /// <param name="configuration">Service configuration</param>
        /// <param name="serviceHost">HttpContext for the service</param>
        /// <returns>Result of the diagnostic checks</returns>
        internal static Message CreateDiagResponseMessage(SyncServiceConfiguration configuration, HttpContextServiceHost serviceHost)
        {
            // Check core msi presence by creating SyncKnowledge instance.
            DiagTestResult syncFxCoreCheck = CheckForSyncFxCore();

            // Establish connnection to SQL Server.
            DiagTestResult sqlConnectionCheck = CheckSqlConnection(configuration);

            // Check database provisioning.
            DiagTestResult dbProvisionedCheck = CheckDbProvisioning(configuration);

            // Check for clientaccesspolicy.xml or crossdomain.xml file.
            //DiagTestResult clientAccessPolicyCheck = CheckForClientAccessPolicy(serviceHost);

            // Check presence of batching folder.
            DiagTestResult batchingFolderExistsResult = CheckBatchingFolderExists(configuration);

            // Check write access to batching folder.
            DiagTestResult writeAccessToBatchingFolder = CheckWriteAccessToBatchingFolder(configuration);

            // Add configuration related information
            var configElement = new XElement("Configuration",
                                                new XElement("ScopeName", HttpUtility.HtmlEncode(configuration.ScopeNames[0])),

                                                new XElement("ConflictResolution", configuration.ConflictResolutionPolicy),

                                                new XElement("SerializationFormat", configuration.SerializationFormat),

                                                new XElement("VerboseEnabled", configuration.UseVerboseErrors),

                                                new XElement("BatchingDirectory", configuration.DownloadBatchSizeInKB == null 
                                                                                ? DiagConstants.BATCHING_NOT_ENABLED
                                                                                : configuration.BatchSpoolDirectory),

                                                new XElement("BatchSize", configuration.DownloadBatchSizeInKB == null 
                                                                                ? DiagConstants.BATCHING_NOT_ENABLED 
                                                                                : configuration.DownloadBatchSizeInKB.Value.ToString()));

            var diagXDocument = new XDocument();
            
            var rootNode = new XElement("root");
            
            diagXDocument.AddFirst(rootNode);
            
            // Add the results to the xml document.
            rootNode.Add(
                        new XElement("SyncFxCore",
                            new XElement("Result") { Value = syncFxCoreCheck.TestResult },
                            new XElement("ErrorInfo") { Value = syncFxCoreCheck.ExceptionDetails ?? String.Empty }),

                        new XElement("SqlConnection",
                            new XElement("Result") { Value = sqlConnectionCheck.TestResult },
                            new XElement("ErrorInfo") { Value = sqlConnectionCheck.ExceptionDetails ?? String.Empty }),

                        new XElement("DbProvisioned", 
                            new XElement("Result") { Value = dbProvisionedCheck.TestResult },
                            new XElement("ErrorInfo") { Value = dbProvisionedCheck.ExceptionDetails ?? String.Empty }),

                        new XElement("BatchingFolderPresent",
                            new XElement("Result") { Value = batchingFolderExistsResult.TestResult },
                            new XElement("ErrorInfo") { Value = batchingFolderExistsResult.ExceptionDetails ?? String.Empty }),

                        new XElement("WriteAccessToBatchingFolder",
                            new XElement("Result") { Value = writeAccessToBatchingFolder.TestResult },
                            new XElement("ErrorInfo") { Value = writeAccessToBatchingFolder.ExceptionDetails ?? String.Empty }),

                        //new XElement("PolicyFiles",
                        //    new XElement("Result") { Value = clientAccessPolicyCheck.TestResult },
                        //    new XElement("ErrorInfo") { Value = clientAccessPolicyCheck.ExceptionDetails ?? String.Empty }),

                        // Add the configuration node.
                        new XElement(configElement));

            // Create and cache the XslCompiledTransform if it is already not in the cache.
            ConfigureXslCompiledTransform();

            Message message;

            using (XmlReader diagXmlReader = diagXDocument.CreateReader())
            {
                var document = new XPathDocument(diagXmlReader);

                using (var writer = new StringWriter())
                {
                    // Transform the xml document into HTML.
                    _compiledTransform.Transform(document, null, writer);

                    // Create an return an instance of the Message class.
                    message = Message.CreateMessage(MessageVersion.None, String.Empty, XDocument.Parse(writer.ToString()).CreateReader());

                    message.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Xml));

                    var property = new HttpResponseMessageProperty { StatusCode = HttpStatusCode.OK };

                    property.Headers.Add(HttpResponseHeader.ContentType, SyncServiceConstants.CONTENT_TYPE_HTML);

                    message.Properties.Add(HttpResponseMessageProperty.Name, property);
                }
            }

            return message;
        }
Ejemplo n.º 11
0
        /// <summary>Check whether the batch folder exists.</summary>
        /// <param name="configuration">Service configuration.</param>
        /// <returns>Result of the diagnostic check</returns>
        private static DiagTestResult CheckBatchingFolderExists(SyncServiceConfiguration configuration)
        {
            var result = new DiagTestResult();

            try
            {
                if (configuration.IsBatchingEnabled)
                {
                    result.TestResult = Directory.Exists(configuration.BatchSpoolDirectory) ? DiagConstants.SUCCESS : DiagConstants.DIRECTORY_NOT_FOUND;
                }
                else
                {
                    result.TestResult = DiagConstants.BATCHING_NOT_ENABLED;
                }
            }
            catch (DirectoryNotFoundException directoryNotFoundException)
            {
                result.TestResult = DiagConstants.DIRECTORY_NOT_FOUND;

                AddExceptionInfo(directoryNotFoundException, result);
            }
            catch (Exception exception)
            {
                result.TestResult = DiagConstants.UNKNOWN_ERROR;

                AddExceptionInfo(exception, result);
            }

            return result;
        }
Ejemplo n.º 12
0
        /// <summary>Check whether the service has write permissions to the batch folder.</summary>
        /// <param name="configuration">Service configuration.</param>
        /// <returns>Result of the diagnostic check</returns>
        private static DiagTestResult CheckWriteAccessToBatchingFolder(SyncServiceConfiguration configuration)
        {
            var result = new DiagTestResult();

            try
            {
                if (configuration.IsBatchingEnabled)
                {
                    if (Directory.Exists(configuration.BatchSpoolDirectory))
                    {
                        try
                        {
                            string path = Path.Combine(configuration.BatchSpoolDirectory, Guid.NewGuid().ToString());

                            // attempt to create a file
                            using (File.Create(path)) { }

                            // delete the file.
                            File.Delete(path);

                            result.TestResult = DiagConstants.SUCCESS;
                        }
                        catch (UnauthorizedAccessException unauthorizedAccessException)
                        {
                            result.TestResult = DiagConstants.INSUFFICIENT_PERMISSIONS;

                            AddExceptionInfo(unauthorizedAccessException, result);
                        }
                        catch (PathTooLongException pathTooLongExceptionh)
                        {
                            result.TestResult = DiagConstants.PATH_TOO_LONG;

                            AddExceptionInfo(pathTooLongExceptionh, result);
                        }
                        catch (IOException ioException)
                        {
                            result.TestResult = DiagConstants.IO_ERROR;

                            AddExceptionInfo(ioException, result);
                        }
                    }
                    else
                    {
                        result.TestResult = DiagConstants.DIRECTORY_NOT_FOUND;
                    }
                }
                else
                {
                    result.TestResult = DiagConstants.BATCHING_NOT_ENABLED;
                }
            }
            catch (DirectoryNotFoundException directoryNotFoundException)
            {
                result.TestResult = DiagConstants.DIRECTORY_NOT_FOUND;

                AddExceptionInfo(directoryNotFoundException, result);
            }   
            catch (Exception exception)
            {
                result.TestResult = DiagConstants.UNKNOWN_ERROR;

                AddExceptionInfo(exception, result);
            }

            return result;
        }
Ejemplo n.º 13
0
        /// <summary>Check whether a connection can be opened successfully to the database.</summary>
        /// <param name="configuration">Service configuration</param>
        /// <returns>Result of the diagnostic check</returns>
        private static DiagTestResult CheckSqlConnection(SyncServiceConfiguration configuration)
        {
            var result = new DiagTestResult();

            try
            {
                new SqlConnectionStringBuilder(configuration.ServerConnectionString);
            }
            catch (KeyNotFoundException keyNotFoundException)
            {
                result.TestResult = DiagConstants.INVALID_SQL_CONNECTION_STRING;

                if (IsLocalRequest)
                {
                    result.ExceptionDetails = WebUtil.GetExceptionMessage(keyNotFoundException);
                }
            }
            catch (FormatException formatException)
            {
                result.TestResult = DiagConstants.INVALID_SQL_CONNECTION_STRING;

                if (IsLocalRequest)
                {
                    result.ExceptionDetails = WebUtil.GetExceptionMessage(formatException);
                }
            }
            catch (ArgumentException argumentException)
            {
                result.TestResult = DiagConstants.INVALID_SQL_CONNECTION_STRING;

                if (IsLocalRequest)
                {
                    result.ExceptionDetails = WebUtil.GetExceptionMessage(argumentException);
                }
            }
            catch (Exception e)
            {
                result.TestResult = DiagConstants.UNKNOWN_ERROR;

                if (IsLocalRequest)
                {
                    result.ExceptionDetails = WebUtil.GetExceptionMessage(e);
                }
            }

            if (result.TestResult == DiagConstants.NOT_DETERMINED)
            {
                try
                {
                    using (var connection = new SqlConnection(configuration.ServerConnectionString))
                    {
                        connection.Open();
                    }

                    result.TestResult = DiagConstants.SUCCESS;
                }
                catch (InvalidOperationException invalidOperationException)
                {
                    result.TestResult = DiagConstants.ERROR_OPENING_SQL_CONNECTION;

                    if (IsLocalRequest)
                    {
                        result.ExceptionDetails = WebUtil.GetExceptionMessage(invalidOperationException);
                    }
                }
                catch (SqlException sqlException) 
                {
                    result.TestResult = DiagConstants.ERROR_OPENING_SQL_CONNECTION;

                    if (IsLocalRequest)
                    {
                        result.ExceptionDetails = WebUtil.GetExceptionMessage(sqlException);
                    }
                }
                catch (ArgumentException argumentException)
                {
                    result.TestResult = DiagConstants.ERROR_OPENING_SQL_CONNECTION;

                    if (IsLocalRequest)
                    {
                        result.ExceptionDetails = WebUtil.GetExceptionMessage(argumentException);
                    }
                }
                catch (Exception e)
                {
                    result.TestResult = DiagConstants.UNKNOWN_ERROR;

                    if (IsLocalRequest)
                    {
                        result.ExceptionDetails = WebUtil.GetExceptionMessage(e);
                    }
                }
            }

            return result;
        }
Ejemplo n.º 14
0
        internal static IRequestProcessor GetRequestProcessorInstance(RequestCommand requestCommand, SyncServiceConfiguration configuration,
                                                                      HttpContextServiceHost serviceHost)
        {
            switch (requestCommand)
            {
            case RequestCommand.UploadChanges:
                return(new UploadChangesRequestProcessor(configuration, serviceHost));

            case RequestCommand.DownloadChanges:
                return(new DownloadChangesRequestProcessor(configuration, serviceHost));

            case RequestCommand.SyncScopes:
                return(new SyncScopesRequestProcessor(configuration));

            case RequestCommand.ScopeMetadata:
                return(new ScopeSchemaRequestProcessor(configuration));

            default:
                throw new NotSupportedException();
            }
        }
 public ScopeSchemaRequestProcessor(SyncServiceConfiguration configuration)
 {
     _configuration = configuration;
 }
 public DownloadChangesRequestProcessor(SyncServiceConfiguration configuration, HttpContextServiceHost serviceHost)
     : base(configuration, serviceHost)
 {
     base._syncOperation = SyncOperations.Download;
 }
Ejemplo n.º 17
0
        /// <summary>Check whether the service has write permissions to the batch folder.</summary>
        /// <param name="configuration">Service configuration.</param>
        /// <returns>Result of the diagnostic check</returns>
        private static DiagTestResult CheckWriteAccessToBatchingFolder(SyncServiceConfiguration configuration)
        {
            var result = new DiagTestResult();

            try
            {
                if (configuration.IsBatchingEnabled)
                {
                    if (Directory.Exists(configuration.BatchSpoolDirectory))
                    {
                        try
                        {
                            string path = Path.Combine(configuration.BatchSpoolDirectory, Guid.NewGuid().ToString());

                            // attempt to create a file
                            using (File.Create(path)) { }

                            // delete the file.
                            File.Delete(path);

                            result.TestResult = DiagConstants.SUCCESS;
                        }
                        catch (UnauthorizedAccessException unauthorizedAccessException)
                        {
                            result.TestResult = DiagConstants.INSUFFICIENT_PERMISSIONS;

                            AddExceptionInfo(unauthorizedAccessException, result);
                        }
                        catch (PathTooLongException pathTooLongExceptionh)
                        {
                            result.TestResult = DiagConstants.PATH_TOO_LONG;

                            AddExceptionInfo(pathTooLongExceptionh, result);
                        }
                        catch (IOException ioException)
                        {
                            result.TestResult = DiagConstants.IO_ERROR;

                            AddExceptionInfo(ioException, result);
                        }
                    }
                    else
                    {
                        result.TestResult = DiagConstants.DIRECTORY_NOT_FOUND;
                    }
                }
                else
                {
                    result.TestResult = DiagConstants.BATCHING_NOT_ENABLED;
                }
            }
            catch (DirectoryNotFoundException directoryNotFoundException)
            {
                result.TestResult = DiagConstants.DIRECTORY_NOT_FOUND;

                AddExceptionInfo(directoryNotFoundException, result);
            }
            catch (Exception exception)
            {
                result.TestResult = DiagConstants.UNKNOWN_ERROR;

                AddExceptionInfo(exception, result);
            }

            return(result);
        }
Ejemplo n.º 18
0
        /// <summary>Check whether a connection can be opened successfully to the database.</summary>
        /// <param name="configuration">Service configuration</param>
        /// <returns>Result of the diagnostic check</returns>
        private static DiagTestResult CheckSqlConnection(SyncServiceConfiguration configuration)
        {
            var result = new DiagTestResult();

            try
            {
                new SqlConnectionStringBuilder(configuration.ServerConnectionString);
            }
            catch (KeyNotFoundException keyNotFoundException)
            {
                result.TestResult = DiagConstants.INVALID_SQL_CONNECTION_STRING;

                if (IsLocalRequest)
                {
                    result.ExceptionDetails = WebUtil.GetExceptionMessage(keyNotFoundException);
                }
            }
            catch (FormatException formatException)
            {
                result.TestResult = DiagConstants.INVALID_SQL_CONNECTION_STRING;

                if (IsLocalRequest)
                {
                    result.ExceptionDetails = WebUtil.GetExceptionMessage(formatException);
                }
            }
            catch (ArgumentException argumentException)
            {
                result.TestResult = DiagConstants.INVALID_SQL_CONNECTION_STRING;

                if (IsLocalRequest)
                {
                    result.ExceptionDetails = WebUtil.GetExceptionMessage(argumentException);
                }
            }
            catch (Exception e)
            {
                result.TestResult = DiagConstants.UNKNOWN_ERROR;

                if (IsLocalRequest)
                {
                    result.ExceptionDetails = WebUtil.GetExceptionMessage(e);
                }
            }

            if (result.TestResult == DiagConstants.NOT_DETERMINED)
            {
                try
                {
                    using (var connection = new SqlConnection(configuration.ServerConnectionString))
                    {
                        connection.Open();
                    }

                    result.TestResult = DiagConstants.SUCCESS;
                }
                catch (InvalidOperationException invalidOperationException)
                {
                    result.TestResult = DiagConstants.ERROR_OPENING_SQL_CONNECTION;

                    if (IsLocalRequest)
                    {
                        result.ExceptionDetails = WebUtil.GetExceptionMessage(invalidOperationException);
                    }
                }
                catch (SqlException sqlException)
                {
                    result.TestResult = DiagConstants.ERROR_OPENING_SQL_CONNECTION;

                    if (IsLocalRequest)
                    {
                        result.ExceptionDetails = WebUtil.GetExceptionMessage(sqlException);
                    }
                }
                catch (ArgumentException argumentException)
                {
                    result.TestResult = DiagConstants.ERROR_OPENING_SQL_CONNECTION;

                    if (IsLocalRequest)
                    {
                        result.ExceptionDetails = WebUtil.GetExceptionMessage(argumentException);
                    }
                }
                catch (Exception e)
                {
                    result.TestResult = DiagConstants.UNKNOWN_ERROR;

                    if (IsLocalRequest)
                    {
                        result.ExceptionDetails = WebUtil.GetExceptionMessage(e);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Perform diagnostic checks and return an instance of the <see cref="Message" /> class.
        /// </summary>
        /// <param name="configuration">Service configuration</param>
        /// <param name="serviceHost">HttpContext for the service</param>
        /// <returns>Result of the diagnostic checks</returns>
        internal static Message CreateDiagResponseMessage(SyncServiceConfiguration configuration, HttpContextServiceHost serviceHost)
        {
            // Check core msi presence by creating SyncKnowledge instance.
            DiagTestResult syncFxCoreCheck = CheckForSyncFxCore();

            // Establish connnection to SQL Server.
            DiagTestResult sqlConnectionCheck = CheckSqlConnection(configuration);

            // Check database provisioning.
            DiagTestResult dbProvisionedCheck = CheckDbProvisioning(configuration);

            // Check for clientaccesspolicy.xml or crossdomain.xml file.
            DiagTestResult clientAccessPolicyCheck = CheckForClientAccessPolicy(serviceHost);

            // Check presence of batching folder.
            DiagTestResult batchingFolderExistsResult = CheckBatchingFolderExists(configuration);

            // Check write access to batching folder.
            DiagTestResult writeAccessToBatchingFolder = CheckWriteAccessToBatchingFolder(configuration);

            // Add configuration related information
            var configElement = new XElement("Configuration",
                                             new XElement("ScopeName", HttpUtility.HtmlEncode(configuration.ScopeNames[0])),

                                             new XElement("ConflictResolution", configuration.ConflictResolutionPolicy),

                                             new XElement("SerializationFormat", configuration.SerializationFormat),

                                             new XElement("VerboseEnabled", configuration.UseVerboseErrors),

                                             new XElement("BatchingDirectory", configuration.DownloadBatchSizeInKB == null
                                                                                ? DiagConstants.BATCHING_NOT_ENABLED
                                                                                : configuration.BatchSpoolDirectory),

                                             new XElement("BatchSize", configuration.DownloadBatchSizeInKB == null
                                                                                ? DiagConstants.BATCHING_NOT_ENABLED
                                                                                : configuration.DownloadBatchSizeInKB.Value.ToString()));

            var diagXDocument = new XDocument();

            var rootNode = new XElement("root");

            diagXDocument.AddFirst(rootNode);

            // Add the results to the xml document.
            rootNode.Add(
                new XElement("SyncFxCore",
                             new XElement("Result")
            {
                Value = syncFxCoreCheck.TestResult
            },
                             new XElement("ErrorInfo")
            {
                Value = syncFxCoreCheck.ExceptionDetails ?? String.Empty
            }),

                new XElement("SqlConnection",
                             new XElement("Result")
            {
                Value = sqlConnectionCheck.TestResult
            },
                             new XElement("ErrorInfo")
            {
                Value = sqlConnectionCheck.ExceptionDetails ?? String.Empty
            }),

                new XElement("DbProvisioned",
                             new XElement("Result")
            {
                Value = dbProvisionedCheck.TestResult
            },
                             new XElement("ErrorInfo")
            {
                Value = dbProvisionedCheck.ExceptionDetails ?? String.Empty
            }),

                new XElement("BatchingFolderPresent",
                             new XElement("Result")
            {
                Value = batchingFolderExistsResult.TestResult
            },
                             new XElement("ErrorInfo")
            {
                Value = batchingFolderExistsResult.ExceptionDetails ?? String.Empty
            }),

                new XElement("WriteAccessToBatchingFolder",
                             new XElement("Result")
            {
                Value = writeAccessToBatchingFolder.TestResult
            },
                             new XElement("ErrorInfo")
            {
                Value = writeAccessToBatchingFolder.ExceptionDetails ?? String.Empty
            }),

                new XElement("PolicyFiles",
                             new XElement("Result")
            {
                Value = clientAccessPolicyCheck.TestResult
            },
                             new XElement("ErrorInfo")
            {
                Value = clientAccessPolicyCheck.ExceptionDetails ?? String.Empty
            }),

                // Add the configuration node.
                new XElement(configElement));

            // Create and cache the XslCompiledTransform if it is already not in the cache.
            ConfigureXslCompiledTransform();

            Message message;

            using (XmlReader diagXmlReader = diagXDocument.CreateReader())
            {
                var document = new XPathDocument(diagXmlReader);

                using (var writer = new StringWriter())
                {
                    // Transform the xml document into HTML.
                    _compiledTransform.Transform(document, null, writer);

                    // Create an return an instance of the Message class.
                    message = Message.CreateMessage(MessageVersion.None, String.Empty, XDocument.Parse(writer.ToString()).CreateReader());

                    message.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Xml));

                    var property = new HttpResponseMessageProperty {
                        StatusCode = HttpStatusCode.OK
                    };

                    property.Headers.Add(HttpResponseHeader.ContentType, SyncServiceConstants.CONTENT_TYPE_HTML);

                    message.Properties.Add(HttpResponseMessageProperty.Name, property);
                }
            }

            return(message);
        }
Ejemplo n.º 20
0
        /// <summary>Check if the database is provisioned and has a template/scope that the service is configured for.</summary>
        /// <param name="configuration">Service configuration</param>
        /// <returns>Result of the diagnostic check</returns>
        private static DiagTestResult CheckDbProvisioning(SyncServiceConfiguration configuration)
        {
            Debug.Assert(configuration.ScopeNames.Count > 0, "configuration.ScopeNames.Count > 0");

            var result = new DiagTestResult();

            try
            {
                using (var connection = new SqlConnection(configuration.ServerConnectionString))
                {
                    var provisioning = new SqlSyncScopeProvisioning(connection);

                    // Set the ObjectSchema property. Without this, the TemplateExists and ScopeExists method
                    // always return false if the sync objects are provisioned in a non-dbo schema.
                    if (!String.IsNullOrEmpty(configuration.SyncObjectSchema))
                    {
                        provisioning.ObjectSchema = configuration.SyncObjectSchema;
                    }

                    // Current implementation only supports 1 scope per service head.
                    string scopeName = configuration.ScopeNames[0];
                    
                    if (provisioning.ScopeExists(scopeName) || provisioning.TemplateExists(scopeName))
                    {
                        result.TestResult = DiagConstants.SUCCESS;
                    }
                    else
                    {
                        result.TestResult = DiagConstants.TEMPLATE_OR_SCOPE_DOES_NOT_EXIST;
                    }
                }
            }
            catch (Exception e)
            {
                result.TestResult = DiagConstants.UNKNOWN_ERROR;

                AddExceptionInfo(e, result);
            }

            return result;
        }
 public UploadChangesRequestProcessor(SyncServiceConfiguration configuration, HttpContextServiceHost serviceHost)
     : base(configuration, serviceHost)
 {
     base._syncOperation = SyncOperations.Upload;
 }
Ejemplo n.º 22
0
 internal RequestParser(HttpContextServiceHost serviceHost, SyncServiceConfiguration configuration)
 {
     _serviceHost   = serviceHost;
     _configuration = configuration;
 }