예제 #1
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document doc = commandData.Application.ActiveUIDocument.Document;

            ParameterCommands.Load(doc);
            SlackForm slackForm = new SlackForm();

            slackForm.ShowDialog();

            if (slackForm.DialogResult == DialogResult.OK)
            {
                Autodesk.Revit.ApplicationServices.Application app = doc.Application;

                if (doc.IsFamilyDocument)
                {
                    TaskDialog.Show("Exception", "These settings can only be saved while in a Revit project, not in a Family.");
                }

                SlackSettings s = new SlackSettings();
                s.slackCh            = Variables.slackCh;
                s.slackChId          = Variables.slackChId;
                s.slackOn            = Variables.slackOn;
                s.slackWSWarn        = Variables.slackWSWarn;
                s.slackModelWarn     = Variables.slackModelWarn;
                s.slackBPWarn        = Variables.slackBPWarn;
                s.slackWSInfo        = Variables.slackWSInfo;
                s.slackModelInfo     = Variables.slackModelInfo;
                s.slackBPInfo        = Variables.slackBPInfo;
                s.slackExtraTrackPin = Variables.slackExtraTrackPin;
                s.tidySet            = Variables.tidySet;
                s.giphySet           = Variables.giphySet;
                s.slackToken         = Variables.slackToken;

                ParameterCommands.Set(app, doc, Variables.defNameSettings, s);
            }
            return(Result.Succeeded);
        }
예제 #2
0
        private void appDocOpened(object sender, Autodesk.Revit.DB.Events.DocumentOpenedEventArgs e)
        {
            Variables.logOpenEnd      = DateTime.Now;
            Variables.logOpenDuration = Variables.logOpenEnd - Variables.logOpenStart;

            Autodesk.Revit.ApplicationServices.Application app = sender as Autodesk.Revit.ApplicationServices.Application;
            Document doc = e.Document;

            #region Variables: Document & Application Variables
            string path = GetUNCPath(doc.PathName);

            BasicFileInfo fileInfo = BasicFileInfo.Extract(path);
            FileInfo      f        = new FileInfo(path);

            Variables.logComputerName    = Environment.MachineName;
            Variables.logChangesSaved    = fileInfo.AllLocalChangesSavedToCentral;
            Variables.logFileCentral     = GetUNCPath(fileInfo.CentralPath);
            Variables.logFileCentralName = Path.GetFileName(Variables.logFileCentral);
            Variables.logIsCentral       = fileInfo.IsCentral;
            Variables.logIsWorkshared    = fileInfo.IsWorkshared;
            Variables.logCreatedLocal    = fileInfo.IsCreatedLocal;

            Variables.logFileName = doc.Title;
            Variables.logFilePath = GetUNCPath(doc.PathName);
            Variables.logFileSize = Convert.ToInt32(f.Length / 1000000);

            Variables.logUsername      = app.Username;
            Variables.logVersionBuild  = app.VersionBuild;
            Variables.logVersionName   = app.VersionName;
            Variables.logVersionNumber = app.VersionNumber;
            #endregion

            #region Tracking: Start Logging Pinned Elements
            IEnumerable <Element> a = TrackChanges.Command.GetTrackedElements(doc);
            _start_state = TrackChanges.Command.GetSnapshot(a);
            #endregion


            #region Settings: Load settings if they exist (Extensible Storage)
            ParameterCommands.Load(doc);
            #endregion

            #region Post: Worksharing Warning-Opened Central Model
            bool patheq = string.Equals(Variables.logFileCentral, Variables.logFilePath);

            if (Variables.slackOn && Variables.slackWSWarn)
            {
                if (patheq && Variables.logIsWorkshared)
                {
                    string gif_lg_url = null;
                    string gif_sm_url = null;

                    if (Variables.giphySet > 0)
                    {
                        var    giphyClient = new GiphyClient();
                        string gif_msg     = giphyClient.GetRandomGif("Alarm").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);

                    string text     = "";
                    string channel  = Variables.slackChId;
                    string botname  = "Worksharing Warning";
                    string icon_url = Variables.icon_revit;

                    var attachments = new Attachments
                    {
                        fallback = Variables.logUsername + "has opened the central model",
                        color    = "danger",
                        fields   =
                            new Fields[]
                        {
                            new Fields
                            {
                                title  = "Description",
                                value  = "The user has opened the central model. Close the central model and create a new local file> to work from.",
                                @short = false
                            },
                            new Fields
                            {
                                title  = "User",
                                value  = Variables.logUsername,
                                @short = true
                            },
                            new Fields
                            {
                                title  = "File",
                                value  = Variables.logFileCentralName,
                                @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_ws.Add(resp.ts);
                }
            }
            #endregion

            #region Post: Model Warning-File Size > 300MB
            if (Variables.slackOn && Variables.slackModelWarn)
            {
                string gif_lg_url = null;
                string gif_sm_url = null;

                if (Variables.logFileSize > 300)
                {
                    if (Variables.giphySet > 0)
                    {
                        var    giphyClient = new GiphyClient();
                        string gif_msg     = giphyClient.GetRandomGif("Gasp").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);

                        string text     = "";
                        string channel  = Variables.slackChId;
                        string botname  = "Model Warning";
                        string icon_url = Variables.icon_revit;

                        var attachments = new Attachments
                        {
                            fallback = "The file size has gone above 300MB, time to do some model file size management.",
                            color    = "danger",
                            fields   =
                                new Fields[]
                            {
                                new Fields
                                {
                                    title  = "Description",
                                    value  = "The file size is above 300MB, time to do some model maintenance",
                                    @short = false
                                },
                                new Fields
                                {
                                    title  = "File Size",
                                    value  = Variables.logFileSize.ToString() + "MB",
                                    @short = true
                                },
                                new Fields
                                {
                                    title  = "File",
                                    value  = Variables.logFileCentralName,
                                    @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_model.Add(resp.ts);
                    }
                }
                #endregion

                #region Post: Tracking-Pinned Element-Started

                if (Variables.slackOn && Variables.slackExtraTrackPin)
                {
                    var slackClient = new SlackClient(Variables.slackToken);

                    //Post pinned elements message
                    string text     = "";
                    string channel  = Variables.slackChId;
                    string botname  = "Pinning Info";
                    string icon_url = Variables.icon_revit;


                    var attachments = new Attachments
                    {
                        fallback = Variables.logUsername + "has started tracking pinned elements.",
                        color    = "good",
                        fields   =
                            new Fields[]
                        {
                            new Fields
                            {
                                title  = "Status",
                                value  = Variables.logUsername + " has started tracking pinned elements.\n[" + Variables.logFileCentralName + "]",
                                @short = true
                            }
                        }
                    };

                    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_extra.Add(resp.ts);
                }
                #endregion
            }
        }
예제 #3
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);
            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
        }