public SyncItem BuildSyncItem(IItemData item)
 {
     var syncItem = new SyncItem
     {
         ID = item.Id.ToString("B"),
         DatabaseName = item.DatabaseName,
         ParentID = item.ParentId.ToString("B"),
         Name = item.Name,
         BranchId = item.BranchId.ToString("B"),
         TemplateID = item.TemplateId.ToString("B"),
         ItemPath = item.Path
     };
     //syncItem.TemplateName = item.TemplateName;
     foreach (var field in item.SharedFields) //TODO: ItemSynchronization.BuildSyncItem sorts the fields and versions first, should we ?
     {
         syncItem.AddSharedField(field.FieldId.ToString("B"), null/*name*/, null/*key?*/, field.Value, true);
     }
     foreach (var version in item.Versions)
     {
         var syncVersion = syncItem.AddVersion(version.Language.ToString(), version.VersionNumber.ToString(), version.VersionNumber.ToString() /*revisionid needed?*/);
         if (syncVersion != null)
         {
             foreach (var field in version.Fields)
             {
                 syncVersion.AddField(field.FieldId.ToString("B"), null/*name*/,null /*key?*/, field.Value, true);
             }
         }
     }
     return syncItem;
 }
 public virtual void Serialize(SyncItem item, Stream outputStream)
 {
     using (var writer = new StreamWriter(outputStream))
     {
         item.Serialize(writer);
     }
 }
        private IList<FieldDesynchronization> GetFieldSyncStatus(Item item, SyncItem serializedItem)
        {
            var desyncs = new List<FieldDesynchronization>();

            var serializedVersion = serializedItem.Versions.FirstOrDefault(x => x.Version == item.Version.Number.ToString(CultureInfo.InvariantCulture) && x.Language == item.Language.Name);

            if (serializedVersion == null)
            {
                desyncs.Add(new FieldDesynchronization("Version", item.Version.Number.ToString(CultureInfo.InvariantCulture), "Did not exist"));
                return desyncs;
            }

            item.Fields.ReadAll();

            foreach (Field field in item.Fields)
            {
                // find the field in the serialized item in either versioned or shared fields
                var serializedField = serializedVersion.Fields.FirstOrDefault(x => x.FieldID == field.ID.ToString()) ??
                                    serializedItem.SharedFields.FirstOrDefault(x => x.FieldID == field.ID.ToString());

                // we ignore if the field doesn't exist in the serialized item. This is because if you added a field to a template,
                // that does not immediately re-serialize all items based on that template so it's likely innocuous - we're not overwriting anything.
                if (serializedField == null) continue;

                if (!serializedField.FieldValue.Equals(field.Value, StringComparison.Ordinal))
                {
                    desyncs.Add(new FieldDesynchronization(serializedField.FieldName, field.Value, serializedField.FieldValue));
                }
            }

            return desyncs;
        }
 public TemplateSection(SyncItem sectionItem, List<SyncItem> syncItems)
     : base(sectionItem)
 {
     Fields = syncItems
         .Where(s => s.TemplateID == TemplateIDs.TemplateField.ToString() && s.ParentID == sectionItem.ID)
         .Select(s => new TemplateField(s))
         .ToList();
 }
        private static void WriteResultsToFile(Stream stream, SyncItem syncItem)
        {
            TruncateFile(stream);

            using (TextWriter writer = new StreamWriter(stream))
            {
                syncItem.Serialize(writer);
            }
        }
 public TemplateItem(SyncItem templateItem, List<SyncItem> syncItems)
     : base(templateItem)
 {
     BaseTemplates = new List<TemplateItem>();
     Sections = syncItems
         .Where(s => s.TemplateID == TemplateIDs.TemplateSection.ToString() && s.ParentID == templateItem.ID)
         .Select(s => new TemplateSection(s, syncItems))
         .ToList();
 }
 public SyncItem UpdateStatistics(SyncItem syncItem)
 {
     SyncVersion versionToUpdate = GetVersionToUpdate(syncItem);
     int index = syncItem.Versions.IndexOf(versionToUpdate);
     SyncVersion syncVersion = syncItem.Versions[index];
     syncVersion.SetFieldValue(StatisticsTemplateFields.Updated, DateUtil.IsoNowWithTicks);
     syncVersion.SetFieldValue(StatisticsTemplateFields.UpdatedBy, _config.CurrentUser);
     return syncItem;
 }
Example #8
0
 internal DsDbItem(string serializationFolderName, SyncItem syncItem, FileInfo file, bool includeDescendants, bool deserializeLinkedTemplate = true)
   : base(syncItem.Name, ID.Parse(syncItem.ID), ID.Parse(syncItem.TemplateID))
 {
   this.SerializationFolderName = serializationFolderName;
   this.SyncItem = syncItem;
   this.File = file;
   this.IncludeDescendants = includeDescendants;
   this.DeserializeLinkedTemplate = deserializeLinkedTemplate;
 }
 public static void SaveSyncItem(SyncItem item, string path)
 {
     using (var fileStream = File.Open(path, FileMode.Create, FileAccess.Write, FileShare.None))
     {
         using (var writer = new StreamWriter(fileStream))
         {
             item.Serialize(writer);
         }
     }
 }
Example #10
0
		/// <summary>
		/// Checks if a preset includes a given serialized item
		/// </summary>
		protected FilterResult Includes(IncludeEntry entry, SyncItem item)
		{
			// check for db match
			if (item.DatabaseName != entry.Database) return new FilterResult(false);

			// check for path match
			if (!item.ItemPath.StartsWith(entry.Path, StringComparison.OrdinalIgnoreCase)) return new FilterResult(false);

			// check excludes
			return ExcludeMatches(entry, item.ItemPath, ID.Parse(item.ID), ID.Parse(item.TemplateID), item.TemplateName);
		}
Example #11
0
        public DependencyStatus GetDependencyStatus(SyncItem syncItem)
        {
            DependencyStatus status = DependencyStatus.Expired;

            if (_dependenciesStatus.Contains(syncItem))
            {
                status = (DependencyStatus)_dependenciesStatus[syncItem];
            }

            return(status);
        }
