private void appDocSynched(object sender, Autodesk.Revit.DB.Events.DocumentSynchronizedWithCentralEventArgs e)
        {
            Variables.logSyncEnd = DateTime.Now;
            Variables.logSyncDuration = Variables.logSyncEnd - Variables.logSyncStart;

            #region Slack Post: Synchronized to Central

            if (Variables.slackOn)
            {
                var giphyClient = new GiphyClient();
                string gif_msg = giphyClient.GetRandomGif("ThumbsUp").Content;
                var gif_resp = JsonConvert.DeserializeObject<Giphy.Response>(gif_msg);
                string gif_url = gif_resp.data.image_url;

                var slackClient = new SlackClient(Variables.slackToken);

                //Delete previous synching message
                slackClient.DeleteMessage(msgts_synch, Variables.slackCh);
                msgts_synch.Clear();

                //Post synched message
                string text = "";
                string channel = Variables.slackChId;
                string botname = "Synching Info";
                //string parse = null;
                //bool linkNames = false;
                //bool unfurl_links = false;
                string icon_url = Variables.icon_revit;
                //string icon_emoji = null;

                var attachments = new Attachments
                {
                    fallback = Variables.logUsername + "has synched",
                    color = "good",
                    fields =
                        new Fields[]
                        {
                            new Fields
                            {
                                title = "Status",
                                value = Variables.logUsername + " has synched to central.\n[" + Variables.logFileCentralName + "]",
                                @short = true
                            },
                            new Fields
                            {
                                title = "Duration",
                                value = string.Format("{0:hh\\:mm\\:ss}", Variables.logSyncDuration),
                                @short = true
                            }
                        },
                    image_url = gif_url
                };

                string msg_response = slackClient.PostMessage(text, channel: channel, botName: botname, attachments: attachments, icon_url: icon_url).Content;
                var resp = JsonConvert.DeserializeObject<ChatPostMessageResponse>(msg_response);

            }
            #endregion
        }
Beispiel #2
0
        private void appDocSynched(object sender, Autodesk.Revit.DB.Events.DocumentSynchronizedWithCentralEventArgs e)
        {
            Variables.logSyncEnd = DateTime.Now;
            Variables.logSyncDuration = Variables.logSyncEnd - Variables.logSyncStart;
            Document doc = e.Document;

            #region Settings: Reload from Extensible Storage
            ParameterCommands.Load(doc);
            #endregion

            #region Extra: Tracking-Report Differences after Sync
            IEnumerable<Element> a = TrackChanges.Command.GetTrackedElements(doc);
            Dictionary<int, string> end_state = TrackChanges.Command.GetSnapshot(a);
            var first = end_state.First();
            string results = TrackChanges.Command.ReportDifferences(doc, _start_state, end_state);
            _start_state = TrackChanges.Command.GetSnapshot(a);

            #endregion

            #region Post: Worksharing Info-Synchronized to Central

            if (Variables.slackOn && Variables.slackWSInfo)
            {
                string gif_lg_url = null;
                string gif_sm_url = null;

                if (Variables.giphySet > 0)
                {
                    var giphyClient = new GiphyClient();
                    string gif_msg = giphyClient.GetRandomGif("ThumbsUp").Content;
                    var gif_resp = JsonConvert.DeserializeObject<Giphy.Response>(gif_msg);

                    if (Variables.giphySet == 1)
                    {
                        gif_sm_url = gif_resp.data.fixed_height_small_url;
                    }
                    if (Variables.giphySet == 2)
                    {
                        gif_lg_url = gif_resp.data.image_url;
                    }

                }
                var slackClient = new SlackClient(Variables.slackToken);

                //Delete previous synching message, if enabled
                if (Variables.tidySet > 0)
                {
                    slackClient.DeleteMessage(msgts_synching, Variables.slackChId);
                    msgts_synching.Clear();
                }

                //Post synched message
                string text = "";
                string channel = Variables.slackChId;
                string botname = "Synching Info";
                string icon_url = Variables.icon_revit;

                var attachments = new Attachments
                {
                    fallback = Variables.logUsername + "has synched",
                    color = "good",
                    fields =
                        new Fields[]
                        {
                            new Fields
                            {
                                title = "Status",
                                value = Variables.logUsername + " has synched to central.\n[" + Variables.logFileCentralName + " (Size: "+ Variables.logFileSize.ToString() + "MB) ]",
                                @short = true
                            },
                            new Fields
                            {
                                title = "Duration",
                                value = string.Format("{0:hh\\:mm\\:ss}", Variables.logSyncDuration),
                                @short = true
                            }
                        },
                    image_url = gif_lg_url,
                    thumb_url = gif_sm_url

                };

                string msg_response = slackClient.PostMessage(text, channel: channel, botName: botname, attachments: attachments, icon_url: icon_url).Content;
                var resp = JsonConvert.DeserializeObject<ChatPostMessageResponse>(msg_response);
                msgts_synching.Add(resp.ts);
            }
            #endregion
        }