Example #1
0
 public static List<Book> GetTestBooks()
 {
     List<Book> temp = new List<Book>();
     temp.Add(new Book(1, "Sota ja rauha", "Leo Tolstoi", "Venäjä", 1867));
     temp.Add(new Book(2, "Anna Karenina", "Leo Tolstoi", "Venäjä", 1877));
     return temp;
 }
Example #2
0
        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);

            var installdir = GetParameter("targetdir");

            string msg = "";
            foreach (var k in Context.Parameters.Keys)
                msg += (k + "\n");
            msg += "VALUES:\n";
            foreach (var v in Context.Parameters.Values)
                msg += (v + "\n");
            //MessageBox.Show(msg);

            List<string> writeableDirs = new List<string>();

            string configDir = Path.Combine(Path.Combine(installdir, "Myro"), "config");
            string storeDir = Path.Combine(Path.Combine(installdir, "Myro"), "store");

            writeableDirs.Add(configDir);
            writeableDirs.Add(storeDir);
            writeableDirs.AddRange(Directory.GetDirectories(configDir, "*", SearchOption.AllDirectories));
            writeableDirs.AddRange(Directory.GetDirectories(storeDir, "*", SearchOption.AllDirectories));

            string dirs = "";
            foreach (var d in writeableDirs)
            {
                dirs += (d + "\n");
                if (GrantModifyAccessToFolder("Everyone", d) != true)
                    throw new Exception("Couldn't make " + d + " writeable");
            }

            //MessageBox.Show("Made writeable:\n" + dirs);
        }
Example #3
0
        public static void AddBytes(List<byte> list, int value)
        {
            byte b0 = (byte)value;
            byte b1 = (byte)(value >> 8);

            list.Add(b0);
            list.Add(b1);
        }
Example #4
0
        public static void AddBytes32(List<byte> list, int value)
        {
            byte[] byteArray = BitConverter.GetBytes(value);

            list.Add(byteArray[0]);
            list.Add(byteArray[1]);
            list.Add(byteArray[2]);
            list.Add(byteArray[3]);
        }
        public ProfileWindow(ProfileItem profileItem, OutoposManager outoposManager, BufferManager bufferManager)
        {
            _profileItem = profileItem;
            _outoposManager = outoposManager;
            _bufferManager = bufferManager;

            var digitalSignatureCollection = new List<object>();
            digitalSignatureCollection.Add(new ComboBoxItem() { Content = "" });
            digitalSignatureCollection.AddRange(Settings.Instance.Global_DigitalSignatureCollection.Select(n => new DigitalSignatureComboBoxItem(n)).ToArray());

            InitializeComponent();

            _wikiTextBox.MaxLength = Wiki.MaxNameLength;
            _chatTextBox.MaxLength = Chat.MaxNameLength;

            lock (_profileItem.ThisLock)
            {
                _uploadSignature = _profileItem.UploadSignature;
                _signatureCollection.AddRange(_profileItem.TrustSignatures);
                _wikiCollection.AddRange(_profileItem.Wikis);
                _chatCollection.AddRange(_profileItem.Chats);
            }

            _signatureListView.ItemsSource = _signatureCollection;
            _wikiListView.ItemsSource = _wikiCollection;
            _chatListView.ItemsSource = _chatCollection;

            _signatureComboBox.ItemsSource = digitalSignatureCollection;

            this.Sort();
        }