Example #12
0
    string ApplyTargetPathTemplate(SyncItem syncItem)
    {
        if (string.IsNullOrEmpty(syncItem.Target))
        {
            return syncItem.Parts.Path;
        }

        return syncItem.Target
            .Replace("{{src.root}}", SrcRoot)
            .Replace("{{solution.name}}", SolutionName);
    }
        internal DsDbTemplate(string serializationFolderName, SyncItem syncItem, FileInfo file)
            : base(syncItem.Name, ID.Parse(syncItem.ID))
        {
            Assert.IsTrue(
                syncItem.TemplateID == TemplateIDs.Template.ToString(),
                string.Format("File '{0}' is a correct item file, but does not represent a template; use DsDbItem instead to deserialize this", file.FullName));

            this.SerializationFolderName = serializationFolderName;
            this.SyncItem = syncItem;
            this.File     = file;
        }
        public SerializationFile DownloadFileFromSerializationItem(string itemPath)
        {
            SyncItem syncItem = SyncItemProvider.GetSyncItem(itemPath);

            string blobValue = syncItem.SharedValues[FileTemplateFields.Blob.FieldId];
            string extension = syncItem.SharedValues[FileTemplateFields.Extension.FieldId];

            byte[] fromBase64String = System.Convert.FromBase64String(blobValue);

            return(new SerializationFile(syncItem.Name, extension, fromBase64String));
        }
Example #15
0
        /// <summary>
        /// Sets the upload retry counter.
        /// </summary>
        /// <param name="item">Path of the local file.</param>
        /// <param name="counter">Counter.</param>
        /// <param name="type"></param>
        public void SetOperationRetryCounter(SyncItem item, long counter, OperationType type)
        {
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            switch (type)
            {
            case OperationType.DOWNLOAD:
                goto case OperationType.DELETE;

            case OperationType.DELETE:
                parameters.Add("date", DateTime.Now.ToFileTimeUtc());
                break;

            default:
                parameters.Add("date", File.GetLastWriteTimeUtc(item.LocalPath));
                break;
            }
            parameters.Add("path", item.RemoteRelativePath);
            parameters.Add("counter", (counter >= 0) ? counter : 0);
            string uploadCounter   = "(SELECT CASE WHEN lastLocalModificationDate=@date THEN uploadCounter ELSE '' END FROM failedoperations WHERE path=@path)";
            string downloadCounter = "(SELECT CASE WHEN lastLocalModificationDate=@date THEN downloadCounter ELSE '' END FROM failedoperations WHERE path=@path)";
            string changeCounter   = "(SELECT CASE WHEN lastLocalModificationDate=@date THEN changeCounter ELSE '' END FROM failedoperations WHERE path=@path)";
            string deleteCounter   = "(SELECT CASE WHEN lastLocalModificationDate=@date THEN deleteCounter ELSE '' END FROM failedoperations WHERE path=@path)";

            switch (type)
            {
            case OperationType.UPLOAD:
                uploadCounter = "@counter";
                break;

            case OperationType.DOWNLOAD:
                downloadCounter = "@counter";
                break;

            case OperationType.CHANGE:
                changeCounter = "@counter";
                break;

            case OperationType.DELETE:
                deleteCounter = "@counter";
                break;
            }
            string command = String.Format(@"INSERT OR REPLACE INTO failedoperations (path, lastLocalModificationDate,
                                uploadCounter, downloadCounter, changeCounter, deleteCounter,
                                uploadMessage, downloadMessage, changeMessage, deleteCounter)
                                VALUES( @path, @date, {0},{1},{2},{3},
                                (SELECT CASE WHEN lastLocalModificationDate=@date THEN uploadMessage ELSE '' END FROM failedoperations WHERE path=@path ), 
                                (SELECT CASE WHEN lastLocalModificationDate=@date THEN downloadMessage ELSE '' END FROM failedoperations WHERE path=@path),
                                (SELECT CASE WHEN lastLocalModificationDate=@date THEN changeMessage ELSE '' END FROM failedoperations WHERE path=@path),
                                (SELECT CASE WHEN lastLocalModificationDate=@date THEN deleteMessage ELSE '' END FROM failedoperations WHERE path=@path)
                            )", uploadCounter, downloadCounter, changeCounter, deleteCounter);

            ExecuteSQLAction(command, parameters);
        }
Example #16
0
        /// <summary>
        /// Deserializes all .item files below the item's children folder and all deeper directories.
        /// Also traverses shortened paths.
        /// </summary>
        /// <param name="itemFile"></param>
        /// <param name="syncItem"></param>
        /// <param name="serializationFolder"></param>
        /// <param name="maxDepth"></param>
        /// <returns></returns>
#pragma warning disable 618
        internal static List <SyncItem> DeserializeAll(this FileInfo itemFile, SyncItem syncItem, DirectoryInfo serializationFolder, int maxDepth)
#pragma warning restore 618
        {
            if (maxDepth <= 0)
            {
#pragma warning disable 618
                return(new List <SyncItem>());

#pragma warning restore 618
            }

            Assert.ArgumentNotNull(itemFile, "itemFile");

#pragma warning disable 618
            var result = new List <SyncItem>();
#pragma warning restore 618

            // Find descendants in direct subfolder
            if (itemFile.Directory != null)
            {
                var childItemsFolder = new DirectoryInfo(itemFile.Directory.FullName + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(itemFile.Name));
                if (childItemsFolder.Exists)
                {
                    foreach (var childItemFile in childItemsFolder.GetFiles("*.item", SearchOption.AllDirectories))
                    {
                        var childSyncItem = childItemFile.Deserialize();
                        result.AddRange(childItemFile.DeserializeAll(childSyncItem, serializationFolder, maxDepth - 1));
                        result.Add(childSyncItem);
                    }
                }
            }

            // Find descendants in shortened paths
            var linkFiles = ShortenedPathsDictionary.GetLocationsFromLinkFiles(serializationFolder);
            if (!linkFiles.ContainsKey(syncItem.ItemPath))
            {
                return(result);
            }

            var truePath = new DirectoryInfo(linkFiles[syncItem.ItemPath]);
            if (!truePath.Exists)
            {
                return(result);
            }

            foreach (var childItemFile in truePath.GetFiles("*.item", SearchOption.AllDirectories))
            {
                var childSyncItem = childItemFile.Deserialize();
                result.AddRange(childItemFile.DeserializeAll(childSyncItem, serializationFolder, maxDepth - 1));
                result.Add(childSyncItem);
            }

            return(result);
        }
Example #17
0
        /// <summary>
        /// Remove a file from the database.
        /// </summary>
        public void RemoveFile(SyncItem item)
        {
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("path", item.RemoteRelativePath);
            ExecuteSQLAction("DELETE FROM files WHERE path=@path", parameters);

            parameters = new Dictionary <string, object>();
            parameters.Add("path", item.RemoteRelativePath);
            ExecuteSQLAction("DELETE FROM downloads WHERE path=@path", parameters);
        }
    internal DsDbTemplate(string serializationFolderName, SyncItem syncItem, FileInfo file)
      : base(syncItem.Name, ID.Parse(syncItem.ID))
    {
      Assert.IsTrue(
        syncItem.TemplateID == TemplateIDs.Template.ToString(), 
        string.Format("File '{0}' is a correct item file, but does not represent a template; use DsDbItem instead to deserialize this", file.FullName));

      this.SerializationFolderName = serializationFolderName;
      this.SyncItem = syncItem;
      this.File = file;
    }
