public void CloseSession(string sessionKey)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            RepositoryWebservice repo = new RepositoryWebservice(_url);
            repo.CloseSession(sessionKey, loginName, pass);

            /*
            Resource r = new Resource();
            r.TemporaryStoragePath = "/app_data/courier/temp_log.temp";

            byte[] remoteLog = Convert.FromBase64String( repo.GetResourceContents(sessionKey, null, "", r, loginName, pass));
            repo.Dispose();

            string path = Context.Current.MapPath(Core.Settings.logsPath) + Core.Helpers.IO.DirSepChar + sessionKey + ".remotelog";

            System.IO.File.WriteAllBytes(path, remoteLog);
            */

            RevisionLog.Instance.AddRevisionEntry(this.GetType(), "ExtractRevisions", "Session closed", LogItemEntryType.Information);
        }
        public void Clear(string revisionAlias)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            RepositoryWebservice repo = new RepositoryWebservice(_url);
               // repo.Clear(revisionAlias, loginName, pass);
            repo.Dispose();
        }
        public void Rollback(string sessionKey)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            RevisionLog.Instance.AddRevisionEntry(this.GetType(), "ExtractRevisions", "Rolling back changes", LogItemEntryType.Information);

            RepositoryWebservice repo = new RepositoryWebservice(_url);
            repo.Rollback(sessionKey, loginName, pass);
            repo.Dispose();
        }
        public RepositoryActionResponse PostProcess(Item item, bool overwrite)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            RepositoryWebservice repo = new RepositoryWebservice(_url);
            repo.Credentials = new System.Net.NetworkCredential(loginName, pass);

            byte[] obj = Core.Serialization.Serializer.Serialize(item, item.GetType());

            RepositoryActionResponse response = repo.PostProcess(this.SessionKey, obj, item.ItemId, overwrite, loginName, pass);
            repo.Dispose();
            return response;
        }
        public Item Package(ItemIdentifier itemId)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            RepositoryWebservice repo = new RepositoryWebservice(_url);
            //repo.Commit(loginName, pass);
            byte[] item = Convert.FromBase64String(repo.Package(this.SessionKey, itemId, loginName, pass));
            repo.Dispose();

            if (item == null || item.Length <= 0)
                return null;

            var provider = Umbraco.Courier.Core.ProviderModel.ItemProviderCollection.Instance.GetProvider(itemId.ProviderId);
            Item it = provider.Deserialize(itemId, item);

            return it;
        }
        public void OpenSession(string sessionKey)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            this.SessionKey = sessionKey;

            RevisionLog.Instance.AddRevisionEntry(this.GetType(), "ExtractRevisions", "Session opening: " + sessionKey, LogItemEntryType.Information);

            RepositoryWebservice repo = new RepositoryWebservice(_url);
            repo.OpenSession(SessionKey, loginName, pass);
            repo.Dispose();
        }
        public List<ItemConflict> Compare(Item item)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            RepositoryWebservice repo = new RepositoryWebservice(_url);
            repo.Credentials = new System.Net.NetworkCredential(loginName, pass);

            byte[] obj = Core.Serialization.Serializer.Serialize(item, item.GetType());

            var conflicts = repo.Compare(obj, item.ItemId, loginName, pass).ToList<ItemConflict>();

            repo.Dispose();
            return conflicts;
        }
        public bool TransferResource(ResourceTransfer resource)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            RepositoryWebservice repo = new RepositoryWebservice(_url);
            repo.Credentials = new System.Net.NetworkCredential(loginName, pass);

            var res = resource.Resource;

            if (!Core.Settings.disableZip)
                res.ResourceContents = Compression.Compress(res.ResourceContents);

            if (!Core.Settings.disableBase64Encoding)
            {
                res.ResourceAsBase64 = Convert.ToBase64String(res.ResourceContents);
                res.ResourceContents = new byte[0];
            }

            bool transfered = false;

            try
            {
                transfered = repo.TransferResource(this.SessionKey, resource.ItemID, resource.ItemType, res, resource.OverWrite, loginName, pass);

                if (transfered)
                    RevisionLog.Instance.AddItemEntry(resource.ItemID, this.GetType(), "resources", resource.Resource.ExtractToPath + " transfered", LogItemEntryType.Success);
                else
                    RevisionLog.Instance.AddItemEntry(resource.ItemID, this.GetType(), "resources", resource.Resource.ExtractToPath + " not transfered", LogItemEntryType.Error);
            }
            catch (Exception ex)
            {
                RevisionLog.Instance.AddItemEntry(resource.ItemID, this.GetType(), "resources", ex.ToString(), LogItemEntryType.Error);
            }

            repo.Dispose();
            return transfered;
        }
        public byte[] GetResourceContents(ItemIdentifier itemId, Type itemType, Resource resource, string revision)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            string typeName = itemType.AssemblyQualifiedName;

            RepositoryWebservice repo = new RepositoryWebservice(_url);
            byte[] resourceContent = Convert.FromBase64String( repo.GetResourceContents(this.SessionKey, itemId, typeName, resource, loginName, pass));
            repo.Dispose();

            return resourceContent;
        }
        public SystemItem[] GetChildren(ItemIdentifier itemId)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            RepositoryWebservice repo = new RepositoryWebservice(_url);
            var children = repo.GetChildren(itemId, loginName, pass);
            repo.Dispose();

            return children;
        }
        public override string[] GetAvailableRevisions()
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);

            string _url = getWSUrl(this.Url);

            //call asmx
            RepositoryWebservice repo = new RepositoryWebservice(_url);
            repo.Credentials = new System.Net.NetworkCredential(loginName, pass);

            return repo.GetAvailableRevisions(loginName, pass);
        }
        public RepositoryActionResponse ExtractItem(Item item, bool overwrite)
        {
            try {
                //encrypt login and password
                string loginName = "";
                string pass = "";
                getloginAndPass(UserId, ref loginName, ref pass);
                string _url = getWSUrl(this.Url);

                RepositoryWebservice repo = new RepositoryWebservice(_url);
                repo.Credentials = new System.Net.NetworkCredential(loginName, pass);

                foreach (var r in item.Resources)
                {
                    r.ResourceAsBase64 = string.Empty;
                    r.ResourceContents = new byte[0];
                }

                byte[] obj = Core.Serialization.Serializer.Serialize(item, item.GetType());

                RepositoryActionResponse result = repo.Extract(this.SessionKey, obj, item.ItemId, overwrite, loginName, pass);
                repo.Dispose();

                return result;
            }
            catch (Exception ex)
            {

                RevisionLog.Instance.Error(item, this, RevisionLog.ExtractionManager, ex.ToString());

                RepositoryActionResponse response = new RepositoryActionResponse();
                response.LoadException(ex);
                response.ItemStatus = ItemStatus.Error;
                response.ItemId = item.ItemId;
                response.ItemName = item.Name;

                return response;
            }
        }
        public bool Exists(ItemIdentifier itemId)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            RepositoryWebservice repo = new RepositoryWebservice(_url);
            repo.Credentials = new System.Net.NetworkCredential(loginName, pass);

            bool exists = repo.Exists(itemId, loginName, pass);

            repo.Dispose();
            return exists;
        }
        public void ExecuteQueue(string queueAlias)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            RepositoryWebservice repo = new RepositoryWebservice(_url);
            repo.ExecuteQueue(this.SessionKey, queueAlias, loginName, pass);
            repo.Dispose();
        }
        public void ExecuteEvent(string eventAlias, ItemIdentifier itemId, SerializableDictionary<string, string> parameters)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            RevisionLog.Instance.AddItemEntry(itemId, this.GetType(), "EventManager", "Executing event" + eventAlias, LogItemEntryType.Information);

            RepositoryWebservice repo = new RepositoryWebservice(_url);
            repo.Execute(this.SessionKey, eventAlias, itemId, null, loginName, pass);
            repo.Dispose();
        }
        public string SaveItem(Item item, string providerDirectory, string revisionAlias)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            string itemAsBase64 = Convert.ToBase64String( Umbraco.Courier.Core.Serialization.Serializer.Serialize(item, item.GetType()));

            RepositoryWebservice repo = new RepositoryWebservice(_url);

            string path = repo.SaveItem(item.ItemId, itemAsBase64, providerDirectory, revisionAlias, loginName, pass);

            //byte[] resourceContent = repo.GetResourceContents(this.SessionKey, itemId, typeName, resource, loginName, pass);
            repo.Dispose();

            return path;
        }
        public string SaveResourceContents(ItemIdentifier itemId, Type itemType, Resource resource, string revisionAlias)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            if (!Core.Settings.disableBase64Encoding)
            {
                resource.ResourceAsBase64 = Convert.ToBase64String(resource.ResourceContents);
                resource.ResourceContents = new byte[0];
            }

            string typestr = string.Empty;
            if (itemType != null)
                typestr = itemType.ToString();

            RepositoryWebservice repo = new RepositoryWebservice(_url);
            string path = repo.SaveResourceContents(itemId, typestr, resource, revisionAlias, loginName, pass);
            repo.Dispose();

            return path;
        }
        public override Umbraco.Courier.Core.Revision GetRevision(string alias)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            RepositoryWebservice repo = new RepositoryWebservice(_url);
            repo.Credentials = new System.Net.NetworkCredential(loginName, pass);

            Revision revi = repo.GetRevision(alias, loginName, pass);
            repo.Dispose();
            return revi;
        }
        public bool TransferResources(ResourceTransfer[] resources)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            RepositoryWebservice repo = new RepositoryWebservice(_url);
            repo.Credentials = new System.Net.NetworkCredential(loginName, pass);

            int totalTransferSize = 0;

            foreach (var rt in resources)
            {
                totalTransferSize += rt.Resource.ResourceContents.Length;
                rt.Resource.ResourceContents = Compression.Compress(rt.Resource.ResourceContents);
                rt.Resource.ResourceAsBase64 = Base64Converter.ConvertToBase64(rt.Resource.ResourceContents);
                rt.Resource.ResourceContents = new byte[0];
            }

            bool transfered = false;
            try
            {
                transfered = repo.TransferResources(this.SessionKey, resources, loginName, pass);
            }
            catch (Exception ex)
            {
                RevisionLog.Instance.AddItemEntry(resources[0].ItemID, this.GetType(), "resources", ex.ToString(), LogItemEntryType.Error);
            }

            repo.Dispose();
            return transfered;
        }
        public string Hash(ItemIdentifier itemId)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            RepositoryWebservice repo = new RepositoryWebservice(_url);
            repo.Credentials = new System.Net.NetworkCredential(loginName, pass);

            string hash = string.Empty;
            try
            {
                hash = repo.GetItemHash(this.SessionKey, itemId, loginName, pass);
            }
            catch { }

            repo.Dispose();

            return hash;
        }
        public string Hash(Resource resource)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);
            string _url = getWSUrl(this.Url);

            RepositoryWebservice repo = new RepositoryWebservice(_url);
            repo.Credentials = new System.Net.NetworkCredential(loginName, pass);

            //just a stub to pass to the service so we pass as little information as possible
            Resource r = new Resource();
            r.ExtractToPath = resource.ExtractToPath;
            r.TemporaryStoragePath = resource.TemporaryStoragePath;

            string hash = repo.GetResourceHash(this.SessionKey, r, loginName, pass); // repo.get .Exists(itemId, loginName, pass);
            repo.Dispose();

            return hash;
        }
        //�Public�Methods�(4)
        public override void CommitRevision(Revision revision)
        {
            //encrypt login and password
            string loginName = "";
            string pass = "";
            getloginAndPass(UserId, ref loginName, ref pass);

            string _url = getWSUrl(this.Url);

            RepositoryWebservice repo = new RepositoryWebservice(_url);

            foreach (var i in revision.GetAllRevisionItems().Values)
            {
                repo.CommitRevisionitem(revision.Name, i, loginName, pass);

                RevisionFileEventArgs e = new RevisionFileEventArgs();
                e.Name = i.Name;

                OnRevisionItemCommitted(e);
            }

            foreach (var i in revision.GetAllResources().Values)
            {
                repo.CommitResourceitem(revision.Name, i, loginName, pass);

                RevisionFileEventArgs e = new RevisionFileEventArgs();
                e.Name = i.Name;
                OnRevisionResourceCommitted(e);
            }

            foreach (var i in revision.GetAllVirtualResources().Values)
            {
                repo.CommitResourceitem(revision.Name, i, loginName, pass);

                RevisionFileEventArgs e = new RevisionFileEventArgs();
                e.Name = i.Name;
                OnRevisionResourceCommitted(e);
            }
            repo.Dispose();
        }