public DodoConversion(DodoItem item, DodoApplication app, long delayMs)
            : base(app, delayMs)
        {
            this.Item = item;

            Converter = new Doc2Scribd();
        }
Beispiel #2
0
        public DodoItem GetRecord(long uniqueId)
        {
            DodoItem ret = null;

            using (var conn = CreateConnection())
            {
                using (var cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "select " +
                                      "uniqueId, userId, keywords, modified, registered, type, fileName, " +
                                      "fileContentType, fileSize, boxText, folderId, weight, visible " +
                                      "from poweq1 " +
                                      "where uniqueid = @uniqueId";

                    // SqlUtility.AddParameter(cmd, "uniqueId", uniqueId);
                    cmd.Parameters.AddWithValue("uniqueId", uniqueId);

                    using (var reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            ret = DodoItemBase.GetItem <DodoItem>(
                                app, reader.GetInt64(reader.GetOrdinal("uniqueId")));
                        }
                    }
                }
            }
            return(ret);
        }
Beispiel #3
0
        public DodoItem GetFolder(string id, DodoSession s)
        {
            DodoItem ret = null;

            if (id.CompareTo("-1") == 0)
            {
                // objeto nuevo
                ret          = new DodoItem();
                ret.UniqueId = -1;
                ret.UserId   = s.userId;
            }
            else
            {
                using (var conn = CreateConnection())
                    using (var cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = "select uniqueId from poweq1 where uniqueId = @uniqueId";

                        cmd.Parameters.AddWithValue("uniqueId", id);
                        using (var reader = cmd.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                ret = DodoItemBase.GetItem <DodoItem>(
                                    app, reader.GetInt64(reader.GetOrdinal("uniqueId")));
                            }
                        }
                    }
            }
            return(ret);
        }
Beispiel #4
0
        public EnumStatusPoweq2 GetItem2Status(DodoItem item, string contenType)
        {
            var ret = EnumStatusPoweq2.NOT_EXISTS;

            using (var conn = CreateConnection())
                using (var cmd = conn.CreateCommand())
                {
                    string sql = "select status, p1Modified from {0} "
                                 + "where uniqueId = @uniqueId and fileContentType = @type";

                    cmd.CommandText = string.Format(sql, table_poweq2);
                    cmd.Parameters.AddWithValue("uniqueId", item.UniqueId);
                    cmd.Parameters.AddWithValue("type", contenType);

                    using (var reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            var tmpStatus = reader.GetString(reader.GetOrdinal("status"));
                            ret = (EnumStatusPoweq2)Enum.Parse(typeof(EnumStatusPoweq2), tmpStatus);

                            if (ret == EnumStatusPoweq2.AVAILABLE && false)
                            {
                                var p1Mod = reader.GetDateTime(reader.GetOrdinal("p1Modified"));
                                if (item.modified != p1Mod)
                                {
                                    ret = EnumStatusPoweq2.MODIFIED_ITEM;
                                }
                            }
                        }
                    }
                }

            return(ret);
        }
        public void SetDodoItem(DodoItem item)
        {
            item.ReadBlobValues();

            item.boxBinary       = BoxBinary;
            item.fileSize        = FileSize;
            item.modified        = Registered;
            item.fileContentType = FileContentType;
            item.fileName        = FileName;
        }
