Ejemplo n.º 1
0
        private void checkFileForContainer(cloudinfoContainerFile file, string cloudPath, cloudinfoContainer container)
        {
            String filePath = cloudPath;
            String fileName = file.name.Replace("/", "\\");;

            if (fileName.Contains("\\"))
            {
                String[] files = fileName.Split('\\');
                fileName = files.Last();
                int    totalFolders = files.Length - 1;
                string contName     = "\\";
                for (int i = 0; i < totalFolders; i++)
                {
                    contName = contName + files[i];
                    bool isExists = System.IO.Directory.Exists(filePath + contName);

                    if (!isExists)
                    {
                        System.IO.Directory.CreateDirectory(filePath + contName);
                    }
                    //String[] dirs = Directory.GetDirectories(filePath + contName);
                    allLocalDirs.Remove(files[i]);
                    filePath = filePath + contName;
                    contName = "\\";
                }
            }
            //checkFile and upload or download
            updateFile(file, filePath, container.name, fileName, container);
        }
Ejemplo n.º 2
0
        private void updateFile(cloudinfoContainerFile file, string filePath, string containerName, string fileName, cloudinfoContainer container)
        {
            String[] files = Directory.GetFiles(filePath);

            if (getListOfdirs(files).Contains(fileName))
            {
                //check timestamp
                var fileInfo = new FileInfo(filePath + "\\" + fileName);

                //local.compateTo(cloud)
                //string format = "ddd dd MMM h:mm tt yyyy";
                String[] date     = file.timestamp.Split('+');
                DateTime dateTime = Convert.ToDateTime(date[0]);

                //long t = TimeSpan.TryParse(file.timestamp, format,  out dateTime).Ticks;
                int i = fileInfo.LastWriteTimeUtc.CompareTo(dateTime);

                if (i < 0 && new Common().getFileMD5(filePath + "\\" + fileName) != file.md5 && (file.deleted == "False"))
                {
                    //download the cloud file @filePath + "\\" + file.name
                    downloadAsync da = new downloadAsync();
                    da.download(containerName, file.name, filePath, email, file.size);
                }
                else if (i > 0 && new Common().getFileMD5(filePath + "\\" + fileName) != file.md5)
                {
                    if (file.deleted != "False")
                    {
                        //delete the file in the local
                        File.Delete(filePath + "\\" + fileName);
                    }
                    else
                    {
                        //upload the local file filePath + "\\" + file.name
                        Upload upload = new Upload();
                        upload.DocUplaod(containerName, filePath, fileInfo.Length.ToString(), file.name,
                                         new Common().getFileMD5(filePath + "\\" + fileName),
                                         fileInfo.LastWriteTimeUtc.Ticks.ToString(), new Common().getOldHash(container, fileInfo));
                    }
                    //if (result)
                    {
                        //MessageBox.Show("Uploaded Successfully");
                    }
                }
            }
            else
            {
                if (file.deleted == "False")
                {
                    //download the file
                    downloadAsync da = new downloadAsync();
                    da.download(containerName, file.name, filePath, email, file.size);
                }
            }
        }