Ejemplo n.º 1
0
            /// <summary>
            /// move to next element
            /// </summary>
            /// <returns>true if has element</returns>
            public bool MoveNext()
            {
                while (this.files != null)
                {
                    try
                    {
                        if (this.files.MoveNext())
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                        // ok, this enumerator is done
                    }

                    this.files.Dispose();
                    this.files = null;

                    if (this.dirs != null)
                    {
                        try
                        {
                            if (this.dirs.MoveNext())
                            {
                                this.files = SafeEnumerator.GetFileEnumerator(this.dirs.Current, this.pattern);
                                continue;
                            }
                        }
                        catch
                        {
                            // no action
                        }

                        this.dirs.Dispose();
                        this.dirs = null;
                    }
                }

                return(false);
            }
Ejemplo n.º 2
0
        /// <summary>
        /// clean the cluster completely
        /// </summary>
        /// <returns>true if successful</returns>
        public bool TryClusterClean()
        {
            if (!IsEnvironmentOk())
            {
                return(false);
            }

            if (this.IsHostRunning)
            {
                this.Error("Cannot clean cluster while running");
                return(false);
            }

            bool wasSuccessful        = true;
            IEnumerator <string> dirs = SafeEnumerator.GetDirectoryEnumerator(Control.FabricDataRoot, "work");

            while (dirs.MoveNext())
            {
                try
                {
                    Directory.Delete(dirs.Current, true);
                }
                catch (Exception e)
                {
                    wasSuccessful = false;
                    this.Error("delete work folder failed: {0}", e.Message);
                }
            }

            if (Directory.Exists(ClusterSettings.DevImageStoreFolder))
            {
                try
                {
                    Directory.Delete(ClusterSettings.DevImageStoreFolder, true);
                    Directory.CreateDirectory(ClusterSettings.DevImageStoreFolder);
                }
                catch (Exception e)
                {
                    wasSuccessful = false;
                    this.Error("delete image store folder failed: {0}", e.InnerException != null ? e.InnerException.Message : e.Message);
                }
            }
            else
            {
                Directory.CreateDirectory(ClusterSettings.DevImageStoreFolder);
            }

            IEnumerator <string> logFiles = SafeEnumerator.GetFileEnumerator(FabricDataRoot, "ReplicatorShared.log");

            while (logFiles.MoveNext())
            {
                try
                {
                    File.Delete(logFiles.Current);
                }
                catch (Exception e)
                {
                    wasSuccessful = false;
                    this.Error("delete replication log failed: {0}", e.Message);
                }
            }

            if (!wasSuccessful)
            {
                this.Info("failed to clean cluster");
                return(false);
            }

            this.Info("Cluster clean successful");
            return(true);
        }