示例#1
0
        public void Dispose_Test()
        {
            IStreamFilter[]   filters = _usefilters;
            PDFIndirectObject indobj  = new PDFIndirectObject(this);
            StreamProxy       proxy   = new StreamProxy(filters, indobj);
            PDFStream         target  = proxy;

            target.Dispose();
            //As the target owns the inner stream it should be disposed.
            Assert.IsNull(proxy.InnerStreamProxy());

            MemoryStream ms         = new MemoryStream();
            bool         ownsStream = false;

            proxy  = new StreamProxy(ms, filters, indobj, ownsStream);
            target = proxy;

            target.Dispose();
            Assert.IsNull(proxy.InnerStreamProxy()); //reference should have gone from the stream

            ms.WriteByte(12);                        //this will fail if the stream has been disposed.

            ms.Dispose();
            indobj.Dispose();
        }
示例#2
0
        public void WriteTo_Test1()
        {
            PDFIndirectObject indobj = new PDFIndirectObject(this);
            PDFStream         target = new StreamProxy(_usefilters, indobj);

            PDFIndirectObject otherobj = new PDFIndirectObject(this);

            PDFStream other = new StreamProxy(_usefilters, otherobj);

            string source = "Hello world";

            target.WriteLine(source);
            target.Flush();


            byte[] expected = target.GetStreamData();
            target.WriteTo(other);
            byte[] actual = other.GetStreamData();

            CompareByteArray(expected, actual);

            target.Dispose();
            other.Dispose();
            indobj.Dispose();
            otherobj.Dispose();
        }
示例#3
0
        public void GetStreamData_Test()
        {
            MemoryStream      ms     = new MemoryStream();
            PDFIndirectObject indobj = new PDFIndirectObject(this);
            PDFStream         target = new StreamProxy(ms, _usefilters, indobj, false);

            byte[] expected = new byte[] {};
            byte[] actual;
            actual = target.GetStreamData();
            Assert.AreEqual(expected.Length, actual.Length);

            expected = new byte[] { 1, 2, 3, 4, 5 };
            target.Write(expected);
            target.Flush();

            actual = target.GetStreamData();

            Assert.AreEqual(expected.Length, actual.Length);

            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], actual[i]);
            }

            target.Dispose();
            ms.Dispose();
            indobj.Dispose();
        }
示例#4
0
        public void PDFStreamConstructor_Test()
        {
            Stream stream = null;

            IStreamFilter[]   filters = _usefilters;
            PDFIndirectObject indobj  = new PDFIndirectObject(this);
            bool ownstream            = false;

            PDFStream target;

            try
            {
                target = new StreamProxy(stream, filters, indobj, ownstream);
                Assert.Fail("No Exception thrown for a null stream");
            }
            catch (ArgumentNullException)
            {
                TestContext.WriteLine("Sucessfully caught a null reference for the stream");
            }

            stream = new MemoryStream();

            target = new StreamProxy(stream, filters, indobj, ownstream);
            Assert.AreEqual(target.IndirectObject, indobj);
            Assert.AreEqual(filters, target.Filters);

            target.Dispose();
            stream.Dispose();
            indobj.Dispose();
        }
示例#5
0
		private readonly static CharPtr[] f_setvbuf_modenames = {"no", "full", "line", null}; //FIXME: ???static const???
		private static int f_setvbuf (lua_State L) {
		  StreamProxy f = tofile(L);
		  int op = luaL_checkoption(L, 2, null, f_setvbuf_modenames);
		  lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);
		  int res = setvbuf(f, null, f_setvbuf_mode[op], (uint)sz);
		  return luaL_fileresult(L, (res == 0) ? 1 : 0, null);
		}
