コード例 #1
0
        public void ConstructorClientUrlMalformed()
        {
            var mockCxSettings = new Mock <ISitecoreConnectionSettings>();

            mockCxSettings.SetupGet(cxSettings => cxSettings.ClientUrl).Returns("xxx");
            var manager = new SitecoreConnectionManager(mockCxSettings.Object);
        }
コード例 #2
0
        public void ConstructorClientUrlHttps()
        {
            var mockCxSettings = new Mock <ISitecoreConnectionSettings>();

            mockCxSettings.SetupGet(cxSettings => cxSettings.ClientUrl).Returns("https://sc80/sitecore");
            var manager = new SitecoreConnectionManager(mockCxSettings.Object);
        }
コード例 #3
0
        protected virtual void btnOK_Click(object sender, RoutedEventArgs e)
        {
            //
            //save the changes to the driver settings
            if (this.SaveViewToModelCallback != null)
            {
                this.SaveViewToModelCallback(this.Model);
            }
            //
            //update app.config for this connection
            var reader = this.AppConfigReaderType.GetInstance <IAppConfigReader>();

            if (reader == null)
            {
                MessageBox.Show("Unable to get an IAppConfigReader object.", "Error Saving Connection", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                var cxManager = new SitecoreConnectionManager(this.Model.CxSettings);
                var config    = reader.Read(cxManager, this.Model, "web.config", false);
                if (config == null)
                {
                    MessageBox.Show("IAppConfigReader object returned no document.", "Error Saving Connection", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    reader.Save(config, this.Model);
                }
            }
            //
            //
            this.DialogResult = true;
        }
コード例 #4
0
        private async Task <ItemModel> GetEmailConfigurationItem(CommercePipelineExecutionContext context)
        {
            SitecoreConnectionManager connection = new SitecoreConnectionManager();
            var stiboMailSetting = await connection.GetItemByPathAsync(context.CommerceContext, Models.ProductContsants.MailSettings);

            if (stiboMailSetting == null)
            {
                return(null);
            }
            return(stiboMailSetting);
        }
コード例 #5
0
        private async Task <ItemModel> GetStiboImportSettings(CommercePipelineExecutionContext context)
        {
            SitecoreConnectionManager connection = new SitecoreConnectionManager();
            var stiboImportSettingItem           = await connection.GetItemByPathAsync(context.CommerceContext, ProductContsants.StiboImportSettingPath);

            if (stiboImportSettingItem == null)
            {
                return(null);
            }
            return(stiboImportSettingItem);
        }
コード例 #6
0
        public void GetSitecoreConfigClientUrlHostNotFound()
        {
            var mockCxSettings = new Mock <ISitecoreConnectionSettings>();

            mockCxSettings.SetupGet(cxSettings => cxSettings.ClientUrl).Returns("http://localhost/sitecore");
            var manager  = new SitecoreConnectionManager(mockCxSettings.Object);
            var response = manager.GetSitecoreConfig();

            Assert.IsNotNull(response);
            Assert.IsNull(response.Data);
            Assert.IsNotNull(response.GetExceptions());
            Assert.IsTrue(response.GetExceptions().Any(ex => ex.GetType() == typeof(WebException)));
        }
コード例 #7
0
        public void TestConnectionSitecore80()
        {
            var mockCxSettings = new Mock <ISitecoreConnectionSettings>();

            mockCxSettings.SetupGet(cxSettings => cxSettings.Username).Returns(@"sitecore\admin");
            mockCxSettings.SetupGet(cxSettings => cxSettings.Password).Returns("b");
            mockCxSettings.SetupGet(cxSettings => cxSettings.ClientUrl).Returns("http://sc80/sitecore");
            var manager  = new SitecoreConnectionManager(mockCxSettings.Object);
            var response = manager.TestConnection();

            Assert.IsNotNull(response);
            Assert.IsTrue(response.Data);
            Assert.IsNotNull(response.GetExceptions());
            Assert.IsFalse(response.GetExceptions().Any());
        }
コード例 #8
0
        public void GetVersionSitecore80()
        {
            var mockCxSettings = new Mock <ISitecoreConnectionSettings>();

            mockCxSettings.SetupGet(cxSettings => cxSettings.ClientUrl).Returns("http://sc80/sitecore");
            var manager  = new SitecoreConnectionManager(mockCxSettings.Object);
            var response = manager.GetSitecoreVersion();

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.Data);
            Assert.AreEqual(8, response.Data.Major);
            Assert.AreEqual(0, response.Data.Minor);
            Assert.IsNotNull(response.GetExceptions());
            Assert.IsFalse(response.GetExceptions().Any());
        }
コード例 #9
0
        public void TestConnectionPasswordMissing()
        {
            var mockCxSettings = new Mock <ISitecoreConnectionSettings>();

            mockCxSettings.SetupGet(cxSettings => cxSettings.Username).Returns(@"sitecore\admin");
            mockCxSettings.SetupGet(cxSettings => cxSettings.Password).Returns((string)null);
            mockCxSettings.SetupGet(cxSettings => cxSettings.ClientUrl).Returns("http://sc80/sitecore");
            var manager  = new SitecoreConnectionManager(mockCxSettings.Object);
            var response = manager.TestConnection();

            Assert.IsNotNull(response);
            Assert.IsFalse(response.Data);
            Assert.IsNotNull(response.GetExceptions());
            Assert.IsTrue(response.GetExceptions().Any(ex => ex.GetType() == typeof(AuthenticationException)));
        }
コード例 #10
0
        public void TestConnectionClientUrlHostNotFound()
        {
            var mockCxSettings = new Mock <ISitecoreConnectionSettings>();

            mockCxSettings.SetupGet(cxSettings => cxSettings.Username).Returns(@"sitecore\admin");
            mockCxSettings.SetupGet(cxSettings => cxSettings.Password).Returns("b");
            mockCxSettings.SetupGet(cxSettings => cxSettings.ClientUrl).Returns("http://localhost/sitecore");
            var manager  = new SitecoreConnectionManager(mockCxSettings.Object);
            var response = manager.TestConnection();

            Assert.IsNotNull(response);
            Assert.IsFalse(response.Data);
            Assert.IsNotNull(response.GetExceptions());
            Assert.IsTrue(response.GetExceptions().Any(ex => ex.GetType() == typeof(WebException)));
        }
コード例 #11
0
        public void GetSitecoreConfigUsernameIncorrect()
        {
            var mockCxSettings = new Mock <ISitecoreConnectionSettings>();

            mockCxSettings.SetupGet(cxSettings => cxSettings.Username).Returns("xxxx");
            mockCxSettings.SetupGet(cxSettings => cxSettings.Password).Returns("b");
            mockCxSettings.SetupGet(cxSettings => cxSettings.ClientUrl).Returns("http://sc80/sitecore");
            var manager  = new SitecoreConnectionManager(mockCxSettings.Object);
            var response = manager.GetSitecoreConfig();

            Assert.IsNotNull(response);
            Assert.IsNull(response.Data);
            Assert.IsNotNull(response.GetExceptions());
            Assert.IsTrue(response.GetExceptions().Any(ex => ex.GetType() == typeof(AuthenticationException)));
        }
コード例 #12
0
        protected virtual Version GetSitecoreVersion(SitecoreConnectionManager manager)
        {
            var response = manager.GetSitecoreVersion();

            if (response == null)
            {
                MessageBox.Show("GetSitecoreVersion() returned a null response.", TEST_CONNECTION_CAPTION, MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }
            if (response.Data == null)
            {
                var b1 = new StringBuilder();
                b1.AppendLine("The Sitecore server version could not be determined.\n\nThe following messages were returned:\n");
                b1.AppendLine(string.Join("\n", response.GetExceptions().Select(ex => string.Format("* {0}", ex.Message))));
                MessageBox.Show(b1.ToString(), TEST_CONNECTION_CAPTION, MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }
            return(response.Data);
        }
コード例 #13
0
        private void btnTest_Click(object sender, RoutedEventArgs e)
        {
            var manager = new SitecoreConnectionManager(this);

            if (!this.IsValidWebRoot(this.txtWebrootPath.Text))
            {
                return;
            }
            if (!this.IsValidConnectionSettings(manager))
            {
                return;
            }
            var version = GetSitecoreVersion(manager);

            if (version == null)
            {
                return;
            }
            var reader = this.AppConfigReaderType.GetInstance <IAppConfigReader>();

            if (reader == null)
            {
                MessageBox.Show("No app config reader could be resolved.", TEST_CONNECTION_CAPTION, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            var builder = new StringBuilder();

            builder.AppendFormat("Connection settings are valid for {0}.", version);
            if (!reader.IsSupportedVersion(version))
            {
                builder.Append(
                    "\n\nThis version of Sitecore is not supported by the currently selected IAppConfigReader class.");
                builder.Append(
                    "\n\nThis means that config changes implemented by the IAppConfigReader may conflict with your version of Sitecore. This will not affect the Sitecore server, but it may prevent LINQPad from being able to properly communicate with the Sitecore server.");
                builder.Append(
                    "\n\nIf you experience problems you may need to implement a new IAppConfigReader or extend the one currently being used.");
            }
            MessageBox.Show(builder.ToString(), TEST_CONNECTION_CAPTION, MessageBoxButton.OK,
                            MessageBoxImage.Asterisk);
        }
コード例 #14
0
 protected virtual bool IsValidConnectionSettings(SitecoreConnectionManager manager)
 {
     if (string.IsNullOrEmpty(this.ClientUrl))
     {
         return(false);
     }
     Mouse.OverrideCursor = Cursors.Wait;
     try
     {
         var version = GetSitecoreVersion(manager);
         if (version == null)
         {
             return(false);
         }
         var response = manager.TestConnection();
         if (response == null)
         {
             MessageBox.Show("TestConnection() returned a null response.", TEST_CONNECTION_CAPTION, MessageBoxButton.OK, MessageBoxImage.Error);
             return(false);
         }
         if (!response.Data)
         {
             var b1 = new StringBuilder();
             b1.AppendLine("Unable to connect to the Sitecore server using the specified settings.");
             if (response.GetExceptions().Any())
             {
                 b1.AppendLine("\n\nThe following exceptions were thrown:\n");
                 b1.AppendLine(string.Join("\n", response.GetExceptions().Select(ex => string.Format("* {0}", ex.Message))));
             }
             MessageBox.Show(b1.ToString(), TEST_CONNECTION_CAPTION, MessageBoxButton.OK, MessageBoxImage.Error);
         }
         return(response.Data);
     }
     finally
     {
         Mouse.OverrideCursor = null;
     }
 }
コード例 #15
0
 public CategoryPathResolver(SitecoreConnectionManager manager, GetCategoryCommand getCategoryCommand)
 {
     this.manager            = manager;
     this.getCategoryCommand = getCategoryCommand;
 }
コード例 #16
0
 public AddCategoryBlock(SitecoreConnectionManager manager, GetSellableItemCommand getSellableItemCommand)
 {
     _manager = manager;
     this.getSellableItemCommand = getSellableItemCommand;
 }
        public override async Task <MinionRunResultsModel> Run(MinionRunResultsModel arg, CommercePipelineExecutionContext context)
        {
            SitecoreConnectionManager connection = new SitecoreConnectionManager();
            var stiboImportSettingItem           = await connection.GetItemByPathAsync(context.CommerceContext, ProductContsants.StiboImportSettingPath);

            if (stiboImportSettingItem == null)
            {
                context.Logger.LogInformation($"Minion-ProductImport: Could not find stibo import setting at location: {ProductContsants.StiboImportSettingPath}");
                return(arg);
            }

            Host     = (string)stiboImportSettingItem.GetFieldValue(ProductContsants.SFTPHostField);
            Username = (string)stiboImportSettingItem.GetFieldValue(ProductContsants.SFTPUsernameField);
            Password = (string)stiboImportSettingItem.GetFieldValue(ProductContsants.SFTPPasswordField);

            BaseDirectory      = (string)stiboImportSettingItem.GetFieldValue(ProductContsants.BaseDirectoryField);
            CompletedDirectory = (string)stiboImportSettingItem.GetFieldValue(ProductContsants.CompletedDirectoryField);
            FailedDirectory    = (string)stiboImportSettingItem.GetFieldValue(ProductContsants.FailedDirectoryField);

            var BrandRegions = (string)stiboImportSettingItem.GetFieldValue(ProductContsants.BrandRegionMappingField);

            if (string.IsNullOrWhiteSpace(BrandRegions))
            {
                context.Logger.LogInformation($"Minion-ProductImport: Brand settings could not found on stibo import setting: {ProductContsants.StiboImportSettingPath}");
                return(arg);
            }

            foreach (var id in BrandRegions.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
            {
                var brandRegionImportSettingItem = await connection.GetItemByIdAsync(context.CommerceContext, id);

                if (brandRegionImportSettingItem == null)
                {
                    context.Logger.LogInformation($"Minion-ProductImport: Could not find brand settings for stibo import. ID: {id}");
                    continue;
                }

                var CatalogName           = (string)brandRegionImportSettingItem.GetFieldValue(ProductContsants.CatalogNameField);
                var BrandDirectory        = (string)brandRegionImportSettingItem.GetFieldValue(ProductContsants.BrandDirectoryField);
                var RegionLanguagePattern = (string)brandRegionImportSettingItem.GetFieldValue(ProductContsants.RegionLanguagePatternField);

                context.Logger.LogInformation($"Minion-ProductImport: Product import started for Brand: {BrandDirectory}, CatalogName: {CatalogName}, Region/Language: {RegionLanguagePattern}");

                using (SftpClient sftp = new SftpClient(Host, Username, Password))
                {
                    try
                    {
                        context.Logger.LogInformation($"Minion-ProductImport: Download started");

                        sftp.Connect();

                        var files = sftp.ListDirectory($"{BaseDirectory}/{BrandDirectory}");

                        CleanupDirectory(BrandDirectory, context);

                        foreach (var file in files)
                        {
                            if (file.IsDirectory || file.IsSymbolicLink)
                            {
                                continue;
                            }

                            //Ignore other region/language files for same brand
                            if (!file.Name.ToLower().Contains(RegionLanguagePattern.ToLower()))
                            {
                                continue;
                            }

                            ////Temp
                            //if (file.Name != "Grohe-Context1##1607423-1607845_0.xml")
                            //    continue;

                            try
                            {
                                using (Stream fileStream = File.OpenWrite(this.GetFullPath(BrandDirectory + "/" + file.Name)))
                                {
                                    sftp.DownloadFile(file.FullName, fileStream);
                                }
                            }
                            catch (Exception ex)
                            {
                                context.Logger.LogError($"Minion-ProductImport: Error while downloading file from SFTP {file.FullName}" + ex.Message);
                            }
                        }

                        sftp.Disconnect();

                        context.Logger.LogInformation($"Minion-ProductImport: Download completed");

                        var directoryPath = this.GetFullPath(BrandDirectory);
                        var filePaths     = Directory.GetFiles(directoryPath).ToList();
                        foreach (var fileFullName in filePaths)
                        {
                            try
                            {
                                context.Logger.LogInformation($"Minion-ProductImport: Import started");

                                var model = new ImportSellableItemPipelineArgument("");
                                //Call selleble item import pipeline
                                model.XMlFilePath        = fileFullName;
                                model.CatalogName        = CatalogName;
                                model.CatalogDisplayName = CatalogName;
                                var result = await _iImportProuctPipeline.Run(model, context);

                                context.Logger.LogInformation($"Minion-ProductImport: Import completed");

                                context.Logger.LogInformation($"Minion-ProductImport: Moving files to completed/failed started");
                                //Move file to completed/failed folder
                                sftp.Connect();

                                files = sftp.ListDirectory($"{BaseDirectory}/{BrandDirectory}");
                                var fileName = fileFullName.Substring(fileFullName.LastIndexOf("\\") + 1);
                                foreach (var f in files)
                                {
                                    if (f.Name != fileName)
                                    {
                                        continue;
                                    }

                                    if (result.FileImportSuccess)
                                    {
                                        f.MoveTo($"{BaseDirectory}/{BrandDirectory}/{CompletedDirectory}/{f.Name}");
                                    }
                                    else
                                    {
                                        f.MoveTo($"{BaseDirectory}/{BrandDirectory}/{FailedDirectory}/{f.Name}");
                                    }
                                }

                                sftp.Disconnect();

                                context.Logger.LogInformation($"Minion-ProductImport: Moving files to completed/failed completed");
                            }
                            catch (Exception ex)
                            {
                                context.Logger.LogError($"Minion-ProductImport: Error while importing/moving file: {fileFullName}, CatalogName: {CatalogName}" + ex.Message);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        context.Logger.LogError($"Minion-ProductImport: Error while downloading/importing/moving " + ex.Message);
                    }
                }

                context.Logger.LogInformation($"Minion-ProductImport: Product import completed for Brand: {BrandDirectory}, CatalogName: {CatalogName}, Region/Language: {RegionLanguagePattern}");
            }

            return(arg);
        }
コード例 #18
0
 public void ConstructorEmptyCxSettings()
 {
     var mockCxSettings = new Mock <ISitecoreConnectionSettings>();
     var manager        = new SitecoreConnectionManager(mockCxSettings.Object);
 }
コード例 #19
0
 public void ConstructorNullCxSettings()
 {
     var manager = new SitecoreConnectionManager(null);
 }