-#region
-/* -----------------------------------------------------------------------
- * <copyright file="DirectoryRecord.cs" company="GRNet">
- *
- * Copyright 2011-2012 GRNET S.A. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * 1. Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the following
- * disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials
- * provided with the distribution.
- *
- *
- * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- * The views and conclusions contained in the software and
- * documentation are those of the authors and should not be
- * interpreted as representing official policies, either expressed
- * or implied, of GRNET S.A.
- * </copyright>
- * -----------------------------------------------------------------------
- */
-#endregion
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Collections.Specialized;
-using System.IO;
-using System.Linq;
-using System.Text;
-using Caliburn.Micro;
-using Pithos.Client.WPF.Utils;
-using Pithos.Core.Agents;
-using Pithos.Interfaces;
-
-namespace Pithos.Client.WPF.SelectiveSynch
-{
- public class DirectoryRecord :PropertyChangedBase, IEnumerable<DirectoryRecord>
- {
- private ObjectInfo _objectInfo;
- public ObjectInfo ObjectInfo
- {
- get { return _objectInfo; }
- set
- {
- _objectInfo = value;
- Uri = value.Uri;
- }
- }
-
- public Uri Uri { get; set; }
- //public DirectoryInfo LocalInfo { get; set; }
-
- DirectoryRecord _parent;
-
- public bool Added { get; set; }
- public bool Removed { get; set; }
-
- private bool? _isChecked=true;
- #region IsChecked
-
- /// <summary>
- /// Gets/sets the state of the associated UI toggle (ex. CheckBox).
- /// The return value is calculated based on the check state of all
- /// child FooViewModels. Setting this property to true or false
- /// will set all children to the same check state, and setting it
- /// to any value will cause the parent to verify its check state.
- /// </summary>
- public bool? IsChecked
- {
- get { return _isChecked; }
- set { this.SetIsChecked(value, true, true); }
- }
-
- void SetIsChecked(bool? value, bool updateChildren, bool updateParent)
- {
- if (value == _isChecked)
- return;
-
- _isChecked = value;
-
- //If the value is null both Added and Removed should be False
- Added = _isChecked??false;
- Removed = !(_isChecked??true);
-
- if (updateChildren && _isChecked.HasValue)
- this.Directories.Apply(c => c.SetIsChecked(_isChecked, true, false));
-
- if (updateParent && _parent != null)
- _parent.VerifyCheckState();
-
- this.RaisePropertyChangedEventImmediately("IsChecked");
- }
-
- void VerifyCheckState()
- {
- bool? state = null;
- for (var i = 0; i < this.Directories.Count(); ++i)
- {
- bool? current = this.Directories.ElementAt(i).IsChecked;
- if (i == 0)
- {
- state = current;
- }
- else if (state != current)
- {
- state = null;
- break;
- }
- }
- this.SetIsChecked(state, false, true);
- }
-
- #endregion // IsChecked
-
-
- public bool IsInitiallySelected { get; private set; }
-
- private List<DirectoryRecord> _directories=new List<DirectoryRecord>();
- public List<DirectoryRecord> Directories
- {
- get { return _directories; }
- set { _directories= value; }
- }
-
- public DirectoryRecord()
- {
-
-/*
- _directories = new Lazy<List<DirectoryRecord>>(() =>
- new List<DirectoryRecord>());
-*/
-/*
- _directories = new Lazy<List<DirectoryRecord>>(() =>
- (from directory in Info.EnumerateDirectories("*", SearchOption.TopDirectoryOnly)
- where !directory.FullName.StartsWith(ignorePath)
- select new DirectoryRecord(ignorePath) { Info = directory }).ToList());
-*/
- }
-
- private string _displayName;
-
- public string DisplayName
- {
- get
- {
- if (ObjectInfo != null)
- return ObjectInfo.Name.Split('/').Last();
- return _displayName;
- }
- set { _displayName = value; }
- }
-
- public bool IsExplicitlyChecked
- {
- set { _isChecked=value; }
- }
-
- public DirectoryRecord(ObjectInfo info)
- {
- ObjectInfo = info;
- }
-
-
-/*
- public IEnumerable<DirectoryInfo> GetCheckedDirectories()
- {
- var q = from record in this
- where record.IsChecked==true
- select record.Info;
- return q;
- }
-*/
-
-/*
- public void SetSelections(StringCollection selections)
- {
- IsChecked=selections.Contains(Info.FullName);
- foreach (var children in Directories)
- {
- children.SetSelections(selections);
- }
- }
-*/
-
-
- public IEnumerator<DirectoryRecord> GetEnumerator()
- {
- yield return this;
- foreach (var children in Directories)
- foreach (var info in children)
- {
- yield return info;
- }
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
- public override int GetHashCode()
- {
- return ObjectInfo == null
- ? (Uri == null ? DisplayName.GetHashCode() : Uri.GetHashCode())
- : ObjectInfo.GetHashCode();
- }
-
- public override bool Equals(object obj)
- {
- if (!(obj is DirectoryRecord))
- return false;
- var other = (DirectoryRecord)obj;
- if (Uri != other.Uri)
- return false;
- if (ObjectInfo== null ^ other.ObjectInfo== null)
- return false;
-
- if (ObjectInfo!= null && !ObjectInfo.Equals(other.ObjectInfo))
- return false;
- var thisEnum = GetEnumerator();
- var otherEnum = other.GetEnumerator();
- //Skipt the first item, it is the current node itself
- thisEnum.MoveNext();
- otherEnum.MoveNext();
- while (true)
- {
- var thisMove = thisEnum.MoveNext();
- var otherMove = otherEnum.MoveNext();
-
- if (thisMove ^ otherMove)
- return false;
- if (!thisMove)
- return true;
-
- if (!thisEnum.Current.Equals(otherEnum.Current))
- return false;
- }
- }
- }
-}
+#region\r
+/* -----------------------------------------------------------------------\r
+ * <copyright file="DirectoryRecord.cs" company="GRNet">\r
+ * \r
+ * Copyright 2011-2012 GRNET S.A. All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or\r
+ * without modification, are permitted provided that the following\r
+ * conditions are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above\r
+ * copyright notice, this list of conditions and the following\r
+ * disclaimer.\r
+ *\r
+ * 2. Redistributions in binary form must reproduce the above\r
+ * copyright notice, this list of conditions and the following\r
+ * disclaimer in the documentation and/or other materials\r
+ * provided with the distribution.\r
+ *\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS\r
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR\r
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF\r
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED\r
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+ * POSSIBILITY OF SUCH DAMAGE.\r
+ *\r
+ * The views and conclusions contained in the software and\r
+ * documentation are those of the authors and should not be\r
+ * interpreted as representing official policies, either expressed\r
+ * or implied, of GRNET S.A.\r
+ * </copyright>\r
+ * -----------------------------------------------------------------------\r
+ */\r
+#endregion\r
+using System;\r
+using System.Collections;\r
+using System.Collections.Generic;\r
+using System.Collections.Specialized;\r
+using System.Diagnostics;\r
+using System.IO;\r
+using System.Linq;\r
+using System.Text;\r
+using Caliburn.Micro;\r
+using Pithos.Client.WPF.Utils;\r
+using Pithos.Core.Agents;\r
+using Pithos.Interfaces;\r
+\r
+namespace Pithos.Client.WPF.SelectiveSynch\r
+{\r
+ [DebuggerDisplay("{Uri} : {IsChecked}")]\r
+ public class DirectoryRecord :PropertyChangedBase, IEnumerable<DirectoryRecord>\r
+ {\r
+ private ObjectInfo _objectInfo;\r
+ public ObjectInfo ObjectInfo\r
+ {\r
+ get { return _objectInfo; }\r
+ set\r
+ {\r
+ _objectInfo = value;\r
+ Uri = value.Uri;\r
+ }\r
+ }\r
+\r
+ public Uri Uri { get; set; }\r
+ //public DirectoryInfo LocalInfo { get; set; }\r
+\r
+\r
+ private DirectoryRecord _parent;\r
+ public DirectoryRecord Parent\r
+ {\r
+ get { return _parent; }\r
+ private set { _parent = value; }\r
+ }\r
+\r
+ public bool Added { get; set; }\r
+ public bool Removed { get; set; }\r
+\r
+ private bool? _isChecked=true;\r
+ #region IsChecked\r
+\r
+ /// <summary>\r
+ /// Gets/sets the state of the associated UI toggle (ex. CheckBox).\r
+ /// The return value is calculated based on the check state of all\r
+ /// child FooViewModels. Setting this property to true or false\r
+ /// will set all children to the same check state, and setting it \r
+ /// to any value will cause the parent to verify its check state.\r
+ /// </summary>\r
+ public bool? IsChecked\r
+ {\r
+ get\r
+ {\r
+ if (_directories.Count==0)\r
+ return _isChecked;\r
+ \r
+ if (_isChecked == true) \r
+ return _isChecked;\r
+ //Check children to decide whether to display a clear (false) or gray (null)\r
+ return _directories.Any(d => d.IsChecked == true) ? null : (bool?)false;\r
+ }\r
+ set { this.SetIsChecked(value, true, true); }\r
+ }\r
+\r
+ void SetIsChecked(bool? value, bool updateChildren, bool updateParent)\r
+ {\r
+ if (value == _isChecked)\r
+ return;\r
+\r
+ _isChecked = value??false;\r
+\r
+ //If the value is null both Added and Removed should be False\r
+ Added = _isChecked.Value;\r
+ Removed = !(_isChecked.Value);\r
+\r
+ if (updateChildren )\r
+ this.Directories.Apply(c => c.SetIsChecked(_isChecked, true, false));\r
+\r
+ if (updateParent && _parent != null)\r
+ _parent.VerifyCheckState();\r
+\r
+ this.RaisePropertyChangedEventImmediately("IsChecked");\r
+ }\r
+\r
+ void VerifyCheckState()\r
+ {\r
+ RaisePropertyChangedEventImmediately("IsChecked");\r
+ return;\r
+ bool? state = null;\r
+ for (var i = 0; i < this.Directories.Count(); ++i)\r
+ {\r
+ bool? current = this.Directories.ElementAt(i).IsChecked;\r
+ if (i == 0)\r
+ {\r
+ state = current;\r
+ }\r
+ else if (state != current)\r
+ {\r
+ state = null;\r
+ break;\r
+ }\r
+ }\r
+ this.SetIsChecked(state, false, true);\r
+ }\r
+\r
+ #endregion // IsChecked\r
+\r
+\r
+ public bool IsInitiallySelected { get; private set; }\r
+\r
+ private List<DirectoryRecord> _directories=new List<DirectoryRecord>();\r
+ public List<DirectoryRecord> Directories\r
+ {\r
+ get { return _directories; }\r
+ set\r
+ {\r
+ _directories= value;\r
+ foreach (var dir in value)\r
+ {\r
+ dir.Parent = this;\r
+ }\r
+ }\r
+ }\r
+\r
+ public DirectoryRecord()\r
+ {\r
+ \r
+/*\r
+ _directories = new Lazy<List<DirectoryRecord>>(() => \r
+ new List<DirectoryRecord>());\r
+*/\r
+/*\r
+ _directories = new Lazy<List<DirectoryRecord>>(() => \r
+ (from directory in Info.EnumerateDirectories("*", SearchOption.TopDirectoryOnly)\r
+ where !directory.FullName.StartsWith(ignorePath)\r
+ select new DirectoryRecord(ignorePath) { Info = directory }).ToList());\r
+*/\r
+ }\r
+\r
+ private string _displayName;\r
+\r
+ public string DisplayName\r
+ {\r
+ get\r
+ {\r
+ if (ObjectInfo != null)\r
+ return Uri.UnescapeDataString(ObjectInfo.Name.ToString().Split('/').Last());\r
+ return _displayName;\r
+ }\r
+ set { _displayName = value; }\r
+ }\r
+\r
+ public bool IsExplicitlyChecked\r
+ {\r
+ set\r
+ {\r
+ _isChecked=value;\r
+ this.RaisePropertyChangedEventImmediately("IsChecked");\r
+ }\r
+ }\r
+\r
+ public DirectoryRecord(ObjectInfo info)\r
+ {\r
+ ObjectInfo = info;\r
+ }\r
+\r
+\r
+/*\r
+ public IEnumerable<DirectoryInfo> GetCheckedDirectories()\r
+ {\r
+ var q = from record in this\r
+ where record.IsChecked==true\r
+ select record.Info;\r
+ return q;\r
+ }\r
+*/\r
+\r
+/*\r
+ public void SetSelections(StringCollection selections)\r
+ {\r
+ IsChecked=selections.Contains(Info.FullName); \r
+ foreach (var children in Directories)\r
+ {\r
+ children.SetSelections(selections);\r
+ }\r
+ }\r
+*/\r
+\r
+\r
+ public IEnumerator<DirectoryRecord> GetEnumerator()\r
+ {\r
+ yield return this;\r
+ foreach (var children in Directories)\r
+ foreach (var info in children)\r
+ {\r
+ yield return info;\r
+ }\r
+ }\r
+\r
+ IEnumerator IEnumerable.GetEnumerator()\r
+ {\r
+ return GetEnumerator();\r
+ }\r
+\r
+ public override int GetHashCode()\r
+ {\r
+ return ObjectInfo == null\r
+ ? (Uri == null ? DisplayName.GetHashCode() : Uri.GetHashCode())\r
+ : ObjectInfo.GetHashCode();\r
+ }\r
+\r
+ public override bool Equals(object obj)\r
+ {\r
+ if (!(obj is DirectoryRecord))\r
+ return false;\r
+ var other = (DirectoryRecord)obj;\r
+ if (Uri != other.Uri)\r
+ return false;\r
+ if (ObjectInfo== null ^ other.ObjectInfo== null)\r
+ return false;\r
+\r
+ if (ObjectInfo!= null && !ObjectInfo.Equals(other.ObjectInfo))\r
+ return false;\r
+ var thisEnum = GetEnumerator();\r
+ var otherEnum = other.GetEnumerator();\r
+ //Skipt the first item, it is the current node itself\r
+ thisEnum.MoveNext();\r
+ otherEnum.MoveNext();\r
+ while (true)\r
+ {\r
+ var thisMove = thisEnum.MoveNext();\r
+ var otherMove = otherEnum.MoveNext();\r
+\r
+ if (thisMove ^ otherMove)\r
+ return false;\r
+ if (!thisMove)\r
+ return true;\r
+\r
+ if (!thisEnum.Current.Equals(otherEnum.Current))\r
+ return false;\r
+ }\r
+ }\r
+ }\r
+}\r