Exemplo n.º 1
0
        /// <summary>
        /// extracts the resource out of the binary
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public string GetResource(string filename)
        {
            filename = filename.ToLowerInvariant();
            string result;

            if (_resourceCache.TryGetValue(filename, out result))
            {
                return(result);
            }
            using (var stream = GetType().Assembly.GetManifestResourceStream(_registration.GetScsRegistration(GetType()).ResourcesPath + "." + filename))
            {
                if (stream != null)
                {
                    using (var reader = new StreamReader(stream))
                    {
                        result = reader.ReadToEnd();
                    }
                }
                else
                {
                    throw new ScsEmbeddedResourceNotFoundException();
                }
            }

            _resourceCache[filename] = result;
            return(result);
        }
Exemplo n.º 2
0
 public void StartContentMigration(PullItemModel model)
 {
     _model = model;
     if (model.PullParent)
     {
         foreach (var id in model.Ids.Select(Guid.Parse).Where(x => _sitecoreAccess.GetItemData(x) == null))
         {
             var item   = _remoteContent.GetRemoteItemData(id, model.Server);
             var parent = _sitecoreAccess.GetItemData(item.ParentId);
             while (parent == null)
             {
                 item = _remoteContent.GetRemoteItemData(item.ParentId, model.Server);
                 _puller.ItemsToInstall.Add(item);
                 parent = _sitecoreAccess.GetItemData(item.ParentId);
             }
         }
     }
     Task.Run(() =>
     {
         if (model.RemoveLocalNotInRemote)
         {
             _installer.SetupTrackerForUnwantedLocalItems(model.Ids.Select(Guid.Parse));
         }
         _puller.StartGatheringItems(model.Ids.Select(Guid.Parse), _registration.GetScsRegistration <ContentMigrationRegistration>()?.RemoteThreads ?? 1, model.Children, model.Server, _cancellation.Token, model.IgnoreRevId);
         _installer.StartInstallingItems(model, _puller.ItemsToInstall, _registration.GetScsRegistration <ContentMigrationRegistration>()?.WriterThreads ?? 1, _cancellation.Token);
     });
 }
 public ActionResult GetTemplates()
 {
     return(ScsJson(Directory.EnumerateFiles(
                        _registration.GetScsRegistration <ScsSitecoreResourceManagerRegistration>().GetDataDirectory() + "\\Templates")
                    .Select(Path.GetFileName)
                    .Select(x =>
     {
         var wrapper = _registration.GetScsRegistration <ScsSitecoreResourceManagerRegistration>().GetPropertiesWrapper(x);
         return new { wrapper.Name, wrapper.Description, Template = x };
     })
                    ));
 }
        private dynamic GetCommonLocations()
        {
            EditingContextRegistration ec = _registration.GetScsRegistration <EditingContextRegistration>();
            dynamic ret = new ExpandoObject();

            ret.editor = ec.EditorLocations;
            if (IsAdmin.CurrentUserAdmin())
            {
                ret.core   = ec.CoreLocations;
                ret.master = ec.MasterLocations;
            }
            return(ret);
        }
        private string MakeRequest(string url, string parameters)
        {
            string nonce = Guid.NewGuid().ToString();

            WebClient wc = new WebClient {
                Encoding = Encoding.UTF8
            };

            if (_ss == null)
            {
                _ss        = new SignatureService(_registration.GetScsRegistration <ContentMigrationRegistration>().AuthenticationSecret);
                HmacServer = new ScsHmacServer(_ss, new UniqueChallengeStore());
            }
            var signature = _ss.CreateSignature(nonce, url, new[] { new SignatureFactor("payload", parameters) });

            wc.Headers["X-MC-MAC"]   = signature.SignatureHash;
            wc.Headers["X-MC-Nonce"] = nonce;

            var currentPolicy = ServicePointManager.SecurityProtocol;

            try
            {
                // .NET < 4.6.1 uses (insecure) SSL3 by default and does not enable TLS 1.2 for WebClient.
                ServicePointManager.SecurityProtocol = SetSslCiphers();

                return(wc.UploadString(url, "POST", parameters));
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    var response = ex.Response as HttpWebResponse;
                    if (response?.StatusCode == HttpStatusCode.Forbidden)
                    {
                        throw new AccessViolationException("Remote server returned Forbidden. Make sure your shared secrets match.");
                    }
                    throw new Exception("Remote server didn't return a response", ex);
                }
                throw new Exception("Remote server didn't return a response", ex);
            }
            finally
            {
                ServicePointManager.SecurityProtocol = currentPolicy;
            }
        }