示例#6
0
        private static int io_readline(lua_State L)
        {
            StreamProxy f = (lua_touserdata(L, lua_upvalueindex(1)) as FilePtr).file;
            int         sucess;

            if (f == null)        /* file is already closed? */
            {
                luaL_error(L, "file is already closed");
            }
            sucess = read_line(L, f);
            if (ferror(f) != 0)
            {
                return(luaL_error(L, "%s", strerror(errno)));
            }
            if (sucess != 0)
            {
                return(1);
            }
            else                                                /* EOF */
            {
                if (lua_toboolean(L, lua_upvalueindex(2)) != 0) /* generator created file? */
                {
                    lua_settop(L, 0);
                    lua_pushvalue(L, lua_upvalueindex(1));
                    aux_close(L);        /* close it */
                }
                return(0);
            }
        }
示例#7
0
        private static int read_line(lua_State L, StreamProxy f)
        {
            luaL_Buffer b = new luaL_Buffer();

            luaL_buffinit(L, b);
            for (;;)
            {
                uint    l;
                CharPtr p = luaL_prepbuffer(b);
                if (fgets(p, f) == null)                     /* eof? */
                {
                    luaL_pushresult(b);                      /* close buffer */
                    return((lua_objlen(L, -1) > 0) ? 1 : 0); /* check whether read something */
                }
                l = (uint)strlen(p);
                if (l == 0 || p[l - 1] != '\n')
                {
                    luaL_addsize(b, (int)l);
                }
                else
                {
                    luaL_addsize(b, (int)(l - 1)); /* do not include `eol' */
                    luaL_pushresult(b);            /* close buffer */
                    return(1);                     /* read at least an `eol' */
                }
            }
        }
示例#8
0
        private static int g_read(lua_State L, StreamProxy f, int first)
        {
            int nargs = lua_gettop(L) - 1;
            int success;
            int n;

            clearerr(f);
            if (nargs == 0)          /* no arguments? */
            {
                success = read_line(L, f);
                n       = first + 1; /* to return 1 result */
            }
            else                     /* ensure stack space for all results and for auxlib's buffer */
            {
                luaL_checkstack(L, nargs + LUA_MINSTACK, "too many arguments");
                success = 1;
                for (n = first; (nargs-- != 0) && (success != 0); n++)
                {
                    if (lua_type(L, n) == LUA_TNUMBER)
                    {
                        uint l = (uint)lua_tointeger(L, n);
                        success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
                    }
                    else
                    {
                        CharPtr p = lua_tostring(L, n);
                        luaL_argcheck(L, (p != null) && (p[0] == '*'), n, "invalid option");
                        switch (p[1])
                        {
                        case 'n':            /* number */
                            success = read_number(L, f);
                            break;

                        case 'l':            /* line */
                            success = read_line(L, f);
                            break;

                        case 'a':                         /* file */
                            read_chars(L, f, ~((uint)0)); /* read MAX_uint chars */
                            success = 1;                  /* always success */
                            break;

                        default:
                            return(luaL_argerror(L, n, "invalid format"));
                        }
                    }
                }
            }
            if (ferror(f) != 0)
            {
                return(pushresult(L, 0, null));
            }
            if (success == 0)
            {
                lua_pop(L, 1);          /* remove last result */
                lua_pushnil(L);         /* push nil instead */
            }
            return(n - first);
        }
示例#9
0
        private static int test_eof(lua_State L, StreamProxy f)
        {
            int c = getc(f);

            ungetc(c, f);
            lua_pushlstring(L, null, 0);
            return((c != EOF) ? 1 : 0);
        }
示例#10
0
 private void ReceiveConnection(ISocket socket)
 {
     Socket = socket;
     Socket.ConnectionOpened += (sender, args) => { Closed = false; };
     Socket.ConnectionClosed += (sender, args) => Close();
     _proxy = new StreamProxy(Socket, new BmTcpSocket(new IPEndPoint(IPAddress.Loopback, VNCPort)));
     _proxy.Start();
 }
示例#11
0
 private static void createstdfile(lua_State L, StreamProxy f, int k, CharPtr fname)
 {
     newfile(L).file = f;
     if (k > 0)
     {
         lua_pushvalue(L, -1);
         lua_rawseti(L, LUA_ENVIRONINDEX, k);
     }
     lua_setfield(L, -2, fname);
 }
