Example #1
0
        public void Store(string name, PyDataType data, long timestamp)
        {
            PyCacheHint hint = PyCacheHint.FromPyObject(name, data, timestamp, this.mContainer.NodeID);

            // save cache hint
            this.mCacheHints[name] = hint;
            // save cache object
            this.mCacheData[name] = PyCachedObject.FromCacheHint(hint, data);
        }
Example #2
0
        public void Store(string name, PyDataType data, long timestamp)
        {
            byte[] marshalData = Marshal.ToByteArray(data);

            PyCacheHint hint = PyCacheHint.FromPyObject(name, marshalData, timestamp, this.mContainer.NodeID);

            // save cache hint
            this.mCacheHints[name] = hint;
            // save cache object
            this.mCacheData[name] = PyCachedObject.FromCacheHint(hint, marshalData);
        }
Example #3
0
        public void StoreCall(string service, string method, PyDataType data, long timestamp)
        {
            byte[] marshalData = Marshal.ToByteArray(data);

            string      index    = $"{service}::{method}";
            PyDataType  objectID = this.GenerateObjectIDForCall(service, method);
            PyCacheHint hint     = PyCacheHint.FromPyObject(objectID, marshalData, timestamp, this.mContainer.NodeID);

            // save cache hint
            this.mCacheHints[index] = hint;
            // save cache object
            this.mCacheData[index] = PyCachedObject.FromCacheHint(hint, marshalData);
        }
Example #4
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem == null)
            {
                richTextBox2.Text = "";
                return;
            }

            if (Cache.UpdateCache(listBox1.SelectedItem.ToString()) == false)
            {
                WindowLog.Error("Main::LoadCache", "Error loading cache");
                return;
            }

            PyObject cache = Cache.GetCache(listBox1.SelectedItem.ToString());

            PyCachedObject obj = new PyCachedObject();

            if (obj.Decode(cache) == false)
            {
                WindowLog.Error("Main::LoadCache", "Cannot decode the cache data");
                return;
            }

            if (Program.cacheDataDisplayMode == "Pretty")
            {
                try
                {
                    richTextBox2.Text = PrettyPrinter.Print(Unmarshal.Process <PyObject>(obj.cache.Data));
                }
                catch (Exception)
                {
                    WindowLog.Error("Main::LoadCache", "Cannot Unmarshal the cache data");
                    richTextBox2.Text = "Error";
                }
            }
            else
            {
                richTextBox2.Text = ByteToString(obj.cache.Data);
            }

            WindowLog.Debug("Main::LoadCache", "Cache loaded");
        }
Example #5
0
        private void button5_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem == null)
            {
                Message.Error("Main::SaveFile", "Debes elejir la cache a guardar");
                return;
            }

            saveFileDialog1.Filter = "Archivos de cache(*.cache)|*.cache";
            if (saveFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            PyObject cache = Cache.GetCache(listBox1.SelectedItem.ToString());

            PyCachedObject obj = new PyCachedObject();

            if (obj.Decode(cache) == false)
            {
                Message.Error("Main::SaveFile", "No se pudo obtener la información correctamente");
                return;
            }

            if (File.Exists(saveFileDialog1.FileName) == true)
            {
                try
                {
                    File.Delete(saveFileDialog1.FileName);
                }
                catch (Exception)
                {
                }
            }

            FileStream fp = File.OpenWrite(saveFileDialog1.FileName);

            fp.Write(obj.cache.Data, 0, obj.cache.Data.Length);

            fp.Close();

            WindowLog.Debug("Main::SaveFile", "Cache saved sucessful");
        }
Example #6
0
        public static PyObject GetCache(string name)
        {
            if (LoadCacheFor(name) == false)
            {
                return(null);
            }

            PyTuple info = cacheData[name];

            PyCachedObject obj = new PyCachedObject();

            obj.nodeID     = info.Items[2].As <PyIntegerVar>().Value;
            obj.objectID   = new PyString(name);
            obj.shared     = 0;
            obj.compressed = 0;
            obj.cache      = info.Items[0].As <PyBuffer>();
            obj.timestamp  = info.Items[1].As <PyLongLong>().Value;
            obj.version    = info.Items[3].As <PyIntegerVar>().Value;

            return(obj.Encode());
        }
Example #7
0
        public static PyObject GetUserCache(int user, string name)
        {
            if (LoadUserCacheFor(user, name) == false)
            {
                return(null);
            }

            // We can assume this will not throw any exception as we've just checked if it exists
            PyTuple info = userCacheData[user][name];

            PyCachedObject obj = new PyCachedObject();

            obj.nodeID     = info.Items[2].As <PyIntegerVar>().Value;
            obj.objectID   = new PyString(name);
            obj.shared     = 0;
            obj.compressed = 0;
            obj.cache      = info.Items[0].As <PyBuffer>();
            obj.timestamp  = info.Items[1].As <PyLongLong>().Value;
            obj.version    = info.Items[3].As <PyIntegerVar>().Value;

            return(obj.Encode());
        }
Example #8
0
        private void copiaDeSeguridadCompletaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (Message.Ask("Main::CompleteBackup", "¿Seguro que deseas hacer una copia de seguridad de toda la cache? Esto puede llevar varios minutos") == DialogResult.No)
            {
                return;
            }

            folderBrowserDialog1.Description = "Elije la carpeta de destino";
            if (folderBrowserDialog1.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            bool asked = false;

            foreach (string name in cacheNames)
            {
                WindowLog.Debug("Main::CompleteBackup", "Saving cache " + name + " to file");

                string   filename = folderBrowserDialog1.SelectedPath + "/" + name + ".cache";
                PyObject cache    = Cache.GetCache(name);

                PyCachedObject obj = new PyCachedObject();

                if (obj.Decode(cache) == false)
                {
                    Message.Error("Main::CompleteBackup", "No se pudo obtener la información correctamente");
                    return;
                }

                if (File.Exists(filename) == true)
                {
                    if (!asked)
                    {
                        if (Message.Ask("Main::CompleteBackup", "Uno o más archivos ya existen, ¿desea reemplazarlos?") == DialogResult.No)
                        {
                            WindowLog.Error("Main::CompleteBackup", "Cancelled by the user");
                            return;
                        }
                    }

                    asked = true;

                    try
                    {
                        File.Delete(filename);
                    }
                    catch (Exception)
                    {
                    }
                }

                FileStream fp = File.OpenWrite(filename);

                fp.Write(obj.cache.Data, 0, obj.cache.Data.Length);

                fp.Close();

                WindowLog.Debug("Main::CompleteBackup", "Cache " + name + " saved correctly");
            }

            Message.Info("Main::CompleteBackup", "Cache guardada en " + folderBrowserDialog1.SelectedPath + " con éxito");
        }