Example #19
0
        public List <SyncItem> LoadItems()
        {
            var items = new List <SyncItem>();

            using (new SecurityDisabler())
            {
                using (new ProxyDisabler())
                {
                    var      reader = new ZipReader(PackagePath, Encoding.UTF8);
                    ZipEntry entry  = reader.GetEntry("package.zip");

                    using (var stream = new MemoryStream())
                    {
                        StreamUtil.Copy(entry.GetStream(), stream, 0x4000);

                        reader = new ZipReader(stream);

                        foreach (ZipEntry zipEntry in reader.Entries)
                        {
                            var entryData = new ZipEntryData(zipEntry);
                            try
                            {
                                if (entryData.Key.EndsWith("/xml"))
                                {
                                    string xml =
                                        new StreamReader(entryData.GetStream().Stream, Encoding.UTF8).ReadToEnd();
                                    if (!string.IsNullOrWhiteSpace(xml))
                                    {
                                        XmlDocument document = XmlUtil.LoadXml(xml);
                                        if (document != null)
                                        {
                                            SyncItem loadedItem = LoadItem(document);
                                            if (loadedItem != null)
                                            {
                                                items.Add(loadedItem);
                                            }
                                        }
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                Console.WriteLine("Unable to load xml from file {0}", entryData.Key);
                            }
                        }
                    }
                }
            }

            Console.WriteLine("Read {0} items from package {1}", items.Count, PackagePath);

            return(items);
        }
        //--------------------------------------------------------------------------------
        /// <summary>
        /// Adds a single sync item to the listview
        /// </summary>
        /// <param name="item"></param>
        private void AddSyncItem(SyncItem item)
        {
            ListViewItem lvi = new ListViewItem(item.Name);

            lvi.SubItems.Add(item.SyncToPath);
            lvi.SubItems.Add(item.SyncFromPath);
            lvi.SubItems.Add(item.SyncSubfolders.ToString());
            lvi.SubItems.Add(item.BackupBeforeSync.ToString());
            lvi.SubItems.Add(item.DeleteAfterSync.ToString());
            lvi.Tag = item;
            this.listViewSyncItems.Items.Add(lvi);
        }
Example #21
0
        public void SaveAndRenameItem(SyncItem renamedItem, string oldName)
        {
            var oldRootPath = renamedItem.ItemPath.Substring(0, renamedItem.ItemPath.LastIndexOf('/') + 1) + oldName;
            var newRootPath = renamedItem.ItemPath;

            var descendantItems = _index.GetDescendants(renamedItem.GetSitecoreId());

            // write the moved sync item to its new destination
            SaveItem(renamedItem);

            MoveDescendants(oldRootPath, newRootPath, renamedItem.DatabaseName, descendantItems);
        }
 protected virtual string GetUrlFormat(SyncItem item)
 {
     if (!String.IsNullOrEmpty(item.UrlFormat))
     {
         return(item.UrlFormat);
     }
     if (String.IsNullOrEmpty(defaultUrlFormat))
     {
         throw new ConfigurationException(String.Format("无法为IP为{0}设置URL-FORMAT", item.IPAddress));
     }
     return(defaultUrlFormat);
 }
Example #23
0
 /// <summary>
 /// Calculate the SHA1 checksum of a syncitem.
 /// Code from http://stackoverflow.com/a/1993919/226958
 /// </summary>
 /// <param name="item">sync item</param>
 public static string Checksum(SyncItem item)
 {
     using (var fs = new FileStream(item.LocalPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
         using (var bs = new BufferedStream(fs))
         {
             using (var sha1 = new SHA1Managed())
             {
                 byte[] hash = sha1.ComputeHash(bs);
                 return(ChecksumToString(hash));
             }
         }
 }
        /// <summary>
        ///     Creates a new version for a content item in a particular language.
        /// </summary>
        /// <param name="itemDefinition">Used to identify the particular item</param>
        /// <param name="baseVersion">The version to copy off of</param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override int AddVersion(ItemDefinition itemDefinition, VersionUri baseVersion, CallContext context)
        {
            if (!ItemsById.ContainsKey(itemDefinition.ID))
            {
                return(-1);
            }
            SyncItem current = ItemsById[itemDefinition.ID];

            int num = -1;

            Language baseVersionLanguage = baseVersion.Language;

            if (Language.Invariant.Equals(baseVersionLanguage))
            {
                baseVersionLanguage = LanguageManager.DefaultLanguage;
            }

            if (baseVersion.Version != null && baseVersion.Version.Number > 0)
            {
                // copy version
                SyncVersion matchingVersion = (current.Versions ?? new List <SyncVersion>())
                                              .OrderByDescending(vr => int.Parse(vr.Version))
                                              .FirstOrDefault(vr => vr.Language.Equals(baseVersionLanguage.Name));

                int?maxVersionNumber = matchingVersion != null?int.Parse(matchingVersion.Version) : null as int?;

                num = maxVersionNumber.HasValue && maxVersionNumber > 0 ? maxVersionNumber.Value + 1 : -1;

                if (num > 0)
                {
                    SyncVersion newVersion = current.AddVersion(matchingVersion.Language, num.ToString(),
                                                                matchingVersion.Revision);

                    IList <SyncField> currentFieldValues = matchingVersion.Fields;

                    foreach (SyncField fieldValue in currentFieldValues)
                    {
                        newVersion.AddField(fieldValue.FieldID, fieldValue.FieldName, fieldValue.FieldKey,
                                            fieldValue.FieldValue, true);
                    }
                }
            }
            if (num == -1)
            {
                num = 1;

                // add blank version
                current.AddVersion(baseVersionLanguage.Name, num.ToString(), Guid.NewGuid().ToString());
            }

            return(num);
        }
        private string GetErrorValue(SaveArgs args)
        {
            var results = new Dictionary <Item, IList <FieldDesynchronization> >();

            try
            {
                foreach (var item in args.Items)
                {
                    Item     existingItem      = Client.ContentDatabase.GetItem(item.ID);
                    SyncItem serializedVersion = ReadSerializedVersion(existingItem);

                    // not having an existing serialized version means no possibility of conflict here
                    if (serializedVersion == null)
                    {
                        continue;
                    }

                    var fieldIssues = GetFieldSyncStatus(existingItem, serializedVersion);

                    if (fieldIssues.Count == 0)
                    {
                        continue;
                    }

                    results.Add(existingItem, fieldIssues);
                }

                // no problems
                if (results.Count == 0)
                {
                    return(null);
                }

                var sb = new StringBuilder();
                sb.Append("CRITICAL:\n");
                sb.Append(
                    "Item state conflicted with existing serialized value. Chances are you need to sync your database with the filesystem. The following fields had problems:\n");
                foreach (var item in results)
                {
                    sb.AppendFormat("\n{0}: {1}", item.Key.DisplayName, string.Join(", ", item.Value.Select(x => x.FieldName)));
                }

                sb.Append("\n\nDo you want to overwrite anyway? You may cause someone else to lose committed work by doing this.");

                return(sb.ToString());
            }
            catch (Exception ex)
            {
                Log.Error("Exception occurred while performing serialization conflict check!", ex, this);
                return("Exception occurred: " + ex.Message);                // this will cause a few retries
            }
        }
        private void CreateAdvanceItem(RequestArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Item[] scope = args.Scope;
            Assert.IsNotNull(scope, "The scope is null.");

            Item[] scope2 = (scope.Length > 0) ? new Item[]
            {
                scope.First <Item>()
            } : new Item[0];
            if (scope2 != null && scope2.Length > 0)
            {
                Mindtree.ItemWebApi.Pipelines.Advance.Serialize.Entities.LoadOptions loadOptions = null;
                SyncItem syncItem = null;
                try
                {
                    if (args.Context.HttpContext != null && args.Context.HttpContext.Request != null && args.Context.HttpContext.Request.Form != null)
                    {
                        string _enkey = string.Empty;
                        if (args.Context.HttpContext.Request.Form[Settings.enKey] != null)
                        {
                            _enkey = args.Context.HttpContext.Request.Form[Settings.enKey];
                        }

                        if (args.Context.HttpContext.Request.Form[Settings.loadOptions] != null)
                        {
                            string data = args.Context.HttpContext.Request.Form[Settings.loadOptions];
                            loadOptions = Mindtree.ItemWebApi.Pipelines.Advance.Serialize.SerializeManager.DeSerializeLoadOptions(StringCipher.Decrypt(data, _enkey));
                        }
                        if (args.Context.HttpContext.Request.Form[Settings.syncItem] != null)
                        {
                            string dataSyncItem = args.Context.HttpContext.Request.Form[Settings.syncItem];
                            syncItem = Mindtree.ItemWebApi.Pipelines.Advance.Serialize.SerializeManager.DeSerializeItem(StringCipher.Decrypt(dataSyncItem, _enkey), loadOptions);
                        }
                    }
                }
                catch (Exception)
                { }
                //args.Context.HttpContext.Request.Params[""]

                Mindtree.ItemWebApi.Pipelines.Advance.Create.CreateArgs createArgs = new Mindtree.ItemWebApi.Pipelines.Advance.Create.CreateArgs(scope2, Mindtree.ItemWebApi.Pipelines.Advance.Serialize.SerializeManager._loadOption, syncItem)
                {
                    Scope = scope2
                };
                CorePipeline.Run("itemWebApiCreateAdvance", createArgs);
                args.Result = createArgs.Result;
            }
            else
            {
                throw new BadRequestException("Parent Item doesn't Exist");
            }
        }
Example #27
0
        /// <summary>
        /// Deserializes an item file that was serialized with normal Sitecore serialization or TDS.
        /// </summary>
        /// <param name="file">.item file</param>
        /// <returns></returns>
        internal static SyncItem Deserialize(this FileInfo file)
        {
            Assert.ArgumentNotNull(file, "file");
            Assert.IsTrue(file.Exists, string.Format("File '{0}' can not be found or cannot be accessed", file.FullName));
            Assert.IsTrue(".item".Equals(file.Extension, StringComparison.InvariantCultureIgnoreCase), string.Format("File '{0}' is not a .item file", file.FullName));

            var item = SyncItem.ReadItem(new Tokenizer(file.OpenText()));

            Assert.IsTrue(ID.IsID(item.ID), string.Format("Item id '{0}' is not a valid guid", item.ID));
            Assert.IsTrue(ID.IsID(item.TemplateID), string.Format("Item template id '{0}' is not a valid guid", item.TemplateID));

            return(item);
        }
Example #28
0
        public static SyncVersion GetVersion(this SyncItem item, VersionUri uri)
        {
            string versionString = uri.Version.Number.ToString(CultureInfo.InvariantCulture);

            var language = uri.Language;

            if (language.Equals(Language.Invariant))
            {
                language = LanguageManager.DefaultLanguage;
            }

            return(item.Versions.FirstOrDefault(x => x.Language.Equals(language.Name, StringComparison.OrdinalIgnoreCase) && x.Version == versionString));
        }
Example #29
0
        public static ID GetSitecoreParentId(this SyncItem item)
        {
            Assert.ArgumentNotNull(item, "item");

            ID result;

            if (!ID.TryParse(item.ParentID, out result))
            {
                throw new ArgumentOutOfRangeException("item", "SyncItem did not have a parseable ParentID!");
            }

            return(result);
        }
Example #30
0
 /// <summary>
 /// Remove a dependencia.
 /// </summary>
 /// <param name="key">Chave.</param>
 /// <param name="dependency">Instancia da dependencia.</param>
 public void RemoveDependency(object key, CacheSyncDependency dependency)
 {
     if (_context.IsDbSyncCoordinator)
     {
         if (dependency != null)
         {
             try
             {
                 SyncItem item = new SyncItem(key, dependency.Key, dependency.CacheId);
                 lock (_dependenciesStatus.SyncRoot)
                 {
                     if (_dependenciesKeyMap.Contains(item))
                     {
                         ArrayList list = _dependenciesKeyMap[item] as ArrayList;
                         if (list != null)
                         {
                             list.Remove(key);
                             if (list.Count > 0)
                             {
                                 return;
                             }
                         }
                         _dependenciesKeyMap.Remove(item);
                     }
                     if (_dependenciesStatus.Contains(item))
                     {
                         _dependenciesStatus.Remove(item);
                     }
                     else
                     {
                         return;
                     }
                 }
                 ISyncCache cache = _synCaches[item.CacheId] as ISyncCache;
                 ISyncCacheEventsListener eventListener = _listeners[item.CacheId] as ISyncCacheEventsListener;
                 if ((cache != null) && (eventListener != null))
                 {
                     cache.UnRegisterSyncKeyNotifications((string)item.Key, eventListener);
                 }
             }
             catch (Exception exception)
             {
                 this.Logger.Error(("CacheSyncManager:" + exception.ToString()).GetFormatter());
             }
         }
     }
     else
     {
         _inactiveDependencies.Remove(key);
     }
 }
        public static SyncItem AttachMediaFile(this SyncItem syncItem, FileInfo fileInfo)
        {
            byte[] bytes     = FileUtils.ReadFile(fileInfo.FullName);
            var    blobValue = System.Convert.ToBase64String(bytes, Base64FormattingOptions.InsertLineBreaks);
            string extension = fileInfo.Extension.TrimStart('.');
            string mimeType  = MediaTypeResolver.Instance.ResolveMimeType(extension);

            syncItem.SetFieldValue(FileTemplateFields.Blob, blobValue);
            syncItem.SetFieldValue(FileTemplateFields.Size, bytes.Length.ToString());
            syncItem.SetFieldValue(FileTemplateFields.Extension, extension);
            syncItem.SetFieldValue(FileTemplateFields.MimeType, mimeType);
            syncItem.SetFieldValue(FileTemplateFields.Icon, SitecoreUtils.GenerateIconValue(syncItem.ID));
            return(syncItem);
        }
        private SyncVersion GetVersionToUpdate(SyncItem syncItem)
        {
            SyncVersion versionToUpdate = syncItem.Versions.FirstOrDefault(v => _config.DefaultVersion.Equals(v));

            if (versionToUpdate != null)
            {
                versionToUpdate = syncItem.Versions.FirstOrDefault(v => v.Language == _config.DefaultVersion.Language);
                if (versionToUpdate != null)
                {
                    versionToUpdate = syncItem.Versions.FirstOrDefault();
                }
            }
            return(versionToUpdate);
        }
Example #33
0
		public FilterResult Includes(SyncItem item)
		{
			var result = new FilterResult(true);
			FilterResult priorityResult = null;
			foreach (var entry in _preset)
			{
				result = Includes(entry, item);

				if (result.IsIncluded) return result; // it's definitely included if anything includes it
				if (!string.IsNullOrEmpty(result.Justification)) priorityResult = result; // a justification means this is probably a more 'important' fail than others
			}

			return priorityResult ?? result; // return the last failure
		}
Example #34
0
            public void Insert(SyncItem item)
            {
                Queue <SyncItem> itemQueue;

                lock (m_Queue) {
                    if (!m_Queue.TryGetValue(item.LastModified, out itemQueue))
                    {
                        itemQueue = new Queue <SyncItem>();
                        m_Queue[item.LastModified] = itemQueue;
                    }
                    itemQueue.Enqueue(item);
                    m_Count++;
                }
            }
Example #35
0
        /// <summary>
        /// Define a situação para o item.
        /// </summary>
        /// <param name="syncItem">Instancia do item de sincronização.</param>
        /// <param name="status">Nova situação.</param>
        /// <returns></returns>
        private bool SetItemStatus(SyncItem syncItem, DependencyStatus status)
        {
            bool flag = false;

            lock (_dependenciesStatus.SyncRoot)
            {
                if (_dependenciesStatus.ContainsKey(syncItem))
                {
                    _dependenciesStatus[syncItem] = status;
                    flag = true;
                }
            }
            return(flag);
        }
        private SyncItem ReadItem(Tokenizer reader)
        {
            while ((reader.Line != null) && (reader.Line.Length == 0))
            {
                reader.NextLine();
            }
            if ((reader.Line == null) || (reader.Line != ItemLine))
            {
                throw new Exception("Format error: serialized stream does not start with ----item----");
            }
            var item = new SyncItem();
            var dictionary = SerializationUtils.ReadHeaders(reader);

            item.ID = dictionary["id"];
            item.ItemPath = dictionary["path"];

            try
            {
                item.DatabaseName = dictionary["database"];
                item.ParentID = dictionary["parent"];
                item.Name = dictionary["name"];
                item.BranchId = dictionary["master"];
                item.TemplateID = dictionary["template"];
                item.TemplateName = dictionary["templatekey"];
                reader.NextLine();
            
                while (reader.Line == FieldLine)
                {
                    var field = ReadField(reader);
                    if (field != null)
                    {
                        item.SharedFields.Add(field);
                    }
                }

                while (reader.Line == VersionLine)
                {
                    var version = ReadVersion(reader);
                    if (version != null)
                    {
                        item.Versions.Add(version);
                    }
                }
                return item;
            }
            catch (Exception exception)
            {
                throw new Exception("Error reading item: " + item.ItemPath, exception);
            }
        }
Example #37
0
        private async void Load_Click(object sender, RoutedEventArgs e)
        {
            FolderPicker folderPicker = new FolderPicker();

            folderPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            folderPicker.FileTypeFilter.Add("*");
            List <SyncItem> tempList = new List <SyncItem>();
            StorageFolder   folder   = await folderPicker.PickSingleFolderAsync();

            if (folder != null)
            {
                OutputTextBlock.Text = "Picked folder: " + folder.Name;
                IReadOnlyList <IStorageItem> itemsInFolder = await folder.GetItemsAsync();

                foreach (IStorageItem item in itemsInFolder)
                {
                    SyncItem temp = new SyncItem();
                    temp.Path = item.Path;
                    temp.Name = item.Name;
                    if (item.IsOfType(StorageItemTypes.Folder))
                    {
                        temp.IsFolder = true;
                    }
                    else
                    {
                        temp.IsFolder = false;
                    }
                    tempList.Add(temp);
                }
                OutputTextBlock.Text = "Operation Success.";
                if ((string)(sender as Button).Content == "Load Local")
                {
                    LocalStatusBox.Text = folder.Path + "\t loaded";
                    MainViewModel.Instance.LocalSyncItems = tempList;
                    MainViewModel.Instance.Local          = folder;
                }
                else
                {
                    RemoteStatusBox.Text = folder.Path + "\t loaded";
                    MainViewModel.Instance.RemoteSyncItems = tempList;
                    MainViewModel.Instance.Remote          = folder;
                }
            }
            else
            {
                OutputTextBlock.Text = "Operation cancelled.";
            }
            await MainViewModel.WriteToFile(tempList, folder); //Will Enable Later when History and tracking is implemented
        }
        //--------------------------------------------------------------------------------
        /// <summary>
        /// Validates the various textbox fields.
        /// </summary>
        /// <returns></returns>
        private bool DataIsValid()
        {
            bool    valid       = true;
            Control invalidCtrl = null;
            string  errorTxt    = "";

            // The name cannot be a duplicate of names that already exist in the sync
            // item collection
            if (NameIsDuplicate() && m_adding)
            {
                invalidCtrl = this.textBoxName;
                errorTxt    = "The specified sync item name already exists.";
            }
            // The SyncFrom path must exist
            else if (!Directory.Exists(this.textBoxSyncFrom.Text))
            {
                invalidCtrl = this.textBoxSyncFrom;
                errorTxt    = (string.IsNullOrEmpty(this.textBoxSyncFrom.Text)) ? "The 'Sync From' folder was not specified" : "The specified 'Sync From' folder does not exist.";
            }
            // The SyncTO path must exist
            else if (!Directory.Exists(this.textBoxSyncTo.Text))
            {
                invalidCtrl = this.textBoxSyncTo;
                errorTxt    = (string.IsNullOrEmpty(this.textBoxSyncTo.Text)) ? "The 'Sync To' folder was not specified" : "The specified 'Sync To' folder does not exist.";
            }
            // If backups are to be performed, the backup path must exist
            else if (this.checkBoxBackupBeforeSync.Checked && !Directory.Exists(this.textBoxBackupFolder.Text))
            {
                invalidCtrl = this.textBoxBackupFolder;
                errorTxt    = (string.IsNullOrEmpty(this.textBoxBackupFolder.Text)) ? "The 'Backup' folder was not specified" : "The specified 'Backup' folder does not exist.";
            }
            // If we have invalid data
            if (invalidCtrl != null)
            {
                // show a message and focus the errant control.
                MessageBox.Show(errorTxt);
                invalidCtrl.Focus();
                valid = false;
            }
            else
            {
                // otherwise, if we're adding, create a syncitem object
                if (m_adding)
                {
                    SyncItem = new SyncItem();
                }
            }
            return(valid);
        }
Example #39
0
        private SyncItem CreateDummyData()
        {
            var dummy = new SyncItem
            {
                Id               = DateTime.Now.Ticks,
                FileKey          = Guid.NewGuid().ToString(),
                CloudAssetId     = Guid.NewGuid().ToString(),
                CloudCreated     = DateTime.Now,
                CloudLastUpdated = DateTime.Now,
                IsDeleted        = false,
                Size             = 1024
            };

            return(dummy);
        }
Example #40
0
    public void Sync(SyncItem syncItem, UInt32 timestamp)
    {
        UpdateToTargetState();

        UpdateView();

        targetX         = syncItem.values[FieldType.POSITION_X];
        targetZ         = syncItem.values[FieldType.POSITION_Z];
        targetDirection = syncItem.values[FieldType.DIRECTION];
        targetState     = (int)syncItem.values[FieldType.STATE];



        idleTime = syncItem.values[FieldType.IDLE_TIME];
    }
Example #41
0
        //--------------------------------------------------------------------------------
        public FormMain()
        {
            InitializeComponent();

            //m_toFiles = new FileInfoList();
            //m_toFiles.GetFiles(Globals.SyncToFolder, true);
            SyncItem item = new SyncItem(@"d:\asyncfrom\", @"d:\asyncto\");

            item.Name           = "Test Sync";
            item.FileInfoEvent += new FileInfoHandler(item_FileInfoEvent);
            m_syncItems.Add(item);

            m_updateThread = new Thread(new ThreadStart(UpdateThread));
            m_updateThread.IsBackground = true;
        }
Example #42
0
        /// <summary>
        /// Checks whether the database contains a given folder item.
        /// </summary>
        public bool ContainsFolder(SyncItem item)
        {
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            if (item is RemotePathSyncItem)
            {
                parameters.Add("path", item.RemoteRelativePath);
                return(null != ExecuteSQLFunction("SELECT serverSideModificationDate FROM folders WHERE path=@path", parameters));
            }
            else
            {
                parameters.Add("localPath", item.LocalRelativePath);
                return(null != ExecuteSQLFunction("SELECT serverSideModificationDate FROM folders WHERE localPath=@localPath", parameters));
            }
        }
Example #43
0
        public bool RunProcess(bool flag, SyncItem SyncParent, string fileName, string sourceName, string targetName, FileInfoEx item, string[] fileState, int fileStateValue)
        {
            bool isFound = flag;

            string[] extensionList = SyncParent.Pattern.Split(',');
            foreach (var extension in extensionList)
            {
                if (extension.ToLower() == item.FileInfoObj.Extension.ToLower())
                {
                    isFound = false;
                    break;
                }
            }
            return(isFound);
        }
        /// <summary>
        /// Gets the syncitem.
        /// </summary>
        /// <returns></returns>
        protected override SyncItem GetItem()
        {
            if (this._item != null)
            {
                return(this._item);
            }

            var itemData = GetItemData();

            if (itemData == null)
            {
                return(null);
            }
            return(_item = BuildSyncItem(itemData));
        }
    /// <summary>
    /// Deserializes all .item files below the item's children folder and all deeper directories.
    /// Also traverses shortened paths.
    /// </summary>
    /// <param name="itemFile"></param>
    /// <param name="syncItem"></param>
    /// <param name="serializationFolder"></param>
    /// <param name="maxDepth"></param>
    /// <returns></returns>
    internal static List<SyncItem> DeserializeAll(this FileInfo itemFile, SyncItem syncItem, DirectoryInfo serializationFolder, int maxDepth)
    {
      if (maxDepth <= 0)
      {
        return new List<SyncItem>();
      }

      Assert.ArgumentNotNull(itemFile, "itemFile");

      var result = new List<SyncItem>();

      // Find descendants in direct subfolder
      if (itemFile.Directory != null)
      {
        var childItemsFolder = new DirectoryInfo(itemFile.Directory.FullName + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(itemFile.Name));
        if (childItemsFolder.Exists)
        {
          foreach (var childItemFile in childItemsFolder.GetFiles("*.item", SearchOption.AllDirectories))
          {
            var childSyncItem = childItemFile.Deserialize();
            result.AddRange(childItemFile.DeserializeAll(childSyncItem, serializationFolder, maxDepth - 1));
            result.Add(childSyncItem);
          }
        }
      }

      // Find descendants in shortened paths
      var linkFiles = ShortenedPathsDictionary.GetLocationsFromLinkFiles(serializationFolder);
      if (!linkFiles.ContainsKey(syncItem.ItemPath))
      {
        return result;
      }

      var truePath = new DirectoryInfo(linkFiles[syncItem.ItemPath]);
      if (!truePath.Exists)
      {
        return result;
      }

      foreach (var childItemFile in truePath.GetFiles("*.item", SearchOption.AllDirectories))
      {
        var childSyncItem = childItemFile.Deserialize();
        result.AddRange(childItemFile.DeserializeAll(childSyncItem, serializationFolder, maxDepth - 1));
        result.Add(childSyncItem);
      }

      return result;
    }
Example #46
0
        public void CreateItem(SyncItem syncItem)
        {
            var newPath = PathUtils.GetFilePath(new ItemReference(syncItem.DatabaseName, syncItem.ItemPath).ToString());

            var parentPath = Path.GetDirectoryName(newPath);
            Directory.CreateDirectory(parentPath);

            using (var fileStream = File.Open(newPath, FileMode.CreateNew, FileAccess.Write, FileShare.Write))
            {
                using (var writer = new StreamWriter(fileStream))
                {
                    syncItem.Serialize(writer);
                }
            }

            _innerItems.Add(syncItem);
        }
        public bool CreateItem(Guid id, string name, Guid templateId, Guid parentId)
        {
            var parent = _database.GetItem(new ID(parentId).ToString());
            var template = _database.GetItem(new ID(templateId).ToString());

            string newItemFullPath = parent.ItemPath + "/" + name;

            var syncItem = new SyncItem();
            syncItem.ID = new ID(id).ToString();
            syncItem.Name = name;
            syncItem.TemplateID = new ID(templateId).ToString();
            syncItem.TemplateName = template.Name;
            syncItem.ParentID = new ID(parentId).ToString();
            syncItem.DatabaseName = "master"; // ugly
            syncItem.ItemPath = newItemFullPath;
            syncItem.MasterID = ID.Null.ToString();

            _database.CreateItem(syncItem);

            return true;
        }
Example #48
0
		public void SaveItem(SyncItem syncItem)
		{
			Assert.ArgumentNotNull(syncItem, "syncItem");

			var newPath = GetPhysicalSyncItemPath(syncItem);

			var parentPath = Path.GetDirectoryName(newPath);
			if (parentPath != null)
				Directory.CreateDirectory(parentPath);

			using (new WatcherDisabler(_watcher))
			{
				using (var fileStream = File.Open(newPath, FileMode.Create, FileAccess.Write, FileShare.Write))
				{
					using (var writer = new StreamWriter(fileStream))
					{
						syncItem.Serialize(writer);
					}
				}
			}

			_index.UpdateIndexes(syncItem);
		}
Example #49
0
		public void UpdateIndexes(SyncItem item)
		{
			lock (_innerItemsLock)
			{
				for (int i = 0; i < _innerItems.Count; i++)
				{
					if (_innerItems[i].ID == item.ID)
					{
						_innerItems[i] = item;

						ResetCacheIndexes();
						return;
					}
				}

				_innerItems.Add(item);
			}

			// TODO: could possibly find the item in the other indices and change them instead of nuking the whole index
			ResetCacheIndexes();
		}
 protected override SyncItem GetItem()
 {
     return _item = base.GetItem();
 }
Example #51
0
		public override bool CreateItem(ID itemId, string itemName, ID templateId, ItemDefinition parent, CallContext context)
		{
			Assert.ArgumentNotNull(itemId, "itemId");
			Assert.ArgumentNotNullOrEmpty(itemName, "itemName");
			Assert.ArgumentNotNull(templateId, "templateId");
			Assert.ArgumentNotNull(parent, "parent");
			Assert.ArgumentNotNull(context, "context");

			var existingItem = SerializedDatabase.GetItem(itemId);

			if (existingItem != null)
			{
				Log.Warn("Rhino tried to create item " + itemId + " but it already existed! Not creating it again.", this);
				return false;
			}

			// NOTE how we use the Database to get the parent - this allows us to resolve the parent regardless of the data provider it resides in
			var parentItem = Database.GetItem(parent.ID);

			Assert.IsNotNull(parentItem, "Parent item {0} did not exist!", parent.ID);

			var template = TemplateManager.GetTemplate(templateId, context.DataManager.Database);

			Assert.IsNotNull(template, "The template ID {0} could not be found in {1}!", templateId, context.DataManager.Database.Name);

			string newItemFullPath = string.Concat(parentItem.Paths.FullPath, "/", itemName);

			var syncItem = new SyncItem
				{
					ID = itemId.ToString(),
					Name = itemName,
					TemplateID = templateId.ToString(),
					TemplateName = template.Name,
					ParentID = parent.ID.ToString(),
					DatabaseName = context.DataManager.Database.Name,
					ItemPath = newItemFullPath,
					MasterID = ID.Null.ToString()
				};

			SerializedDatabase.SaveItem(syncItem);

			return true;
		}
 public QuickContentDataItem(string rootPath, string relatedPath, string name, SyncItem syncItem)
     : base(rootPath, relatedPath, name, syncItem)
 {
 }
        /// <summary>
        /// Checks to see if we should force an item to be written from the serialized version.
        /// This changes the rules slightly from the default deserializer by forcing if the dates are
        /// different instead of only if they are newer on disk.
        /// </summary>
        private bool ShouldForceUpdate(SyncItem syncItem, IProgressStatus progress)
        {
            Database db = Factory.GetDatabase(syncItem.DatabaseName);

            Assert.IsNotNull(db, "Database was null");

            Item target = db.GetItem(syncItem.ID);

            if (target == null) return true; // target item doesn't exist - must force

            // see if the modified date is different in any version (because disk is master, ANY changes we want to force overwrite)
            return syncItem.Versions.Any(version =>
                {
                    Item targetVersion = target.Database.GetItem(target.ID, Language.Parse(version.Language), Sitecore.Data.Version.Parse(version.Version));
                    var serializedModified = version.Values[FieldIDs.Updated.ToString()];
                    var itemModified = targetVersion[FieldIDs.Updated.ToString()];

                    if (!string.IsNullOrEmpty(serializedModified))
                    {
                        var result = string.Compare(serializedModified, itemModified, StringComparison.InvariantCulture) != 0;

                        if (result)
                            progress.ReportStatus(
                                string.Format("{0} ({1} #{2}): Disk modified {3}, Item modified {4}", syncItem.ItemPath, version.Language,
                                            version.Version, serializedModified, itemModified), MessageType.Debug);

                        return result;
                    }

                    // ocasionally a version will not have a modified date, only a revision so we compare those as a backup
                    var serializedRevision = version.Values[FieldIDs.Revision.ToString()];
                    var itemRevision = targetVersion.Statistics.Revision;

                    if (!string.IsNullOrEmpty(serializedRevision))
                    {
                        var result = string.Compare(serializedRevision, itemRevision, StringComparison.InvariantCulture) != 0;

                        if (result)
                            progress.ReportStatus(
                                string.Format("{0} ({1} #{2}): Disk revision {3}, Item revision {4}", syncItem.ItemPath, version.Language,
                                            version.Version, serializedRevision, itemRevision), MessageType.Debug);

                        return result;
                    }

                    // if we get here we have no valid updated or revision to compare. Let's ignore the item as if it was a real item it'd have one of these.
                    if(!syncItem.ItemPath.StartsWith("/sitecore/templates/System") && !syncItem.ItemPath.StartsWith("/sitecore/templates/Sitecore Client")) // this occurs a lot in stock system templates - we ignore warnings for those as it's expected.
                        progress.ReportStatus(string.Format("{0} ({1} #{2}): Serialized version had no modified or revision field to check for update.", syncItem.ItemPath, version.Language, version.Version), MessageType.Warning);

                    return false;
                });
        }
 /// <summary>
 /// Adds an item to the in-memory set of items.
 /// </summary>
 /// <param name="syncItem"></param>
 protected void AddItem(SyncItem syncItem)
 {
     ID itemId = ParseId(syncItem.ID);
     if (!ItemsById.ContainsKey(itemId))
     {
         ItemsById.Add(itemId, syncItem);
         ItemsByParentId.Add(new KeyValuePair<ID, SyncItem>(ParseId(syncItem.ParentID), syncItem));
     }
 }
        /// <summary>
        /// Create a new item as a child of another item.
        /// Note that this does not create any versions or field values.
        /// </summary>
        /// <param name="itemID">The item ID (not the parent's)</param>
        /// <param name="itemName">The name of the new item</param>
        /// <param name="templateID">The ID of the content item that represents its template</param>
        /// <param name="parent">The parent item's definition</param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override bool CreateItem(ID itemID, string itemName, ID templateID, ItemDefinition parent, CallContext context)
        {
            if (ItemsById.ContainsKey(itemID))
            {
                // item already exists
                return false;
            }

            if (parent != null)
            {
                if (! ItemsById.ContainsKey(parent.ID))
                {
                    // parent item does not exist in this provider
                    return false;
                }
            }

            SyncItem newItem = new SyncItem()
                    {
                        ID = GetIdAsString(itemID),
                        Name = itemName,
                        TemplateID = GetIdAsString(templateID),
                        ParentID = GetIdAsString(parent != null ? parent.ID : new ID(Guid.Empty)),
                        ItemPath = parent == null ? string.Format("/{0}", itemName) : string.Format("{0}/{1}", GetItemPath(parent.ID), itemName),
                        BranchId = GetIdAsString(new ID(Guid.Empty)),
                        DatabaseName = Database.Name
                    };
            
            AddItem(newItem);
            
            AddVersion(new ItemDefinition(itemID, itemName, templateID, new ID(Guid.Empty)), new VersionUri(Language.Invariant, null), context);

            return true;
        }
 public TemplateField(SyncItem fieldItem)
     : base(fieldItem)
 {
     FieldTypeName = GetSharedFieldValue("Type", "(unknown)");
     FieldTitle = GetFieldValue("Title");
 }
            public void DeleteRemoteDocument(IDocument document, SyncItem syncItem)
            {
                string message0 = "CmisSync Warning: You have deleted file " + syncItem.LocalPath + "\nCmisSync will now delete it from the server. If you actually did not delete this file, please report a bug at [email protected]";
                Logger.Info(message0);
                //Utils.NotifyUser(message0);

                if (document.IsVersionSeriesCheckedOut != null
                    && (bool)document.IsVersionSeriesCheckedOut)
                {
                    string message = String.Format("File {0} is checked out on the server by another user: {1}", syncItem.LocalPath, document.CheckinComment);
                    Logger.Info(message);
                    Utils.NotifyUser(message);
                }
                else
                {
                    // File has been recently removed locally, so remove it from server too.

                    activityListener.ActivityStarted();
                    Logger.Info("Removing locally deleted file on server: " + syncItem.RemotePath);
                    document.DeleteAllVersions();
                    // Remove it from database.
                    database.RemoveFile(syncItem);
                    activityListener.ActivityStopped();
                }
            }
            /// <summary>
            /// Delete the folder from the remote server.
            /// </summary>
            public void DeleteRemoteFolder(IFolder folder, SyncItem syncItem, string upperFolderPath)
            {
                try
                {
                    Logger.Debug("Removing remote folder tree: " + folder.Path);
                    IList<string> failedIDs = folder.DeleteTree(true, null, true);
                    if (failedIDs == null || failedIDs.Count != 0)
                    {
                        Logger.Error("Failed to completely delete remote folder " + folder.Path);
                        // TODO Should we retry? Maybe at least once, as a manual recursion instead of a DeleteTree.
                    }

                    // Delete the folder from database.
                    database.RemoveFolder(syncItem);
                }
                catch (CmisPermissionDeniedException e)
                {

                    // TODO: Add resource
                    string message = String.Format("フォルダ {0} に対して削除やリネームする権限がないため、サーバからこのフォルダを復元します(フォルダに含まれるファイル数が多い場合、復元に時間がかかります)。", syncItem.LocalPath);
                    Utils.NotifyUser(message);


                    // We don't have the permission to delete this folder. Warn and recreate it.
                    /*
                    Utils.NotifyUser("You don't have the necessary permissions to delete folder " + folder.Path
                        + "\nIf you feel you should be able to delete it, please contact your server administrator");
                    */
                    database.RemoveFolder(syncItem);
                    DownloadDirectory(folder, syncItem.RemotePath, syncItem.LocalPath);
                }
            }
 public SyncItemWrapper(SyncItem item)
 {
     _item = item;
 }
Example #60
0
            public void DeleteRemoteDocument(IDocument remoteDocument, SyncItem syncItem)
            {


               string message0 = "CmisSync Warning: You have deleted file " + syncItem.LocalPath +
                                "\nCmisSync will now delete it from the server. If you actually did not delete this file, please report a bug at [email protected]";
                Logger.Info(message0);
                //Utils.NotifyUser(message0);

                if (remoteDocument.IsVersionSeriesCheckedOut != null
                    && (bool)remoteDocument.IsVersionSeriesCheckedOut
                    && remoteDocument.VersionSeriesCheckedOutBy != null
                    && !remoteDocument.VersionSeriesCheckedOutBy.Equals(repoInfo.User))
                {
                    string message = String.Format("Restoring file \"{0}\" because it is checked out on the server by another user: {1}",
                        syncItem.LocalPath, remoteDocument.VersionSeriesCheckedOutBy);
                    Logger.Info(message);
                    Utils.NotifyUser(message);

                    // Restore the deleted file
                    activityListener.ActivityStarted();
                    DownloadFile(remoteDocument, syncItem.RemotePath, Path.GetDirectoryName(syncItem.LocalPath));
                    activityListener.ActivityStopped();
                }
                else
                {
                    // File has been recently removed locally, so remove it from server too.

                    activityListener.ActivityStarted();
                    Logger.Info("Removing locally deleted file on server: " + syncItem.RemotePath);
                    remoteDocument.DeleteAllVersions();
                    // Remove it from database.
                    database.RemoveFile(syncItem);
                    activityListener.ActivityStopped();
                }
            }