예제 #1
0
파일: Node.cs 프로젝트: GarageInc/all
        public List<bool> Traverse(char symbol, List<bool> data)
        {
            // Лист
            if (Right == null && Left == null)
            {
                if (symbol.Equals(this.Symbol))
                {
                    return data;
                }
                else
                {
                    return null;
                }
            }
            else
            {
                List<bool> left = null;
                List<bool> right = null;

                if (Left != null)
                {
                    List<bool> leftPath = new List<bool>();
                    leftPath.AddRange(data);
                    leftPath.Add(false);

                    left = Left.Traverse(symbol, leftPath);
                }

                if (Right != null)
                {
                    List<bool> rightPath = new List<bool>();
                    rightPath.AddRange(data);
                    rightPath.Add(true);
                    right = Right.Traverse(symbol, rightPath);
                }

                if (left != null)
                {
                    return left;
                }
                else
                {
                    return right;
                }
            }
        }
예제 #2
0
        // Кодирование
        public BitArray Encode(string source)
        {
            List<bool> encodedSource = new List<bool>();

            for (int i = 0; i < source.Length; i++)
            {
                //str += "'"+source[i]+"':[";
                List<bool> encodedSymbol = this.Root.Traverse(source[i], new List<bool>());
                foreach (bool ee in encodedSymbol)
                {
                    str+=ee?"1":"0";
                }
                //str += "] ";
                if(i!=source.Length-1)
                    str += " ";

                encodedSource.AddRange(encodedSymbol);
            }

            BitArray bits = new BitArray(encodedSource.ToArray());

            return bits;
        }
예제 #3
0
        /// <summary>
        /// Tries to save the file according to the info shown in the view. 
        /// 
        /// First it is tried to merge and rename the current file, with the one on the server.
        /// If the file cant be mearged with the file on the server, 
        /// the user is being directed to the merge-view (merge.aspx).
        /// 
        /// Then it is tried to move the current file (if needed).
        /// If the file cant be moved, the move is being droped, 
        /// and the user is sent back to the info.aspx page
        /// </summary>
        protected void SaveChanges(object sender, EventArgs e)
        {
            // Gets all the differences between the new local file, and the old local file.
            FileModifiedChange modification = ModificationManager.CompareFileModifications(_path.Substring(4), VersionSystemFacade.ReadAllText(_path.Substring(3)), FileContent.Value);

            string oldFolderName = _path.Substring(0, _path.LastIndexOf(@"\"));
            bool hasBeenMoved = !oldFolderName.Equals(FolderDropDown.SelectedItem.ToString());
            bool hasBeenRenamed = !_name.Equals(NameTextBox.Text);

            string newName = NameTextBox.Text;

            if (hasBeenRenamed) { modification.Rename(newName); }

            // respond URI is the orignal path (but might be with a new name)
            _responeUri = "info.aspx?path=Pie\\" + newName;

            var vsc = VersionSystemFacade.GetVersionControlSystem(_path.Substring(3));
            Conflict? saveConflict = vsc.Save(modification);
            // If there occurs any conflicts while merging the current file with the server-version,
            // send the user to the merge.aspx page
            if (saveConflict != null)
            {
                Merge.CurrentConflinct = saveConflict;
                Response.Redirect("merge.aspx");
            }

            if (hasBeenMoved)
            {
                string newFolder = FolderDropDown.SelectedItem.ToString().Substring(3) + @"\";
                List<AbstractChange> fileMovedChanges = new List<AbstractChange>();
                ICollection<AbstractChange> moveChanges = MoveFile(_path.Substring(3), (newFolder + newName), FileContent.Value);

                fileMovedChanges.AddRange(moveChanges);

                // Adds the move-changes to the version control system.
                // Sets the respond URI.
                if (vsc.Save(fileMovedChanges).Count > 0)
                {
                    // If there was any errors while moving (returned a not-empty collction),
                    // respond URI is the orignal path (but might be with a new name).
                    _responeUri = "info.aspx?path=Pie\\" + newName;
                }
                else
                {
                    // Else the respond URI is the new path.
                    _responeUri = "info.aspx?path=Pie\\" + newFolder + newName;
                }
            }

            // Redirect to view the info.aspx page, for the current file.
            Response.Redirect(_responeUri);
        }
예제 #4
0
        /// <summary>
        /// Tries to save the folder according to the info shown in the view. 
        /// If the folder can't be renamed or moved the change wont take effect.
        /// And the user is sent back to the info.aspx page
        /// </summary>
        protected void SaveChanges(object sender, EventArgs e)
        {
            string oldFolderName = _path.Substring(0, _path.LastIndexOf(@"\"));
            string newName = NameTextBox.Text;

            bool hasBeenMoved = !oldFolderName.Equals(FolderDropDown.SelectedItem.ToString());
            bool hasBeenRenamed = !_name.Equals(newName);

            var vsc = VersionSystemFacade.GetVersionControlSystem(_path.Substring(4));

            if (hasBeenRenamed)
            {
                FileModifiedChange modification = new FileModifiedChange(VersionSystemFacade.GetPathRelativeToRepository(_absolutPath));
                modification.Rename(newName + "\\");

                if (vsc.Save(modification) != null)
                {
                    base.ShowWarning();
                    Response.Redirect("Info.aspx?path=" + _path);
                }
            }

            // respond URI is the orignal path (but might be with a new name)
            _responeUri = "info.aspx?path=Pie\\" + newName;

            if (hasBeenMoved)
            {
                string newFolder = FolderDropDown.SelectedItem.ToString().Substring(3) + @"\";
                List<AbstractChange> fileMovedChanges = new List<AbstractChange>();
                ICollection<AbstractChange> moveChanges = base.MoveFolder(_path.Substring(3), (newFolder + newName));

                fileMovedChanges.AddRange(moveChanges);

                // Adds the move-changes to the version control system.
                // Sets the respond URI.
                if (vsc.Save(fileMovedChanges).Any())
                {
                    // If there was any errors while moving (returned a not-empty collction),
                    // respond URI is the orignal path (but might be with a new name).
                    _responeUri = "info.aspx?path=Pie\\" + newName;
                }
                else
                {
                    // Else the respond URI is the new path.
                    _responeUri = "info.aspx?path=Pie\\" + newFolder + newName;
                }
            }

            // Redirect to view the info.aspx page, for the current file.
            Response.Redirect(_responeUri);
        }