示例#12
0
        public void LeaveOpen()
        {
            var src  = new MemoryStream(new byte[] { 0, 1, 2, 3, 4, 5 });
            var dest = new StreamProxy(src, true);

            dest.Dispose();
            var bytes = new byte[3];

            Assert.That(src.Read(bytes, 0, 3), Is.EqualTo(3));
        }
示例#13
0
        private static int io_gc(lua_State L)
        {
            StreamProxy f = topfile(L).file;

            /* ignore closed files */
            if (f != null)
            {
                aux_close(L);
            }
            return(0);
        }
示例#14
0
		private static void createstdfile (lua_State L, StreamProxy f, CharPtr k, 
		                                   CharPtr fname) {
		  LStream p = newprefile(L);
		  p.f = f;
          p.closef = io_noclose;
		  if (k != null) {
			lua_pushvalue(L, -1);
			lua_setfield(L, LUA_REGISTRYINDEX, k);  /* add file to registry */
		  }
		  lua_setfield(L, -2, fname);  /* add file to module */
		}
示例#15
0
		private static int read_chars (lua_State L, StreamProxy f, uint n) {
		  uint nr;  /* number of chars actually read */
		  CharPtr p;
		  luaL_Buffer b = new luaL_Buffer();
		  luaL_buffinit(L, b);
		  p = luaL_prepbuffsize(b, n);  /* prepare buffer to read whole block */
		  nr = (uint)fread(p, 1/*sizeof(char)*/, (int)n, f);  /* try to read 'n' chars */ //FIXME:changed
		  luaL_addsize(b, nr);
		  luaL_pushresult(b);  /* close buffer */
		  return (nr > 0)?1:0;  /* true iff read something */
		}
示例#16
0
        private static int io_gc(lua_State L)
        {
            StreamProxy f = tofilep(L).file;       //FIXME:FilePtr p = tofilep(L);

            /* ignore closed files */
            if (f != null)
            {
                aux_close(L);
            }
            return(0);
        }
示例#17
0
        private static int f_setvbuf(lua_State L)
        {
            CharPtr[]   modenames = { "no", "full", "line", null };
            int[]       mode      = { _IONBF, _IOFBF, _IOLBF };
            StreamProxy f         = tofile(L);
            int         op        = luaL_checkoption(L, 2, null, modenames);
            lua_Integer sz        = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);
            int         res       = setvbuf(f, null, mode[op], (uint)sz);

            return(pushresult(L, (res == 0) ? 1 : 0, null));
        }
示例#18
0
		/*
		** {======================================================
		** READ
		** =======================================================
		*/


		private static int read_number (lua_State L, StreamProxy f) {
		  //lua_Number d; //FIXME:???
		  object[] parms = { (object)(double)0.0 }; //FIXME:???
		  if (fscanf(f, LUA_NUMBER_SCAN, parms) == 1) {
			lua_pushnumber(L, (double)parms[0]); //FIXME:d???
			return 1;
		  }
		  else {
		   lua_pushnil(L);  /* "result" to be removed */
		   return 0;  /* read fails */
		  }
        }
示例#19
0
        public void Read()
        {
            var src  = new MemoryStream(new byte[] { 0, 1, 2, 3, 4, 5 });
            var dest = new StreamProxy(src);

            var bytes = new byte[3];

            Assert.That(dest.Read(bytes, 0, 3), Is.EqualTo(3));

            dest.Dispose();
            Assert.That(() => dest.Read(bytes, 0, 3), Throws.TypeOf <NullReferenceException>());
        }
示例#20
0
        /*
        ** {======================================================
        ** READ
        ** =======================================================
        */


        private static int read_number(lua_State L, StreamProxy f)
        {
            //lua_Number d;
            object[] parms = { (object)(double)0.0 };
            if (fscanf(f, LUA_NUMBER_SCAN, parms) == 1)
            {
                lua_pushnumber(L, (double)parms[0]);
                return(1);
            }
            else
            {
                return(0);  /* read fails */
            }
        }
