public void ItemAddedToListEventHandler(ClientContext clientContext, Guid listId, int listItemId)
        {
            try
            {
                List news = clientContext.Web.Lists.GetById(listId);
                ListItem item = news.GetItemById(listItemId);
                clientContext.Load(item);
                clientContext.ExecuteQuery();

                string itemTitle = item["Title"].ToString();
                string itemBody = item["Body"].ToString();
                string itemArticle = item["Article"].ToString();
                string itemDate = item["Date"].ToString();

                var storageAccount = CloudStorageAccount.Parse(
                CloudConfigurationManager.GetSetting("StorageConnectionString"));

                var client = storageAccount.CreateCloudTableClient();

                var stebraTable = client.GetTableReference("StebraNyhetsList");

                if (!stebraTable.Exists())
                {
                    stebraTable.Create();
                }

                var newsEntry = new StebraEntity("Nyhet", itemTitle, itemBody, itemArticle, itemDate);

                var batchOperation = new TableBatchOperation();
                batchOperation.Insert(newsEntry);
                stebraTable.ExecuteBatch(batchOperation);
                Global.globalError += "242-";
            }

            catch (Exception oops)
            {
                System.Diagnostics.Trace.WriteLine(oops.Message);
                Global.globalError += "248-";
            }
            Global.globalError += "250-";
        }
        public void FirstTimeInstall(ClientContext clientContext)
        {
            List nyhetsLista = clientContext.Web.Lists.GetByTitle(LIST_TITLE);

            CamlQuery camlQuery = new CamlQuery();
            camlQuery.ViewXml = "<View><Query><Where><IsNotNull><FieldRef Name='Title'/>" +
                "</IsNotNull></Where></Query></View>";
            ListItemCollection items = nyhetsLista.GetItems(camlQuery);

            clientContext.Load(items);
            clientContext.ExecuteQuery();

            //foreach (ListItem item in items)
            //{
            if (Global.globalX != items.Count)
            {
                var storageAccount = CloudStorageAccount.Parse(
                   CloudConfigurationManager.GetSetting("StorageConnectionString"));

                var client = storageAccount.CreateCloudTableClient();

                var stebraTable = client.GetTableReference("StebraNyhetsList");

                if (!stebraTable.Exists())
                {
                    stebraTable.Create();
                }
                int i = 0;

                for (i = 0; i < items.Count; i++)
                {

                    ListItem item = items[i];
                    string itemTitle = item["Title"].ToString();
                    string itemBody = item["Body"].ToString();
                    string itemArticle = item["Article"].ToString();
                    string itemDate = item["Date"].ToString();

                    var newsEntry = new StebraEntity("Nyhet", itemTitle, itemBody, itemArticle, itemDate);

                    var batchOperation = TableOperation.InsertOrReplace(newsEntry);
                    stebraTable.Execute(batchOperation);

                    Global.globalX++;
                }

            }
        }