コード例 #1
0
        public void noid()
        {
            File.Delete("mocument");
            var s = new SQLiteStore("mocument");
            s.ClearDatabase();
            var x = s.List();
            Assert.AreEqual(0, x.Count);

            var tape = new Tape()
                           {
                               Id = "foo.bar",
                               Comment = "comment",
                               Description = "desc",
                               OpenForRecording = false,
                               AllowedIpAddress = "1.2.2.2"
                           };

            s.Insert(tape);
            x = s.List();
            Assert.AreEqual(1, x.Count);

            s.Delete(tape.Id);
            x = s.List();
            Assert.AreEqual(0, x.Count);
        }
コード例 #2
0
        public void BasicCRUDPersistent()
        {
            var path = Path.GetTempFileName();

            try
            {
                var store = new JsonFileStore(path);
                var tape = new Tape()
                               {
                                   Id = "foo"
                               };
                store.Insert(tape);
                var tape2 = store.Select(tape.Id);
                Assert.IsNotNull(tape2);

                // make sure tapes are cloned
                tape2.Comment = "bar";
                var tape3 = store.Select(tape2.Id);
                Assert.AreNotEqual(tape2.Comment, tape3.Comment);

                // update
                store.Update(tape2);
                tape3 = store.Select(tape2.Id);
                Assert.AreEqual(tape2.Comment, tape3.Comment);

                // delete
                store.Delete(tape3.Id);
                Assert.AreEqual(0, store.List().Count);

            }
            finally
            {
                File.Delete(path);
            }
        }
コード例 #3
0
        public void BasicCRUD()
        {
            var store = new MemoryStore();
                var tape = new Tape()
                {
                    Id = "foo"
                };
                store.Insert(tape);
                var tape2 = store.Select(tape.Id);
                Assert.IsNotNull(tape2);

                // make sure tapes are cloned
                tape2.Comment = "bar";
                var tape3 = store.Select(tape2.Id);
                Assert.AreNotEqual(tape2.Comment, tape3.Comment);

                // update
                store.Update(tape2);
                tape3 = store.Select(tape2.Id);
                Assert.AreEqual(tape2.Comment, tape3.Comment);

                // delete
                store.Delete(tape3.Id);
                Assert.AreEqual(0, store.List().Count);
        }
コード例 #4
0
ファイル: AddTape.aspx.cs プロジェクト: bitpusher/mocument
 protected void AddButton_Click(object sender, EventArgs e)
 {
     var tape = new Tape()
                    {
                        Id = ProxySettings.GetUserId() + "." + NameTextBox.Text,
                        Description = DescTextBox.Text,
                        AllowedIpAddress = IpTextBox.Text,
                        OpenForRecording = LockedCheckBox.Checked
                    };
     var store = new SQLiteStore("mocument");
     store.Insert(tape);
     Response.Redirect("~/tapes/mytapes.aspx");
 }
コード例 #5
0
ファイル: MemoryStore.cs プロジェクト: bitpusher/mocument
 public void Insert(Tape tape)
 {
     lock (_lockObject)
     {
         if (string.IsNullOrEmpty(tape.Id))
         {
     // ReSharper disable NotResolvedInText
             throw new ArgumentNullException("id");
     // ReSharper restore NotResolvedInText
         }
         if (Select(tape.Id) != null)
         {
             throw new Exception("cannot insert duplicate key");
         }
         // hack in lieu of complicated cloning
         _list.Add(JsonConvert.DeserializeObject<Tape>(JsonConvert.SerializeObject(tape, Formatting.Indented)));
     }
 }
コード例 #6
0
        public static Tape Export(IEnumerable<Session> sessions)
        {
            var tape = new Tape();
            tape.log = new Log
                           {
                               version = "1.2",
                               comment = "exported @ " + DateTime.Now.ToString(CultureInfo.InvariantCulture)
                           };
            tape.log.creator = new VersionInfo()
                                   {
                                       name = "mocument",
                                       version = "//#TODO: get executing assembly version",
                                       comment = "http://mocment.it"
                                   };
            // #FIXME - why the truck is tape.log.Entries null? it is instantiated in the ctor of Log?
            tape.log.entries = new List<Entry>();

            foreach (Session session in sessions)
            {
                if (session.state != SessionStates.Done)
                {
                    continue;
                }

                try
                {
                    var entry = Export(session);

                    tape.log.entries.Add(entry);
                }
                    // ReSharper disable EmptyGeneralCatchClause
                catch
                    // ReSharper restore EmptyGeneralCatchClause
                {
                    // #TODO: report?
                    // "Failed to Export Session"
                }
            }

            return tape;
        }
コード例 #7
0
ファイル: MemoryStore.cs プロジェクト: bitpusher/mocument
 public void Update(Tape tape)
 {
     lock (_lockObject)
     {
         if (string.IsNullOrEmpty(tape.Id))
         {
     // ReSharper disable NotResolvedInText
             throw new ArgumentNullException("id");
     // ReSharper restore NotResolvedInText
         }
         Tape existing = _list.FirstOrDefault(t => t.Id == tape.Id);
         if (existing == null)
         {
             throw new Exception("cannot find key");
         }
         _list.Remove(existing);
         // hack in lieu of complicated cloning
         _list.Add(JsonConvert.DeserializeObject<Tape>(JsonConvert.SerializeObject(tape, Formatting.Indented)));
     }
 }
