Esempio n. 1
0
        public static string ToFriendlyString(this ChatFlow chatFlow)
        {
            switch (chatFlow)
            {
            case ChatFlow.FreeFlow: return("Free flow");

            case ChatFlow.LineByLine: return("Line by line");

            default: return(chatFlow.ToString());
            }
        }
Esempio n. 2
0
        public bool SaveChatFlowProject()
        {
            try
            {
                if (ChatFlow != null)
                {
                    if (string.IsNullOrWhiteSpace(ProjectFilePath))
                    {
                        var saveFileDialog = new SaveFileDialog()
                        {
                            FileName         = "ChatProject.anaproj",
                            Filter           = "ANA Project Files | *.anaproj",
                            AddExtension     = true,
                            CheckPathExists  = true,
                            InitialDirectory = Settings.ANADocumentsDirectory,
                            OverwritePrompt  = true,
                            Title            = "Specify the ANA Project save location",
                            ValidateNames    = true
                        };
                        var done = saveFileDialog.ShowDialog();
                        if (done != true)
                        {
                            return(false);
                        }
                        ProjectFilePath = saveFileDialog.FileName;
                    }

                    var rawProjectJson = ChatFlow.ToJson();
                    File.WriteAllText(ProjectFilePath, rawProjectJson);
                    LastChatFlowSavedHash = Utilities.GenerateHash(rawProjectJson);

                    if (!Utilities.Settings.RecentChatFlowFiles.Contains(ProjectFilePath))
                    {
                        Utilities.Settings.RecentChatFlowFiles.Insert(0, ProjectFilePath);
                        Utilities.Settings.Save(App.Cryptio);
                    }

                    return(true);
                }
                MessageBox.Show("Chat flow project Not loaded properly!", "Unable to save the flow");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Unable to save the flow");
            }
            return(false);
        }
Esempio n. 3
0
        public bool AreChatFlowChangesMadeAfterLastSave()
        {
            if (!IsProjectLoaded(false))
            {
                return(false);
            }
            if (string.IsNullOrWhiteSpace(LastChatFlowSavedHash))
            {
                return(true);
            }

            var currentHash = Utilities.GenerateHash(ChatFlow.ToJson());

            if (LastChatFlowSavedHash == currentHash)
            {
                return(false);                //no changes
            }
            return(true);
        }
Esempio n. 4
0
        public (bool, string) LoadChatFlowProject()
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(ProjectFilePath))
                {
                    var rawProjectJson = File.ReadAllText(ProjectFilePath);
                    ChatFlow = BsonSerializer.Deserialize <ChatFlowPack>(rawProjectJson);
                }
                else
                {
                    var firstNode = new ChatNode {
                        Name = "New Node"
                    };
                    firstNode.Id = ObjectId.GenerateNewId().ToString();

                    ChatFlow = new ChatFlowPack
                    {
                        ChatNodes     = new List <ChatNode>(new[] { firstNode }),
                        ChatContent   = new List <Models.BaseContent>(),
                        NodeLocations = new Dictionary <string, Models.LayoutPoint> {
                            { firstNode.Id, new Models.LayoutPoint {
                                  X = 500, Y = 500
                              } }
                        }
                    };
                }
                LastChatFlowSavedHash = Utilities.GenerateHash(ChatFlow.ToJson());
                ChatFlowBuilder.Build(ChatFlow);
                return(true, "");
            }
            catch (Exception ex)
            {
                return(false, ex.Message);
            }
        }