Пример #1
0
        public void ListFolder(cloudinfo cloudinfo)
        {
            bool isExists = System.IO.Directory.Exists((cloudPath));

            if (!isExists)
            {
                System.IO.Directory.CreateDirectory((cloudPath));
            }

            String[] dirs = Directory.GetDirectories(cloudPath);

            cloudinfoContainer[] itemsField = cloudinfo.Items;

            allLocalDirs = getListOfdirs(dirs);

            foreach (cloudinfoContainer container in itemsField)
            {
                checkContainer(container, dirs);
                if (allLocalDirs.Contains(container.name))
                {
                    allLocalDirs.Remove(container.name);
                }
            }

            foreach (String dir in allLocalDirs)
            {
                String[] files = Directory.GetFiles(cloudPath + "\\" + dir);
                foreach (String file in files)
                {
                    Upload upload   = new Upload();
                    var    fileInfo = new FileInfo(file);
                    upload.DocUplaod(email, cloudPath, fileInfo.Length.ToString(), dir + "\\" + fileInfo.Name, new Common().getFileMD5(file), fileInfo.LastWriteTimeUtc.Ticks.ToString(), new Common().getOldHash(email, fileInfo));
                }
            }
        }
Пример #2
0
        private void OnTimedEvent(Object source, ElapsedEventArgs e)
        {
            watcherUtil.stopWatcher();
            cloudinfo cloudinfo = sf.Listing();

            watcherUtil.startWatcher();
        }
