Esempio n. 1
0
        public IFileElement GetElement(string path)
        {
            using (var pathEnumerator = new PathEnumerator(path)) {
                pathEnumerator.Reset();

                if (!pathEnumerator.MoveNext())
                {
                    throw new ArgumentException();
                }

                if (pathEnumerator.Current != this.Disk.Index.ToString())
                {
                    throw new ArgumentException();
                }

                var element = this.Root;
                while (pathEnumerator.MoveNext())
                {
                    if (!(element is IFolder))
                    {
                        throw new ArgumentException();
                    }

                    element = (element as IFolder) [pathEnumerator.Current];
                }

                return(element);
            }
        }
Esempio n. 2
0
        public static string ExtractDiskIndex(string path)
        {
            using (var pathEnumerator = new PathEnumerator(path)) {
                pathEnumerator.Reset();

                if (!pathEnumerator.MoveNext())
                {
                    throw new ArgumentException();
                }

                return(pathEnumerator.Current);
            }
        }
        virtual protected void OnDrawGizmos()
        {
            if (!this.IsCurveInputValid)
            {
                return;
            }

            const float radius = 0.1f;

            Gizmos.color = Color.green;
            Gizmos.DrawWireSphere(this.StartPoint.position, radius);
            Gizmos.color = new Color(0.0f, 0.5f, 0.0f, 1.0f);
            Gizmos.DrawWireSphere(this.StartControl.position, radius);
            Gizmos.color = new Color(0.5f, 0.0f, 0.0f, 1.0f);
            Gizmos.DrawWireSphere(this.EndControl.position, radius);
            Gizmos.color = Color.red;
            Gizmos.DrawWireSphere(this.EndPoint.position, radius);

            PathEnumerator points = this.GetPointsEnumerator();

            if (points.MoveNext())
            {
                Gizmos.color  = Color.yellow;
                Gizmos.matrix = this.Transform.localToWorldMatrix;

                Vector3 previous;
                Vector3 current = (Vector3)points.Current;

                while (points.MoveNext())
                {
                    previous = current;
                    current  = (Vector3)points.Current;

                    Gizmos.DrawLine(previous, current);
                }
            }
        }
        /// <summary>Create direcotry</summary>
        /// <exception cref="FileNotFoundException">If <see cref="Path"/> is not found.</exception>
        /// <exception cref="FileSystemExceptionEntryExists">If file or directory already existed at <see cref="Path"/> and <see cref="OperationPolicy.DstThrow"/> is true.</exception>
        protected override void InnerRun()
        {
            // Cannot get entry
            if (!FileSystem.CanGetEntry())
            {
                CreateBlind(); return;
            }

            try
            {
                // Test that directory already exists
                if (FileSystem.CanGetEntry())
                {
                    try
                    {
                        IEntry e = FileSystem.GetEntry(Path, this.Option.OptionIntersection(session.Option));
                        // Directory already exists
                        if (e != null)
                        {
                            // Throw
                            if (EffectivePolicy.HasFlag(OperationPolicy.DstThrow))
                            {
                                // Nothing is done
                                CanRollback = true;
                                if (e.IsDirectory())
                                {
                                    throw new FileSystemExceptionDirectoryExists(FileSystem, Path);
                                }
                                else if (e.IsFile())
                                {
                                    throw new FileSystemExceptionFileExists(FileSystem, Path);
                                }
                                else
                                {
                                    throw new FileSystemExceptionEntryExists(FileSystem, Path);
                                }
                            }
                            // Skip
                            if (EffectivePolicy.HasFlag(OperationPolicy.DstSkip))
                            {
                                CanRollback = true; SetState(OperationState.Skipped); return;
                            }
                            // Delete prev
                            if (EffectivePolicy.HasFlag(OperationPolicy.DstOverwrite))
                            {
                                // Delete File
                                if (e.IsFile())
                                {
                                    CanRollback = false; FileSystem.Delete(Path, recurse: false, this.Option.OptionIntersection(session.Option));
                                }
                                // Skip
                                else if (e.IsDirectory())
                                {
                                    CanRollback = true; SetState(OperationState.Skipped); return;
                                }
                            }
                        }
                    }
                    catch (NotSupportedException) { }
                }

                // Enumerate paths
                PathEnumerator etor = new PathEnumerator(Path, true);
                while (etor.MoveNext())
                {
                    string path = Path.Substring(0, etor.Current.Length + etor.Current.Start);
                    IEntry e    = FileSystem.GetEntry(path, this.Option.OptionIntersection(session.Option));

                    // Entry exists
                    if (e != null)
                    {
                        continue;
                    }

                    FileSystem.CreateDirectory(path, this.Option.OptionIntersection(session.Option));
                    DirectoriesCreated.Add(path);
                }
            }
            catch (NotSupportedException)
            {
                CreateBlind();
            }
        }