コード例 #1
0
 public static List <TablaImages> validadorImage()
 {
     listachk = Obtiene.obtener();
     if (listachk.Count() != 0)
     {
         using (SqlConnection con = new SqlConnection(Obtiene.connString))
         {
             con.Open();
             using (DataClasses1DataContext dc = new TareaStoragePepsi.DataClasses1DataContext(Obtiene.connString))
             {
                 for (int i = 0; i <= (listachk.Count() - 1); i++)
                 {
                     //ACTUALIZAR CLCHKTAR
                     //CLCHKIMG ima = dc.CLCHKIMG.FirstOrDefault(empl => empl.CLCHKIMGNAME.Equals(listachk[i].CLCHKIMGNAME)
                     CLCHKIMG ima = dc.CLCHKIMG.FirstOrDefault(actu => actu.CMCIAID.Equals(listachk[i].CMCIAID) && actu.CLCHKID.Equals(listachk[i].CLCHKID) && actu.CLCHKPROID.Equals(listachk[i].CLCHKPROID) && actu.CLCHKACTID.Equals(listachk[i].CLCHKACTID) && actu.CLCHKIMGLIN.Equals(listachk[i].CLCHKIMGLIN));
                     try
                     {
                         using (var ms = new MemoryStream(listachk[i].CLCHKIMGBLOB, 0, listachk[i].CLCHKIMGBLOB.Length))
                         {
                             Image image = Image.FromStream(ms, true);
                         }
                         ima.CLCHKIMGSTS = 1;
                         dc.SubmitChanges();
                     }
                     catch (Exception)
                     {
                         ima.CLCHKIMGSTS = 2;
                         dc.SubmitChanges();
                         errores.Add(i);
                         Console.WriteLine("Error en el registro:  " + listachk[i].CMCIAID + "-" + listachk[i].CLCHKID + "-" + listachk[i].CLCHKPROID + "-" + listachk[i].CLCHKACTID + "-" + listachk[i].CLCHKIMGLIN + " Se encontró una anomalía en la imagen ");
                     }
                     finally
                     {
                     }
                 }
             }
         }
         for (int i = 0; i <= (errores.Count() - 1); i++)
         {
             listachk.RemoveAt(errores[i]);
         }
     }
     else
     {
     }
     return(listachk);
 }
コード例 #2
0
        public static void mistorage()
        {
            StorageClient storageClient = StorageClient.Create();

            while (true)
            {
                listachk = VerificadorImagenes.validadorImage();
                if (listachk.Count() != 0)
                {
                    int compa = Convert.ToInt32(listachk[0].CMCIAID);
                    listadato = Obtiene.InfoStora(compa);
                    //string img64, int idActividad, int idRespuesta
                    using (SqlConnection con = new SqlConnection(Obtiene.connString))
                    {
                        con.Open();
                        using (DataClasses1DataContext dc = new TareaStoragePepsi.DataClasses1DataContext(con))
                        {
                            dc.SubmitChanges();
                            for (int i = 0; i <= (listachk.Count() - 1); i++)
                            {
                                Console.WriteLine(listachk[i].CLCHKID);
                                Random         rnd   = new Random();
                                int            tmp   = rnd.Next(1000);
                                DateTimeOffset now   = DateTimeOffset.Now;
                                string         route = Convert.ToString(listadato[0].IdFolder) + now.ToString("yyyy-MM") + "/";
                                route += string.Format("{0:00000}", Convert.ToString(listachk[i].CLCHKID)) + "/";
                                string fileName = route + string.Format("{0:000}", Convert.ToString(listachk[i].CMCIAID)) + "_" + string.Format("{0:000}", Convert.ToString(listachk[i].CLCHKID)) + "_" + string.Format("{0:000}", Convert.ToString(listachk[i].CLCHKPROID)) + "_" + string.Format("{0:000}", Convert.ToString(listachk[i].CLCHKACTID)) + "_" + string.Format("{0:000}", Convert.ToString(listachk[i].CLCHKIMGLIN)) + "_" + string.Format("{0:000}", tmp) + ".jpeg";
                                try
                                {
                                    var options = new UploadObjectOptions {
                                        PredefinedAcl = PredefinedObjectAcl.PublicRead
                                    };
                                    var      obj1 = storageClient.UploadObject(Convert.ToString(listadato[0].IdBucket), fileName, "image/jpeg", new MemoryStream(listachk[i].CLCHKIMGBLOB), options);
                                    CLCHKIMG ima  = dc.CLCHKIMG.FirstOrDefault(actu => actu.CMCIAID.Equals(listachk[i].CMCIAID) && actu.CLCHKID.Equals(listachk[i].CLCHKID) && actu.CLCHKPROID.Equals(listachk[i].CLCHKPROID) && actu.CLCHKACTID.Equals(listachk[i].CLCHKACTID) && actu.CLCHKIMGLIN.Equals(listachk[i].CLCHKIMGLIN));
                                    ima.CLCHKIMGSTORAGE = 1;
                                    try
                                    {
                                        CLCHKTAR tarea = dc.CLCHKTAR.FirstOrDefault(tar => tar.CMCIAID.Equals(listachk[i].CMCIAID) && tar.CLCHKID.Equals(listachk[i].CLCHKID) && tar.CLCHKPROID.Equals(listachk[i].CLCHKPROID) && tar.CLCHKACTID.Equals(listachk[i].CLCHKACTID) && tar.CLCHKTARLIN.Equals(listachk[i].CLCHKIMGLIN));
                                        tarea.CLCHKTARTXC = listadato[0].IdUrl + listadato[0].IdBucket + '/' + obj1.Name.ToString();
                                        dc.SubmitChanges();
                                    }
                                    catch (Exception)
                                    {
                                        Console.WriteLine("Los datos no coinciden en la tabla CLCHKTAR", listachk[i].CMCIAID + "-" + listachk[i].CLCHKID + "-" + listachk[i].CLCHKPROID + "-" + listachk[i].CLCHKACTID + "-" + listachk[i].CLCHKIMGLIN);
                                    }
                                    finally
                                    {
                                    }
                                }
                                catch (Google.GoogleApiException e)
                                {
                                    // The bucket already exists.  That's fine.
                                    // throw e;
                                }
                            }
                        }
                    }
                }
                else
                {
                    //liberar memoria
                    break;
                }
            }
        }