示例#1
0
        public void ExportJavaScriptAsync(string pathFileName, Action <string> callback)
        {
            var scripts = new List <JavaScriptBackup>();

            using (var context = new ZvsContext(EntityContextConnection))
            {
                foreach (var script in context.JavaScriptCommands)
                {
                    var scriptBackup = new JavaScriptBackup
                    {
                        Script           = script.Script,
                        Name             = script.Name,
                        UniqueIdentifier = script.UniqueIdentifier,
                        ArgumentType     = (int)script.ArgumentType,
                        Description      = script.Description,
                        CustomData1      = script.CustomData1,
                        CustomData2      = script.CustomData2,
                        Help             = script.Help,
                        SortOrder        = script.SortOrder
                    };
                    scripts.Add(scriptBackup);
                }
            }

            Stream stream = null;

            try
            {
                stream = File.Open(pathFileName, FileMode.Create);
                var xmlSerializer = new XmlSerializer(typeof(List <JavaScriptBackup>));
                xmlSerializer.Serialize(stream, scripts);
                callback($"Exported {scripts.Count} JavaScript commands to '{Path.GetFileName(pathFileName)}'");
            }
            catch (Exception e)
            {
                callback("Error saving " + pathFileName + ": (" + e.Message + ")");
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }
        }
        public void ExportJavaScriptAsync(string pathFileName, Action<string> callback)
        {
            var scripts = new List<JavaScriptBackup>();
            using (var context = new ZvsContext(EntityContextConnection))
            {
                foreach (var script in context.JavaScriptCommands)
                {
                    var scriptBackup = new JavaScriptBackup
                    {
                        Script = script.Script,
                        Name = script.Name,
                        UniqueIdentifier = script.UniqueIdentifier,
                        ArgumentType = (int) script.ArgumentType,
                        Description = script.Description,
                        CustomData1 = script.CustomData1,
                        CustomData2 = script.CustomData2,
                        Help = script.Help,
                        SortOrder = script.SortOrder
                    };
                    scripts.Add(scriptBackup);
                }
            }

            Stream stream = null;
            try
            {
                stream = File.Open(pathFileName, FileMode.Create);
                var xmlSerializer = new XmlSerializer(typeof(List<JavaScriptBackup>));
                xmlSerializer.Serialize(stream, scripts);
                callback($"Exported {scripts.Count} JavaScript commands to '{Path.GetFileName(pathFileName)}'");
            }
            catch (Exception e)
            {
                callback("Error saving " + pathFileName + ": (" + e.Message + ")");
            }
            finally
            {
                if (stream != null)
                    stream.Close();
            }
        }