Example #6
0
        public static List<byte> ConvertBoolsToBytes(bool[] data)
        {
            List<byte> result = new List<byte>();
            //wrap into 8 bit bunches of a byte

            byte eightBits = 0;
            int counter = 0;
            foreach (bool b in data)
            {
                //write to next location on eightBits

                if (b)
                {
                    eightBits |= Writer.Masks[counter];
                }

                counter++;

                if (counter > 7)
                {
                    counter = 0;
                    result.Add(eightBits);
                    eightBits = 0;
                }
            }

            if (counter > 0)
            {
                //pad out the eightBits with zeros then add
                result.Add(eightBits);
            }

            return result;
        }
 private void btnBrowse_Click(object sender, EventArgs e)
 {
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         btnUpload.Enabled = true;
         lblError.Text = "";
         #region dataGridView stuff
         List<String> files = openFileDialog1.SafeFileNames.ToList();
         List<Library.File> myFiles = new List<Library.File>();
         foreach (string f in files)
         {
             Library.File file = new Library.File(f, "", Project);
             myFiles.Add(file);
         }
         dataGridView1.DataSource = myFiles;
         dataGridView1.Columns.Remove("id");
         dataGridView1.Columns.Remove("VersionNr");
         dataGridView1.Columns.Remove("FileLock");
         dataGridView1.Columns.Remove("FileLockTime");
         dataGridView1.Columns.Remove("Project");
         dataGridView1.AutoResizeColumns();
         #endregion
         foreach (string filepath in openFileDialog1.FileNames)
         {
             fullFilePathList.Add(filepath);
             fileToUploadList.Add(Path.GetFileName(filepath));
         }
     }
 }
        public List<PortInfo> GetPortInfo()
        {
            List<PortInfo> portInfo = new List<PortInfo>();

            string ip = Convert.ToString(Net.GetExternalIpAddress(30000));
            foreach (INetFwOpenPort port in GetAuthOpenPortsList())
            {
                portInfo.Add(new PortInfo()
                {
                    IP = ip,
                    Port = port.Port,
                    Name = port.Name
                });
                //sb.AppendLine(ip + ":" + port.Port + " - " + port.Name + " - " + port.Enabled + " - " + port.IpVersion);
                Console.WriteLine(port.Port + ", " + port.Name);
            }
            /*StringBuilder sb = new StringBuilder();
            foreach (INetFwOpenPort port in GetAuthOpenPortsList())
            {
                
                sb.AppendLine(ip + ":" + port.Port + " - " + port.Name + " - " + port.Enabled + " - " + port.IpVersion);
                Console.WriteLine(port.Port + ", " + port.Name);
            }
            System.Windows.Forms.MessageBox.Show(sb.ToString());*/
            return portInfo;
        }
Example #9
0
 public static void AddBytes(List<byte> list, byte[] array)
 {
     foreach (byte b in array)
     {
         list.Add(b);
     }
 }
Example #10
0
        public Setup()
        {
            LoadPlugins();
            AllTitlesProcessed = false;
            CurrentTitle = null;
            CurrentTitleIndex = 0;
            current = this;
            //_titleCollection.loadTitleCollection();
            _ImporterSelection = new Choice();
            List<string> _Importers = new List<string>();
            foreach (OMLPlugin _plugin in availablePlugins) {
                OMLApplication.DebugLine("[Setup] Adding " + _plugin.Name + " to the list of Importers");
                _Importers.Add(_plugin.Description);
            }

            _ImporterSelection.Options = _Importers;
            _ImporterSelection.ChosenChanged += delegate(object sender, EventArgs e)
            {
                OMLApplication.ExecuteSafe(delegate
                {
                    Choice c = (Choice)sender;
                    ImporterDescription = @"Notice: " + GetPlugin().SetupDescription();
                    OMLApplication.DebugLine("Item Chosed: " + c.Options[c.ChosenIndex]);
                });
            };
        }
        public override string ReadLine()
        {
            if (stream.Position == stream.Length)
            {
                return null;
            }

            var byteList = new List<int>();
            while (stream.Position != stream.Length)
            {
                int b = stream.ReadByte();
                if (b == (int)'\n')
                {
                    break;
                }
                else
                {
                    byteList.Add(b);
                }
            }
            while (byteList[byteList.Count - 1] == (int)'\r')
            {
                byteList.RemoveAt(byteList.Count - 1);
            }
            return Encoding.UTF8.GetString(byteList.Select(value => (byte)value).ToArray());
        }
