Esempio n. 1
0
        public override DataInfo Ping(DataServer ds)
        {
            ds.GetFreeze.WaitOne();

            Console.WriteLine("I'm Alive");
            return ds.DataInfo;
        }
Esempio n. 2
0
        public override void Create(DataServer ds, string fileName)
        {
            ds.GetFreeze.WaitOne();

            File file = new File();
            string[] args = Util.SplitArguments(fileName);

            file.Version = Convert.ToInt64(args[0]);
            file.Content = new byte[1];

            ds.CurrentDir = Environment.CurrentDirectory;
            string path = ds.CurrentDir + @"\" + ds.Name + @"\" + args[1] + @".txt";

            Console.WriteLine("Create: " + path);

            Util.SerializeFile(path, file);
            ds.AddFile(args[1]);

            //add file to datainfo
            ds.DataInfo.AddFile(args[1]);
        }
Esempio n. 3
0
        public override File Read(DataServer ds, string localFile, string semantics)
        {
            ds.GetFreeze.WaitOne();

            File file = new File();
            string path = ds.CurrentDir + @"\" + ds.Name + @"\" + localFile + ".txt";
            Console.WriteLine("Read: " + path);

            if (System.IO.File.Exists(path))
            {
                file = Util.DeserializeFile(path, file);
            }
            else
            {
                throw new FileNotFoundException("File: " + localFile + " not found in server " + ds.Name);
            }
            //add access to this file
            ds.DataInfo.AddAccess(localFile);

            return file;
        }
Esempio n. 4
0
 public override int Write(DataServer ds, string localFile, byte[] bytearray)
 {
     //failure
     return -1;
 }
Esempio n. 5
0
 public override DataInfo Ping(DataServer ds)
 {
     throw new ServerNotAvailableException("The server " + ds.Name + " is not available.");
 }
Esempio n. 6
0
 public override File Read(DataServer ds, string localFile, string semantics)
 {
     return null;
 }
Esempio n. 7
0
 public abstract int Write(DataServer ds, string localFile, byte[] bytearray);
Esempio n. 8
0
 public override void Create(DataServer ds, string fileName)
 {
 }
Esempio n. 9
0
 public abstract File Read(DataServer ds, string localFile, string semantics);
Esempio n. 10
0
 public abstract DataInfo Ping(DataServer ds);
Esempio n. 11
0
 public abstract void Create(DataServer ds, string fileName);
Esempio n. 12
0
        public override int Write(DataServer ds, string localFile, byte[] bytearray)
        {
            ds.GetFreeze.WaitOne();

            string[] content = Util.SplitArguments(Util.ConvertByteArrayToString(bytearray));
            string version = content[0];
            byte[] bytes = Util.ConvertStringToByteArray(content[1]);

            File newFile = new File();
            File oldFile = new File();

            string path = ds.CurrentDir + @"\" + ds.Name + @"\" + localFile + ".txt";
            if (System.IO.File.Exists(path))
            {
                oldFile = Util.DeserializeFile(path, oldFile);
            }

            if (oldFile.Version < Convert.ToInt64(version))
            {
                newFile.Version = Convert.ToInt64(version);
                newFile.Content = bytes;
                ds.CurrentDir = Environment.CurrentDirectory;
                string readPath = ds.CurrentDir + @"\" + ds.Name + @"\" + localFile + @".txt";

                Console.WriteLine("Write: " + readPath);
                Util.SerializeFile(readPath, newFile);
                ds.AddFile(localFile);

                //add access to this file
                ds.DataInfo.AddAccess(localFile);
            }

            //success
            return 0;
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            string[] arguments = Util.SplitArguments(args[0]);
            DataServer ds = new DataServer(arguments[0], arguments[1]);
            Console.Title = "Iurie's Data Server: " + ds.Name;

            // Ficar esperar pedidos de Iurie
            Channel = new TcpChannel(ds.Port);
            ChannelServices.RegisterChannel(Channel, true);
            RemotingServices.Marshal(ds, ds.Name, typeof(DataServer));

            int origWidth = Console.WindowWidth;
            int origHeight = Console.WindowHeight;

            Console.SetWindowSize(origWidth, origHeight / 2);

            Console.ReadLine();
        }