Beispiel #6
0
        /// <summary>
        /// añadir y modificar registro
        /// </summary>
        /// <param name="record"></param>
        public void ModifyFolder(ref DodoItem folder, DodoSession s)
        {
            int retErr = 0;

            using (var conn = CreateConnection())
            {
                using (var cmd = conn.CreateCommand())
                {
                    if (folder.UniqueId == -1)
                    {
                        cmd.CommandText = "insert into poweq1 " +
                                          "(uniqueId, userId, folderId, keywords, type, visible, weight, registered, modified) values " +
                                          "(@uniqueId, " +
                                          "@userId, " +
                                          "@folderId, " +
                                          "@keywords, " +
                                          "'folder', " +
                                          "@visible, " +
                                          "100, " +
                                          "CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);";

                        // cmd.CommandText += "SELECT @@IDENTITY";

                        folder.UniqueId = GetCounter();

                        cmd.Parameters.AddWithValue("uniqueId", folder.UniqueId);
                        cmd.Parameters.AddWithValue("userId", folder.UserId);
                        cmd.Parameters.AddWithValue("keywords", folder.Keywords);
                        cmd.Parameters.AddWithValue("visible", folder.Visible);
                        cmd.Parameters.AddWithValue("folderId", folder.FolderId);

                        retErr = cmd.ExecuteNonQuery();
                    }
                    else
                    {
                        cmd.CommandText = "update poweq1 set " +
                                          "keywords = @keywords, " +
                                          "folderId = @folderId, " +
                                          "modified = CURRENT_TIMESTAMP, " +
                                          "visible = @visible " +
                                          "where uniqueId = @uniqueId";

                        cmd.Parameters.AddWithValue("uniqueId", folder.UniqueId);
                        cmd.Parameters.AddWithValue("keywords", folder.Keywords);
                        cmd.Parameters.AddWithValue("folderId", folder.FolderId);
                        cmd.Parameters.AddWithValue("visible", folder.Visible);

                        retErr = cmd.ExecuteNonQuery();
                    }

                    folder = GetFolder(folder.UniqueId.ToString(), s);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// añadir y modificar registro
        /// </summary>
        /// <param name="record"></param>
        public void ModifyRecord(ref DodoItem record)
        {
            using (MySqlConnection conn = CreateConnection())
            {
                using (MySqlCommand cmd = conn.CreateCommand())
                {
                    //  && record.isNewItem
                    if (false)
                    {
                        cmd.CommandText = "insert into poweq1 " +
                                          "(userId, keywords, boxText, type, registered, modified, visible) values " +
                                          "(@userId, " +
                                          "@keywords, " +
                                          "@boxText, " +
                                          "'text', " +
                                          "@visible, " +
                                          "CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);";

                        cmd.CommandText += "SELECT @@IDENTITY";

                        cmd.Parameters.AddWithValue("userId", record.UserId);
                        cmd.Parameters.AddWithValue("keywords", record.Keywords);
                        cmd.Parameters.AddWithValue("visible", record.Visible);

                        CleanText(ref record.boxText);
                        cmd.Parameters.AddWithValue("boxText", record.boxText);

                        // record = GetRecord((decimal)cmd.ExecuteScalar());
                    }
                    else
                    {
                        cmd.CommandText = "update poweq1 set " +
                                          "keywords = @keywords, " +
                                          "boxText = @boxText, " +
                                          "modified = CURRENT_TIMESTAMP, " +
                                          "visible = @visible " +
                                          "where uniqueId = @uniqueId";

                        cmd.Parameters.AddWithValue("uniqueId", record.UniqueId);
                        cmd.Parameters.AddWithValue("keywords", record.Keywords);
                        cmd.Parameters.AddWithValue("visible", record.Visible);
                        CleanText(ref record.boxText);
                        cmd.Parameters.AddWithValue("boxText", record.boxText);

                        int retErr = cmd.ExecuteNonQuery();

                        record = GetRecord(record.UniqueId);
                    }
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// any content type mandatory for specific content type of a user
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="contentType"></param>
        /// <returns></returns>
        public bool AnyContentTypeMandatory(DodoItem item, out string newContentType)
        {
            bool ret = false;

            using (var conn = app.CurrentDb.CreateConnection())
                using (var cmd = conn.CreateCommand())
                {
                    string sql = "select fileContentTypeOut from {0} "
                                 + "where userId = @userId and "
                                 + "fileContentTypeIn = @type";

                    cmd.CommandText = string.Format(sql, DodoDb.table_rules_content_types);

                    cmd.Parameters.AddWithValue("userId", item.UserId);
                    cmd.Parameters.AddWithValue("type", item.fileContentType);

                    var tmpRet = cmd.ExecuteScalar();
                    newContentType = Convert.ToString(tmpRet);

                    ret = !string.IsNullOrEmpty(newContentType);
                }

            return(ret);
        }
Beispiel #9
0
        /// <summary>
        /// any content type mandatory for specific content type of a user
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="contentType"></param>
        /// <returns></returns>
        public bool CheckDeniedRules(DodoEnumRules rules, DodoItem item)
        {
            bool ret = false;

            using (var conn = app.CurrentDb.CreateConnection())
                using (var cmd = conn.CreateCommand())
                {
                    string sql = "select denyOptions from {0} "
                                 + "where userId = @userId and "
                                 + "fileContentTypeIn = @type";

                    cmd.CommandText = string.Format(sql, DodoDb.table_rules_content_types);

                    cmd.Parameters.AddWithValue("userId", item.UserId);
                    cmd.Parameters.AddWithValue("type", item.fileContentType);

                    var tmpRet   = cmd.ExecuteScalar();
                    var tmpRules = Convert.ToString(tmpRet);

                    ret = tmpRules.IndexOf(rules.ToString()) > -1;
                }

            return(ret);
        }
        public void Interpret()
        {
            string method = Path.GetFileNameWithoutExtension(request.Url);
            object answer = null;

            StringBuilder sb     = new StringBuilder();
            StringWriter  writer = new StringWriter(sb);

            string idcall = "";

            try
            {
                idcall = request.UriArgs["id"];
                DodoSession s = null;
                if (request.UriArgs["auth"] != null)
                {
                    s = app.Sessions[(WebAuth)request.UriArgs["auth"]] as DodoSession;
                }

                switch (method)
                {
                case "getFolders":
                    int folderId_0 = 0;
                    int.TryParse(request.UriArgs["f"], out folderId_0);
                    var tmpGetFolders = app.CurrentDb.GetFolders(s, folderId_0);

                    writer.WriteLine("var reply = new dbapi.async(" + idcall + ", " + JavaScriptConvert.SerializeObject(tmpGetFolders) + ");");

                    /*
                     * if (tmpGetFolders.Count > 0)
                     *
                     * else
                     *  writer.WriteLine("var reply = new dbapi.async(" + idcall + ", new Array());");
                     */

                    // writer.WriteLine("dbapi.cb(reply);");
                    break;

                case "setVisibleRecord":
                    string _code = request.UriArgs["code"];
                    long   code  = Convert.ToInt64(_code);
                    string _show = request.UriArgs["show"];
                    bool   show  = Convert.ToBoolean(_show);
                    answer = app.CurrentDb.SetVisibleRecord(code, show, s);
                    writer.WriteLine("var reply = new dbapi.async(" + idcall + ", " + JavaScriptConvert.SerializeObject(answer) + ");");
                    break;

                case "getRecord":
                    string c = request.UriArgs["code"];
                    answer = app.CurrentDb.GetRecord(c, s);
                    writer.WriteLine("var reply = new dbapi.async(" + idcall + ", " + JavaScriptConvert.SerializeObject(answer) + ");");
                    // writer.WriteLine("dbapi.cb(reply);");
                    break;

                case "getItem":
                    answer = app.CurrentDb.GetItem(app.CalcUniqueId(request.UriArgs["code"]));
                    writer.WriteLine("var reply = new dbapi.async(" + idcall + ", " + JavaScriptConvert.SerializeObject(answer) + ");");
                    // writer.WriteLine("dbapi.cb(reply);");
                    break;

                case "getContenPreview":
                    DodoItem previewContent = app.CurrentDb.GetItem(app.CalcUniqueId(request.UriArgs["code"]));

                    var dodoContent = new DodoContent()
                    {
                        Content = previewContent.GetContent()
                    };

                    writer.WriteLine("var reply = new dbapi.async(" + idcall + ", " + JavaScriptConvert.SerializeObject(dodoContent) + ");");
                    // writer.WriteLine("dbapi.cb(reply);");
                    break;

                case "searchRecords":
                    string search     = request.UriArgs["s"];
                    int    folderId_1 = 0;
                    int.TryParse(request.UriArgs["f"], out folderId_1);
                    answer = app.CurrentDb.SearchMyRecords(s.userId, search, folderId_1);
                    writer.WriteLine("var reply = new dbapi.async(" + idcall + ", " + JavaScriptConvert.SerializeObject(answer) + ");");
                    // writer.WriteLine("dbapi.cb(reply);");
                    break;

                case "modifyRecord":
                    var rec2 = (DodoItem)JavaScriptConvert.DeserializeObject(
                        request.UriArgs["record"].ToString(), typeof(DodoItem));
                    app.CurrentDb.ModifyRecord(ref rec2);
                    writer.WriteLine("var reply = new dbapi.async(" + idcall + ", " + JavaScriptConvert.SerializeObject(rec2) + ");");
                    // writer.WriteLine("dbapi.cb(reply);");
                    break;

                case "modifyFolder":
                    DodoItem folder = (DodoItem)JavaScriptConvert.DeserializeObject(
                        request.UriArgs["folder"].ToString(), typeof(DodoItem));
                    app.CurrentDb.ModifyFolder(ref folder, s);
                    writer.WriteLine("var reply = new dbapi.async(" + idcall + ", " + JavaScriptConvert.SerializeObject(folder) + ");");
                    // writer.WriteLine("dbapi.cb(reply);");
                    break;

                case "removeRecord":
                    string id = request.UriArgs["code"] != null ? (string)request.UriArgs["code"] : "";
                    app.CurrentDb.RemoveRecord(id);
                    writer.WriteLine("var reply = new dbapi.async(" + idcall + ", 'ok');");
                    // writer.WriteLine("dbapi.cb(reply);");
                    break;

                default:
                    throw new Exception("El método no existe " + method);
                }
            }
            catch (Exception err)
            {
                sb.Length = 0;

                writer.WriteLine(string.Format("var e = new Error('{0}');", err.Message.Replace("\n", " ")));
                writer.WriteLine("var reply = new dbapi.async(" + idcall + ", e);");
            }
            // mandamos la respuesta
            reply.LoadText(sb.ToString());
        }
Beispiel #11
0
        public DodoItem GetItem(long id)
        {
            DodoItem ret = DodoItemBase.GetItem <DodoItem>(app, id);

            return(ret);
        }
Beispiel #12
0
        public DodoItem2 GetItem2(DodoItem item, string contentType)
        {
            DodoItem2 ret = null;

            lock (Sync)
            {
                CheckInstanceOfItem2(item.UniqueId, contentType, app.InstanceId);

                using (var conn = CreateConnection())
                    using (var cmd = conn.CreateCommand())
                    {
                        var sql = "select boxBinary, registered, status, p1Modified, instanceId, pathPhysical from {0} "
                                  + "where uniqueId = @uniqueId and "
                                  + "fileContentType = @type";

                        cmd.CommandText = string.Format(sql, table_poweq2);
                        cmd.Parameters.AddWithValue("uniqueId", item.UniqueId);
                        cmd.Parameters.AddWithValue("type", contentType);

                        using (var reader = cmd.ExecuteReader())
                        {
                            bool gotCreateItem = false;

                            if (reader.Read())
                            {
                                var tmpStatus = reader.GetString(reader.GetOrdinal("status"));
                                var status    = (EnumStatusPoweq2)Enum.Parse(typeof(EnumStatusPoweq2), tmpStatus);

                                switch (status)
                                {
                                case EnumStatusPoweq2.AVAILABLE:
                                    ret           = new DodoItem2();
                                    ret.BoxBinary = SqlUtility.GetBytesFromBlob(reader, "boxBinary");

                                    var pathPhysical = reader.GetString(reader.GetOrdinal("pathPhysical"));
                                    //ret.FileName = Path.GetFileNameWithoutExtension(item.fileName) +
                                    //    Path.GetExtension(pathPhysical);
                                    ret.FileName        = pathPhysical;
                                    ret.FileSize        = ret.BoxBinary.Length;
                                    ret.FileContentType = contentType;
                                    ret.Registered      = reader.GetDateTime(reader.GetOrdinal("registered"));
                                    break;

                                case EnumStatusPoweq2.PROCESSING:
                                    throw new ItemNotAvailableException();

                                case EnumStatusPoweq2.NOT_EXISTS:
                                case EnumStatusPoweq2.MODIFIED_ITEM:
                                    gotCreateItem = true;
                                    throw new ItemNotFoundException();
                                }
                            }
                            else
                            {
                                gotCreateItem = true;
                            }

                            if (gotCreateItem)
                            {
                                var task = new DodoConversion(item, app, 1000);
                                task.PrepareConversion();
                                app.LocalNode.SetTimer(task);

                                throw new ItemNotAvailableException();
                            }
                        }
                    }
            }

            return(ret);
        }