Example #12
0
        private void buttonReLoan_Click(object sender, EventArgs e)
        {
            LibraryReader.LibraryEntities context = new LibraryReader.LibraryEntities();

            List<int> books = new List<int>();

            foreach (DataGridViewRow row in dataGridViewLoaned.SelectedRows)
            {
                if (row.Cells[0].Value != null)
                {
                    books.Add(Convert.ToInt32(row.Cells[0].Value));
                }
            }

            if (books.Count > 0)
            {

                var client = (from c in context.Clients
                              where c.ClientID == id
                              select c).SingleOrDefault();

                foreach (LibraryReader.ClientsBook cBook in client.ClientsBooks)
                {
                    if (books.Contains(cBook.BookID))
                    {
                        cBook.DateLoaned = DateTime.Now;
                        cBook.DateReturned = DateTime.Now.AddMonths(1);
                        MessageBox.Show("Презаписването е успешно!");
                    }
                }

                context.SaveChanges();
            }
        }
Example #13
0
        private void buttonReserve_Click(object sender, EventArgs e)
        {
            LibraryReader.LibraryEntities context = new LibraryReader.LibraryEntities();

            List<int> books = new List<int>();

            foreach (DataGridViewRow row in dataGridViewBooks.SelectedRows)
            {
                if (row.Cells[0].Value != null)
                {
                    books.Add(Convert.ToInt32(row.Cells[0].Value));
                }
            }

            if (books.Count > 0)
            {

                var client = (from c in context.Clients
                              where c.ClientID == id
                              select c).SingleOrDefault();

                foreach (LibraryReader.ClientsBook cBook in client.ClientsBooks)
                {
                    if (books.Contains(cBook.BookID))
                    {
                        cBook.Reservation = true;
                        MessageBox.Show("Резервирането е успешно!");
                    }
                }

                context.SaveChanges();
            }
        }
        /// <summary>兄弟ノードを取得する。
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public static TreeNode[] GetBrotherNodes(this TreeNode node)
        {
            var broNodes = new List<TreeNode>();

            for (var iNode = node.PrevNode; iNode != null; iNode = iNode.PrevNode)
            {
                broNodes.Add(iNode);
            }

            broNodes.Reverse();

            for (var iNode = node.NextNode; iNode != null; iNode = iNode.NextNode)
            {
                broNodes.Add(iNode);
            }

            return broNodes.ToArray();
        }
Example #15
0
 public static List<ProcessInfo> GetProcesses()
 {
     //var result = new StringBuilder();
     var result = new List<ProcessInfo>();
     var processList = Process.GetProcesses();
     foreach (Process p in processList)
     {
         result.Add(new ProcessInfo() { Name = p.ProcessName, PID = p.Id });
         //result.AppendLine("Name: " + p.ProcessName + ", PID: " + p.Id);// + ", Start Time: " + p.StartTime + ", CPU Time: " + p.TotalProcessorTime + ", Threads: " + p.Threads);
     }
     //return result.ToString();
     return result;
 }
Example #16
0
        public List<Book> GetBooksByTitle(string title)
        {
            List<Book> result = new List<Book>();
            foreach (Book book in Books)
            {
                if (book.Title == title)
                {
                    result.Add(book);
                }
            }

            return result;
        }
