Exemplo n.º 1
0
        private void OnGazeCircularButton(object sender, GazeAwareEventArgs e)
        {
            CBook oBook = CConfig.Instance.GetBook(m_iBookId);
            FBook fBook = new FBook(oBook);

            fBook.Show();
        }
Exemplo n.º 2
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        shoppingCart = Session["cart"] as List <CShoppingCart>;
        if (shoppingCart == null)
        {
            shoppingCart    = new List <CShoppingCart>();
            Session["cart"] = shoppingCart;
        }

        string id    = (sender as Button).ToolTip;
        int    index = Convert.ToInt32(id.Substring(4, 1));
        string count = ((DropDownList)ListView1.Controls[index].FindControl("DropDownList1")).Text;

        CBook  book     = bookFactory.getById(id);
        string price    = book.bookPrice;
        string name     = book.bookName;
        string subtotal = (Convert.ToDouble(price) * Convert.ToInt32(count)).ToString();

        shoppingCart.Add(new CShoppingCart()
        {
            書名 = name, 單價 = price, 數量 = count, 小計 = subtotal, 訂購日期 = DateTime.Now.ToString("yyyy/MM/dd")
        });

        Response.Redirect("shoppingCart.aspx?bid=" + id);
    }
Exemplo n.º 3
0
        private void OnGaze(object sender, GazeAwareEventArgs e)
        {
            var ctr = sender as PictureBox;

            if (ctr != null)
            {
                if (e.HasGaze)
                {
                    ctr.Select();

                    richTextBox1.Clear();
                    richTextBox1.Text = "Título: " + ctr.Image.Tag.ToString();
                    CBook oBook = CConfig.Instance.GetBook(ctr.Image.Tag.ToString());
                    richTextBox1.AppendText("\n");
                    richTextBox1.AppendText("ISBN: " + oBook.ISBN);
                    richTextBox1.AppendText("\n");
                    richTextBox1.AppendText("Autor: " + oBook.Author);
                    richTextBox1.AppendText("\n");
                    richTextBox1.AppendText("Editora: " + oBook.Editora);

                    richTextBox2.Clear();
                    richTextBox2.AppendText("Descrição: " + oBook.Description);

                    m_iBookId = oBook.Id;
                    circularButton1.Location = new System.Drawing.Point(ctr.Location.X + ctr.Width - 30, ctr.Location.Y + ctr.Height - 30);
                    //circularButton1.BackColor = System.Drawing.Color.FromArgb(64, circularButton1.BackColor);
                }
            }
        }
