Esempio n. 1
0
        /// <summary>
        /// Récupère tous les document d'un dossier sharepoint
        /// </summary>
        /// <param name="relativePath"></param>
        /// <param name="folderName"></param>
        public void GetFiles(string cleOuvrage, string typeOuvrage, Action<Exception, List<Document>> completed, string relativePath = null)
        {
            List<Document> res = new List<Document>();
            Logger.Log(LogSeverity.Information, GetType().FullName, MethodBase.GetCurrentMethod().Name);
            ResetContext();
            if (ContextClientSharePoint != null)
            {
                List list = SharepointList;

                // Recherche tous les fichiers correspondants à l'ouvrage
                CamlQuery query = new CamlQuery();
                query.ViewXml = "<View Scope=\"RecursiveAll\"> " +
                               "<Query>" +
                                   "<Where>" +
                                   (!String.IsNullOrEmpty(typeOuvrage) || !String.IsNullOrEmpty(cleOuvrage) ? "<And>" : "") +
                                           "<Eq>" +
                                               "<FieldRef Name=\"FSObjType\" />" +
                                               "<Value Type=\"Integer\">0</Value>" +
                                            "</Eq>" +
                                           (!String.IsNullOrEmpty(typeOuvrage) && !String.IsNullOrEmpty(cleOuvrage) ?
                                             "<Eq>" +
                                               "<FieldRef Name=\"" + typeOuvrage + "\"/>" +
                                               "<Value Type=\"Text\">" + cleOuvrage + "</Value>" +
                                             "</Eq>"
                                             : !String.IsNullOrEmpty(typeOuvrage) ?
                                             "<IsNotNull>" + "<FieldRef Name=\"" + typeOuvrage + "\"/></IsNotNull>"
                                             : "") +
                                             (!String.IsNullOrEmpty(typeOuvrage) || !String.IsNullOrEmpty(cleOuvrage) ? "</And>" : "") +
                                    "</Where>" +
                               "</Query>" +
                               "</View>";
                if (!String.IsNullOrEmpty(relativePath))
                {
                    query.FolderServerRelativeUrl = relativePath;
                }
                var files = list.GetItems(query);

                ContextClientSharePoint.Load(list);
                ContextClientSharePoint.Load(files);
                ContextClientSharePoint.Load(files, fs => fs.Include(
                  fi => fi["FileLeafRef"],
                  fi => fi["ClePP"],
                  fi => fi["CleEquipement"],
                  fi => fi["ClePortion"],
                  fi => fi["CleEnsembleElectrique"],
                  fi => fi["Archive"],
                  fi => fi["NumEnregistrement"],
                  fi => fi["FileDirRef"],
                  fi => fi.File));
                ContextClientSharePoint.ExecuteQueryAsync((o, e) =>
                {
                    int cle = 0;
                    var resFiles = files.ToList();
                    CleOuvrage? fileTypeOuvrage = String.IsNullOrEmpty(typeOuvrage) ? (CleOuvrage?)null : (CleOuvrage?)Enum.Parse(typeof(CleOuvrage), typeOuvrage, true);
                    string fileCleOuvrage = null;
                    CleOuvrage? currentTypeOuvrage = null;
                    if (typeOuvrage == null || resFiles.Where(f => f.FieldValues[typeOuvrage].ToString() == cleOuvrage).Any())
                    {
                        foreach (var file in resFiles)
                        {
                            currentTypeOuvrage = null;
                            if (fileTypeOuvrage == null)
                            {
                                foreach (CleOuvrage type in Enum.GetValues(typeof(CleOuvrage)))
                                {
                                    fileCleOuvrage = string.Empty + file.FieldValues[type.ToString()];
                                    if (!String.IsNullOrEmpty(fileCleOuvrage) && !"0".Equals(fileCleOuvrage))
                                    {
                                        currentTypeOuvrage = type;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                currentTypeOuvrage = fileTypeOuvrage;
                                fileCleOuvrage = string.Empty + file.FieldValues[typeOuvrage];
                            }
                            // Initialisation de l'entité
                            Document doc = new Document(file.File.Name, (bool)file.FieldValues["Archive"], new TypeDocument(0, Path.GetFileName(Path.GetDirectoryName(file.File.ServerRelativeUrl)), file.File.ServerRelativeUrl));
                            doc.TypeOuvrage = currentTypeOuvrage.Value;
                            doc.NumeroVersion = "" + file.FieldValues["NumEnregistrement"];
                            doc.CleOuvrage = int.Parse(fileCleOuvrage);
                            doc.DateEnregistrement = file.File.TimeLastModified;
                            doc.DocumentUrl = new Uri(ContextClientSharePoint.Url + doc.Designation.ServerRelativeUrl + "/" + doc.Libelle, UriKind.Absolute);
                            doc.ItemId = file.Id;
                            doc.Cle = cle;
                            cle++;
                            res.Add(doc);
                        }
                    }
                    _syncCtxt.Post(unused => completed(null, res), null);
                },
                (o, e) =>
                {
                    Logger.Log(LogSeverity.Error, this.GetType().FullName, e.Exception);
                    _syncCtxt.Post(unused => completed(e.Exception, null), null);
                });

            }
            else
            {
                var ex = new Exception(Resource.TypeDocument_SharepointContextError);
                Logger.Log(LogSeverity.Warning, this.GetType().FullName, ex);
                completed(ex, null);
            }
        }
Esempio n. 2
0
        public static Documentation AddDocToDocumentation(Documentation model, Document doc)
        {
            Documentation outDoc = new Documentation();

            //CLONAGE
            outDoc.cleOuvrage = model.cleOuvrage;
            outDoc.Cle = model.Cle;
            outDoc.CodeEquipement = model.CodeEquipement;
            outDoc.ClePp = model.ClePp;
            outDoc.CleEnsElectrique = model.CleEnsElectrique;
            outDoc.ClePortion = model.ClePortion;
            outDoc.CleEquipement = model.CleEquipement;
            outDoc.LibelleEe = model.LibelleEe;
            outDoc.LibellePortion = model.LibellePortion;
            outDoc.LibelleEquipement = model.LibelleEquipement;
            outDoc.LibellePp = model.LibellePp;
            outDoc.Code = model.Code;
            outDoc.LibelleTypeEquipement = model.LibelleTypeEquipement;
            outDoc.NumeroOrdre = model.NumeroOrdre;
            outDoc.Region = model.Region;

            //AJOUT DU DOC
            outDoc.Designation = doc.Designation;
            outDoc.Dossier = doc.Designation.TypeDossier;
            outDoc.TypeOuvrage = doc.TypeOuvrage;
            outDoc.NumeroVersion = doc.NumeroVersion;
            outDoc.Libelle = doc.Libelle;
            outDoc.DateEnregistrement = doc.DateEnregistrement;
            outDoc.DocumentUrl = doc.DocumentUrl;

            return outDoc;
        }