private void CheckForMatches(FilePrint print, List <FilePrint> prints)
        {
            // For each print that is currently generated
            for (int i = 0; i < prints.Count; i++)
            {
                try
                {
                    bool isMatch = CheckPrintsAreMatch(print, prints[i]);

                    if (isMatch)
                    {
                        form.Invoke((MethodInvoker) delegate()
                        {
                            lock (duplicatesLock)
                            {
                                model.Duplicates.Add(new Duplicate(print, prints[i]));
                            }
                        });
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error occured in GeneratePrints");
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// A.L2.P1/1. Создать консольное приложение, которое может выводить
        /// на печатать введенный текст  одним из трех способов:
        /// консоль, файл, картинка.
        /// </summary>
        public static void A_L2_P1_1()
        {
            Console.WriteLine("Введите способ печати (1 - консоль, 2 - файл, 3 - картинка) : ");
            string choose = Console.ReadLine();

            IPrinter printer = null;

            switch (choose)
            {
            case "1":
                printer = new ConsolePrinter(ConsoleColor.Red);
                break;

            case "2":
                Console.WriteLine("Фраза записана в файл.");
                printer = new FilePrint(filename: "test");
                break;

            case "3":
                printer = new ImagePrint("BitmapExample");
                Console.WriteLine("Фраза записана в картинку.");
                break;
            }

            Console.WriteLine("Введите фразу которую необходимо записать: ");

            for (int i = 0; i < 5; i++)
            {
                var text = Console.ReadLine();
                printer?.Print(text);
            }
        }
        private List <FilePrint> GeneratePrints(List <string> files, List <FilePrint> prints, BackgroundWorker worker, DoWorkEventArgs dwea)
        {
            if (!Directory.Exists(Program.THUMBS_PATH))
            {
                Directory.CreateDirectory(Program.THUMBS_PATH);
            }

            if (files == null)
            {
                return(null);
            }

            bool fileTypesNeedMatch = model.SearchImages && model.SearchVideos && model.OnlyMatchSameFileTypes;

            finishedThreads = 0;

            cancelTokenSource = new CancellationTokenSource();

            var options = new ParallelOptions
            {
                MaxDegreeOfParallelism = (int)model.ThreadCount,
                CancellationToken      = cancelTokenSource.Token
            };

            try
            {
                Parallel.ForEach(
                    files,
                    options,
                    (filename, state) =>
                {
                    if (options.CancellationToken.IsCancellationRequested)
                    {
                        state.Break();
                    }
                    else
                    {
                        FilePrint print = CreatePrint(prints, filename);

                        if (print != null)
                        {
                            CheckForMatches(print, prints);

                            // Add print to prints list *after* checking for matches, then don't have to worry about matching self, genius.
                            prints.Add(print);
                        }

                        finishedThreads++;
                        worker.ReportProgress(finishedThreads * 100 / files.Count);
                    }
                });
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception in GeneratingPrints: {e.Message} - {e.StackTrace}");
            }

            return(prints);
        }
Exemplo n.º 4
0
        public async Task <bool> AddFile(FilePrint file)
        {
            try
            {
                var fileTable = App.MobileService.GetTable <FilePrint>();
                await fileTable.InsertAsync(file);

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Exemplo n.º 5
0
    /// <summary>
    /// Returns the difference count between two fileprints.
    /// </summary>
    public static int Compare(FilePrint fp1, FilePrint fp2)
    {
        int differenceCount = 0;

        for (int i = 0; i < fp1.Print.Length; i++)
        {
            if (fp1.Print[i] != fp2.Print[i])
            {
                differenceCount++;
            }
        }

        return(differenceCount);
    }
        private FilePrint CreatePrint(List <FilePrint> prints, string filename)
        {
            FilePrint print;

            try
            {
                print = new FilePrint(Path.Combine(model.Directory, filename));
            }
            catch (Exception e)
            {
                Logs.Log($"Error occured getting print for {filename}", e.GetType().Name, e.Message, e.StackTrace);
                print = null;
            }

            return(print);
        }
        private bool CheckDirectoriesOk(FilePrint print1, FilePrint print2)
        {
            // Check for "between immediate and subdirectories" filter.
            // Other filters are taken care of before this method by only passing in the required files.

            if (model.SearchScopeSelectedValue != DuplicatesFormModel.SearchScope.BetweenImmediateAndSubdirs)
            {
                return(true);
            }
            else if (print1.Directory == model.Directory ^ print2.Directory == model.Directory)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 8
0
 public string PrinttoPrinter(string Type)
 {
     try
     {
         PrintDocument p = new PrintDocument();
         if (Type == "text")
         {
             p.PrintPage += new PrintPageEventHandler(PrintLine);
         }
         p.Print();
         FilePrint.Close();
         return("1");
     }
     catch (Exception e)
     {
         return("cetak gagal. " + e.Message);
     }
 }
Exemplo n.º 9
0
    /// <summary>
    /// Returns a decimal ranging from 0 to 100.
    /// </summary>
    public static decimal GetSimilarityPercentage(FilePrint fp1, FilePrint fp2)
    {
        int differenceCount = 0;

        try
        {
            for (int i = 0; i < fp1.Print.Length; i++)
            {
                if (fp1.Print[i] != fp2.Print[i])
                {
                    differenceCount++;
                }
            }

            return((1 - ((decimal)differenceCount / (decimal)64)) * 100);
        }
        catch (Exception e)
        {
            return(0);
        }
    }
        private bool CheckPrintsAreMatch(FilePrint print1, FilePrint print2)
        {
            if (print1 != null && print2 != null)
            {
                // If the duplicate hasn't already been found or found in reverse (x is like y |or| y is like x)
                if (!fileTypesMustMatch || (fileTypesMustMatch && print1.FileType == print2.FileType))
                {
                    bool dirOK = CheckDirectoriesOk(print1, print2);

                    if (dirOK)
                    {
                        // If above similarity threshold set by user.
                        if (FilePrint.GetSimilarityPercentage(print1, print2) >= model.Similarity)
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Exemplo n.º 11
0
        public Duplicate(FilePrint fp1, FilePrint fp2)
        {
            fileprint1 = fp1;
            //this.File1Path = fp1.filepath;
            //this.File1ThumbPath = fp1.ThumbPath;

            fileprint2 = fp2;
            //this.File2Path = fp2.filepath;
            //this.File2ThumbPath = fp2.ThumbPath;

            DifferenceCount = 0;

            for (int i = 0; i < fp1.Print.Length; i++)
            {
                if (fp1.Print[i] != fp2.Print[i])
                {
                    DifferenceCount++;
                }
            }

            Chance = 1 - ((float)DifferenceCount / (float)64);
        }
Exemplo n.º 12
0
        private void PrintLine(object sender, PrintPageEventArgs e)
        {
            int    totalrowsperpage = (int)((e.MarginBounds.Height - MarginBawah) / JenisFont.GetHeight(e.Graphics));
            float  y         = MarginAtas;
            int    totalrows = 0;
            string Line      = FilePrint.ReadLine();

            while (totalrows < totalrowsperpage && Line != null)
            {
                y = MarginAtas + (totalrows * JenisFont.GetHeight(e.Graphics));
                e.Graphics.DrawString(Line, JenisFont, Brushes.Black, MarginKiri, y);
                totalrows++;
                Line = FilePrint.ReadLine();
            }
            if (Line != null)
            {
                e.HasMorePages = true;
            }
            else
            {
                e.HasMorePages = false;
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// 打印
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tsBtnPrint_Click(object sender, EventArgs e)
 {
     FilePrint.CommonPrint(this.fpUserInformationDetails, 0);
 }
Exemplo n.º 14
0
 /// <summary>
 ///     打印
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tsBtnPrint_Click(object sender, EventArgs e)
 {
     FilePrint.CommonPrint(_fpPreWarningResultDetials, 0);
 }
Exemplo n.º 15
0
 private void tsBtnPrint_Click(object sender, EventArgs e)
 {
     FilePrint.CommonPrint(fpUserInfo, 0);
 }
Exemplo n.º 16
0
 private void tsbPrint_Click(object sender, EventArgs e)
 {
     FilePrint.CommonPrint(fpPreWarningResultTotalTable, 0);
 }
Exemplo n.º 17
0
 /// <summary>
 ///     打印
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tsBtnPrint_Click(object sender, EventArgs e)
 {
     FilePrint.CommonPrint(_fpPreWaringLastedValue, 0);
 }
Exemplo n.º 18
0
 private void tsBtnPrint_Click(object sender, EventArgs e)
 {
     //打印
     FilePrint.CommonPrint(fpDayReportHChuan, 0);
 }
Exemplo n.º 19
0
 public void PrintRules()
 {
     FilePrint.CommonPrint(fpRules, 0);
 }
Exemplo n.º 20
0
 private void btnPrint_Click(object sender, EventArgs e)
 {
     FilePrint.CommonPrint(fpRules, 0);
 }
Exemplo n.º 21
0
 private void toolStripBtnPrint_Click(object sender, EventArgs e)
 {
     FilePrint.CommonPrint(fpPreWarningResultTable, 0);
 }
Exemplo n.º 22
0
 /// <summary>
 /// 打印
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tsBtnPrint_Click(object sender, EventArgs e)
 {
     FilePrint.CommonPrint(_fpDepartmentInfo, 0);
 }
Exemplo n.º 23
0
 /// <summary>
 ///     打印
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tsBtnPrint_Click(object sender, EventArgs e)
 {
     FilePrint.CommonPrint(fpGasConcentrationProbeDataInfo, 0);
 }