Ejemplo n.º 1
0
        /** COPIAR LISTA SELECCIONADA */
        private void BtnCopy_Click(object sender, RoutedEventArgs e)
        {
            string realValue = tbReal.Text.Replace(" ", "");

            while (realValue.StartsWith("0"))
            {
                realValue = realValue.Substring(1);
            }

            if (string.IsNullOrWhiteSpace(realValue) || double.Parse(realValue) <= 0)
            {
                AppMAnager.SetLabel_Error(lCostoReal, "Real:");
                AppMAnager.SetErrorTextBox(tbReal);
                MessageBox.Show("El costo real debe ser mayor que 0");
                return;
            }

            string destination = AppMAnager.showFolderBrowser("");

            if (Directory.Exists(destination))
            {
                string root      = Directory.GetDirectoryRoot(destination);
                long   freespace = new DriveInfo(root).AvailableFreeSpace;

                List <MediaFile_Basic_Info> mf_list = new List <MediaFile_Basic_Info>();
                MediaFile_Basic_Info        MFBI;
                foreach (StackPanel sp in _listSeleccion.Items)
                {
                    MFBI = (MediaFile_Basic_Info)sp.Tag;
                    mf_list.Add(MFBI);
                    //copySize += MFBI.getTotalSize();
                }

                if (freespace < listCopySize)
                {
                    double free = Math.Round(StorageConverter.Convert(Differential.ByteToGiga, freespace, StorageBase.BASE2), 2);
                    double need = Math.Round(StorageConverter.Convert(Differential.ByteToGiga, listCopySize, StorageBase.BASE2), 2);
                    MessageBox.Show("No hay espacio suficiente en el dispositivo seleccionado" + "\n" +
                                    "Necesario: " + need + "Gb       Disponible: " + free + "Gb");
                }
                else
                {
                    if (_copySplitter.Visibility == Visibility.Hidden)
                    {
                        _copysRow.Height         = new GridLength(100);
                        _copySplitter.Visibility = Visibility.Visible;
                    }

                    //  ProgressInfo pinfo = new ProgressInfo();
                    // int pos = _copysContainer.Children.Add(pinfo);  //Uso la posicion del componente para enlazarlo con el BackgroundMediaCopy
                    // pinfo.Tag = pos;

                    double montoReal = 0;
                    if (!string.IsNullOrEmpty(realValue))
                    {
                        montoReal = double.Parse(realValue);
                    }

                    copia c = new copia
                    {
                        user_id        = AppMAnager.CurrentUser().id,
                        punto_copia_id = AppMAnager.CurrentPuntoCopia().id,
                        codigo         = DBManager.CopiasRepo.NextSerie().ToString(),
                        tipo_pago_id   = tpagoId,
                        fecha          = DateTime.Now,
                        monto_sistema  = costoLista,
                        monto_real     = montoReal
                    };
                    copia the_copy = DBManager.CopiasRepo.Add(c);

                    if (the_copy != null)
                    {
                        BackgroundMediaFileCopy copier = new BackgroundMediaFileCopy(the_copy.id);
                        ProgressInfo            pinfo  = new ProgressInfo(copier);
                        _copysContainer.Children.Add(pinfo);
                        copier.StartCopyWorker(mf_list, destination, pinfo);
                        AppMAnager.RUNNING_COPYS_COUNT++;

                        //ClearPageSelection(true);
                        // AppMAnager.thread_copys.Add(pos, copier);

                        _listSeleccion.Items.Clear();
                        btnCopy.IsEnabled = false;

                        restartCostInfo();
                    }
                }
            }
        }
        //Lee lo seleccionado en el arbol de categorias escaneado y lo guarda a la bd
        private void SaveSelectedNodes(List <MediaFile_Basic_Info> List, categoria categ, int parentId, BackgroundWorker worker)
        {
            FileInfo      fi;
            DirectoryInfo di;
            string        subtitle;
            string        poster;
            string        trailer;

            MediaFilesRepository mediaRepo = DBManager.MediaFilesRepo; // new MediaFilesRepository();
            int ptoCopia_id = AppMAnager.CurrentPuntoCopia().id;

            //media_files mf;
            int progress;

            foreach (MediaFile_Basic_Info item in List)
            {
                if (item._fileSystemInfo is FileInfo)  //Es un fichero
                {
                    fi = (FileInfo)item._fileSystemInfo;

                    Console.WriteLine(fi.DirectoryName + "  |  " + fi.Name);

                    /*mf = new media_files
                     * {
                     *  categoria_id = categ.id,
                     *  punto_copia_id = AppMAnager.CurrentPuntoCopia().id, // copia_punto.id,
                     *  titulo = AppMAnager.NameWithoutExt(fi.Name),
                     *  is_folder = false
                     * };*/

                    subtitle = AppMAnager.FindSubtitleFile(fi);
                    poster   = AppMAnager.FindPosterFile(fi);
                    trailer  = AppMAnager.FindTrailerFile(fi);

                    /*
                     *                  if (poster != null)
                     *                      mf.fichero_portada = poster;
                     *
                     *                  mf.parent_id = parentId;
                     *                  mf.file_url = fi.FullName;
                     *                  if (subtitle != null)
                     *                      mf.str_file = subtitle;
                     *
                     *                  mf = mediaRepo.Add(mf);*/

                    nextMediaId++;
                    DBManager.Context.Database.ExecuteSqlCommand("insert into media_files(id, categoria_id, punto_copia_id, parent_id, file_url, str_file, fichero_portada, titulo, fichero_trailer, is_folder) " +
                                                                 "values(" + nextMediaId + "," + categ.id + "," + ptoCopia_id + "," + parentId + ",'" + getScapedString(fi.FullName) + "','" + getScapedString(subtitle) + "','" +
                                                                 getScapedString(poster) + "','" + getScapedString(AppMAnager.NameWithoutExt(fi.Name)) + "','" + getScapedString(trailer) + "', false)");

                    i++;
                    progress = (i * 100) / totalSaveOperations;
                    worker.ReportProgress(progress);
                }
                else
                if (item._fileSystemInfo is DirectoryInfo)  //Es un directorio
                {
                    di = (DirectoryInfo)item._fileSystemInfo;

                    Console.WriteLine("Leyendo directorio: " + di.FullName);

                    if (!item.file_exists)  //No existe el directorio
                    {
                        /* mf = new media_files
                         * {
                         *    categoria_id = categ.id,
                         *    punto_copia_id = AppMAnager.CurrentPuntoCopia().id,
                         *    titulo = di.Name,
                         *    is_folder = true,
                         *    parent_id = parentId,
                         *    file_url = di.FullName
                         * };
                         * mf = mediaRepo.Add(mf);*/

                        nextMediaId++;
                        DBManager.Context.Database.ExecuteSqlCommand("insert into media_files(id, categoria_id, punto_copia_id, parent_id, file_url, titulo, is_folder) " +
                                                                     "values(" + nextMediaId + "," + categ.id + "," + ptoCopia_id + "," + parentId + ",'" + getScapedString(di.FullName) + "','" + getScapedString(di.Name) + "', true)");

                        SaveSelectedNodes(item.Childrens, categ, nextMediaId, worker);
                    }

                    /*  else
                     *    mf = mediaRepo.FindByUrl(di.FullName);
                     *
                     * SaveSelectedNodes(item.Childrens, categ, mf.id, worker); */
                }
            }
        }