Example #17
0
        public List<Book> GetBooksByAuthor(string author)
        {
            List<Book> result = new List<Book>();
            foreach (Book book in books)
            {
                if (book.Author == author)
                {
                    result.Add(book);
                }
            }

            return result;
        }
        public BoxEditWindow(IEnumerable<Box> boxes)
        {
            _boxes = boxes.ToList();

            var digitalSignatureCollection = new List<object>();
            digitalSignatureCollection.Add(new ComboBoxItem() { Content = "" });
            digitalSignatureCollection.AddRange(Settings.Instance.Global_DigitalSignatureCollection.Select(n => new DigitalSignatureComboBoxItem(n)).ToArray());

            InitializeComponent();

            _nameTextBox.MaxLength = Box.MaxNameLength;
            _commentTextBox.MaxLength = Box.MaxCommentLength;

            {
                var icon = new BitmapImage();

                icon.BeginInit();
                icon.StreamSource = new FileStream(Path.Combine(App.DirectoryPaths["Icons"], "Amoeba.ico"), FileMode.Open, FileAccess.Read, FileShare.Read);
                icon.EndInit();
                if (icon.CanFreeze) icon.Freeze();

                this.Icon = icon;
            }

            lock (_boxes[0].ThisLock)
            {
                _nameTextBox.Text = _boxes[0].Name;

                if (_boxes.Count != 1)
                {
                    foreach (var box in _boxes)
                    {
                        if (_nameTextBox.Text != box.Name)
                        {
                            _nameTextBox.Text = "";
                            _nameTextBox.IsReadOnly = true;

                            break;
                        }
                    }
                }

                _commentTextBox.Text = _boxes[0].Comment;
            }

            _signatureComboBox.ItemsSource = digitalSignatureCollection;
            if (digitalSignatureCollection.Count > 0) _signatureComboBox.SelectedIndex = 1;

            _nameTextBox.TextChanged += _nameTextBox_TextChanged;
            _nameTextBox_TextChanged(null, null);
        }
 private List<string> GenerateReport()
 {
     if (!Files.Any()) return null;
     var fileHelper = new FileHelper();
     var days = Files.Select(fileHelper.GetEntries).ToList();
     var lines = new List<string>();
     var runningTotal = new TimeSpan(0, 0, 0, 0);
     foreach (var d in days)
     {
         lines.AddRange(d.Select(entry => entry.ToString()));
         var hours = d.Sum(te => te.Hours);
         var minutes = d.Sum(te => te.Minutes);
         var seconds = d.Sum(te => te.Seconds);
         var ts = new TimeSpan(0, hours, minutes, seconds);
         runningTotal = runningTotal.Add(ts);
         lines.Add(string.Format("---- Total Time For Day ---- {0}:{1:D2}:{2:D2} ---------------", ts.Hours, ts.Minutes,
             ts.Seconds));
     }
     lines.Add(string.Format("---- Total Time For All Days Selected ---- {0}:{1:D2}:{2:D2} ---------------",
         (runningTotal.Days * 24 + runningTotal.Hours), runningTotal.Minutes,
         runningTotal.Seconds));
     return lines;
 }
Example #20
0
        public static List<string> ParseBaoMoi(string content)
        {
            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(content);

            HtmlNodeCollection nc = doc.DocumentNode.SelectNodes("//*[@rel='tag']");

            List<string> result = new List<string>();

            foreach (HtmlNode n in nc)
            {
                result.Add(n.InnerHtml);
            }
            return result;
        }
Example #21
0
        internal static List<Patron> getAll(SqliteConnection conn)
        {
            List<Patron> plist = new List<Patron>();

            SqliteCommand cmd = new SqliteCommand("select id, name, type from patron order by name", conn);
            SqliteDataReader rdr = cmd.ExecuteReader();
            while (rdr.NextResult())
            {
                OurPatron p = new OurPatron(conn, rdr.GetInt32(0));
                p.name = rdr.GetString(1);
                p.type = (PatronType)rdr.GetInt32(2);
                plist.Add(p);
            }

            return plist;
        }
        private static List<FileItem> GetFiles(DirectoryInfo directory)
        {
            List<FileItem> files = new List<FileItem>();

            foreach (FileInfo file in directory.GetFiles())
            {
                files.Add(new FileItem(file));
            }

            foreach (DirectoryInfo dir in directory.GetDirectories())
            {
                files.AddRange(GetFiles(dir));
            }

            return files;
        }