示例#21
0
        private static int io_tostring(lua_State L)
        {
            StreamProxy f = topfile(L).file;

            if (f == null)
            {
                lua_pushliteral(L, "file (closed)");
            }
            else
            {
                lua_pushfstring(L, "file (%p)", f);
            }
            return(1);
        }
示例#22
0
		private const int MAX_SIZE_T = MAX_INT;//(~(size_t)0); //FIXME:changed;

		private static void read_all (lua_State L, StreamProxy f) {
		  uint rlen = LUAL_BUFFERSIZE;  /* how much to read in each cycle */
		  luaL_Buffer b = new luaL_Buffer();
		  luaL_buffinit(L, b);
		  for (;;) {
		    CharPtr p = luaL_prepbuffsize(b, rlen);
		    uint nr = (uint)fread(p, 1/*sizeof(char)*/, (int)rlen, f); //FIXME:changed
		    luaL_addsize(b, nr);
		    if (nr < rlen) break;  /* eof? */
		    else if (rlen <= (MAX_SIZE_T / 4))  /* avoid buffers too large */
		      rlen *= 2;  /* double buffer size at each iteration */
		  }
		  luaL_pushresult(b);  /* close buffer */
		}
示例#23
0
        public void IndirectObject_Test()
        {
            MemoryStream      ms     = new MemoryStream();
            PDFIndirectObject indobj = new PDFIndirectObject(this);
            PDFStream         target = new StreamProxy(ms, _usefilters, indobj, false);

            PDFIndirectObject actual;

            actual = target.IndirectObject;

            Assert.AreEqual(actual, indobj);

            target.Dispose();
            indobj.Dispose();
        }
示例#24
0
		private readonly static CharPtr[] f_seek_modenames = { "set", "cur", "end", null }; //FIXME: ???static const???
		private static int f_seek (lua_State L) {
		  StreamProxy f = tofile(L);
		  int op = luaL_checkoption(L, 2, "cur", f_seek_modenames);
		  lua_Number p3 = luaL_optnumber(L, 3, 0);
		  l_seeknum offset = (l_seeknum)p3;
		  luaL_argcheck(L, (lua_Number)offset == p3, 3,
		                  "not an integer in proper range");
		  op = l_fseek(f, offset, f_seek_mode[op]);
		  if (op != 0)
			return luaL_fileresult(L, 0, null);  /* error */
		  else {
			lua_pushnumber(L, (lua_Number)l_ftell(f));
			return 1;
		  }
		}
示例#25
0
 // This is called by the RDP Function, so stop listening and terminate connections
 internal override void Close()
 {
     if (!Closing && !Closed)
     {
         Logger.Debug("Closing RemoteDesktop ServerProxy");
         Closing = true;
         if (_proxy != null)
         {
             _proxy.Close();
         }
         _proxy  = null;
         Closing = false;
         Closed  = true;
     }
 }
示例#26
0
        public void Write_Test1()
        {
            PDFIndirectObject indobj = new PDFIndirectObject(this);
            PDFStream         target = new StreamProxy(_usefilters, indobj);

            byte[] expected = new byte[] { 1, 2, 3, 4, 5 };
            target.Write(expected);
            target.Flush();
            byte[] actual = target.GetStreamData();

            CompareByteArray(expected, actual);

            target.Dispose();
            indobj.Dispose();
        }
示例#27
0
        public void Type_Test()
        {
            IStreamFilter[]   filters = _usefilters;
            PDFIndirectObject indobj  = new PDFIndirectObject(this);
            PDFStream         target  = new StreamProxy(filters, indobj);
            PDFObjectType     actual;

            actual = target.Type;
            PDFObjectType expected = PDFObjectTypes.Stream;

            Assert.AreEqual(expected, actual);

            target.Dispose();
            indobj.Dispose();
        }
