Exemple #1
0
        /// <summary>
        /// Load a file from disk
        /// </summary>
        /// <param name="fileName">full path of fileName</param>
        /// <returns>object</returns>
        public static LuigiObject Load(string fileName)
        {
            LuigiObject po = null;

            using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                BinaryFormatter bf = new BinaryFormatter();
                try
                {
                    po = bf.Deserialize(fs) as LuigiObject;
                    if (String.IsNullOrEmpty(po.CurrentDirectory))
                    {
                        po.CurrentDirectory = Path.GetDirectoryName(fileName);
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    fs.Close();
                }
            }

            return(po);
        }
Exemple #2
0
 /// <summary>
 /// Constructor with currentDirectory setted
 /// </summary>
 /// <param name="cd">current directory</param>
 public LuigiObject(string cd)
 {
     LuigiObject.InitializePersonalDirectory();
     this.variables        = new Dictionary <string, Accumulate.Accu>();
     this.datas            = new List <string>();
     this.unique           = new Printer.UniqueStrings();
     this.config           = new Printer.Configuration();
     this.types            = new Dictionary <string, Accumulate.Accu>();
     this.copy             = new List <KeyValuePair <string, string> >();
     this.currentDirectory = cd;
 }
Exemple #3
0
        /// <summary>
        /// Save a LuigiObject to memory
        /// You must close the stream after this method
        /// </summary>
        /// <param name="obj">object to save</param>
        /// <param name="stream">stream buffer</param>
        public static void Save(LuigiObject obj, Stream stream)
        {
            BinaryFormatter bf = new BinaryFormatter();

            try
            {
                bf.Serialize(stream, obj);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #4
0
        /// <summary>
        /// Load a file from memory
        /// You must close the stream after this method
        /// </summary>
        /// <param name="stream">stream buffer</param>
        /// <returns>object</returns>
        public static LuigiObject Load(Stream stream)
        {
            LuigiObject     po = null;
            BinaryFormatter bf = new BinaryFormatter();

            try
            {
                po = bf.Deserialize(stream) as LuigiObject;
            }
            catch (Exception)
            {
                throw;
            }

            return(po);
        }
Exemple #5
0
 /// <summary>
 /// Save a LuigiObject to disk
 /// </summary>
 /// <param name="obj">object to save</param>
 /// <param name="fileName">full path of fileName to save</param>
 public static void Save(LuigiObject obj, string fileName)
 {
     using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.Write))
     {
         BinaryFormatter bf = new BinaryFormatter();
         try
         {
             obj.CurrentDirectory = Path.GetDirectoryName(fileName);
             bf.Serialize(fs, obj);
         }
         catch (Exception)
         {
             throw;
         }
         finally
         {
             fs.Close();
         }
     }
 }
Exemple #6
0
        /// <summary>
        /// Clone this object
        /// </summary>
        /// <returns>new object</returns>
        public object Clone()
        {
            LuigiObject newPo = new LuigiObject();

            newPo.Configuration = this.Configuration.Clone() as Printer.Configuration;
            foreach (string key in this.types.Keys)
            {
                newPo.types.Add(key, this.types[key].Clone() as Accumulate.Accu);
            }
            foreach (string s in this.datas)
            {
                newPo.datas.Add(s.Clone() as string);
            }
            newPo.unique = new Printer.UniqueStrings(this.unique.Counter);
            foreach (string key in this.variables.Keys)
            {
                newPo.variables.Add(key, this.variables[key].Clone() as Accumulate.Accu);
            }
            return(newPo);
        }
Exemple #7
0
 /// <summary>
 /// Write output as interpretation result
 /// </summary>
 /// <param name="w">writer</param>
 /// <param name="indentValue">space size</param>
 /// <param name="currentLine">in-progress line add</param>
 /// <param name="conf">configuration data</param>
 public void Execute(TextWriter w, ref int indentValue, ref string currentLine, Printer.Configuration conf)
 {
     foreach (KeyValuePair <string, string> kv in this.copy)
     {
         Accumulate.AccuChild a = Accumulate.Accu.RecursiveFindByName(this.types, this.variables, kv.Key);
         if (kv.Value.StartsWith("$const."))
         {
             string val             = kv.Value.Substring(7);
             Accumulate.AccuChild b = Accumulate.Accu.RecursiveFindByName(this.types, this.variables, "$const.value");
             b.Value = val;
             a.Value = b.Execute(conf, this.CurrentDirectory);
         }
         else
         {
             Accumulate.AccuChild b = Accumulate.Accu.RecursiveFindByName(this.types, this.variables, kv.Value);
             a.Value = b.Execute(conf, this.CurrentDirectory);
         }
     }
     foreach (string e in this.datas)
     {
         if (e.StartsWith("[") && e.EndsWith("]"))
         {
             string r = e.Substring(1, e.Length - 2);
             r = conf.Execute(r);
             // TO DO : execute an accu with its values
             if (this.variables.ContainsKey(r))
             {
                 this.variables[r].Execute(w, ref indentValue, ref currentLine, config);
             }
         }
         else
         {
             string res = conf.Execute(e);
             LuigiObject.IndentSource(w, indentValue, ref currentLine, res);
         }
     }
 }