Ejemplo n.º 1
0
        public StateNode(States parent, StateNode parentNode, KeyValueState <string, string> value, JTokenType type,
                         bool isLeafNode)
            : base(parent)
        {
            _id         = Guid.NewGuid();
            _parentNode = parentNode;
            _value      = value;
            _type       = type;
            _isLeafNode = isLeafNode;
            _childNodes = new List <StateNode>();

            _value.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == "State" && InvalidStates.Contains(_value.State))
                {
                    foreach (var child in _childNodes)
                    {
                        child.Value.State = _value.State;
                    }
                }
            };
        }
        public Model.DataStructures.DownloadItem[] GetFilesAndPathsForItem(Connection connection, List <Tuple <FileFolder, Option <string> > > fileAndFolders, List <File> addedFiles, string vaultRoot, bool allowChildren, int networkRetries)
        {
            List <string> skipFolder = new List <string>();

            VaultEagle.VaultCommunication com = new VaultEagle.VaultCommunication();
            com.InitializeFromConnection(connection);
            //  List<Tuple<File, string, bool, bool>> filesAndPaths = new List<Tuple<File, string, bool, bool>>();
            List <Model.DataStructures.DownloadItem> filesToDownload = new List <Model.DataStructures.DownloadItem>();

            foreach (Tuple <FileFolder, Option <string> > fileAndFolderComponent in fileAndFolders)
            {
                FileFolder fileAndFolder = fileAndFolderComponent.Item1;
                foreach (string fp in SkipFolders)
                {
                    if ((!skipFolder.Contains(fileAndFolder.Folder.FullName)) && (fileAndFolder.Folder.Cat.CatName.Equals(fp)))
                    {
                        skipFolder.Add(fileAndFolder.Folder.FullName);
                    }
                }
                if ((AbhereSynchronizationRules(fileAndFolder, Recursive, allowChildren)) && (!skipFolder.Contains(fileAndFolder.Folder.FullName)))
                {
                    if ((Mirrors.Where(m => fileAndFolder.Folder.FullName.ToLower().Contains(m.ToLower())).Count() > 0) && !(RecursiveMirrors.Where(m => fileAndFolder.Folder.FullName.Equals(m, StringComparison.InvariantCultureIgnoreCase)).Count() == 1))
                    {
                        RecursiveMirrors.Add(fileAndFolder.Folder.FullName);
                        MirrorsToFiles.Add(new Tuple <string, List <File> >(fileAndFolder.Folder.FullName, new List <File>()));
                    }
                    foreach (Tuple <string, List <File> > mirrorItem in MirrorsToFiles)
                    {
                        if (mirrorItem.Item1.Equals(fileAndFolder.Folder.FullName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            mirrorItem.Item2.Add(fileAndFolder.File);
                        }
                    }
                    string localFilePath = GetLocalFolder(fileAndFolder.Folder.FullName + "/" + fileAndFolder.File.Name, vaultRoot);
                    // if (System.IO.Path.
                    string localPath = System.IO.Path.GetDirectoryName(localFilePath);
                    File   file      = null;
                    if ((DownloadOnState.Count > 0) /* && (DownloadOnState.Get().Equals("Released", StringComparison.InvariantCultureIgnoreCase))*/)
                    {
                        File releasedFile = null;
                        VaultEagle.VaultUtils.FileState state = VaultEagle.VaultUtils.GetLastRelevantFileState(fileAndFolder.File.VerNum, fileAndFolder.File.MasterId, connection, ref releasedFile, DownloadOnState, InvalidStates.ToList());
                        if (state == VaultEagle.VaultUtils.FileState.Ok)
                        {
                            file = releasedFile;
                        }
                        else if (state == VaultEagle.VaultUtils.FileState.Obsolete)
                        {
                            DeleteFile(localFilePath, networkRetries);
                            //Delete file?
                        }
                    }
                    else
                    {
                        file = fileAndFolder.File;
                    }
                    if (file == null)
                    {
                        continue;
                    }
                    if (VaultEagle.VaultUtils.HandleNetworkErrors(() => System.IO.File.Exists(localPath + "/" + fileAndFolder.File.Name), networkRetries))
                    {
                        if (file != null)
                        {
                            if (Force || file.Cksum != VaultEagle.VaultUtils.HandleNetworkErrors(() => { return(VaultEagle.VaultCommunication.CalculateCrc32(localPath + "/" + fileAndFolder.File.Name)); }, networkRetries))
                            {
                                if (!addedFiles.Contains(file))
                                {
                                    if (DownloadToTemp)
                                    {
                                        bool run = RunFile(file);
                                        TempFilesAndFinalPath.Add(new Tuple <string, string>(System.IO.Path.Combine(TempPath, file.Name), System.IO.Path.Combine(localPath, file.Name)));
                                        //filesAndPaths.Add(new Tuple<File, string, bool, bool>(PatternsToSynchronize.Count() == 1 && PatternsToSynchronize[0].Equals("/") ? null : file, TempPath, Writable, run));
                                        filesToDownload.Add(GetDownloadItem(TempPath, file, Writable, run, fileAndFolderComponent.Item2));
                                    }
                                    else
                                    {
                                        bool run = RunFile(file);
                                        //filesAndPaths.Add(new Tuple<File, string, bool, bool>(PatternsToSynchronize.Count() == 1 && PatternsToSynchronize[0].Equals("/") ? null : file, localPath, Writable, run));
                                        filesToDownload.Add(GetDownloadItem(localPath, file, Writable, run, fileAndFolderComponent.Item2));
                                    }
                                    addedFiles.Add(file);
                                }
                            }
                        }
                    }
                    else if (file != null)
                    {
                        if (!addedFiles.Contains(file))
                        {
                            if (DownloadToTemp)
                            {
                                bool run = RunFile(file);
                                TempFilesAndFinalPath.Add(new Tuple <string, string>(System.IO.Path.Combine(TempPath, file.Name), System.IO.Path.Combine(localPath, file.Name)));
                                //  filesAndPaths.Add(new Tuple<File, string, bool, bool>(PatternsToSynchronize.Count() == 1 && PatternsToSynchronize[0].Equals("/") ? null : file, TempPath, Writable, run));
                                filesToDownload.Add(GetDownloadItem(TempPath, file, Writable, run, fileAndFolderComponent.Item2));
                            }
                            else
                            {
                                bool run = RunFile(file);
                                //filesAndPaths.Add(new Tuple<File, string, bool, bool>(PatternsToSynchronize.Count() == 1 && PatternsToSynchronize[0].Equals("/") ? null : file, localPath, Writable, run));
                                filesToDownload.Add(GetDownloadItem(localPath, file, Writable, run, fileAndFolderComponent.Item2));
                            }
                            addedFiles.Add(file);
                        }
                    }
                }
                else if (!Recursive && fileAndFolder.Folder.FullName.Equals(VaultPath))
                {
                    filesToDownload.Add(new Model.DataStructures.DownloadFolder(GetLocalFolder(VaultPath, vaultRoot)));
                }
                //filesAndPaths.Add(new Tuple<File, string, bool, bool>(null, GetLocalFolder(VaultPath, vaultRoot), false, false));
            }
            UpdateMirrorToFiles(vaultRoot);
            return(filesToDownload.ToArray());
        }