示例#28
0
 internal override void Close()
 {
     if (!Closing && !Closed)
     {
         Logger.Debug("Closing RemoteDesktop Proxy to local service");
         Closing = true;
         if (_proxy != null)
         {
             _proxy.Close();
         }
         Closing = false;
         Closed  = true;
         _proxy  = null;
     }
 }
示例#29
0
        public void PDFStreamConstructor_Test1()
        {
            IStreamFilter[]   filters = _usefilters;
            PDFIndirectObject indobj  = new PDFIndirectObject(this);
            PDFStream         target  = new StreamProxy(filters, indobj);

            Assert.IsNotNull(target);

            StreamProxy proxy = (StreamProxy)target;

            Assert.IsNotNull(proxy.InnerStreamProxy());
            Assert.IsTrue(proxy.OwnsStreamProxy());

            target.Dispose();
            indobj.Dispose();
        }
示例#30
0
        internal int Start(String connectionId)
        {
            // First we need p2p connection
            Socket = GwupeClientAppContext.CurrentAppContext.P2PManager.GetP2PConnection(SecondParty, connectionId);
            // Now we need to create a proxy
            var tcpSocket = new BmTcpSocket(new IPEndPoint(IPAddress.Any, 0));

            tcpSocket.BindListen();
            _proxy = new StreamProxy(tcpSocket, Socket);
            Socket.ConnectionOpened += (sender, args) => { Closed = false; };
            Socket.ConnectionClosed += (sender, args) => Close();
            _proxy.Start();
            Thread.Sleep(5000); // sometimes we connect before the listener has started listening, pause here.
            LocalEndPoint = tcpSocket.LocalEndPoint;
            return(tcpSocket.LocalEndPoint.Port);
        }