Exemplo n.º 4
0
        private bool LoadBookData(XmlNode oBooksNode)
        {
            string sErrorMsg = "Não existem livros cadastrados.";

            if (oBooksNode == null)
            {
                MessageBox.Show(sErrorMsg, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            try
            {
                int iBookId = 1;

                foreach (XmlNode oNode in oBooksNode)
                {
                    if (oNode.Name == "book")
                    {
                        CBook oBook = new CBook(iBookId, oNode);
                        m_htBooks.Add(iBookId, oBook);
                        iBookId++;
                    }
                }
            }
            catch
            {
                MessageBox.Show("Erro ao carregar livros.", "Erro",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            return(true);
        }
Exemplo n.º 5
0
        private async void CWebView_Navigated(object sender, WebNavigatedEventArgs e)
        {
            // This regex checks if the url is a book and gets the id
            Match regex = new Regex(@"(\d+)[-b]*.epub").Match(e.Url);

            if (regex.Success)
            {
                string            id    = regex.Groups[1].Value;
                CBook             book  = CApi.SearchBooks(id, "id", "exact").Books[0];
                ChitankaBookModel cBook = new ChitankaBookModel()
                {
                    Book = book, DownloadURL = e.Url
                };

                await Navigation.PushModalAsync(new NavigationPage(new BookDetailView(cBook)));
            }
            else
            {
                bool regexFb  = new Regex(@"(\d+)[-b]*.fb2.zip").Match(e.Url).Success;
                bool regexTxt = new Regex(@"(\d+)[-b]*.txt.zip").Match(e.Url).Success;
                bool regexSfb = new Regex(@"(\d+)[-b]*.sfb.zip").Match(e.Url).Success;
                if (!(regexFb || regexTxt || regexSfb))
                {
                    vm.LastPage = e.Url;
                }
            }
        }
Exemplo n.º 6
0
 public void CopyFrom(CBook cb)
 {
     if (this._bookName == null)
         this._bookName = new String[(int)(Preferences.Max_Macro_Sets / 10)];
     for (int i = 0; i < _bookName.Length; i++)
         this._bookName[i] = cb.GetBookName(i);
     this._changed = true;
 }
Exemplo n.º 7
0
        private void pictureBox_DoubleClick(object sender, EventArgs e)
        {
            var pb = sender as PictureBox;

            CBook oBook = CConfig.Instance.GetBook(pb.Image.Tag.ToString());
            FBook fBook = new FBook(oBook);

            fBook.Show();
        }
Exemplo n.º 8
0
 public void CopyFrom(CBook cb)
 {
     if (this._bookName == null)
     {
         this._bookName = new String[(int)(Preferences.Max_Macro_Sets / 10)];
     }
     for (int i = 0; i < _bookName.Length; i++)
     {
         this._bookName[i] = cb.GetBookName(i);
     }
     this._changed = true;
 }
Exemplo n.º 9
0
        public void ShouldGetBookById()
        {
            //Arrange
            CBook testBook = new CBook {
                Id = 1, Name = "Test-Driven Development by Example", AuthorsIds = new Int32[] { 1 }
            };

            //Act
            CBook bookFromMock = interactorUnderTest.GetBookById(1);

            //Assert
            testBook.Should().BeEquivalentTo(bookFromMock);
        }
Exemplo n.º 10
0
        public CBook GetComicBook(int id)
        {
            CBook comicbook_return = null;

            foreach (var comicbook in _comicBooks)
            {
                if (comicbook.Id == id)
                {
                    comicbook_return = comicbook;
                    break;
                }
            }
            return(comicbook_return);
        }
Exemplo n.º 11
0
        private void circularButton1_MouseEnter(object sender, EventArgs e)
        {
            CBook oBook = CConfig.Instance.GetBook(m_iBookId);

            if (oBook.Pages.Count != 0)
            {
                FBook fBook = new FBook(oBook, null);
                fBook.Show();
            }
            else
            {
                FChapter fChapter = new FChapter(oBook, this);
                fChapter.Show();
            }
        }
Exemplo n.º 12
0
        public void ShouldGetBooksByAuthor()
        {
            //Arrange
            IEnumerable <CBook> testBooks = new CBook[]
            { new CBook {
                  Id = 2, Name = "Compilers: Principles, Techniques, and Tools", AuthorsIds = new Int32[] { 2, 3, 4, 5 }
              },
              new CBook {
                  Id = 5, Name = "Foundations of Computer Science", AuthorsIds = new int[] { 2, 5 }
              } };
            //Act
            IEnumerable <CBook> booksFromMock = interactorUnderTest.GetBooksByAuthorId(2);

            //Assert
            testBooks.Should().BeEquivalentTo(booksFromMock);
        }
Exemplo n.º 13
0
        public void setAllMetaData(int iBookId, XmlNode oBookNode)
        {
            CBook book  = new CBook(iBookId, oBookNode);
            Page  pages = book.Pages;

            foreach (Page pg in book.Pages)
            {
                foreach (Line ln in pg.lines)
                {
                    foreach (Effect efct in ln.m_htEffects)
                    {
                        //em desenvolvimento
                    }
                }
            }
        }
Exemplo n.º 14
0
        async Task <IEnumerable <IBook> > IBookstoreService.GetBooksAsync(string searchString)
        {
            using (var httpClient = new HttpClient())
            {
                var json = await httpClient.GetStringAsync("https://raw.githubusercontent.com/contribe/contribe/dev/arbetsprov-net/books.json");

                var          des       = (CListBooks)Newtonsoft.Json.JsonConvert.DeserializeObject(json, typeof(CListBooks));
                var          B         = des;
                List <CBook> lstBocker = new List <CBook>();
                foreach (var item in des.books)
                {
                    CBook b = new CBook(item.Title, item.Author, item.Price, item.InStock);
                    lstBocker.Add(b);
                }
                return(lstBocker);
            }
        }
Exemplo n.º 15
0
 private void OnGazeCircularButton(object sender, GazeAwareEventArgs e)
 {
     if (e.HasGaze)
     {
         /*CBook oBook = CConfig.Instance.GetBook(m_iBookId);
          * FBook fBook = new FBook(oBook);
          * fBook.Show();*/
         CBook oBook = CConfig.Instance.GetBook(m_iBookId);
         if (oBook.Pages.Count != 0)
         {
             FBook fBook = new FBook(oBook, null);
             fBook.Show();
         }
         else
         {
             FChapter fChapter = new FChapter(oBook, this);
             fChapter.Show();
         }
     }
 }
Exemplo n.º 16
0
        private void pictureBox_DoubleClick(object sender, EventArgs e)
        {
            var pb = sender as PictureBox;

            /*CBook oBook = CConfig.Instance.GetBook(pb.Image.Tag.ToString());
             * FBook fBook = new FBook(oBook);
             * fBook.Show();*/

            CBook oBook = CConfig.Instance.GetBook(pb.Image.Tag.ToString());

            if (oBook.Pages.Count != 0)
            {
                FBook fBook = new FBook(oBook, null);
                fBook.Show();
            }
            else
            {
                FChapter fChapter = new FChapter(oBook, this);
                fChapter.Show();
            }
        }
Exemplo n.º 17
0
    private void loadData()
    {
        SqlDataSource sds = new SqlDataSource();

        sds.ConnectionString  = connectionString;
        sds.SelectCommand     = "dbo.getbook";
        sds.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
        DataView dv = sds.Select(DataSourceSelectArguments.Empty) as DataView;

        if (dv.Count > 0)
        {
            for (int i = 0; i < dv.Count; i++)
            {
                CBook book = new CBook();
                book.id        = (int)dv.Table.Rows[i]["book_id"];
                book.bookName  = dv.Table.Rows[i]["bookName"].ToString();
                book.bookPrice = dv.Table.Rows[i]["price"].ToString();
                book.bookPhoto = dv.Table.Rows[i]["bookPhoto"].ToString();
                bookList.Add(book);
            }
        }
    }
Exemplo n.º 18
0
        public FBook(CBook oBook)
        {
            InitializeComponent();

            speaker = new SpeechSynthesizer();

            Program.EyeXHost.Connect(behaviorMap1);
            //behaviorMap1.Add(btNext, new EyeXFramework.GazeAwareBehavior(OnGaze));
            behaviorMap1.Add(btNext, new EyeXFramework.GazeAwareBehavior(OnGazeClick)
            {
                DelayMilliseconds = 2000
            });

            behaviorMap1.Add(btBack, new EyeXFramework.GazeAwareBehavior(OnGaze));
            behaviorMap1.Add(btBack, new EyeXFramework.ActivatableBehavior(OnButtonActivated));
            behaviorMap1.Add(richTextBox1, new EyeXFramework.GazeAwareBehavior(OnGazeRichTextBox));

            behaviorMap1.Add(button1, new EyeXFramework.GazeAwareBehavior(OnGazeWord));
            behaviorMap1.Add(button2, new EyeXFramework.GazeAwareBehavior(OnGazeWord));
            behaviorMap1.Add(button3, new EyeXFramework.GazeAwareBehavior(OnGazeWord));
            behaviorMap1.Add(button4, new EyeXFramework.GazeAwareBehavior(OnGazeWord));
            behaviorMap1.Add(button5, new EyeXFramework.GazeAwareBehavior(OnGazeWord));
            behaviorMap1.Add(button6, new EyeXFramework.GazeAwareBehavior(OnGazeWord));
            behaviorMap1.Add(button7, new EyeXFramework.GazeAwareBehavior(OnGazeWord));
            behaviorMap1.Add(button8, new EyeXFramework.GazeAwareBehavior(OnGazeWord));
            behaviorMap1.Add(button9, new EyeXFramework.GazeAwareBehavior(OnGazeWord));

            KeyDown += OnKeyDown;
            KeyUp   += OnKeyUp;

            m_oBook       = oBook;
            m_iActualPage = 1;
            m_oPage       = m_oBook.GetPage(m_iActualPage);
            GetPage();

            m_sWords = new string[] { "Halloween", "brincar", "pizza", "floresta", "porta", "barulho", "monstro", "televisão" };
            btNext.Select();
        }
Exemplo n.º 19
0
        private void FMain_Load(object sender, EventArgs e)
        {
            pictureBox1.Select();
            CBook oBook = CConfig.Instance.GetBook(pictureBox1.Image.Tag.ToString());

            richTextBox1.Clear();
            richTextBox1.AppendText("\n");
            richTextBox1.Text = "Título: " + pictureBox1.Image.Tag.ToString();
            richTextBox1.AppendText("\n");
            richTextBox1.AppendText("ISBN: " + oBook.ISBN);
            richTextBox1.AppendText("\n");
            richTextBox1.AppendText("Autor: " + oBook.Author);
            richTextBox1.AppendText("\n");
            richTextBox1.AppendText("Editora: " + oBook.Editora);

            richTextBox2.Clear();
            richTextBox1.AppendText("\n");
            richTextBox2.AppendText("Descrição: " + oBook.Description);

            m_iBookId = oBook.Id;
            circularButton1.Location = new System.Drawing.Point(pictureBox1.Location.X + pictureBox1.Width - 30, pictureBox1.Location.Y + pictureBox1.Height - 30);
            //circularButton1.BackColor = System.Drawing.Color.FromArgb(64, circularButton1.BackColor);
        }
Exemplo n.º 20
0
        public FBook(CBook oBook, object iIdChapter)
        {
            InitializeComponent();


            Program.EyeXHost.Connect(behaviorMap1);

            behaviorMap1.Add(btNext, new EyeXFramework.GazeAwareBehavior(OnGazeNextBack)
            {
                DelayMilliseconds = 300
            });
            behaviorMap1.Add(btBack, new EyeXFramework.GazeAwareBehavior(OnGazeNextBack)
            {
                DelayMilliseconds = 300
            });
            behaviorMap1.Add(btExit, new EyeXFramework.GazeAwareBehavior(OnGazeExit)
            {
                DelayMilliseconds = 2000
            });

            // behaviorMap1.Add(btBack, new EyeXFramework.ActivatableBehavior(OnButtonActivated));

            KeyDown += OnKeyDown;
            KeyUp   += OnKeyUp;

            m_oBook       = oBook;
            m_iActualPage = 1;
            m_IdChapter   = iIdChapter;

            this.Text    = GetTitle();
            lbTitle.Text = GetTitle();
            //GetPage();

            FillPage();
            btNext.Select();
        }
Exemplo n.º 21
0
        private void HandleBookToOthers(TreeNode dragNode, TreeNode dropNode)
        {
            Thread notifyThread = new Thread(new ParameterizedThreadStart(ShowNotifyForm));
            TagInfo ti = new TagInfo(String.Empty, "Processing book...");

            TreeNode dragchildren = dragNode.FirstNode;
            TagInfo tIdrag = dragNode.Tag as TagInfo;
            TagInfo tIdrop = dropNode.Tag as TagInfo;

            if ((tIdrop.Type == "folder") ||
                (tIdrop.Type == "template") ||
                (tIdrop.Type == "main") ||
                (tIdrop.Type == "char"))
            {
                TagInfo tIp = dragNode.Parent.Tag as TagInfo;
                String newttlfile = tIdrop.Text.Trim('\\') + "\\mcr.ttl";
                String oldttlfile = tIp.Text.Trim('\\') + "\\mcr.ttl";

                #region Catch any error with TTL file manipulation
                try
                {
                    newttlfile = Path.GetFullPath(newttlfile);
                    oldttlfile = Path.GetFullPath(oldttlfile);
                }
                catch (PathTooLongException e)
                {
                    LogMessage.LogF("..HandleBookToOthers(): TTL file path is too long {0}, skipping", e.Message);
                    newttlfile = String.Empty;
                    oldttlfile = String.Empty;
                }
                catch (Exception e)
                {
                    LogMessage.LogF("..HandleBookToOthers(): Unknown Exception {0}, ignoring", e.Message);
                }
                #endregion

                if (newttlfile != oldttlfile)
                {
                    #region If future ttlfile is within system limits on Path Length and is not the SAME FILE
                    CBook cbold = null, cbnew = null;
                    for (int i = 0; i < BookList.Count; i++)
                    {
                        #region Locate any existing book for either file
                        if (BookList[i].fName == oldttlfile)
                        {
                            BookList[i].Restore();
                            cbold = BookList[i];
                        }
                        else if (BookList[i].fName == newttlfile)
                        {
                            BookList[i].Restore();
                            cbnew = BookList[i];
                        }
                        #endregion
                    }

                    if ((cbold == null) && (File.Exists(oldttlfile)))
                    {
                        #region If didn't find the drag mcr.ttl file and it does exist, Load it
                        cbold = new CBook(oldttlfile);
                        BookList.Add(cbold);
                        #endregion
                    }

                    if ((cbnew == null) && (File.Exists(newttlfile)))
                    {
                        #region If didn't find the drop mcr.ttl file and it does exist, Load it
                        cbnew = new CBook(newttlfile);
                        BookList.Add(cbnew);
                        #endregion
                    }

                    if ((cbold != null) && (cbnew != null))
                    {
                        #region If old ttl file and new ttlfile info was found in memory
                        DialogResult dr = MessageBox.Show("Book name file found in both directories, Yes to overwite the destination Book File.",
                            "Overwrite?",
                            MessageBoxButtons.YesNoCancel,
                            MessageBoxIcon.Question,
                            MessageBoxDefaultButton.Button2);
                        if (dr == DialogResult.Yes)
                        {
                            cbnew.CopyFrom(cbold);
                        }
                        else if (dr == DialogResult.Cancel)
                            return;
                        #endregion
                    }
                    else if ((cbold != null) && (cbnew == null))
                    {
                        #region If old ttl file info was found, but newttlfile was not
                        DialogResult dr = MessageBox.Show("Book name file found in source directory, Yes to copy to the destination directory.",
                            "Copy?",
                            MessageBoxButtons.YesNoCancel,
                            MessageBoxIcon.Question,
                            MessageBoxDefaultButton.Button2);
                        if (dr == DialogResult.Yes)
                        {
                            cbnew = new CBook(cbold, newttlfile);
                            BookList.Add(cbnew);
                        }
                        else if (dr == DialogResult.Cancel)
                            return;
                        #endregion
                    }
                    #endregion
                }

                #region Loop through the dragnode's children (macro files) doing copy as necessary
                CMacroFile[] draglist = new CMacroFile[0];

                for (dragchildren = dragNode.FirstNode; dragchildren != null;
                    dragchildren = dragchildren.NextNode)
                {
                    CMacroFile cmf_drag = FindMacroFileExactByNode(dragchildren);

                    if (cmf_drag != null)
                    {
                        Array.Resize(ref draglist, draglist.Length + 1);
                        draglist[draglist.Length - 1] = cmf_drag;
                    }
                }

                if (draglist.Length <= 0)
                {
                    #region If no files to transfer, return
                    LogMessage.Log("..HandleBookToOthers: No valid files to drag, returning");
                    return;
                    #endregion
                }

                #region Show Notify Form
                if (draglist.Length > FILES_TO_HIDE)
                {
                    ti.Object1 = (Object)draglist.Length;
                    notifyThread.Start((object)ti);
                }
                #endregion

                exitLoop = false;
                String[] errorFiles = new String[0];
                String errorString = String.Empty;
                String oldName = String.Empty;
                String newName = String.Empty;
                for (int x = 0; (x < draglist.Length) && (exitLoop == false); x++)
                {
                    #region Loop through draglist attempting to create new files if necessary
                    oldName = Path.GetFileName(draglist[x].fName);
                    if ((oldName != null) && (oldName != String.Empty))
                    {
                        newName = String.Format("{0}\\{1}", tIdrop.Text.Trim('\\'), oldName);
                        try
                        {
                            #region Catch an error if FullPath to newName is too long, otherwise Copy file
                            // if too long this should kick it out automatically
                            newName = Path.GetFullPath(newName);
                            if (draglist.Length > FILES_TO_HIDE)
                            {
                                UpdateNotifyUI(Utilities.EllipsifyPath(newName), x);
                                Thread.Sleep(25);
                            }
                            CMacroFile cmf_drop = FindMacroFileExactByFileName(newName);
                            if (cmf_drop != null)
                            {
                                cmf_drop.CopyFrom(draglist[x]);
                            }
                            else
                            {
                                NewFileInMemory(draglist[x], newName);
                            }
                            #endregion
                        }
                        catch (PathTooLongException e)
                        {
                            LogMessage.Log("HandleBookToOthers(): Filename {0} Error -- {1}", newName, e.Message);
                            Array.Resize(ref errorFiles, errorFiles.Length + 1);
                            errorFiles[errorFiles.Length - 1] = Utilities.EllipsifyPath(newName);
                            errorString += errorFiles[errorFiles.Length - 1] + "\r\n";
                        }
                        catch (Exception e)
                        {
                            LogMessage.Log("HandleBookToOthers(): Filename {0} Error -- {1}", newName, e.Message);
                        }
                    }
                    #endregion
                }

                #region Close Notify Form
                if (draglist.Length > FILES_TO_HIDE)
                {
                    UpdateNotifyProgress(notifyForm.NotifyBarMax);
                    Thread.Sleep(200);
                    CloseNotifyForm();
                }
                #endregion

                #region Notify of any errors due to long path names
                if ((errorFiles.Length > 0) && (errorString != String.Empty))
                {
                    MessageBox.Show("The following " + errorFiles.Length + " files can not be copied (Path to file is TOO long):\r\n" + errorString, "Error: Path(s) to " + errorFiles.Length + " files are too long!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                #endregion
                #endregion
            }
        }
Exemplo n.º 22
0
 public CBook(CBook cb, String filename)
     : this()
 {
     this._fName = filename;
     this.CopyFrom(cb);
 }
 public DetailsBookWindow(CBook BookDetails)
 {
     InitializeComponent();
     this.DataContext = new DetailsBookWindowVM(BookDetails);
 }
Exemplo n.º 24
0
        private void HandleCharOrFolder(TreeNode dragNode, TreeNode dropNode)
        {
            #region Handle copying files from char to folder
            Thread notifyThread = new Thread(new ParameterizedThreadStart(ShowNotifyForm));
            TagInfo ti = new TagInfo(String.Empty, "Processing book...");

            TagInfo tIdrop = dropNode.Tag as TagInfo;
            TagInfo tIdrag = dragNode.Tag as TagInfo;

            CMacroFile[] draglist = new CMacroFile[0];

            LogMessage.Log("DragDrop: Creating list of valid files");
            for (int i = 0; i < MacroFiles.Count; i++)
            {
                #region Locate all files matching the dragNode's folder path
                if ((MacroFiles[i] != null) &&
                    (MacroFiles[i].fName != null) && 
                    (MacroFiles[i].fName.Contains(tIdrag.Text)))
                {
                    Array.Resize(ref draglist, draglist.Length + 1);
                    draglist[draglist.Length - 1] = MacroFiles[i];
                }
                #endregion
            }

            if (draglist.Length > 0)
            {
                #region If there are valid files for dragging
                CMacroFile tmp_drop = null;
                exitLoop = false;

                List<TagInfo> ttlFileList = new List<TagInfo>();
                for (int i = 0; i < draglist.Length; i++)
                {
                    // remove the common directory, to merge and create a path

                    String PathToRemove = String.Empty;
                    String FileWithFolder = draglist[i].fName;
                    String newpath = String.Empty;
                    try
                    {
                        // draglist[i].fName
                        PathToRemove = Path.GetDirectoryName(tIdrag.Text.Trim('\\'));
                        FileWithFolder = FileWithFolder.Remove(0, PathToRemove.Length);
                        // Attempt to throw an error here.
                        newpath = Path.GetFullPath(tIdrop.Text.Trim('\\') + "\\" + FileWithFolder.Trim('\\'));

                        #region Check for valid TTL files here
                        String newttlfile = String.Empty;
                        String oldttlfile = String.Empty;

                        try
                        {
                            newttlfile = Path.GetDirectoryName(newpath) + "\\mcr.ttl"; // (tIdrop.Text.Trim('\\') + "\\mcr.ttl");
                            oldttlfile = Path.GetDirectoryName(draglist[i].fName) + "\\mcr.ttl";
                        }
                        catch (PathTooLongException e)
                        {
                            // File.Exists(String.Empty) always returns false
                            // This will catch an PathTooLongException errors and ignore transfer
                            LogMessage.LogF("..HandleCharOrFolder(): TTL file path is too long {0}, skipping", e.Message);
                        }
                        catch (Exception e)
                        {
                            LogMessage.LogF("..HandleCharOrFolder(): Unknown exception {0}, ignoring", e.Message);
                        }

                        if (newttlfile != oldttlfile)
                        {
                            #region If future ttlfile is within system limits on Path Length and is not the SAME FILE
                            int oldcnt = 0;
                            for (oldcnt = 0; oldcnt < ttlFileList.Count; oldcnt++)
                            {
                                TagInfo tmpTTL = ttlFileList[oldcnt];
                                CBook cbTTL = tmpTTL.Object1 as CBook;
                                if (cbTTL.fName == oldttlfile)
                                    break;
                            }
                            if (oldcnt >= ttlFileList.Count) // not been handled yet
                            {
                                #region If not handled yet
                                CBook cbold = null, cbnew = null;
                                for (int bcnt = 0; bcnt < BookList.Count; bcnt++)
                                {
                                    #region Locate any existing book for either file
                                    if (BookList[bcnt].fName == oldttlfile)
                                    {
                                        BookList[bcnt].Restore();
                                        cbold = BookList[bcnt];
                                    }
                                    else if (BookList[bcnt].fName == newttlfile)
                                    {
                                        BookList[bcnt].Restore();
                                        cbnew = BookList[bcnt];
                                    }
                                    #endregion
                                }

                                if ((cbold == null) && (File.Exists(oldttlfile)))
                                {
                                    #region If didn't find the drag mcr.ttl file and it does exist, Load it
                                    cbold = new CBook(oldttlfile);
                                    BookList.Add(cbold);
                                    #endregion
                                }

                                if ((cbnew == null) && (File.Exists(newttlfile)))
                                {
                                    #region If didn't find the drop mcr.ttl file and it does exist, Load it
                                    cbnew = new CBook(newttlfile);
                                    BookList.Add(cbnew);
                                    #endregion
                                }

                                if ((cbold != null) && (cbnew != null))
                                {
                                    #region If old ttl file and new ttlfile info was found in memory
                                    ttlFileList.Add(new TagInfo("Overwrite_TTL", cbold, cbnew));
                                    #endregion
                                }
                                else if ((cbold != null) && (cbnew == null))
                                {
                                    #region If old ttl file was found but new ttl file was not
                                    cbnew = new CBook(cbold, newttlfile);
                                    ttlFileList.Add(new TagInfo("Copy_TTL", Path.GetDirectoryName(newttlfile), cbold, cbnew));
                                    #endregion
                                }
                                #endregion
                            }
                            #endregion
                        }
                        #endregion
                    }
                    catch (PathTooLongException error)
                    {
                        LogMessage.Log("While processing book files, encountered Path Too Long error -- {0}", error.Message);
                    }
                    catch (Exception error)
                    {
                        LogMessage.Log("While processing book files, encountered Unexpected error -- {0}", error.Message);
                    }
                } // end for loop

                #region Test for list
                if (ttlFileList.Count != 0)
                {
                    if (ttlFileList.Count == 1)
                    {
                        #region If only one book file is being processed, show generic MessageBox instead
                        String path = ttlFileList[0].Text;
                        CBook cbold = ttlFileList[0].Object1 as CBook;
                        CBook cbnew = ttlFileList[0].Object2 as CBook;
                        if (ttlFileList[0].Type == "Overwrite_TTL")
                        {
                            DialogResult dr = MessageBox.Show(
                                    String.Format("Book name file found in both directories,\r\nSource: {0}\r\nDestination: {1}\r\n\r\nOverwite the destination Book File?", Utilities.EllipsifyPath(cbold.fName, 60), Utilities.EllipsifyPath(cbnew.fName, 60)),
                                    "Overwrite?",
                                    MessageBoxButtons.YesNoCancel,
                                    MessageBoxIcon.Question,
                                    MessageBoxDefaultButton.Button2);
                            if (dr == DialogResult.Yes)
                            {
                                cbnew.CopyFrom(cbold);
                            }
                            else if (dr == DialogResult.Cancel)
                            {
                                LogMessage.Log("..Cancelled drop");
                                return;
                            }
                        }
                        else if (ttlFileList[0].Type == "Copy_TTL")
                        {
                            DialogResult dr = MessageBox.Show(
                                    String.Format("Book name file found in source directory:\r\n'{0}',\r\n\r\nCopy to the destination directory:\r\n'{1}'?", Utilities.EllipsifyPath(cbold.fName, 60), Utilities.EllipsifyPath(path, 60)),
                                    "Copy?",
                                    MessageBoxButtons.YesNoCancel,
                                    MessageBoxIcon.Question,
                                    MessageBoxDefaultButton.Button2);
                            if (dr == DialogResult.Yes)
                            {
                                BookList.Add(cbnew);
                            }
                            else if (dr == DialogResult.Cancel)
                            {
                                LogMessage.Log("..Cancelled drop");
                                return;
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        #region Else go with the CheckedListBox
                        ExitAndSaveBox esb = new ExitAndSaveBox("Confirmation box...", "Select what actions to take:", "Confirm", "No To All", "Cancel Operation");
                        esb.checkedListBox1.Items.Clear();
                        foreach (TagInfo x in ttlFileList)
                            esb.checkedListBox1.Items.Add(x, true);
                        bool ExitTTLLoop = false;
                        do
                        {
                            DialogResult dr = esb.ShowDialog(this);
                            if (dr == DialogResult.Cancel)
                            {
                                LogMessage.Log("..HandleSwapOrCopy(): Copy cancelled");
                                return;
                            }
                            else if (dr == DialogResult.No)
                                ExitTTLLoop = true;
                            else if (dr == DialogResult.Yes)
                            {
                                if (esb.checkedListBox1.CheckedItems.Count == 0)
                                    MessageBox.Show("If you're going to select to save, you must select something!", "Select 'No To All' to ignore this.");
                                else
                                {
                                    foreach (TagInfo x in esb.checkedListBox1.CheckedItems)
                                    {
                                        CBook cbold = x.Object1 as CBook;
                                        CBook cbnew = x.Object2 as CBook;
                                        String type = x.Type;
                                        if (type == "Copy_TTL")
                                        {
                                            BookList.Add(cbnew);
                                        }
                                        else if (type == "Overwrite_TTL")
                                        {
                                            cbnew.CopyFrom(cbold);
                                        }
                                    }
                                    ExitTTLLoop = true;
                                }
                            }

                        } while (ExitTTLLoop == false);
                        #endregion
                    }
                }
                #endregion
                #region Show Notify Form
                if (draglist.Length > FILES_TO_HIDE)
                {
                    ti.Object1 = draglist.Length as Object;
                    notifyThread.Start((object)ti);
                }
                #endregion

                String[] errorFiles = new String[0];
                String errorString = String.Empty;
                for (int i = 0; (i < draglist.Length) && (exitLoop == false); i++)
                {
                    #region Loop through draglist Copying files
                    #region Update NotifyForm UI
                    if (draglist.Length > FILES_TO_HIDE)
                    {
                        UpdateNotifyUI(Utilities.EllipsifyPath(draglist[i].fName), i);
                        Thread.Sleep(25);
                    }
                    #endregion
                    String PathToRemove = String.Empty;
                    String FileWithFolder = draglist[i].fName;
                    String newpath = String.Empty;

                    try
                    {
                        #region Copy files or Create new files here
                        // draglist[i].fName
                        PathToRemove = Path.GetDirectoryName(tIdrag.Text.Trim('\\'));
                        FileWithFolder = FileWithFolder.Remove(0, PathToRemove.Length);
                        // Attempt to throw an error here.
                        newpath = Path.GetFullPath(tIdrop.Text.Trim('\\') + "\\" + FileWithFolder.Trim('\\'));

                        tmp_drop = FindMacroFileExactByFileName(newpath);
                        if (tmp_drop != null)
                        {
                            tmp_drop.CopyFrom(draglist[i]);
                        }
                        else
                        {
                            NewFileInMemory(draglist[i], newpath);
                        }
                        #endregion
                    }
                    catch (PathTooLongException e)
                    {
                        #region Setup for error processing for Too long filenames
                        LogMessage.Log("..HandleCharOrFolder(): Path is too long, could not copy: {0}, skipping -- Error: {1}", newpath, e.Message);
                        Array.Resize(ref errorFiles, errorFiles.Length + 1);
                        errorFiles[errorFiles.Length - 1] = Utilities.EllipsifyPath(newpath);
                        errorString += errorFiles[errorFiles.Length - 1] + "\r\n";
                        #endregion
                    }
                    catch (Exception e)
                    {
                        #region Generic Error
                        LogMessage.LogF("..HandleCharOrFolder(): Unexpected error -- {0}, ignoring.", e.Message);
                        Array.Resize(ref errorFiles, errorFiles.Length + 1);
                        errorFiles[errorFiles.Length - 1] = Utilities.EllipsifyPath(newpath);
                        errorString += errorFiles[errorFiles.Length - 1] + "\r\n";
                        #endregion
                    }
                    #endregion
                }

                #region Close Notify Form
                if (draglist.Length > FILES_TO_HIDE)
                {
                    UpdateNotifyProgress(notifyForm.NotifyBarMax);
                    Thread.Sleep(200);
                    CloseNotifyForm();
                }
                #endregion

                #region Notify of any errors encountered
                if ((errorFiles.Length > 0) && (errorString != String.Empty))
                {
                    MessageBox.Show("The following " + errorFiles.Length + " files can not be saved (Path to file is TOO long):\r\n" + errorString, "Error: Path(s) too long on " + errorFiles.Length + " files!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                #endregion
                #endregion
            }
            else
            {
                LogMessage.Log("...Unable to determine list of files in char directory {0}", tIdrag.Text);
                MessageBox.Show("Unable to complete the request, I'm sorry.", "Drag & Drop Error!");
            }
            #endregion
        }
Exemplo n.º 25
0
 public async Task OnGet(int id)
 {
     Book = await _db.Book.FindAsync(id);
 }
Exemplo n.º 26
0
 public CBook(CBook cb, String filename)
     : this()
 {
     this._fName = filename;
     this.CopyFrom(cb);
 }