コード例 #1
0
    public ScApiSession(
      ISessionConfig config,
      IWebApiCredentials credentials,
      IMediaLibrarySettings mediaSettings,
      ItemSource defaultSource = null,
      HttpMessageHandler httpMessageHandler = null)
    {
      if (null == config)
      {
        throw new ArgumentNullException("ScApiSession.config cannot be null");
      }

      this.sessionConfig = config.SessionConfigShallowCopy();
      this.requestMerger = new UserRequestMerger(this.sessionConfig, defaultSource);

      if (null != credentials)
      {
        this.credentials = credentials.CredentialsShallowCopy();
      }

      if (null != mediaSettings)
      {
        this.mediaSettings = mediaSettings.MediaSettingsShallowCopy();
      }

      this.httpClient = httpMessageHandler == null ? new HttpClient() : new HttpClient(httpMessageHandler);
    }
コード例 #2
0
        public ScApiSession(
            ISessionConfig config,
            IWebApiCredentials credentials,
            IMediaLibrarySettings mediaSettings,
            ItemSource defaultSource = null)
        {
            if (null == config)
            {
                throw new ArgumentNullException("ScApiSession.config cannot be null");
            }

            this.sessionConfig = config.SessionConfigShallowCopy();
            this.requestMerger = new UserRequestMerger(this.sessionConfig, defaultSource);

            if (null != credentials)
            {
                this.credentials = credentials.CredentialsShallowCopy();
            }

            if (null != mediaSettings)
            {
                this.mediaSettings = mediaSettings.MediaSettingsShallowCopy();
            }

            this.httpClient = new HttpClient();
        }
コード例 #3
0
        public static bool IsAnonymousSession(IWebApiCredentials credentials)
        {
            if (!IsValidCredentials(credentials))
            {
                return(false);
            }

            return(string.IsNullOrWhiteSpace(credentials.Username));
        }
    public static bool IsAnonymousSession(IWebApiCredentials credentials)
    {
      if (!IsValidCredentials(credentials))
      {
        return false;
      }

      return string.IsNullOrWhiteSpace(credentials.Username);
    }
コード例 #5
0
 public ScTestApiSession(
     ISessionConfig config,
     IWebApiCredentials credentials,
     IMediaLibrarySettings mediaSettings,
     ItemSource defaultSource = null) :
     base(config, credentials, mediaSettings, defaultSource)
 {
     this.GetPublicKeyInvocationsCount = 0;
 }
コード例 #6
0
 public ScTestApiSession(
   ISessionConfig config,
   IWebApiCredentials credentials,
   IMediaLibrarySettings mediaSettings,
   ItemSource defaultSource = null) :
   base(config, credentials, mediaSettings, defaultSource)
 {
   this.GetPublicKeyInvocationsCount = 0;
 }
コード例 #7
0
        public IBaseSessionBuilder Credentials(IWebApiCredentials credentials)
        {
            // @adk : won't be invoked more than once.
            // No validation needed.
            BaseValidator.CheckForNullAndEmptyOrThrow(credentials.Username, this.GetType().Name + ".Credentials.Username");
            BaseValidator.CheckForNullAndEmptyOrThrow(credentials.Password, this.GetType().Name + ".Credentials.Password");

            this.credentials = credentials.CredentialsShallowCopy();
            return(this);
        }
コード例 #8
0
    public void SetUp()
    {
      this.credentials = new WebApiCredentialsPOD(
        "alex.fergusson", 
        "man u is a champion");

      this.mediaSettings = new MediaLibrarySettings(
        "/sitecore/media library",
        "ashx",
        "~/media/");

      this.localhostConnection = new SessionConfig("localhost");
    }
コード例 #9
0
        public void SetUp()
        {
            this.credentials = new WebApiCredentialsPOD(
                "alex.fergusson",
                "man u is a champion");

            this.mediaSettings = new MediaLibrarySettings(
                "/sitecore/media library",
                "ashx",
                "~/media/");

            this.localhostConnection = new SessionConfig("localhost");
        }
コード例 #10
0
        private async Task <ISitecoreWebApiSession> GetSession()
        {
            Models.Settings settings = await _settingsRepository.GetWithFallback();

            using (IWebApiCredentials credentials = DependencyService.Get <ICustomSecureStringPasswordProvider> ().Login(settings.SitecoreUserName, settings.SitecorePassword)) {
                {
                    ISitecoreWebApiSession session = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost(settings.RestBaseUrl)
                                                     .Credentials(credentials)
                                                     .Site(settings.SitecoreShellSite)
                                                     .DefaultDatabase(settings.SitecoreDefaultDatabase)
                                                     .DefaultLanguage(settings.SitecoreDefaultLanguage)
                                                     .MediaLibraryRoot(settings.SitecoreMediaLibraryRoot)
                                                     .MediaPrefix(settings.SitecoreMediaPrefix)
                                                     .DefaultMediaResourceExtension(settings.SitecoreDefaultMediaResourceExtension)
                                                     .BuildSession();

                    return(session);
                }
            }
        }
コード例 #11
0
        public void TestAuthenticatedSessionShouldBeCreatedByTheBuilder()
        {
            IWebApiCredentials credentials = this.adminCredentials;

            var builder = SitecoreWebApiSessionBuilder.AuthenticatedSessionWithHost("sitecore.net")
                          .Credentials(credentials)
                          .WebApiVersion("v1")
                          .DefaultDatabase("web")
                          .DefaultLanguage("en")
                          .Site("/sitecore/shell")
                          .MediaLibraryRoot("/sitecore/media library")
                          .DefaultMediaResourceExtension("ashx");


            ISitecoreWebApiSession session = builder.BuildSession();

            Assert.IsNotNull(session);

            var roSession = builder.BuildReadonlySession();

            Assert.IsNotNull(roSession);
        }
コード例 #12
0
 public static bool IsValidCredentials(IWebApiCredentials credentials)
 {
     if (null == credentials)
     {
         return(false);
     }
     else if (string.IsNullOrWhiteSpace(credentials.Username))
     {
         // anonymous session
         return(true);
     }
     else
     {
         if (string.IsNullOrEmpty(credentials.Password))
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
 }
 public static bool IsValidCredentials(IWebApiCredentials credentials)
 {
   if (null == credentials)
   {
     return false;
   }
   else if (string.IsNullOrWhiteSpace(credentials.Username))
   {
     // anonymous session
     return true;
   }
   else
   {
     if (string.IsNullOrEmpty(credentials.Password))
     {
       return false;
     }
     else
     {
       return true;
     }
   }
 }
コード例 #14
0
 public void TearDown()
 {
   this.mediaSettings = null;
   this.credentials = null;
   this.localhostConnection = null;
 }
コード例 #15
0
 public void TearDown()
 {
     this.mediaSettings       = null;
     this.credentials         = null;
     this.localhostConnection = null;
 }
コード例 #16
0
    public IBaseSessionBuilder Credentials(IWebApiCredentials credentials)
    {
      // @adk : won't be invoked more than once.
      // No validation needed.
      BaseValidator.CheckForNullAndEmptyOrThrow(credentials.Username, this.GetType().Name + ".Credentials.Username");
      BaseValidator.CheckForNullAndEmptyOrThrow(credentials.Password, this.GetType().Name + ".Credentials.Password");

      this.credentials = credentials.CredentialsShallowCopy();
      return this;
    }