Example #23
0
 public void FilterPlatRequestUpLog(DataTable dataTable_0, string string_0, string string_1)
 {
     List<DataRow> list = new List<DataRow>();
     foreach (DataRow row in dataTable_0.Rows)
     {
         if (row["msgType"].ToString() == "4353")
         {
             if ((row["OBJECT_TYPE"].ToString() == "1") && (string_1 != "1"))
             {
                 list.Add(row);
             }
             else if ((row["OBJECT_TYPE"].ToString() == "2") && (row["OBJECT_ID"].ToString() != string_0))
             {
                 list.Add(row);
             }
             else if ((row["OBJECT_TYPE"].ToString() == "3") && (string.IsNullOrEmpty(string_0) || (string_1 == "1")))
             {
                 list.Add(row);
             }
         }
         if (row["msgType"].ToString() == "4911")
         {
             if (((((row["OBJECT_TYPE"].ToString() == "0") || (row["OBJECT_TYPE"].ToString() == "1")) || ((row["OBJECT_TYPE"].ToString() == "4") || (row["OBJECT_TYPE"].ToString() == "4"))) || (((row["OBJECT_TYPE"].ToString() == "7") || (row["OBJECT_TYPE"].ToString() == "8")) || (row["OBJECT_TYPE"].ToString() == "9"))) && (string_1 != "1"))
             {
                 list.Add(row);
             }
             else if ((row["OBJECT_TYPE"].ToString() == "2") && (row["OBJECT_ID"].ToString() != string_0))
             {
                 list.Add(row);
             }
             else if ((row["OBJECT_TYPE"].ToString() == "3") && (string.IsNullOrEmpty(string_0) || (string_1 == "1")))
             {
                 list.Add(row);
             }
             else if (((row["OBJECT_TYPE"].ToString() == "5") && string.IsNullOrEmpty(string_0)) && (string_1 != "1"))
             {
                 list.Add(row);
             }
         }
         if ((row["msgType"].ToString() == "4355") && (string_1 != "1"))
         {
             list.Add(row);
         }
     }
     for (int i = 0; i < list.Count; i++)
     {
         dataTable_0.Rows.Remove(list[i]);
     }
 }
        public List<string> ReadReadables()
        {
            using (StreamReader reader = new StreamReader(@"..\..\Database\Books\Readables.txt"))
            {
                string line = string.Empty;
                List<string> allLines = new List<string>();

                StringBuilder result = new StringBuilder();

                while ((line = reader.ReadLine()) != null)
                {
                    allLines.Add(line);
                }

                return allLines;
            }
        }