示例#31
0
        public MainWindow()
        {
            InitializeComponent();

            NextCommand.InputGestures.Add(new KeyGesture(Key.N, ModifierKeys.Alt));
            PreviousCommand.InputGestures.Add(new KeyGesture(Key.P, ModifierKeys.Alt));
            PlayPauseCommand.InputGestures.Add(new KeyGesture(Key.Space, ModifierKeys.Alt));

            try
            {
                String appData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AppName);
                var appDir = new DirectoryInfo(appData);
                
                if (!appDir.Exists)
                    System.IO.Directory.CreateDirectory(appData);
                
                String logFile = Path.Combine(appData, "ultrasonic.log");

                FileLogger = new FileLogger(logFile, Subsonic.Client.Common.Enums.LoggingLevel.Verbose);
                FileLogger.Log("UltraSonic Started", Subsonic.Client.Common.Enums.LoggingLevel.Basic);
                
                WindowStartupLocation = WindowStartupLocation.Manual;

                FileLogger.Log(string.Format("WindowLeft: {0}", Settings.Default.WindowLeft), Subsonic.Client.Common.Enums.LoggingLevel.Verbose);
                Left = Settings.Default.WindowLeft;

                FileLogger.Log(string.Format("WindowTop: {0}", Settings.Default.WindowTop), Subsonic.Client.Common.Enums.LoggingLevel.Verbose);
                Top = Settings.Default.WindowTop;
                
                FileLogger.Log(string.Format("WindowHeight: {0}", Settings.Default.WindowHeight), Subsonic.Client.Common.Enums.LoggingLevel.Verbose);
                Height = Settings.Default.WindowHeight;

                FileLogger.Log(string.Format("WindowWidth: {0}", Settings.Default.WindowWidth), Subsonic.Client.Common.Enums.LoggingLevel.Verbose);
                Width = Settings.Default.WindowWidth;

                FileLogger.Log(string.Format("WindowMaximized: {0}", Settings.Default.WindowMaximized), Subsonic.Client.Common.Enums.LoggingLevel.Verbose);
                
                if (Settings.Default.WindowMaximized)
                    WindowState = WindowState.Maximized;

                PopulateSettings();
                MusicPlayStatusLabel.Content = "Stopped";
                ArtistTreeView.DataContext = ArtistItems;
                //DataGridDragAndDrop<TrackItem> playlistTrackDragAndDrop = DataGridDragAndDrop<TrackItem>.Create(_playlistTrackItems, PlaylistTrackGrid, this, PlaylistDragPopup);

                //PlaylistTrackGrid.BeginningEdit += playlistTrackDragAndDrop.DataGridOnBeginEdit;
                //PlaylistTrackGrid.CellEditEnding += playlistTrackDragAndDrop.DataGridOnEndEdit;
                //PlaylistTrackGrid.PreviewMouseLeftButtonDown += playlistTrackDragAndDrop.DataGridOnMouseLeftButtonDown;
                //MainGrid.MouseLeftButtonUp += playlistTrackDragAndDrop.DataGridOnMouseLeftButtonUp;
                //MainGrid.MouseMove += playlistTrackDragAndDrop.DataGridOnMouseMove;

                if (StreamProxy == null)
                {
                    FileLogger.Log("Creating StreamProxy", Subsonic.Client.Common.Enums.LoggingLevel.Information);

                    StreamProxy = new StreamProxy();
                    StreamProxy.Start();

                    FileLogger.Log(string.Format("StreamProxy Port: {0}", StreamProxy.GetPort()), Subsonic.Client.Common.Enums.LoggingLevel.Information);
                }

                if (!string.IsNullOrWhiteSpace(Username) && !string.IsNullOrWhiteSpace(Password) && !string.IsNullOrWhiteSpace(ServerUrl))
                {
                    InitSubsonicApi();

                    if (SubsonicClient != null)
                    {
                        License license = SubsonicClient.GetLicense();
                        UpdateLicenseInformation(license);

                        if (!license.Valid)
                        {
                            MessageBox.Show(string.Format("You must have a valid REST API license to use {0}", AppName));
                        }
                        else
                        {
                            UpdateArtists();
                            PopulatePlaylist();
                            PopulatePlaybackList();
                            UpdatePlaylists();
                        }
                    }
                }
                else
                {
                    SettingsTab.IsSelected = true;
                    ServerSettingsExpander.IsExpanded = true;
                    SettingsServerAddressTextBox.Focus();
                }

                _mainTimer.Interval = TimeSpan.FromMilliseconds(500);
                _mainTimer.Tick += (o, s) => Ticktock();
                _mainTimer.Start();

                if (_nowPlayingInterval > 0)
                    UpdateNowPlaying();

                _nowPlayingTimer.Interval = TimeSpan.FromSeconds(_nowPlayingInterval);
                _nowPlayingTimer.Tick += (o, s) => UpdateNowPlaying();
                _nowPlayingTimer.Start();

                if (_chatMessagesInterval > 0)
                    UpdateChatMessages();

                _chatMessagesTimer.Interval = TimeSpan.FromSeconds(_chatMessagesInterval);
                _chatMessagesTimer.Tick += (o, s) => UpdateChatMessages();
                _chatMessagesTimer.Start();

                MediaPlayer.MediaEnded += (o, args) => PlayNextTrack();
                MediaPlayer.Volume = Settings.Default.Volume;
                MediaPlayer.IsMuted = Settings.Default.VolumeMuted;
                VolumeSlider.Value = MediaPlayer.Volume*10;

                AlbumDataGrid.ItemsSource = _albumItems;
                NowPlayingDataGrid.ItemsSource = _nowPlayingItems;
                ChatListView.ItemsSource = _chatMessages;
                PlaylistTrackGrid.ItemsSource = _playlistTrackItems;
                PlaybackTrackGrid.ItemsSource = _playbackTrackItems;
                PlaylistsDataGrid.ItemsSource = _playlistItems;
                TrackDataGrid.ItemsSource = _trackItems;
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Exception:\n\n{0}\n{1}", ex.Message, ex.StackTrace), AppName, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }