Exemplo n.º 1
0
 static void PrintDeleteProgress(
     SlackFile file, int processed, int total)
 {
     Console.WriteLine(
         "[{0} / {1}] Deleting '{2}'",
         processed, total, file.Name);
 }
Exemplo n.º 2
0
 public async Task DownloadFile(string slackKey, SlackFile file, string path)
 {
     await file.UrlPrivateDownload
     .AbsoluteUri
     .WithOAuthBearerToken(slackKey)
     .DownloadFileAsync(path, file.Name);
 }
Exemplo n.º 3
0
        static void DeleteFiles(string token, List <SlackFile> files)
        {
            for (int i = 0; i < files.Count; i++)
            {
                SlackFile currentFile = files[i];

                PrintDeleteProgress(currentFile, i + 1, files.Count);

                if (!DeleteFileWithRetries(token, currentFile.FileId))
                {
                    PrintDeleteError(currentFile);
                }
            }
        }
        public async Task should_download_file_with_given_slack_key(
            string slackKey,
            SlackFile slackFile,
            string path)
        {
            // given

            // when
            await _fileClient.DownloadFile(slackKey, slackFile, path);

            // then
            _httpTest
            .ShouldHaveCalled(slackFile.UrlPrivateDownload.AbsoluteUri)
            .WithOAuthBearerToken(slackKey)
            .Times(1);
        }
Exemplo n.º 5
0
        private void PopulateTreeView(SlackFile slackFile)
        {
            var priorSlackFile = _treeView.Tag as SlackFile;

            priorSlackFile?.Save();
            _treeView.Nodes.Clear();
            _treeView.Tag = slackFile;
            var elementsWithNoChildElements = new List <XElement>();

            foreach (var channelElement in slackFile.RootData.Elements("channel"))
            {
                if (!channelElement.HasElements)
                {
                    elementsWithNoChildElements.Add(channelElement);
                    continue;
                }
                var channelNode = new TreeNode(channelElement.Attribute("uiName").Value)
                {
                    Tag = channelElement
                };
                _treeView.Nodes.Add(channelNode);
                foreach (var messageElement in channelElement.Elements("messagesForDate"))
                {
                    if (!messageElement.HasElements)
                    {
                        elementsWithNoChildElements.Add(messageElement);
                        continue;
                    }
                    var dateNode = new TreeNode(messageElement.Attribute("date").Value)
                    {
                        Tag = messageElement
                    };
                    channelNode.Nodes.Add(dateNode);
                }
            }
            if (!elementsWithNoChildElements.Any())
            {
                return;
            }
            foreach (var elementWithNoChildElements in elementsWithNoChildElements)
            {
                elementWithNoChildElements.Remove();
            }
            slackFile.Save();
        }
Exemplo n.º 6
0
 public async Task Download(SlackFile file, String path)
 {
     var client = _connectionFactory.CreateFileClient();
     await client.DownloadFile(SlackKey, file, path);
 }
Exemplo n.º 7
0
        /// <summary>
        ///          Index all files of a channel
        /// </summary>
        /// <param name="channelName">Channel name for logging</param>
        /// <param name="channel">Json object which contains messages</param>
        /// <returns></returns>
        public bool IndexChannelFiles(string channelName, JsonObject channel)
        {
            Sys.Log("Index Files of '" + channelName + "'");
            bool      ok  = true;
            SlackFile doc = new SlackFile();

            doc.cntr = this;
            if (Connector.IsModeRealTime())
            {
                Sys.Log("Index files from date: " + Connector.RealTimeReferenceDate);
            }
            string latest = Connector.IsModeRealTime() ? Sys.ToStr(Dat.ToUnixTimestamp(Connector.RealTimeReferenceDate)) : "";

            bool has_more = false;
            int  page     = 0;
            int  pages    = 1;

            do
            {
                //iterate on all files by page (has_more = true)
                has_more = false;
                page++;
                JsonObject response = slackGet("files.list?channel=" + channel.ValueStr("id") + "&ts_from=" + latest + "&page=" + page) as JsonObject;
                if (response == null || (response != null && !response.ValueBoo("ok")))
                {
                    Sys.LogError(Json.Serialize(response)); return(false);
                }
                if (response != null)
                {
                    pages    = response.ValueInt("paging.pages");
                    has_more = response.ValueBoo("has_more", false);
                    JsonArray files = response.GetAsArray("files");
                    if (files != null)
                    {
                        for (int i = 0; i < files.EltCount(); i++)
                        {
                            //clear and reuse the doc instance
                            doc.Clear();

                            //current message
                            JsonObject file = files.Elt(i) as JsonObject;

                            //set custom to connectorDoc (slackDoc)
                            doc.channel = channel;
                            doc.file    = file;

                            //set mandatory fields: id, fileext & version
                            doc.Id      = file.GetValue("id");
                            doc.Version = file.GetValue("timestamp");
                            string mimetype = file.GetValue("mimetype");
                            if (Str.EQ(mimetype, "text/html"))
                            {
                                doc.FileExt = "htm";
                            }
                            else
                            {
                                doc.FileExt = Str.PathGetFileExt(file.GetValue("name"));
                            }


                            //set latest for Slack API Pagination
                            latest = doc.Version;

                            //Process Doc (send to Indexer)
                            ok &= Connector.ProcessConnectorDoc(doc);
                        }
                    }
                }
            }while (page < pages);
            return(ok);
        }
Exemplo n.º 8
0
 static void PrintDeleteError(SlackFile file)
 {
     Console.WriteLine(
         "Error deleting the file '{0}'",
         file.Name);
 }
Exemplo n.º 9
0
 public async Task <SlackResponse> RemoveStarAsync(SlackFile file)
 {
     return(await GetApiData <SlackResponse>(ApiCommands.RemoveStar, null,
                                             new KeyValuePair <string, string>("file", file.Id)));
 }
Exemplo n.º 10
0
 public async Task <SlackResponse> RemoveReactionAsync(SlackFile file, string emojiName)
 {
     return(await GetApiData <SlackResponse>(ApiCommands.RemoveReaction, null,
                                             new KeyValuePair <string, string>("file", file.Id),
                                             new KeyValuePair <string, string>("name", emojiName)));
 }
Exemplo n.º 11
0
 public ReactionAddedEventArgs(string reaction, SlackUser user, SlackFile file)
 {
     User     = user;
     Reaction = reaction;
     File     = file;
 }