Example #25
0
        public static AuthResult Authorize(AuthData data)
        {
            Keys keys = GetKeys();
            if (keys != null && keys.Public.Equals(data.PublicKey))
            {
                var privateKey = keys.Private;
                var hashCheck = General.Sha1Hash(data.Data + privateKey + data.PublicKey);
                if (hashCheck.Equals(data.Hash))
                {
                    var newToken = General.Sha1Hash(privateKey + hashCheck + GetDateTimeFormatted());
                    var computersJsonFile = GetFile("~/App_Data/", "computers.json");
                    var computers = new List<ComputerData>();
                    try
                    {
                        computers = JsonConvert.DeserializeObject<List<ComputerData>>(GetFileContents(computersJsonFile));
                    }
                    catch { }

                    var computerData = new ComputerData()
                    {
                        Name = data.HostName,
                        IpExternal = data.IpExternal,
                        IpInternal = data.IpInternal,
                        LastActive = DateTime.Now,
                        FileUploaded = null,
                        BytesUploaded = 0,
                        Hash = null
                    };
                    computerData.Hash = Transmitter.GetComputerHash(computerData);
                    if (computers.Where(c => c.Hash == computerData.Hash).FirstOrDefault() == null)
                    {
                        computers.Add(computerData);
                    }

                    var computersJson = JsonConvert.SerializeObject(computers);
                    File.WriteAllText(computersJsonFile, computersJson);

                    return new AuthResult()
                    {
                        Token = newToken,
                        IpExternal = data.IpExternal
                    };
                }
            }
            return null;
        }
        public IList<string> GrabBackDropUrls(XPathNavigator nav)
        {
            List<string> urls = new List<string>();
            XPathNodeIterator nIter = nav.SelectChildren("backdrop", "");
            if (nav.MoveToFollowing("backdrop", ""))
            {
                XPathNavigator localNav = nav.CreateNavigator();
                nav.MoveToParent();
                for (int i = 0; i < nIter.Count; i++)
                {
                    if (localNav.GetAttribute("size", "").ToUpperInvariant().Equals("original".ToUpperInvariant()))
                        urls.Add(localNav.Value);

                    localNav.MoveToNext();
                }
            }
            return urls;
        }
        /// <summary>
        /// Returns the top 20 messages
        /// </summary>
        /// <returns>top 20 messages to file</returns>
        public List<ChatMessage> GetTop20ChatMessages(int fileId)
        {
            List<ChatMessage> messages = new List<ChatMessage>();
            var list =
                (from filechat in dbContext.FileChats
                where filechat.file.Id == fileId
                orderby filechat.chatMessage.Id
                 select filechat.chatMessage.Id).Take(20);
            foreach (int messageId in list)
            {
                messages.Add(GetChatMessage(messageId));
            }
            return messages;

            //var messages = (from chatMessage in dbContext.ChatMessages
            //                orderby chatMessage.Id
            //                select chatMessage).Take(20);
            //return messages.ToList();
        }
        private List<int> AddFiles()
        {
            List<string> filenames = new List<string>();
            List<string> filedescs = new List<string>();
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                filenames.Add(dataGridView1.Rows[i].Cells[0].Value.ToString());
                filedescs.Add(dataGridView1.Rows[i].Cells[1].Value.ToString());
            }
            AddMultiFilesMessage amfm = new AddMultiFilesMessage();
            amfm.filenames = filenames.ToArray<string>();
            amfm.filedescs = filedescs.ToArray<string>();
            amfm.project = Project;
            AddMultiFilesReturn idlist = client.AddMultiFiles(amfm);

            btnUpload.Enabled = false;
            lblError.Text = "Upload done";
            return idlist.ids.ToList();
        }
        public ICollection<IReadable> SearchReadableItem(string keyword)
        {
            if (keyword.Length < 3)
            {
                throw new LibraryCommonException(LibraryCommonException.ExceptionMessageForKeywordsLength);
            }

            var searchResult = new List<IReadable>();

            foreach (var readable in Library.Instance.ReadableItems)
            {
                if (readable.Name.ToLower().Contains(keyword.ToLower()))
                {
                    searchResult.Add(readable);
                }
            }

            return searchResult;
        }
 public List<int> AddMutiFiles(List<string> fileNames, List<string> fileDescs, Library.Project project)
 {
     List<int> ids = new List<int>();
     List<File> files = new List<File>();
     User owner = new Library.User(1);
     int i = 0;
     try
     {
         foreach (String fn in fileNames)
         {
             File file = new File(fn, fileDescs[i], project);
             file.FileLock = 1;
             file.FileLockTime = DateTime.Now;
             file.VersionNr = 1;
             files.Add(file);
             i++;
         }
         var option = new TransactionOptions();
         option.IsolationLevel = IsolationLevel.ReadCommitted;
         using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, option))
         {
             foreach (File f in files)
             {
                 bool af = dbFile.AddFIle(f);
                 FileVersion fv = new FileVersion(f.Id.ToString(), f, f.VersionNr, owner);
                 bool version = dbFileVersion.AddFileVersion(fv);
                 if (!af && !version)
                 {
                     scope.Dispose();
                     break;
                 }
                 ids.Add(f.Id);
             }
             scope.Complete();
         }
         return ids;
     }
     catch (Exception e)
     {
         throw new Exception("Files not added to DB: \n" + e);
     }
 }