Пример #1
0
        /// <summary>
        /// Get asset details
        /// </summary>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static async Task <AssetData> GetAssetDetails(IConfiguration configuration)
        {
            SharePointRepository repository = new SharePointRepository(configuration);
            var data = await repository.GetAllItemsAsync <DocumentLibrary>(configuration["StagingFolder"]);

            string readFileFromTemp = System.IO.File.ReadAllText(@"Temp/TempFile.txt");
            string filename         = Path.GetFileName(readFileFromTemp).Split('_')[1];

            var recentFile = data.ToList().Where(x => x.Name.ToLower().Contains(filename.ToLower())).FirstOrDefault();

            string[] submitter        = System.IO.File.ReadAllText(@"Temp/UserFile.txt").Split(',');
            var      submitterDetails = await GetUserDetails(configuration, submitter[1]);

            string ownerId = await GetManagerId(configuration);

            var approverName = await GetUserDetails(configuration, ownerId);

            AssetData assetData = new AssetData();

            assetData.ApproverName     = approverName.displayName;
            assetData.DateOfSubmission = recentFile.TimeLastModified;
            assetData.NameOfDocument   = recentFile.Name;
            assetData.SubmittedBy      = submitterDetails.displayName;
            assetData.SubitteTo        = configuration["ApprovedFolder"];
            assetData.DocName          = filename;
            assetData.url      = configuration["BaseURL"] + recentFile.ServerRelativeUrl;
            assetData.userMRI  = ownerId;
            assetData.userChat = "https://teams.microsoft.com/l/chat/0/0?users=" + submitterDetails.mail;
            return(assetData);
        }
Пример #2
0
        /// <summary>
        /// Gets the configuration value by key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns>returns configuration key.</returns>
        public static string GetConfigurationValueByKey(string key)
        {
            string returnValue = null;

            try
            {
                returnValue = SharePointRepository.GetConfigValueByKey(key);
            }
            catch (Exception)
            {
                throw;
            }

            return(returnValue);
        }
Пример #3
0
        /// <summary>
        /// Gets the configuration details from SharePoint.
        /// </summary>
        /// <returns>returns configuration details object.</returns>
        public static IList <Core.Models.ConfigurationDetails> GetConfigurationDetailsFromSharepoint()
        {
            IList <Core.Models.ConfigurationDetails> returnValue = null;

            try
            {
                returnValue = SharePointRepository.GetConfigurationDetails().ToList();
            }
            catch (Exception)
            {
                throw;
            }

            return(returnValue);
        }
Пример #4
0
 public IList <ImageGallery> GetNews()
 {
     try
     {
         var repositorySharePoint = new SharePointRepository <ImageGallery>(this.List.ParentWeb, this.Logger,
                                                                            this.List.Title, this.Items);
         var imageCollection = repositorySharePoint.GetAll();
         return(imageCollection.ToList());
     }
     catch (Exception exception)
     {
         this.Logger.Error(string.Concat("Error GetNews", exception.Message));
         return(null);
     }
 }