コード例 #8
0
ファイル: SQLiteStore.cs プロジェクト: bitpusher/mocument
        public void Update(Tape tape)
        {
            // there is a bug in the web admin that i am having trouble finding
            // so some hacks are needed here

            using (DbConnection connection = CreateConnection())
            {
                using (DbCommand command = connection.CreateCommand())
                {
                    connection.Open();
                    if (tape.log == null)
                    {
                        // updating only meta from webui -
                        var t = Select(tape.Id);
                        t.AllowedIpAddress = tape.AllowedIpAddress;
                        t.Comment = tape.Comment;
                        t.Description = tape.Description;
                        t.OpenForRecording = tape.OpenForRecording;
                        tape = t;
                    }

                    command.CommandText =
                "UPDATE TAPES SET  Description=@Description,Comment=@Comment,OpenForRecording=@OpenForRecording,AllowedIpAddress=@AllowedIpAddress,JSON=@JSON  WHERE Id=@Id";

                    SetParameter(command, "Description", tape.Description);
                    SetParameter(command, "Comment", tape.Comment);
                    SetParameter(command, "OpenForRecording", tape.OpenForRecording);
                    SetParameter(command, "AllowedIpAddress", tape.AllowedIpAddress);
                    SetParameter(command, "JSON", JsonConvert.SerializeObject(tape, Formatting.Indented));

                    SetParameter(command, "Id", tape.Id);
                    command.ExecuteNonQuery();
                }
            }
        }
コード例 #9
0
ファイル: SQLiteStore.cs プロジェクト: bitpusher/mocument
        public void Insert(Tape tape)
        {
            using (DbConnection connection = CreateConnection())
            {
                using (DbCommand command = connection.CreateCommand())
                {
                    connection.Open();
                    command.CommandText =
                        "insert into tapes (Id,Description,Comment,OpenForRecording,AllowedIpAddress,JSON) values (@Id,@Description,@Comment,@OpenForRecording,@AllowedIpAddress,@JSON)";

                    SetParameter(command, "Id", tape.Id);
                    SetParameter(command, "Description", tape.Description);
                    SetParameter(command, "Comment", tape.Comment);
                    SetParameter(command, "OpenForRecording", tape.OpenForRecording);
                    SetParameter(command, "AllowedIpAddress", tape.AllowedIpAddress);
                    SetParameter(command, "JSON", JsonConvert.SerializeObject(tape, Formatting.Indented));
                    command.ExecuteNonQuery();
                }
            }
        }
コード例 #10
0
 public static List<Session> Import(Tape tape)
 {
     return tape.log.entries.Select(Import)
         .Where(session => session != null)
         .ToList();
 }
コード例 #11
0
ファイル: JsonFileStore.cs プロジェクト: Domer79/CIAPI.CS
        public void Update(Tape tape)
        {
            lock (_lockObject)
            {
                if (string.IsNullOrEmpty(tape.Id))
                {
                    throw new ArgumentNullException("id");
                }
                Tape existing = _list.FirstOrDefault(t => t.Id == tape.Id);
                if (existing == null)
                {
                    throw new Exception("cannot find key");
                }
                _list.Remove(existing);
                // hack in lieu of complicated cloning
                _list.Add(JsonConvert.DeserializeObject<Tape>(JsonConvert.SerializeObject(tape, Formatting.Indented, GetJsonSerializerSettings()), GetJsonSerializerSettings()));

                WriteJson();
            }
        }
コード例 #12
0
ファイル: JsonFileStore.cs プロジェクト: Domer79/CIAPI.CS
 public void Insert(Tape tape)
 {
     lock (_lockObject)
     {
         if (string.IsNullOrEmpty(tape.Id))
         {
             throw new ArgumentNullException("id");
         }
         if (Select(tape.Id) != null)
         {
             throw new Exception("cannot insert duplicate key");
         }
         // hack in lieu of complicated cloning
         _list.Add(JsonConvert.DeserializeObject<Tape>(JsonConvert.SerializeObject(tape, Formatting.Indented, GetJsonSerializerSettings()), GetJsonSerializerSettings()));
         WriteJson();
     }
 }
コード例 #13
0
ファイル: Server.cs プロジェクト: bitpusher/mocument
        private void ProcessEndResponse(Session oS)
        {
            {
                if (RecordCache.ContainsKey(oS))
                {
                    if (oS.state != SessionStates.Done)
                    {
                        // dirty: #TODO: report and discard
                        return;
                    }

                    SessionInfo info;
                    RecordCache.TryRemove(oS, out info);
                    string tapeId = info.UserId + "." + info.TapeId;
                    Tape tape = _store.Select(tapeId);
                    if (tape == null)
                    {
                        tape = new Tape
                                   {
                                       Id = tapeId
                                   };
                        _store.Insert(tape);
                    }
                    Entry entry = HttpArchiveTranscoder.Export(oS);
                    Entry matched = _store.MatchEntry(tapeId, entry);
                    if (matched == null)
                    {
                        tape.log.entries.Add(entry);
                        _store.Update(tape);
                    }
                }
            }
        }
コード例 #14
0
 public void Update(Tape tape)
 {
     _store.Update(tape);
 }
コード例 #15
0
 public void Insert(Tape tape)
 {
     _store.Insert(tape);
 }
コード例 #16
0
 public void Delete(Tape tape)
 {
     _store.Delete(tape.Id);
 }