Esempio n. 1
0
        /// <summary>Create a new Event Reader</summary>
        /// <param name="in"/>
        /// <exception cref="System.IO.IOException"/>
        public EventReader(DataInputStream @in)
        {
            this.@in     = @in;
            this.version = @in.ReadLine();
            if (!EventWriter.Version.Equals(version))
            {
                throw new IOException("Incompatible event log version: " + version);
            }
            Schema myschema = new SpecificData(typeof(Event).GetClassLoader()).GetSchema(typeof(
                                                                                             Event));

            this.schema  = Schema.Parse(@in.ReadLine());
            this.reader  = new SpecificDatumReader(schema, myschema);
            this.decoder = DecoderFactory.Get().JsonDecoder(schema, @in);
        }
        private void HandleInvitation(DataInputStream dataInputStream, model.RtpMidiServer rtpMidiServer)
        {
            int protocolVersion = dataInputStream.ReadInt();

            if (protocolVersion != PROTOCOL_VERSION)
            {
                Log.Info("RtpMidi", "Protocol version: {} did not match version {}", protocolVersion, PROTOCOL_VERSION);
                return;
            }
            int initiatorToken = dataInputStream.ReadInt();
            int ssrc           = dataInputStream.ReadInt();
            //Scanner scanner = new Scanner(dataInputStream).UseDelimiter(NUL_TERMINATOR);
            //if (!scanner.HasNext)
            //{
            //    Log.Info("RtpMidi","Could not find \\0 terminating string");
            //    return;
            //}
            //string name = scanner.Next();
            string name = dataInputStream.ReadLine();

            foreach (IRtpMidiCommandListener listener in listeners)
            {
                listener.OnMidiInvitation(new RtpMidiInvitationRequest(protocolVersion, initiatorToken, ssrc, name), rtpMidiServer);
            }
        }
Esempio n. 3
0
        protected override AbstractDockItem OnAcceptDrop(string uri)
        {
            File         tempFile = FileFactory.NewForPath(System.IO.Path.GetTempFileName());
            FileDockItem bookmark = FileDockItem.NewFromUri(uri);

            // make sure the bookmarked location actually exists
            if (!bookmark.OwnedFile.Exists)
            {
                return(null);
            }

            using (DataInputStream reader = new DataInputStream(BookmarksFile.Read(null))) {
                using (DataOutputStream writer = new DataOutputStream(tempFile.AppendTo(FileCreateFlags.None, null))) {
                    string line;
                    ulong  length;
                    while ((line = reader.ReadLine(out length, null)) != null)
                    {
                        writer.PutString(string.Format("{0}{1}", line, reader.NewLineString()), null);
                    }

                    writer.PutString(string.Format("{0}{1}", bookmark.Uri, reader.NewLineString()), null);
                }
            }

            items.Add(bookmark);
            Items = InnerItems;

            if (tempFile.Exists)
            {
                tempFile.Move(BookmarksFile, FileCopyFlags.Overwrite, null, null);
            }

            return(bookmark);
        }
Esempio n. 4
0
        void DataRead(GLib.Object obj, GLib.AsyncResult res)
        {
            File file = FileAdapter.GetObject(obj);

            Regex keyValueRegex = new Regex(
                @"(^(\s)*(?<Key>([^\=^\n]+))[\s^\n]*\=(\s)*(?<Value>([^\n]+(\n){0,1})))",
                RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled |
                RegexOptions.CultureInvariant
                );

            using (DataInputStream stream = new DataInputStream(file.ReadFinish(res))) {
                ulong  len;
                string line;
                while ((line = stream.ReadLine(out len, null)) != null)
                {
                    line = line.Trim();

                    Match match = keyValueRegex.Match(line);
                    if (match.Success)
                    {
                        string key = match.Groups["Key"].Value;
                        string val = match.Groups["Value"].Value;

                        if (key.Equals(NameTag))
                        {
                            Name = val;
                        }
                        else if (key.Equals(DescTag))
                        {
                            Description = val;
                        }
                        else if (key.Equals(AppUriTag))
                        {
                            AppUri = val;
                        }
                        else if (key.Equals(IconTag))
                        {
                            if (val.StartsWith("./") && val.Length > 2)
                            {
                                IconFile = file.Parent.GetChild(val.Substring(2));
                                if (IconFile.Exists)
                                {
                                    Icon = DockServices.Drawing.LoadIcon(IconFile.Path + ";;extension");
                                }
                            }
                            else
                            {
                                Icon = DockServices.Drawing.LoadIcon(val + ";;extension", 128);
                            }
                        }
                    }
                }
            }
            OnDataReady();
        }
