Exemplo n.º 1
0
        /// <summary>
        /// Create instance of Shareoint manager and initialise the context
        /// </summary>
        /// <param name="spUrl"> SharePoint url</param>
        /// <param name="spUser">UserName</param>
        /// <param name="spPwd">Password</param>
        ///
        public SharePointManager(string spDomain, string spClientId, string spClientSecret, KizeoFormsApiManager kfApiManager_)
        {
            KfApiManager = kfApiManager_;
            Log.Debug($"Configuring Sharepoint Context");
            locky         = new object();
            lockyFileName = new object();
            try
            {
                Context = new AuthenticationManager().GetAppOnlyAuthenticatedContext(spDomain, spClientId, spClientSecret);
                var web = Context.Web;
                lock (locky)
                {
                    Context.Load(web);
                    Context.ExecuteQuery();
                }

                Log.Debug($"Configuration succeeded");
            }
            catch (Exception ex)
            {
                TOOLS.LogErrorAndExitProgram("Error occured while initializing sharepoint config : " + ex.Message);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("en-US");

            // Please don't choose too short time
            int kfToSpsyncTime = 5;
            int spToKfSyncTime = 30;


            try
            {
                XmlConfigurator.Configure();

                Log.Info("Configuration");

                Log.Debug($"Get and serialize config file from : {ConfFile}.");
                Config = GetConfig(ConfFile);
                Log.Debug($"Configuration succeeded");
                Log.Info($"The application will automatically restart in 12 hours to renew SharePoint's access token.");
                Thread t = new Thread(
                    () =>
                {
                    Thread.Sleep(3600 * 12 * 1000);
                    Application.Restart();
                    Environment.Exit(0);
                }
                    );
                t.Start();
                if (Config == null || Config.KizeoConfig == null || Config.SharepointConfig == null)
                {
                    TOOLS.LogErrorAndExitProgram("The config file is empty or some data is missing.");
                }

                KfApiManager = new KizeoFormsApiManager(Config.KizeoConfig.Url, Config.KizeoConfig.Token);
                HttpClient   = KfApiManager.HttpClient;

                SpManager = new SharePointManager(Config.SharepointConfig.SPDomain, Config.SharepointConfig.SPClientId, Config.SharepointConfig.SPClientSecret, KfApiManager);
                Context   = SpManager.Context;


                FillKfExtListsFromSp().Wait();
                FillSpListsFromKfData().Wait();
                UploadExportsToSpLibraries().Wait();

                initTimers(kfToSpsyncTime, spToKfSyncTime);

                Log.Info($"Synchronisation will be executed every {kfToSpsyncTime} minutes.");

                Console.ReadKey();
            }
            catch (Exception EX)
            {
                Log.Fatal(EX);
            }
            finally
            {
                Context.Dispose();
            }
            while (true)
            {
                Console.ReadKey();
            }
        }