Exemplo n.º 6
0
        private string GetAllSidekickDirectives()
        {
            ScsMainRegistration sidekick = _registration.GetScsRegistration <ScsMainRegistration>();
            var basicAngularIf           = $"!vm.sidekick || ({"vm.sidekick != '" + string.Join("' && vm.sidekick != '", _registration.GetAllSidekicks().Select(x => x.Name).ToArray())}')";
            var sb = new StringBuilder($"<div ng-style=\"({basicAngularIf}) && {{'width':'{sidekick.CssStyle}', 'background-color':'white'}}\"><h3 id=\"sidekickHeader\" ng-if=\"{basicAngularIf}\">{sidekick.Name}<span class='close' onclick='window.top.document.getElementById(\"scs\").style.display=\"none\";'></span></h3>");

            foreach (var sk in _registration.GetAllSidekicks().Where(x => x.ApplicableSidekick() && x.Name != "Sitecore Sidekick"))
            {
                sb.Append(
                    $"<div ng-if=\"{basicAngularIf}\" ng-click=\"vm.selectSidekick('{sk.Name}')\" class=\"btn scsbtn\"><img ng-src=\"{sk.Icon}\" width=\"32\" height=\"32\" class=\"scContentTreeNodeIcon\" border=\"0\"><div>{sk.Name}</div></div>");
                sb.Append($"<div id=\"{sk.Name.Replace(" ", string.Empty).ToLower()}\" ng-if=\"vm.sidekick == '{sk.Name}'\" targetWidth=\"{sk.CssStyle}\"><div id=\"desktopSidekickHeader\"><span class=\"back\" ng-click=\"vm.goHome()\"><svg class=\"icon icon-arrow-left\"><use xlink:href=\"#icon-arrow-left\"></use></svg> Return Home</span><span class=\"subheader-logo\">{sk.Name}</span><span class='close' onclick='window.top.document.getElementById(\"scs\").style.display=\"none\";'></span></div><h3 id=\"sidekickHeader\">{sk.Name}<span class=\"back\" ng-click=\"vm.goHome()\">Return Home</span><span class='close' onclick='window.top.document.getElementById(\"scs\").style.display=\"none\";'></span></h3><div class=\"scs-form\"><{sk.Directive} ");
                if (sk.DirectiveAttributes != null && sk.DirectiveAttributes.Count > 0)
                {
                    foreach (var key in sk.DirectiveAttributes.AllKeys)
                    {
                        sb.Append($"{key}=\"{sk.DirectiveAttributes[key]}\" ");
                    }
                }
                sb.Append($"></{sk.Directive}></div></div>");
            }
            sb.Append("</div>");
            return(sb.ToString());
        }
Exemplo n.º 7
0
 public ActionResult GetServerList()
 {
     return(ScsJson(_registration.GetScsRegistration <ContentMigrationRegistration>().ServerList));
 }
Exemplo n.º 8
0
 public ActionResult GetTemplates()
 {
     return(ScsJson(Directory.EnumerateFiles(_registration.GetScsRegistration <ScsSitecoreResourceManagerRegistration>().GetDataDirectory() + "\\Templates").Select(x => Path.GetFileName(x))));
 }
 public RemoteContentService(IScsRegistrationService registration)
 {
     _registration             = registration;
     _ss                       = Bootstrap.Container.Resolve <ISignatureService>(registration.GetScsRegistration <ContentMigrationRegistration>().AuthenticationSecret);
     _jsonSerializationService = Bootstrap.Container.Resolve <IJsonSerializationService>();
 }
Exemplo n.º 10
0
        /// <summary>
        /// extracts the resource out of the binary
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public string GetResource(string filename)
        {
            filename = filename.ToLowerInvariant();
            string result;

            Response.AppendHeader("scs", "true");
            if (_resourceCache.TryGetValue(filename, out result))
            {
                return(result);
            }

            result = _manifestResourceStreamService.GetManifestResourceText(GetType(), _registration.GetScsRegistration(GetType()).ResourcesPath + "." + filename, () => throw new ScsEmbeddedResourceNotFoundException());

            _resourceCache[filename] = result;
            return(result);
        }
 public SavedPropertiesService()
 {
     _json         = Bootstrap.Container.Resolve <IJsonSerializationService>();
     _registration = Bootstrap.Container.Resolve <IScsRegistrationService>();
     _properties   = _registration.GetScsRegistration <ScsSitecoreResourceManagerRegistration>().GetDataDirectory();
 }
Exemplo n.º 12
0
        /// <summary>
        /// extracts the resource out of the binary
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public string GetResource(string filename)
        {
            filename = filename.ToLowerInvariant();
            Sitecore.Context.SetActiveSite("scs");
            _resourceCache.TryGetValue(GetType(), out var cache);
            if (cache != null && cache.TryGetValue(filename, out var result))
            {
                return(result);
            }

            result = _manifestResourceStreamService.GetManifestResourceText(GetType(), _registration.GetScsRegistration(GetType()).ResourcesPath + "." + filename, () => throw new ScsEmbeddedResourceNotFoundException());
            if (!_resourceCache.ContainsKey(GetType()))
            {
                _resourceCache[GetType()] = new ConcurrentDictionary <string, string>();
            }
            _resourceCache[GetType()][filename] = result;
            return(result);
        }