Esempio n. 5
0
        void UpdateItems()
        {
            List <AbstractDockItem> old = items;

            items = new List <AbstractDockItem> ();

            Log <BookmarksItemProvider> .Debug("Updating bookmarks.");

            if (!BookmarksFile.QueryExists(null))
            {
                Log <BookmarksItemProvider> .Error("File '{0} does not exist.", BookmarksFile);

                return;
            }

            using (DataInputStream stream = new DataInputStream(BookmarksFile.Read(null))) {
                ulong  length;
                string line, name, uri;
                while ((line = stream.ReadLine(out length, null)) != null)
                {
                    uri = line.Split(' ').First();
                    File bookmark = FileFactory.NewForUri(uri);
                    name = line.Substring(uri.Length).Trim();
                    if (old.Cast <FileDockItem> ().Any(fdi => fdi.Uri == uri))
                    {
                        FileDockItem item = old.Cast <FileDockItem> ().First(fdi => fdi.Uri == uri);
                        old.Remove(item);
                        items.Add(item);
                        item.ForcedHoverText = name;
                    }
                    else if (bookmark.StringUri().StartsWith("file://") && !bookmark.Exists)
                    {
                        Log <BookmarksItemProvider> .Warn("Bookmark path '{0}' does not exist, please fix the bookmarks file", bookmark.StringUri());

                        continue;
                    }
                    else
                    {
                        FileDockItem item = FileDockItem.NewFromUri(bookmark.StringUri(), name, "folder");
                        if (item != null)
                        {
                            items.Add(item);
                        }
                    }
                }
            }

            Items = InnerItems;

            foreach (AbstractDockItem item in old)
            {
                item.Dispose();
            }
        }
Esempio n. 6
0
 public override void Configure(JobConf jconf)
 {
     conf = jconf;
     try
     {
         Path[] localArchives = DistributedCache.GetLocalCacheArchives(conf);
         Path[] localFiles    = DistributedCache.GetLocalCacheFiles(conf);
         // read the cached files (unzipped, unjarred and text)
         // and put it into a single file TEST_ROOT_DIR/test.txt
         string     TestRootDir = jconf.Get("test.build.data", "/tmp");
         Path       file        = new Path("file:///", TestRootDir);
         FileSystem fs          = FileSystem.GetLocal(conf);
         if (!fs.Mkdirs(file))
         {
             throw new IOException("Mkdirs failed to create " + file.ToString());
         }
         Path fileOut = new Path(file, "test.txt");
         fs.Delete(fileOut, true);
         DataOutputStream @out = fs.Create(fileOut);
         for (int i = 0; i < localArchives.Length; i++)
         {
             // read out the files from these archives
             FilePath        f   = new FilePath(localArchives[i].ToString());
             FilePath        txt = new FilePath(f, "test.txt");
             FileInputStream fin = new FileInputStream(txt);
             DataInputStream din = new DataInputStream(fin);
             string          str = din.ReadLine();
             din.Close();
             @out.WriteBytes(str);
             @out.WriteBytes("\n");
         }
         for (int i_1 = 0; i_1 < localFiles.Length; i_1++)
         {
             // read out the files from these archives
             FilePath        txt = new FilePath(localFiles[i_1].ToString());
             FileInputStream fin = new FileInputStream(txt);
             DataInputStream din = new DataInputStream(fin);
             string          str = din.ReadLine();
             @out.WriteBytes(str);
             @out.WriteBytes("\n");
         }
         @out.Close();
     }
     catch (IOException ie)
     {
         System.Console.Out.WriteLine(StringUtils.StringifyException(ie));
     }
 }
Esempio n. 7
0
        public override bool RemoveItem(AbstractDockItem item)
        {
            if (!ItemCanBeRemoved(item))
            {
                return(false);
            }

            FileDockItem bookmark = item as FileDockItem;

            if (!bookmark.OwnedFile.Exists)
            {
                return(false);
            }

            File tempFile = FileFactory.NewForPath(System.IO.Path.GetTempFileName());

            using (DataInputStream reader = new DataInputStream(BookmarksFile.Read(null))) {
                using (DataOutputStream writer = new DataOutputStream(tempFile.AppendTo(FileCreateFlags.None, null))) {
                    string line;
                    ulong  length;
                    while ((line = reader.ReadLine(out length, null)) != null)
                    {
                        if (line.Split(' ')[0] != bookmark.Uri)
                        {
                            writer.PutString(string.Format("{0}{1}", line, reader.NewLineString()), null);
                        }
                        else
                        {
                            items.Remove(bookmark);
                            Items = InnerItems;
                            Log <BookmarksItemProvider> .Debug("Removing '{0}'", bookmark.HoverText);
                        }
                    }
                }
            }

            if (tempFile.Exists)
            {
                tempFile.Move(BookmarksFile, FileCopyFlags.Overwrite, null, null);
            }

            return(true);
        }