Пример #3
0
        private void listView2_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            ListView.SelectedListViewItemCollection selectedItem = listView2.SelectedItems;
            foreach (ListViewItem item in selectedItem)
            {
                if (!item.Text.Contains("kb"))
                {
                    button3.Enabled = false;
                    cloudinfo cloud = SearchFile.cloud;

                    cloudinfoContainer[] itemsField = cloud.Items;
                    if (!(itemsField == null || itemsField.Length == 0))
                    {
                        foreach (cloudinfoContainer container in itemsField)
                        {
                            if ((container.name.Equals(item.Text)))
                            {
                                if ((container.user != null && container.user.Length != 0))
                                {
                                    publicFlrOptions.Enabled = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        publicFlrOptions.Enabled = false;
                    }
                }
                else
                {
                    button3.Enabled = true;
                }
            }
        }
Пример #4
0
 public void startListing()
 {
     cloudinfo = sf.Listing();
     ListFolder(cloudinfo);
     //Create a timer with a two second interval.
     aTimer = new System.Timers.Timer(300000);
     //Hook up the Elapsed event for the timer.
     aTimer.Elapsed += OnTimedEvent;
     aTimer.Enabled  = true;
 }
Пример #5
0
        private cloudinfoContainer getContainerIfShared(String e)
        {
            cloudinfo cloud = SearchFile.cloud;

            cloudinfoContainer[] itemsField = cloud.Items;


            foreach (cloudinfoContainer container in itemsField)
            {
                if (container.name == e)
                {
                    return(container);
                }
            }
            return(null);
        }
Пример #6
0
        public string getOldHash(string email, FileInfo fileInfo)
        {
            cloudinfo cloud = SearchFile.cloud;

            cloudinfoContainer[] itemsField = cloud.Items;


            foreach (cloudinfoContainer container in itemsField)
            {
                if (container.name == email)
                {
                    return(getOldHash(container, fileInfo));
                }
            }

            return(null);
        }
Пример #7
0
        public cloudinfo Listing()
        {
            allpaths = new ArrayList();
            socket   = connection.connect();
            NetworkStream networkStream = socket.GetStream();
            var           streamReader  = new System.IO.StreamReader(networkStream);
            var           streamWriter  = new System.IO.StreamWriter(networkStream);

            string listing = "LS\n";

            streamWriter.WriteLine(listing);
            //Console.WriteLine("Unable to write to the server");
            streamWriter.Flush();

            string newUserResponse = streamReader.ReadLine();
            string value;

            do
            {
                value           = streamReader.ReadLine();
                newUserResponse = newUserResponse + value;
            } while (!value.Equals("</cloudinfo>"));

            if (newUserResponse == "ERROR")
            {
            }
            else
            {
                cloudinfo     ct         = new cloudinfo();
                XmlSerializer serializer = new XmlSerializer(ct.GetType());
                //StreamReader reader = new StreamReader(newUserResponse);//@"F:\\workspace\\visual studio\\Solution2\\cics525\\Client\\Listing123.xml");
                StringReader rdr          = new StringReader(newUserResponse);
                object       deserialized = serializer.Deserialize(rdr);
                cloud = (cloudinfo)deserialized;//serializer.Deserialize(reader.BaseStream);
                return(cloud);
            }



            return(null);
        }
Пример #8
0
        private void publicFlrOptions_Click(object sender, EventArgs e)
        {
            SharedFolderForm sharedFolder = new SharedFolderForm(this);

            ListView.SelectedListViewItemCollection selectedItem = listView2.SelectedItems;
            foreach (ListViewItem item in selectedItem)
            {
                cloudinfo cloud = SearchFile.cloud;

                cloudinfoContainer[] itemsField = cloud.Items;
                if (!(itemsField == null || itemsField.Length == 0))
                {
                    foreach (cloudinfoContainer container in itemsField)
                    {
                        if ((container.name.Equals(item.Text)) && (container.user != null && container.user.Length != 0))
                        {
                            SharedFolderForm.isCreate = false;
                            sharedFolder.display(container);
                        }
                    }
                }
            }
        }
Пример #9
0
        // Define the event handlers.
        private void OnChanged(object source, FileSystemEventArgs e)
        {
            //getting the lastwrite time to check with lastRead to avoid multiple updates - bugfix
            DateTime lastWriteTime = File.GetLastWriteTime(e.FullPath);

            //checking with the last change
            if (lastWriteTime != lastChange)
            {
                //setting the lastVhange time
                lastChange = lastWriteTime;

                //Getting the changed file info to upload
                var            fileInfo         = new FileInfo(e.FullPath.ToString());
                Regex          regex            = new Regex(@"\bDBLite\\\b");
                Regex          regexForBacklash = new Regex(@"\\\b");
                String[]       nameSplit        = regex.Split(e.FullPath.ToString(), 2);
                FileAttributes attr             = File.GetAttributes(e.FullPath.ToString());
                String[]       fName            = regexForBacklash.Split(nameSplit[1], 2);
                //detect whether its a directory or file
                if (!((attr & FileAttributes.Directory) == FileAttributes.Directory))
                {
                    String fileName;
                    if (nameSplit[1].Contains("\\"))
                    {
                        String   path  = uploadPath;
                        String[] files = nameSplit[1].Split('\\');
                        fileName = files.Last();
                        int totalFolders = files.Length - 1;

                        string contName = "\\";
                        for (int i = 0; i < totalFolders; i++)
                        {
                            contName = contName + files[i];
                            path     = path + contName;
                            contName = "\\";
                        }
                        cloudinfo cloud = SearchFile.cloud;

                        cloudinfoContainer[] itemsField = cloud.Items;
                        if (!(itemsField == null || itemsField.Length == 0))
                        {
                            bool isShared = false;
                            foreach (cloudinfoContainer container in itemsField)
                            {
                                if ((container.name.Equals(files[0])))
                                {
                                    if ((container.user != null && container.user.Length != 0))
                                    {
                                        isShared = true;
                                        //upload the file
                                        if (new Upload().DocUplaod(files[0], path, fileInfo.Length.ToString(), fName[1].Replace('\\', '/'),
                                                                   new Common().getFileMD5(e.FullPath.ToString()),
                                                                   fileInfo.LastWriteTimeUtc.Ticks.ToString(), new Common().getOldHash(container, fileInfo)))
                                        {
                                            //Notifying the change
                                            new Notify().notifyChange(e.FullPath.ToString(), e.ChangeType.ToString());
                                            new Notify().notifyChange(e.FullPath.ToString(), "Upload Successful");
                                        }
                                    }
                                }
                            }
                            if (!isShared)
                            {
                                //upload the file
                                if (new Upload().DocUplaod(email, path, fileInfo.Length.ToString(), nameSplit[1].Replace("\\", "/"),
                                                           new Common().getFileMD5(e.FullPath.ToString()),
                                                           fileInfo.LastWriteTimeUtc.Ticks.ToString(), new Common().getOldHash(email, fileInfo)))
                                {
                                    //Notifying the change
                                    new Notify().notifyChange(e.FullPath.ToString(), e.ChangeType.ToString());
                                    new Notify().notifyChange(e.FullPath.ToString(), "Upload Successful");
                                }
                            }
                        }
                    }


                    else
                    {
                        //upload the file
                        if (new Upload().DocUplaod(email, uploadPath, fileInfo.Length.ToString(), nameSplit[1],
                                                   new Common().getFileMD5(e.FullPath.ToString()),
                                                   fileInfo.LastWriteTimeUtc.Ticks.ToString(), new Common().getOldHash(email, fileInfo)))
                        {
                            //Notifying the change
                            new Notify().notifyChange(e.FullPath.ToString(), e.ChangeType.ToString());
                            new Notify().notifyChange(e.FullPath.ToString(), "Upload Successful");
                        }
                    }
                }
            }
        }