Пример #5
0
        /// <summary>
        /// Inserts the configuration values in SharePoint.
        /// </summary>
        /// <param name="configDetails">The configuration details.</param>
        /// <returns>returns number of rows inserted.</returns>
        public static int InsertConfigurationValuesInSharepoint(List <Core.Models.ConfigurationDetails> configDetails)
        {
            try
            {
                foreach (Core.Models.ConfigurationDetails config in configDetails)
                {
                    SharePointRepository.InsertConfigurationDetails(config.Key, config.Value);
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(1);
        }
        public IList<ImageGallery> GetNews()
        {
            try
            {
                var repositorySharePoint = new SharePointRepository<ImageGallery>(this.List.ParentWeb, this.Logger,
                    this.List.Title, this.Items);
                var imageCollection = repositorySharePoint.GetAll();
                return imageCollection.ToList();
            }
            catch (Exception exception)
            {
                this.Logger.Error(string.Concat("Error GetNews",exception.Message));
                return null;
            }

        }
        public static void DemoRun()
        {
            // We have defined an interface IRepository
            // And we implement 2 classes SQL and SharePoint
            // which does serve the common purpose to Save and Retrieve the recods.
            // Observe, with this design, we are making the classes
            // to be extendible but not modifiable.
            // These classes can be further extended to add more features
            // but need not have to be modified.

            // SQL way
            IRepositoryConnection connection = new SQLRepositoryConnection();
            IRepository           repository = new SQLRepository(connection);
            AppData data = repository.Retrieve(1);

            repository.Save(data);

            // SharePoint way
            connection = new SharePointRepositoryConnection();
            repository = new SharePointRepository(connection);
            data       = repository.Retrieve(1);
            repository.Save(data);
        }
Пример #8
0
        public async Task <IActionResult> Upload(FileUploadViewModel fileUpload)
        {
            if (ModelState.IsValid)
            {
                string uploadsfolder  = Path.Combine(this.hostingEnvironment.WebRootPath, "Files");
                string uniqueFileName = Guid.NewGuid().ToString() + "_" + fileUpload.File.FileName;
                string fileLocation   = @"wwwroot/Files/" + uniqueFileName;
                if (fileUpload.File != null)
                {
                    // Write it to server.
                    using (FileStream fs = System.IO.File.Create(fileLocation))
                    {
                        await fileUpload.File.CopyToAsync(fs);
                    }

                    SharePointRepository repository = new SharePointRepository(configuration);

                    if (await repository.UploadFileToSPAsync(fileLocation, true))
                    {
                        var tempFilePath = @"Temp/TempFile.txt";
                        System.IO.File.WriteAllText(tempFilePath, fileLocation);

                        //send the card to channel based on team member role
                        ChannelHandler channelHandler = new ChannelHandler();
                        await channelHandler.SendConversation(configuration);

                        return(View("Create"));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Failed to upload your file. Please try again later.");
                    }
                }
            }

            return(View(fileUpload));
        }
Пример #9
0
        private static void Main()
        {
            const string urlSharePointOnpremise = "urlsiteSharePoint";
            const string listName = "Employed";
            using (var site = new SPSite(urlSharePointOnpremise))
            {
                var web = site.OpenWeb();
                var list = web.Lists.TryGetList(listName);
                if (list == null)
                {
                    var createList= web.CreateList(listName, "List of Employed of my Company", TypeList.GenericList, false,
                        typeof (Employed));
                    Console.WriteLine(string.Concat("List Employed Created", createList));
               }

                var employed = new Employed
                {
                    Country = "Spain",
                    DateBorn = new DateTime(1981, 5, 10),
                    Job = "Sofware Architect",
                    LastName = "Diaz Cervera",
                    Name = "Adrian"
                };

                var employed2 = new Employed
                {
                    Country = "Spain",
                    DateBorn = new DateTime(1979, 5, 10),
                    Job = "Head of Innovation",
                    LastName = "Diaz Martin",
                    Name = "Alberto"
                };

                var  logger = new LogManager().GetLogger(new System.Diagnostics.StackTrace().GetFrame(0)); ;
                var repository= new SharePointRepository<Employed>(web,logger,listName,10);

                var  resultInsert= repository.Insert(employed);
                Console.WriteLine(string.Concat("Insertado el elemento: ", resultInsert));
                resultInsert = repository.Insert(employed2);
                Console.WriteLine(string.Concat("Insertado el elemento: ", resultInsert));

                var employed3= repository.Get(resultInsert);
                Console.WriteLine(string.Concat("Return employed: ", employed3.Name));
                var employedCollection= repository.GetAll();
                Console.WriteLine(string.Concat("Count Employed: ", employedCollection.Count));                
                var resultBool = repository.Delete(resultInsert);
                Console.WriteLine(string.Concat("Elemento Eliminado ", resultBool));
                employedCollection = repository.GetAll();
                Console.WriteLine(string.Concat("Count Employed: ", employedCollection.Count));
                var queryCaml = @"<Where>
                                      <Eq>
                                         <FieldRef Name='Name' />
                                         <Value Type='Text'>Adrian</Value>
                                      </Eq>
                                   </Where>";
                var queryCollection = repository.Query(queryCaml, 1);
                Console.WriteLine(string.Concat("Count Employed: ", queryCollection.Count));               
                var query = new Query().Where().Field("Name",string.Empty).Operator(TypeOperators.Eq).Value("Text","Adrian");
                queryCollection = repository.Query(query, 1);
                Console.WriteLine(string.Concat("Count Employed: ", queryCollection.Count));
                var firstEmployed = queryCollection.FirstOrDefault();
                firstEmployed.Name = "Alberto Javier";
                var updateOperation= repository.Save(Convert.ToInt32(firstEmployed.ID), firstEmployed);
                Console.WriteLine(string.Concat("Update Employed: ", updateOperation));                
                Console.ReadLine();
            }
        }
        // Uncomment the method below to handle the event raised after a feature has been activated.

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            var site = properties.Feature.Parent as SPSite;
            var web = site.RootWeb;
            ILog log = new LogManager().GetLogger(new StackTrace().GetFrame(0)); ;
            var columnSiteCollection = web.CreateColumnSite("Image Galery", typeof(ImageGallery));
            web.CreateContentType(Constants.ContentType.ImageGallery, "Enmarcha ContentType", "Elemento", columnSiteCollection);
            web.CreateList(Constants.List.ImageGallery, "Lista de la galeria de imagenes", TypeList.GenericList, true);
            var list = web.Lists.TryGetList(Constants.List.ImageGallery);
            if (list != null)
            {
                list.AddContentTypeLibrary("Image Galery");
                var repository = new SharePointRepository<ImageGallery>(web, log, Constants.List.ImageGallery, 40);
                IList<ImageGallery> collection = new List<ImageGallery>
                {
                    new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/01.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/01.jpg" },
                    OpenWindows = true,
                    Visible = true
                },
                       new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/02.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/02.jpg" },
                    OpenWindows = true,
                    Visible = true
                },
                          new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/03.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/03.jpg" },
                    OpenWindows = true,
                    Visible = true
                },
                             new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/04.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/04.jpg" },
                    OpenWindows = true,
                    Visible = true
                },
                                new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/05.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/05.jpg" },
                    OpenWindows = true,
                    Visible = true
                },
                                   new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/06.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/06.jpg" },
                    OpenWindows = true,
                    Visible = true
                },
                                      new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/07.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/07.jpg" },
                    OpenWindows = true,
                    Visible = true
                },   new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/08.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/08.jpg" },
                    OpenWindows = true,
                    Visible = true
                },
                                         new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/09.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/09.jpg" },
                    OpenWindows = true,
                    Visible = true
                },
                                         new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/10.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/10.jpg" },
                    OpenWindows = true,
                    Visible = true
                }
                                         ,
                                         new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/11.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/11.jpg" },
                    OpenWindows = true,
                    Visible = true
                }
                                         ,
                                         new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/12.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/12.jpg" },
                    OpenWindows = true,
                    Visible = true
                },
                                         new ImageGallery
                {
                    Description = string.Empty,
                    Image = new UrlField { Description = "Image", Url = "/Style%20Library/Images/09.jpg"},
                    UrlNew = new UrlField { Description = "New", Url = "/Style%20Library/Images/09.jpg" },
                    OpenWindows = true,
                    Visible = true
                }

                };
                foreach (var element in collection)
                {
                    repository.Insert(element);
                }


            }
        }