Ejemplo n.º 1
0
        public void GetFileFailTest()
        {
            doTransaction();
            server.commit();

            FBVersion vers = new FBVersion();
            FBFile    file = (FBFile)(new FBFileBuilder(@"asd\due.txt")).generate();

            file.hash = "asdsdaasd";
            vers.addElement(file);
            SerializedVersion serV = new SerializedVersion(vers.serialize());
            var uploadData         = server.getFile(serV);

            Assert.IsNull(uploadData);
        }
Ejemplo n.º 2
0
        public void GetFileTest()
        {
            doTransaction();
            server.commit();

            FBVersion vers = new FBVersion();
            FBFile    file = (FBFile)(new FBFileBuilder(@"asd\due.txt")).generate();

            vers.addElement(file);
            SerializedVersion serV = new SerializedVersion(vers.serialize());
            var uploadData         = server.getFile(serV);

            UsefullMethods.ReceiveFile(uploadData.ip, uploadData.port, uploadData.token, @"asd\test.txt");
            String content = File.ReadAllText(@"asd\test.txt");

            Assert.IsTrue(content.Contains("Third lines"));
        }
Ejemplo n.º 3
0
        public string getFile(FBFile f)
        {
            SerializedVersion serV   = new SerializedVersion();
            FBVersion         tmpVer = new FBVersion();

            tmpVer.addElement(f);
            serV.encodedVersion = tmpVer.serialize();
            var    uploadData = server.getFile(serV);
            string tmpPath    = Path.GetTempPath() + f.Name;

            if (File.Exists(tmpPath))
            {
                File.Delete(tmpPath);
            }
            UsefullMethods.ReceiveFile(uploadData.ip, uploadData.port, uploadData.token, tmpPath);
            return(tmpPath);
        }
Ejemplo n.º 4
0
        public void resetToVersion(FBVersion v)
        {
            this.sync();
            SerializedVersion serV = new SerializedVersion();

            serV.encodedVersion = v.serialize();
            UploadData ud = null;

            try
            {
                ud = server.resetToCraftedVersion(serV);
                resetVersion(ud, v);
            }
            catch (System.ServiceModel.CommunicationException e)
            {
                MessageBox.Show("There is a problem with connection, please retry to login!", "Error in connection");
            }
        }
Ejemplo n.º 5
0
        public SerializedVersion getCurrentVersion()
        {
            this.checkAuthentication();

            this.checkTransactionIsNotEnabled();

            try
            {
                FBVersion         version    = currentVersion();
                SerializedVersion serVersion = new SerializedVersion(version.serialize());

                return(serVersion);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw new FaultException <ServiceErrorMessage>(new ServiceErrorMessage(ServiceErrorMessage.ROOTDIRECTORYNOTFOUND));
            }
        }
Ejemplo n.º 6
0
        private void sync()
        {
            String dirPath = conf.targetPath.get();

            if (dirPath == null || !Directory.Exists(dirPath))
            {
                throw new DirectoryNotFoundException("Directory in configuration is not valid");
            }
            try
            {
                cv = (FBVersion)vb.generate();
            }catch (Exception e)
            {
                MessageBox.Show(e.Message + "\nThe application will be closed", "Unexpected error");
                Environment.Exit(0);
            }
            SerializedVersion serV = new SerializedVersion();

            serV.encodedVersion = cv.serialize();
            threadCallback.Invoke(TypeThread.SYNC, StatusCode.WORKING, "Start syncing");
            FileStream fs = null;

            try {
                if (server.newTransaction(serV))
                {
                    this.status = "Syncing";
                    byte[][]      bfiles     = server.getFilesToUpload();
                    List <FBFile> fileToSync = new List <FBFile>();
                    foreach (byte[] bf in bfiles)
                    {
                        fileToSync.Add(FBFile.deserialize(bf));
                    }

                    int i = 0;

                    foreach (FBFile f in fileToSync)
                    {
                        if (!this.stopSync)
                        {
                            threadCallback.Invoke(TypeThread.SYNC, StatusCode.WORKING, "Syncing file " + i + " of " + fileToSync.Count);
                            i++;
                            FBFileClient cf        = FBFileClient.generate(f);
                            UploadData   cedential = server.uploadFile();
                            UsefullMethods.SendFile(cedential.ip, cedential.port, cedential.token, new FileStream(cf.FullName, FileMode.Open));
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (!this.stopSync)
                    {
                        server.commit();
                        threadCallback.Invoke(TypeThread.SYNC, StatusCode.SUCCESS, "Sync completed");
                    }
                    else
                    {
                        threadCallback.Invoke(TypeThread.SYNC, StatusCode.ABORTED, "Syncing Stopped");
                        server.rollback();
                    }
                    this.status = "Idle";
                }
                else
                {
                    threadCallback.Invoke(TypeThread.SYNC, StatusCode.IDLE, "Nothing to be done");
                }
            }
            catch (System.ServiceModel.CommunicationException e)
            {
                MessageBox.Show("There is a problem with connection, please retry to login!", "Error in connection");
                threadCallback.Invoke(TypeThread.SYNC, StatusCode.ABORTED, "Connection error");
            }
            catch
            {
                server.rollback();
            }
        }